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
bpo-40447: accept all path-like objects in compileall.compile_file #19883
base: main
Are you sure you want to change the base?
Conversation
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA). CLA MissingOur records indicate the following people have not signed the CLA: For legal reasons we need all the people listed to sign the CLA before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. If you have recently signed the CLA, please wait at least one business day You can check yourself to see if the CLA has been received. Thanks again for the contribution, we look forward to reviewing it! |
99f62ad
to
453d882
Compare
Nop, I just totally forgot about that. Good catch :D |
924a7fd
to
7b48ce8
Compare
4a1312b
to
6cafeac
Compare
Lib/compileall.py
Outdated
@@ -157,8 +157,8 @@ def compile_file(fullname, ddir=None, force=False, rx=None, quiet=0, | |||
dfile = os.path.join(ddir, name) | |||
|
|||
if stripdir is not None: | |||
fullname_parts = fullname.split(os.path.sep) | |||
stripdir_parts = stripdir.split(os.path.sep) | |||
fullname_parts = os.fspath(fullname).split(os.path.sep) |
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.
This has redundancy with the logic on line 151. Not sure why that's gated by the condition on quiet
, though.
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.
Oh, yes. It is odd.
@berkerpeksag sorry for bothering, do you remember why the quiet check is there? It looks like quiet
is being used across the code to provide some set some kind of failing level here. The docstring is also a bit ambiguous.
full output with False or 0, errors only with 1, no output with 2
I am not sure how to parse the behavior for 1
.
Should this behavior be changed? If not, the docstring should definitely be touched up.
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.
Anyway, I am moving the path-like object translation up there.
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 also added the other path arguments.
Misc/NEWS.d/next/Library/2020-05-03-12-55-55.bpo-40447.oKR0Lj.rst
Outdated
Show resolved
Hide resolved
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
d63b4e5
to
31251fb
Compare
requested changes; please review again |
Thanks @FFY00, that was quick! The NEWS entry mentions fixing |
Lib/compileall.py
Outdated
@@ -152,8 +152,14 @@ def compile_file(fullname, ddir=None, force=False, rx=None, quiet=0, | |||
"in combination with stripdir or prependdir")) | |||
|
|||
success = True | |||
if quiet < 2 and isinstance(fullname, os.PathLike): | |||
if isinstance(fullname, os.PathLike): |
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.
nit: os.fspath is happy to take str
and bytes
, so you don't need this check for fullname (for the other three, you do need something to guard against 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.
You're right! The last threeos.fspath
calls can simply be moved below into each of the blocks handling the three directory arguments, without the isinstance
checks. The first one shouldn't need the isinstance
guard at all; letting os.fspath
error on invalid types seems like precisely what we want 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.
Sorry for the delay! This fell off my working pool. Made the changes
a6a1788
to
599bfd9
Compare
Lib/compileall.py
Outdated
name = os.path.basename(fullname) | ||
|
||
dfile = None | ||
|
||
if ddir is not None: | ||
dfile = os.path.join(ddir, name) | ||
dfile = os.path.join(os.fspath(ddir), name) |
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.
One more nit: I think the call to os.fspath
is only needed on line 165 with stripdir; os.path.join is happy to take PathLike objects
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.
Although actually neither split works when stripdir
is bytes, which the documentation says it's allowed to be, since os.path.sep
is a str. Same for fullname
although the documentation doesn't mention that bytes is allowed there.
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 made the changes, let me know if there's anything else.
This got stale, I now rebased it on |
Signed-off-by: Filipe Laíns <lains@archlinux.org>
@FFY00, I'll try to take a look today. |
Lib/compileall.py
Outdated
@@ -165,7 +164,7 @@ def compile_file(fullname, ddir=None, force=False, rx=None, quiet=0, | |||
|
|||
if stripdir is not None: | |||
fullname_parts = fullname.split(os.path.sep) | |||
stripdir_parts = stripdir.split(os.path.sep) | |||
stripdir_parts = os.fspath(stripdir).split(os.path.sep) |
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.
ISTM it would be clearer to put the input normalization (os.fspath()
) up above with the normalization of fullname
and name
. I.e., add up above:
stripdir = os.fspath(stripdir) if stripdir is not None else None
stripdir_parts = os.fspath(stripdir).split(os.path.sep) | |
stripdir_parts = stripdir.split(os.path.sep) |
Accept :class:`pathlib.Path` in the ``ddir``, ``stripdir`` and ``prependdir`` | ||
arguments of :meth:`compileall.compile_file` and :meth:`compileall.compile_dir`. |
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.
This NEWS entry mentions ddir
and compile_file()
, but this PR still doesn't address those, unless I'm missing something.
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 think they already work, so we can just remove their mention from here.
The original version of this PR had some more os.fspath, but that was unnecessary and removed because #19883 (comment)
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 agree, their mention should be removed from the NEWS entry.
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 think you mean ddir
and prependdir
, and yes, it seems like they already work due to the os.path.join
usage.
@FFY00, this still needs some more attention. If the changes are made quickly then I'll be able to review them promptly. |
Signed-off-by: Filipe Laíns <lains@riseup.net>
@taleinat pushed the requested changes. |
Thanks, this looks correct to me.
There's still one issue that I pointed out in #19883 (comment) , but that is separate enough that we can deal with it later.
I'm not sure whether to backport. While the code itself is "new feature" it is a feature that the docs in previous versions promise exists. We should either a) backport this change, or b) amend the docs on old branches. I lean towards a) for simplicity.
https://bugs.python.org/issue40447