-
Notifications
You must be signed in to change notification settings - Fork 262
Use pathlib.Path #376
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
Use pathlib.Path #376
Conversation
Argh. Of course: we monkeypatched To fix later, then. |
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 big +1 from me! Improves readability, and makes things more explicit.
If you're keen, converting the tests would be valuable I think, yes.
cibuildwheel/macos.py
Outdated
dst = os.path.join(options.output_dir, os.path.basename(repaired_wheel)) | ||
shutil.move(repaired_wheel, dst) | ||
dst = options.output_dir / repaired_wheel.name | ||
shutil.move(str(repaired_wheel), dst) |
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.
Mayybe this str()
can also go?
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.
Yes, I just tested it, and that should work, but mypy was complaining here. I don't really know why :-(
The other alternative is shutting up mypy?
cibuildwheel/util.py
Outdated
specific_file_path = specific + ext | ||
if os.path.exists(specific_file_path): | ||
specific_stem = self.base_file_path.stem + f'-python{version_parts[0]}{version_parts[1]}' | ||
sepcific_name = specific_stem + self.base_file_path.suffix |
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.
typo! sepcific_name -> specific_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.
Thanks!
Not sure the os.path
to pathlib
conversion is worth it here, but let's be consistent?
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.
Good PR, but for me not all conversation to Path object are necessary, and reduce readability of code.
cibuildwheel/macos.py
Outdated
# pure Python wheel or empty repair command | ||
shutil.move(built_wheel, repaired_wheel_dir) | ||
shutil.move(str(built_wheel), repaired_wheel_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.
Path.rename
?
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.
Hmmm, shutil.move
is slightly smarter (just looked it up: apparently it works when the files are on different filesystems), and I suppose /tmp
could be on a different partition?
@joerick, do you remember why shutil.move
rather than os.rename
? Is it worth trying os.rename
/Path.rename
?
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 string conversion here is needed?
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.
@joerick made the same comment already. mypy does something weird:
cibuildwheel/macos.py:210: error: Argument 1 to "move" has incompatible type "Path"; expected "str"
I think it's wrong, but to silence the error, we probably need str(...)
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.
...
Some bug report to mypy?
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.
Turns out it's not wrong... exactly
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.
@joerick, do you remember why
shutil.move
rather thanos.rename
? Is it worth tryingos.rename
/Path.rename
?
Probably just because there are fewer gotchas, as you mention. But Path.rename is worth a shot.
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.
Turns out it's not wrong... exactly
Ah, thanks for finding that!
Probably just because there are fewer gotchas, as you mention. But Path.rename is worth a shot.
OK, just did that. I think I just figured out á potential reason for it: the second argument to shutil.move
(destination) was in some cases (like this one) a directory. I suppose this wouldn't work with rename
.
Great. I'll do that, one of these days! :-)
I agree it does not always look better, but I think it almost never looks worse than all the sprinkled That's why I wanted to just first do it, then see how you both feel about it :-) But I think that for consistency, it might be nice to switch as much as possible to But I'm open to changing some things back. The current state of this PR was just to show: what would happen if we replace |
Finally, the elephant in the room, the signature of the
results in
or
but at that point I gave up, as that looked worse than putting
|
1618a7e
to
e5267ff
Compare
hmm maybe hide conversion to str in |
Did you read the rest of my explanation? I tried that.
|
d46b91f
to
fc0e336
Compare
Less occurrences of |
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.
Nice one @YannickJadoul - let's get this merged :)
Hurray! :-) So we're giving up on solving the issue with |
I played with a few approaches and concluded that your approach was neatest. I still don't understand why |
Great! :-) I had also reasoned it might be fine to force a conversion from the object to a plain string once you're creating a command to run. See python/mypy#720 and python/mypy#5492, btw, for the interested. |
As per #316, we can now play around with
pathlib.Path
and do it safely, because:Path
objects to oldos.path
functions, etc.