Skip to content
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

Merged
merged 6 commits into from
Apr 5, 2024
Merged

Add --orientation option to pagerotate command #705

merged 6 commits into from
Apr 5, 2024

Conversation

gatesphere
Copy link
Contributor

@gatesphere gatesphere commented Mar 6, 2024

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

  • feature/fix implemented
  • code formatting ok (black and ruff check .)
  • mypy returns no error
  • tests added/updated and pytest succeeds
  • documentation added/updated
    • command docstring and option/argument help
    • README.md updated (Feature Overview)
    • CHANGELOG.md updated
    • added new command to reference.rst
    • RTD doc updated and building with no error (make clean && make html in docs/)

Copy link

codecov bot commented Mar 7, 2024

Codecov Report

Attention: Patch coverage is 86.95652% with 3 lines in your changes are missing coverage. Please review.

Project coverage is 94.68%. Comparing base (1df9e63) to head (066d246).

Files Patch % Lines
vpype_cli/operations.py 66.66% 2 Missing and 1 partial ⚠️
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.
📢 Have feedback on the report? Share it here.

Copy link
Owner

@abey79 abey79 left a 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() in test_commands.py
  • update CHANGELOG.md—do include "(thanks @gatesphere)"

vpype_cli/operations.py Outdated Show resolved Hide resolved
vpype_cli/operations.py Outdated Show resolved Hide resolved
@@ -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):
Copy link
Owner

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.

Copy link
Contributor Author

@gatesphere gatesphere Mar 7, 2024

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.

Copy link
Owner

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.

Copy link
Owner

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 :)

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Garbage input?

Copy link
Owner

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.

Copy link
Contributor Author

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'.

Copy link
Contributor Author

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...

Copy link
Contributor Author

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.

vpype_cli/operations.py Outdated Show resolved Hide resolved
Copy link
Owner

@abey79 abey79 left a 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!

Copy link

sonarqubecloud bot commented Apr 5, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

@abey79 abey79 merged commit 9c9de12 into abey79:master Apr 5, 2024
12 of 14 checks passed
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