-
-
Notifications
You must be signed in to change notification settings - Fork 151
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
fix: nox.session.run-ing commands with pathlib.Path arguments #649
Conversation
3275143
to
7e0c7d7
Compare
Previously this should have worked in theory, but the string which is logged for debugging calls shlex.quote, which was blowing up trying to quote the pathlib.Path. I'm slightly surprised shlex.quote doesn't support pathlib.Path objects (yet?) but for now here this just falls back to a cruder representation when quoting fails.
I'd think |
Happy to do that instead obviously -- do you mean just what I just pushed (I don't think one needs to do the isinstance check, unless you meant to filter out non-fspath args silently, which seems unlikely)? |
Actually, I guess it doesn't need a check, since |
FYI, I recently wrote a class that wrapped a commandline tool, and realized I could define But the important thing is the |
To But obviously I'm happy to do whatever you'd like here, just lemme know what you suggest. |
Right I've made CLIs that worked precisely as you describe (where they allow lots of fun objects to become filepaths). Certainly supporting more objects would indeed be nice. |
Anything else you'd like to see changed from this one? |
I think this is great, and would avoid me having to write things like: session.run("check-wheel-contents", str(*Path("dist").glob("*.whl")), "--ignore=W002") That obviously only works if one wheel is found; if I could get rid of the |
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 was initially concerned about using os.fspath
on any argument, whether or not it is "PathLike". But it turns out that if os.fspath
gets passed str
or bytes
they are returned unchanged so no worries there! Looks good to me @Julian thanks!
Link to os.fspath
: https://docs.python.org/3/library/os.html#os.fspath
Thanks! |
Everything previously really worked fine in theory, but the debug string
which is logged (and calls shlex.quote) was blowing up trying
to quote a pathlib.Path object. I'm somewhat surprised upstream
shlex.quote doesn't support pathlib.Path objects (yet?) but for
now this just falls back to a cruder representation.
(Obviously there are other ways to handle this, like calling str() on all the args, let me know if you prefer something else).
This also apparently doesn't work on Windows, but that's because
subprocess.Popen
is apparently broken with WindowsPaths. The upstream bug is python/cpython#85815.