Skip to content

Commit 2d1858a

Browse files
committed
fix: Address all Copilot review feedback and polish for merge
- Reorder imports in encryptpdf.py to follow PEP 8 (stdlib → third-party → local) - Fix passifypdf/__init__.py placeholder text from cookiecutter template - Fix unclosed code fence and inline security warning in docs/CLI_OPTIONS.md - Update README.md stale 'Sample Run' section to use Poetry CLI entry point - Clean up blank lines in integration test file - All 8 Copilot suggestions now fully addressed - All tests pass (pytest + unittest)
1 parent 8d6b48e commit 2d1858a

5 files changed

Lines changed: 26 additions & 33 deletions

File tree

README.md

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,12 @@ passifypdf --help
3636

3737

3838
Sample Run:
39-
```
40-
change dir to "passifypdf/passifypdf",
41-
42-
Then run,
43-
python encryptpdf.py
39+
```bash
40+
passifypdf -i input.pdf -o protected.pdf -p mySecretPassword
4441

45-
-------------------------Sample output----------------------
46-
$python encryptpdf.py
47-
Congratulations!
48-
PDF file encrypted successfully and saved as 'Sample_PDF_protected.pdf'
49-
$
42+
# -------------------------Sample output----------------------
43+
# Congratulations!
44+
# PDF file encrypted successfully and saved as 'protected.pdf'
5045
```
5146

5247
## Known Issues

docs/CLI_OPTIONS.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,13 @@ The `passifypdf` tool accepts the following command-line arguments:
66
| :--- | :--- | :--- | :--- |
77
| `-i` | `--input` | Yes | Path to the input PDF file. |
88
| `-o` | `--output` | Yes | Path to the output (encrypted) PDF file. |
9-
| `-p` | `--passwd` | Yes | Password to use for encryption. |
9+
| `-p` | `--passwd` | Yes | Password to use for encryption. **Avoid passing sensitive passwords directly on the command line, as they may be exposed via process listings and shell history.** |
1010
| `-v` | `--version` | No | Show the program's version number and exit. |
1111
| `-h` | `--help` | No | Show the help message and exit. |
1212

1313
## Example Usage
1414

1515
```bash
16-
# Using the installed CLI command
16+
# Using the installed CLI command (after `poetry install`)
1717
passifypdf -i input.pdf -o protected.pdf -p mySecretPassword
1818
```
19-
20-
**Security Note:** Avoid passing sensitive passwords directly on the command line if possible, as they may be exposed in process listings.
21-
```

passifypdf/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
"""Unit test package for {{ cookiecutter.project_slug }}."""
1+
"""passifypdf - Protect PDF files with a password of your choice."""

passifypdf/encryptpdf.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
from .cli import get_arg_parser
2-
from pypdf import PdfReader, PdfWriter
3-
1+
"""Core PDF encryption module."""
42

53
import sys
6-
import os
74
from pathlib import Path
85
from typing import Union
96

7+
from pypdf import PdfReader, PdfWriter
8+
9+
from .cli import get_arg_parser
10+
11+
1012
def encrypt_pdf(input_pdf: Union[str, Path], output_pdf: Union[str, Path], password: str) -> None:
1113
"""
1214
Encrypts a PDF file with a password.
@@ -18,14 +20,15 @@ def encrypt_pdf(input_pdf: Union[str, Path], output_pdf: Union[str, Path], passw
1820
1921
Raises:
2022
FileNotFoundError: If the input PDF file does not exist.
23+
IsADirectoryError: If the input path is a directory.
2124
Exception: For other errors during processing.
2225
"""
2326
input_path = Path(input_pdf)
2427
if not input_path.exists():
2528
raise FileNotFoundError(f"Input file '{input_pdf}' not found.")
26-
29+
2730
if not input_path.is_file():
28-
raise IsADirectoryError(f"Input path '{input_pdf}' is not a file.")
31+
raise IsADirectoryError(f"Input path '{input_pdf}' is not a file.")
2932

3033
try:
3134
reader = PdfReader(input_path)
@@ -49,13 +52,13 @@ def encrypt_pdf(input_pdf: Union[str, Path], output_pdf: Union[str, Path], passw
4952
def main() -> int:
5053
"""
5154
Main function to run the CLI.
52-
55+
5356
Returns:
5457
int: Exit code (0 for success, 1 for failure).
5558
"""
5659
arg_parser = get_arg_parser()
5760
args = arg_parser.parse_args()
58-
61+
5962
try:
6063
encrypt_pdf(args.input, args.output, args.passwd)
6164
print(f"Congratulations!\nPDF file encrypted successfully and saved as '{args.output}'")
Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1+
import os
12
from unittest import TestCase
23

4+
from pypdf import PdfReader, PdfWriter
35

4-
5-
6-
import os
7-
from pathlib import Path
8-
from pypdf import PdfWriter, PdfReader
96
from passifypdf.encryptpdf import encrypt_pdf
107

8+
119
class TestPdfIntegrationTests(TestCase):
1210
def setUp(self):
1311
self.input_pdf = "test_input.pdf"
1412
self.output_pdf = "test_output.pdf"
1513
self.password = "strongpassword"
16-
14+
1715
# Create a dummy PDF
1816
writer = PdfWriter()
1917
writer.add_blank_page(width=100, height=100)
@@ -30,14 +28,14 @@ def tearDown(self):
3028
def test_encrypt_pdf_integration(self):
3129
# Encrypt the PDF
3230
encrypt_pdf(self.input_pdf, self.output_pdf, self.password)
33-
31+
3432
# Verify output exists
3533
self.assertTrue(os.path.exists(self.output_pdf))
36-
34+
3735
# Verify it is encrypted
3836
reader = PdfReader(self.output_pdf)
3937
self.assertTrue(reader.is_encrypted)
40-
38+
4139
# Verify we can decrypt it
4240
self.assertTrue(reader.decrypt(self.password))
4341
self.assertEqual(len(reader.pages), 1)

0 commit comments

Comments
 (0)