-
-
Notifications
You must be signed in to change notification settings - Fork 63
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
Add --orientation option to pagerotate command #705
Conversation
…nally rotating a page to a target orientation.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #705 +/- ##
==========================================
- Coverage 94.71% 94.68% -0.04%
==========================================
Files 62 62
Lines 5756 5777 +21
Branches 1272 1275 +3
==========================================
+ Hits 5452 5470 +18
- Misses 187 189 +2
- Partials 117 118 +1 ☔ View full report in Codecov by Sentry. |
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.
Very useful addition, thanks! Some minor comments, should be straightforward to fix (mores so than the failing doc build with which I'm currently struggling—unrelated to the present PR).
Edit: please also:
- add a test similar to
test_pagerotate()
intest_commands.py
- update CHANGELOG.md—do include "(thanks @gatesphere)"
@@ -677,6 +686,12 @@ def pagerotate(document: vp.Document, clockwise: bool): | |||
return document | |||
w, h = page_size | |||
|
|||
# check orientation constraint, and do nothing if target orientation | |||
# won't match desired result | |||
if (orientation == "portrait" and h > w) or (orientation == "landscape" and w > h): |
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.
A test for orientation is None
is needed here because of the change above.
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.
Is an explicit test needed? If orientation == None
, then orientation == "portrait"
will evaluate False. The code works fine without an explicit test here.
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.
I'd be surprised if mypy
agreed with that, but let's see :) In any case, I generally dislike such implicit tests for None
. Also, arguably any other string input should be checked and trigger a logging.warning()
, and that requires an explicit check for None
.
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.
well apparently mypy is on your side :)
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.
mypy or not, I'm good either way. I can add it if you'd like.
Guido's 'explicit is better than implicit' perhaps applies here.
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.
Garbage input?
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.
I mean, if the use says pagerotate --orientation garbage
. This should trigger a warning.
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.
Click or ChoiceType is already doing that:
(vpype-py3.11) [redacted@redacted]$ vpype read dscope_liked_1.svg pagerotate -o garbage
Usage: vpype [OPTIONS] COMMAND1 [ARGS]... [COMMAND2 [ARGS]...]...
Error: Invalid value: 'garbage' is not one of 'portrait', 'landscape'.
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.
I do realize now that we can't rely on click for people using it via the API...
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.
Added a check to the most recent commit.
…of `pagerotate` command, per @abey79 - Added new tests for `pagerotate --orientation` - Updated CHANGELOG.md
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.
Thanks for bearing with me—great addition!
Quality Gate passedIssues Measures |
Added '--orientation' option to pagerotate command, to allow conditionally rotating a page to a target orientation.
Description
Allows conditionally rotating a page with the pagerotate command by specifying a target orientation. If the rotated page would not match the target orientation, pagerotate does nothing. Defaults to 'any', default behavior is unchanged.
Checklist
black
andruff check .
)mypy
returns no errorpytest
succeedshelp
reference.rst
make clean && make html
indocs/
)