Skip to content

Conversation

echoix
Copy link
Member

@echoix echoix commented Oct 18, 2025

Ruff rule: https://docs.astral.sh/ruff/rules/os-path-exists/

Ignored the "python/grass/__init__.py" file, as it might be the most critical if there's a chance that there is a slight performance penalty to this higher level function.

@echoix echoix requested a review from ninsbl October 18, 2025 19:23
Copy link
Member

@ninsbl ninsbl left a comment

Choose a reason for hiding this comment

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

I made some suggestions using the GitHub Web-UI. So suggested changes are checked by pre-commit...
Most changes replace more os.path usage, to avoid we have to touch those lines again alter. If you feel that is out of scope or interferes with your plans / stategy for introducing more pathlib, please feel free to reject suggested changes.

One thing I noticed in this context is that there is a number of cases where Path(file_path).exists() is preceeded by os.path.join(). I guess once we replace os.path.join by pathlib usage as well, we would have to change the lines again that we modified here. Not sure if ruff would catch that and fix automatically...
So I am wondering if there is an order in which the introduction of pathlib would be most efficient....

@echoix
Copy link
Member Author

echoix commented Oct 18, 2025

Since the amount of changes were really big, fixing all the suggestions for pathlib that are now available (they are better and better as time goes) would be too much (over like 2000 places), I reverted back and stuck to only fixing one single rule. I didn't want to pass my time analyzing if the output is accepted as a Path object vs a string, and the effect on the functions called/calling with that new value. For this one, it is a boolean, and maybe it was converted to a Path object for nothing, but I didn't want to analyze too close.

So, if you feel like adding more to the scope, I don't really mind, but it is an extra risk for a PR on the bigger side.

@echoix
Copy link
Member Author

echoix commented Oct 18, 2025

Oh, seems like there's a place that we will need to revert for a test on macOS

@ninsbl
Copy link
Member

ninsbl commented Oct 18, 2025

Since the amount of changes were really big, fixing all the suggestions for pathlib that are now available (they are better and better as time goes) would be too much (over like 2000 places), I reverted back and stuck to only fixing one single rule. I didn't want to pass my time analyzing if the output is accepted as a Path object vs a string, and the effect on the functions called/calling with that new value. For this one, it is a boolean, and maybe it was converted to a Path object for nothing, but I didn't want to analyze too close.

I see. Fully understand.

@github-actions github-actions bot added GUI wxGUI related vector Related to vector data processing raster Related to raster data processing temporal Related to temporal data processing Python Related code is in Python translation Message translation related database Related to database management libraries module docs general display imagery tests Related to Test Suite raster3d notebook misc labels Oct 18, 2025
Copy link
Member Author

@echoix echoix left a comment

Choose a reason for hiding this comment

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

Found two things to revert

echoix and others added 6 commits October 19, 2025 10:30
Co-authored-by: Stefan Blumentrath <[email protected]>
Co-authored-by: Stefan Blumentrath <[email protected]>
Co-authored-by: Stefan Blumentrath <[email protected]>
Co-authored-by: Stefan Blumentrath <[email protected]>
echoix and others added 8 commits October 19, 2025 10:32
Co-authored-by: Stefan Blumentrath <[email protected]>
Co-authored-by: Stefan Blumentrath <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@echoix echoix requested a review from ninsbl October 19, 2025 17:45
@echoix
Copy link
Member Author

echoix commented Oct 19, 2025

Ready to review again, checks passing now. And others: sorry for the emails, the new files tab in the web UI doesn't implement batching multiple suggestions

Copy link
Member

@ninsbl ninsbl left a comment

Choose a reason for hiding this comment

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

There is one file where I earlier overlooked that a path was already a pathlib object. Not sure how important that is in a test...

@echoix echoix requested a review from ninsbl October 21, 2025 12:27
Copy link
Member

@ninsbl ninsbl left a comment

Choose a reason for hiding this comment

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

Nice. Not being a software developer by education, I do see the value of annotations even clearer...

@echoix echoix enabled auto-merge (squash) October 21, 2025 12:52
@echoix echoix merged commit fb0165c into OSGeo:main Oct 21, 2025
28 checks passed
@echoix echoix deleted the ruff-PTH110-os-path-exists branch October 21, 2025 13:57
@github-actions github-actions bot added this to the 8.5.0 milestone Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

database Related to database management display docs general GUI wxGUI related imagery libraries misc module notebook Python Related code is in Python raster Related to raster data processing raster3d temporal Related to temporal data processing tests Related to Test Suite translation Message translation related vector Related to vector data processing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants