refactor: use pathlib for the paths in the source updates - #337
Merged
Conversation
os.path is replaced by pathlib where a path is built and where a file is removed or renamed, which is 67 of the 75 calls. The file edits the source files a target is released with rather than working out paths, so it does not use os.path.relpath, os.path.normpath, os.path.splitext or os.path.dirname, which is what the other files are left with. os.listdir lists a directory without building a path for each entry, and os.path.abspath takes the parent directories out of a path without following a symbolic link, which Path.resolve does.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #337 +/- ##
=========================================
Coverage 80.231% 80.231%
=========================================
Files 20 20
Lines 3283 3283
=========================================
Hits 2634 2634
Misses 649 649
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
os.pathis replaced bypathlibwhere a path is built and where a file is removed or renamed in_usgs_src_update.py, which is 67 of the 75 calls.This is the cleanest of the files. It edits the source files a target is released with rather than working out paths, so it does not use
os.path.relpath,os.path.normpath,os.path.splitext,os.path.dirnameoros.path.commonpath, which is what has been left behind in the others.The calls were rewritten from the syntax tree rather than by matching text, one at a time so that a call inside another, such as
os.path.isfile(os.path.join(tpth, f)), is rewritten from the inside out. All of them are on one line.What is left uses
os:os.listdirlists a directory without building a path for each entry, andos.path.abspathtakes the parent directories out of a path without following a symbolic link, whichPath.resolvedoes.Checked by building the eleven targets whose source these functions edit: triangle, mt3dms, swtv4, mf2005, mfnwt, mp6, mp7, vs2dt, sutra, mflgr and mf2000. A path that was converted wrongly would fail the edit or corrupt the source, and the build would not succeed.