-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
MAINT: Run PTH flake test in prep for supporting pathlib #16060
base: main
Are you sure you want to change the base?
Conversation
Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.
|
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.
Lots of good things in this PR! I have a few suggestions that are applicable in many places to further simplify the code, e.g. using read_text
.
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.
Looks good for time
.
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 of the os.path.join
got replaced by os-dependent strings.
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.
Fine for convolution
and stats
.
The way I understand it the intent behind the Ruff PTH rules is that if code is representing filesystem paths as |
There might be a slight misunderstanding here, that not what I understand the intention of this rule set to be. Here's the one liner description for
That said, I agree with @eerovaher that back-and-forth conversions should be avoided ! |
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.
Failure on Windows, see #16060 (comment)
Also please rebase and squash instead of pulling in merge commits, because at its current state, I cannot rebase this PR on top of latest main (gives me conflict). Thanks!
ead3be5
to
4455c78
Compare
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.
Generally, this is a good idea and very nice. That said, quite a few comments. A number are just that if a plain string with no directory is given, open
is perfectly fine and reasonable, so no need to replace.
A more general one is whether we can pass "file names" through Path
unconditionally; certainly, any time we do, we should adjust the docstring.
Finally, I'd hope we can get rid of a lot of str(path)
, by ensuring get_package_data_*
work - would seem worth doing that here, given how many people have now looked at this...
astropy/coordinates/tests/accuracy/generate_spectralcoord_ref.py
Outdated
Show resolved
Hide resolved
Sure, I am happy to get this into this PR. Should the changes be backward compatible? I am currently working on making the util functions work with the If not a hard break, does it make sense to deprecate usage of |
For this PR at least, I don't think we should have anything that is not backwards compatible. But presumably passing a |
@@ -34,7 +35,7 @@ def _docdir(request): | |||
# Don't apply this fixture to io.rst. It reads files and doesn't write. | |||
# Implementation from https://github.com/pytest-dev/pytest/discussions/10437 | |||
if "io.rst" not in request.node.name: | |||
old_cwd = os.getcwd() | |||
old_cwd = Path.cwd() |
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 os.getcwd()
getting deprecated?
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.
No, this is to make to standardized usage of PathLike objects rather than str
.
(It's fine either way, but to not litter noqa
all around we could make this change.
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.
pathlib
was introduced in 3.4 and is now pretty feature-complete. Seems a good opportunity to update our approach to paths from the function-oriented manipulation of strings to an object-oriented manipulation of paths. os.getcwd
isn't deprecated and probably isn't going to be. It's just the next best thing: superceded.
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 thing to keep in mind though is that Path
objects are much heavier than strings. It doesn't make a measurable difference here but in intensive loops, switching to pathlib
can add a significant overhead.
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.
Yeah, and I don't think there are places where we are doing a lot of string/path manipulation inside astropy (maybe I missed something?). A lot of this is indeed aesthetic-y changes. But IMO we should indeed move on to using the obj oriented pathlib way as it make manipulating these path much easier, plus in a typing heavy future of python, os.PathLike
gives a lot more information than str
.
@@ -34,7 +35,7 @@ def _docdir(request): | |||
# Don't apply this fixture to io.rst. It reads files and doesn't write. | |||
# Implementation from https://github.com/pytest-dev/pytest/discussions/10437 | |||
if "io.rst" not in request.node.name: | |||
old_cwd = os.getcwd() | |||
old_cwd = Path.cwd() |
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.
pathlib
was introduced in 3.4 and is now pretty feature-complete. Seems a good opportunity to update our approach to paths from the function-oriented manipulation of strings to an object-oriented manipulation of paths. os.getcwd
isn't deprecated and probably isn't going to be. It's just the next best thing: superceded.
375f264
to
982c78a
Compare
@MridulS. This is looking nearly complete. What are the next steps, fixing |
This PR starts work on making a unified i/o interface for reading and writing to disk. In some places using strings for filenames work, in other pathlib objects works too. We should be able to pass around
Path
objects all around the code. For a first go I want to make thePTH
ruff flake8 linter happy.As a start this fixes ruff complaints in couple of sub packages. Didn't want to make the PR too big.
Also want to check if this works with windows CI all fine. (
pathlib
has had some issues with windows from what I remember).One way to go about #14893