-
Notifications
You must be signed in to change notification settings - Fork 1
feat: Comprehensive Fix - Issues #2, #3, #7, #8, #9, #10 #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
31ad8c9
feat: Address Issues #2, #3, #7, #8, #9 - Add CI, Unit Tests, CLI Ent…
ambicuity 8c8679a
feat: Address Issue #10 - Migrate to Poetry
ambicuity 7d58f57
fix: Update test imports to use full package path for Poetry compatib…
ambicuity 5690157
fix: Address code review feedback (relative imports, docs, deps)
ambicuity 9712d0c
ci: Add debug steps to investigate Python 3.11 failure
ambicuity 5a3aec9
Merge remote-tracking branch 'upstream/main'
ambicuity 81135f7
ci: Remove legacy upstream workflow python-ci.yml and cleanup debug s…
ambicuity 8d6b48e
feat: Finalize comprehensive fixes for issues #2-#11 and Copilot review
ambicuity 2d1858a
fix: Address all Copilot review feedback and polish for merge
ambicuity File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| name: Python CI | ||
|
|
||
| on: | ||
| push: | ||
| branches: [ "main" ] | ||
| pull_request: | ||
| branches: [ "main" ] | ||
|
|
||
| jobs: | ||
| build: | ||
|
|
||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| matrix: | ||
| python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - name: Set up Python ${{ matrix.python-version }} | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: ${{ matrix.python-version }} | ||
| - name: Install dependencies | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install poetry | ||
| poetry install | ||
| - name: Test with unittest | ||
| run: | | ||
| poetry run coverage run -m unittest discover tests | ||
| - name: Upload coverage reports to Codecov | ||
| uses: codecov/codecov-action@v5 | ||
| with: | ||
| token: ${{ secrets.CODECOV_TOKEN }} | ||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # CLI Options | ||
|
|
||
| The `passifypdf` tool accepts the following command-line arguments: | ||
|
|
||
| | Option | Long Option | Required | Description | | ||
| | :--- | :--- | :--- | :--- | | ||
| | `-i` | `--input` | Yes | Path to the input PDF file. | | ||
| | `-o` | `--output` | Yes | Path to the output (encrypted) PDF file. | | ||
| | `-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.** | | ||
| | `-v` | `--version` | No | Show the program's version number and exit. | | ||
| | `-h` | `--help` | No | Show the help message and exit. | | ||
|
|
||
| ## Example Usage | ||
|
|
||
| ```bash | ||
| # Using the installed CLI command (after `poetry install`) | ||
| passifypdf -i input.pdf -o protected.pdf -p mySecretPassword | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| """Unit test package for {{ cookiecutter.project_slug }}.""" | ||
| """passifypdf - Protect PDF files with a password of your choice.""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,13 @@ | ||
| import argparse | ||
|
|
||
|
|
||
| def get_arg_parser(): | ||
| arg_parser = argparse.ArgumentParser(description=("Encrypt a PDF file with a password of your choice."), epilog=("For more information, visit: https://github.com/SUPAIDEAS/passifypdf")) | ||
| def get_arg_parser() -> argparse.ArgumentParser: | ||
| arg_parser = argparse.ArgumentParser( | ||
| description="Encrypt a PDF file with a password of your choice.", | ||
| epilog="For more information, visit: https://github.com/SUPAIDEAS/passifypdf" | ||
| ) | ||
| arg_parser.add_argument("-v", "--version", action="version", version="%(prog)s 1.0") | ||
| arg_parser.add_argument("-i", "--input", required=True, help="path to the input pdf file") | ||
| arg_parser.add_argument("-o", "--output", required=True, help="path to the output encrypted pdf file") | ||
| arg_parser.add_argument("-p", "--passwd", required=True, type=str, help="password to encrypt the pdf file") | ||
| arg_parser.add_argument("-i", "--input", required=True, help="Path to the input PDF file to be encrypted") | ||
| arg_parser.add_argument("-o", "--output", required=True, help="Path where the encrypted PDF file will be saved") | ||
| arg_parser.add_argument("-p", "--passwd", required=True, type=str, help="Password to encrypt the PDF file with") | ||
| return arg_parser |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,33 +1,72 @@ | ||
| from cli import get_arg_parser | ||
| """Core PDF encryption module.""" | ||
|
|
||
| import sys | ||
| from pathlib import Path | ||
| from typing import Union | ||
|
|
||
| from pypdf import PdfReader, PdfWriter | ||
|
|
||
| from .cli import get_arg_parser | ||
|
|
||
|
|
||
| def encrypt_pdf(input_pdf: Union[str, Path], output_pdf: Union[str, Path], password: str) -> None: | ||
| """ | ||
| Encrypts a PDF file with a password. | ||
|
|
||
| def encrypt_pdf(input_pdf, output_pdf, password): | ||
| reader = PdfReader(input_pdf) | ||
| writer = PdfWriter() | ||
| Args: | ||
| input_pdf (Union[str, Path]): Path to the input PDF file. | ||
| output_pdf (Union[str, Path]): Path to the output PDF file. | ||
| password (str): Password to encrypt the PDF with. | ||
|
|
||
| # Add all pages from the reader to the writer | ||
| for page_num in range(len(reader.pages)): | ||
| writer.add_page(reader.pages[page_num]) | ||
| Raises: | ||
| FileNotFoundError: If the input PDF file does not exist. | ||
| IsADirectoryError: If the input path is a directory. | ||
| Exception: For other errors during processing. | ||
| """ | ||
| input_path = Path(input_pdf) | ||
| if not input_path.exists(): | ||
| raise FileNotFoundError(f"Input file '{input_pdf}' not found.") | ||
|
|
||
| # Encrypt with a password | ||
| writer.encrypt(password) | ||
| if not input_path.is_file(): | ||
| raise IsADirectoryError(f"Input path '{input_pdf}' is not a file.") | ||
|
|
||
| # Write the encrypted PDF to a new PDF file passed as param | ||
| with open(output_pdf, "wb") as f: | ||
| writer.write(f) | ||
| try: | ||
| reader = PdfReader(input_path) | ||
| writer = PdfWriter() | ||
|
|
||
| # Add all pages from the reader to the writer | ||
| for page in reader.pages: | ||
| writer.add_page(page) | ||
|
|
||
| def pipeline(any_thing): | ||
| return any_thing | ||
| # Encrypt with a password | ||
| writer.encrypt(password) | ||
|
|
||
| # Write the encrypted PDF to a new PDF file passed as param | ||
| with open(output_pdf, "wb") as f: | ||
| writer.write(f) | ||
|
|
||
| def main(): | ||
| except Exception as e: | ||
| raise Exception(f"Failed to encrypt PDF: {e}") | ||
|
|
||
|
|
||
| def main() -> int: | ||
| """ | ||
| Main function to run the CLI. | ||
|
|
||
| Returns: | ||
| int: Exit code (0 for success, 1 for failure). | ||
| """ | ||
| arg_parser = get_arg_parser() | ||
| args = arg_parser.parse_args() | ||
| encrypt_pdf(args.input, args.output, args.passwd) | ||
| print(f"Congratulations!\nPDF file encrypted successfully and saved as '{args.output}'") | ||
|
|
||
| try: | ||
| encrypt_pdf(args.input, args.output, args.passwd) | ||
| print(f"Congratulations!\nPDF file encrypted successfully and saved as '{args.output}'") | ||
| return 0 | ||
| except Exception as e: | ||
| print(f"Error: {e}", file=sys.stderr) | ||
| return 1 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
| sys.exit(main()) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CI workflow will fail when it tries to run the tests because of the incorrect import statements in the test files (see comments on test files). The tests import from
encryptpdfinstead ofpassifypdf.encryptpdf, which will cause ImportError when run through Poetry. This needs to be fixed before the CI can pass.