Skip to content

ENH: Add a rotate command, per discussion#128

Merged
Lucas-C merged 20 commits into
py-pdf:mainfrom
hwine:rotate
May 27, 2025
Merged

ENH: Add a rotate command, per discussion#128
Lucas-C merged 20 commits into
py-pdf:mainfrom
hwine:rotate

Conversation

@hwine
Copy link
Copy Markdown
Contributor

@hwine hwine commented May 25, 2025

Adds a rotate sub command to rotate the specified pages by the specified degrees. Design as discussed in #119 (exceptions noted at end).

Current status:

  • all tests pass on GitHub
  • new code has 83% coverage (missing a test of an exception handler)
  • new tests have 100% coverage
pdfly rotate --help

 Usage: pdfly rotate [OPTIONS] FILENAME DEGREES [PGRGS]

 Rotate specified pages by the specified amount
 Example:
     pdfly rotate --output output.pdf input.pdf 90
         Rotate all pages by 90 degrees (clockwise)

 A file not followed by a page range (PGRGS) means all the pages of the file.

 PAGE RANGES are like Python slices.

         Remember, page indices start with zero.

         Page range expression examples:

             :     all pages.                   -1    last page.
             22    just the 23rd page.          :-1   all but the last page.
             0:3   the first three pages.       -2    second-to-last page.
             :3    the first three pages.       -2:   last two pages.
             5:    from the sixth page onward.  -3:-1 third & second to last.

         The third, "stride" or "step" number is also recognized.

             ::2       0 2 4 ... to the end.    3:0:-1    3 2 1 but not 0.
             1:10:2    1 3 5 7 9                2::-1     2 1 0.
             ::-1      all pages in reverse order.

╭─ Arguments ────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ *    filename      FILE     [default: None] [required]                                                         │
│ *    degrees       INTEGER  degrees to rotate [default: None] [required]                                       │
│      pgrgs         [PGRGS]  page range [default: :]                                                            │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Options ──────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ *  --output  -o      PATH  [default: None] [required]                                                          │
│    --help                  Show this message and exit.                                                         │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

The not-implemented-as-discussed elements are:

  • in-place modifications. I'm disinclined to add this as:
    • there doesn't seem to be consensus on this with other features (ref)
    • the current approach in other commands does not appear to address "huge file" issues (i.e. running out of memory to hold both documents)
    • the the current overwrite approach might lead to data loss if there is insufficient disk space. (Perhaps not - the file might be guaranteed to be the same file size, but that requires investigation.)

Comment thread uv.lock Outdated
Comment thread pyproject.toml Outdated
Comment thread tests/test_rotate.py
Comment thread pdfly/rotate.py Outdated
Comment thread pdfly/rotate.py Outdated
Comment thread pdfly/rotate.py Outdated
Comment thread pdfly/rotate.py Outdated
Comment thread pdfly/pagemeta.py Outdated
@Lucas-C
Copy link
Copy Markdown
Member

Lucas-C commented May 26, 2025

The PR Title Check / Title check GitHub Actions rule is failing:
could you please add a ENH prefix to this PR title, please?
cf. https://pdfly.readthedocs.io/en/latest/dev/intro.html#commit-messages

Also could you add a mention of this nice addition into CHANGELOG.md as part of this PR please?

Copy link
Copy Markdown
Member

@Lucas-C Lucas-C left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution @hwine 👍

I made a few feedback comments, but it's great code overall!

@Lucas-C
Copy link
Copy Markdown
Member

Lucas-C commented May 26, 2025

@all-contributors please add @hwine for code: 17ba644

@hwine hwine changed the title Add a rotate command, per discussion ENH: Add a rotate command, per discussion May 26, 2025
@hwine
Copy link
Copy Markdown
Contributor Author

hwine commented May 26, 2025

@Lucas-C thanks for catching my "oops" -- I believe I've addressed all of your comments

Comment thread pdfly/rotate.py Outdated
hwine added 16 commits May 27, 2025 10:48
`uv` claims requirements don't work for python 3.7, and 3.7 is listed as
not being tested.
May be removed in PR, but I want to ensure no changes while I do the
work.
`direnv` is a common developer tool, but not part of this projects
standard development process.
Test coverage now all but execption handling in pdfly/rotate.py
Will not be part of final commit, but shows no regressions in failed
tests due to changes
hwine and others added 4 commits May 27, 2025 10:48
Co-authored-by: Lucas Cimon <925560+Lucas-C@users.noreply.github.com>
Co-authored-by: Lucas Cimon <925560+Lucas-C@users.noreply.github.com>
Not caught in local `pre-commit` run

Co-authored-by: Lucas Cimon <925560+Lucas-C@users.noreply.github.com>
@Lucas-C Lucas-C merged commit 194086c into py-pdf:main May 27, 2025
10 checks passed
@hwine hwine deleted the rotate branch May 28, 2025 17:05
@Lucas-C
Copy link
Copy Markdown
Member

Lucas-C commented Oct 13, 2025

This new command has been included in the latest 0.5.0 release: https://github.com/py-pdf/pdfly/releases/tag/0.5.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants