Skip to content

refactor: use pathlib for the paths in the source updates - #337

Merged
jdhughes-dev merged 1 commit into
developfrom
pathlib-batch-4
Aug 18, 2026
Merged

refactor: use pathlib for the paths in the source updates#337
jdhughes-dev merged 1 commit into
developfrom
pathlib-batch-4

Conversation

@jdhughes-dev

Copy link
Copy Markdown
Collaborator

os.path is replaced by pathlib where 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.dirname or os.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.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.

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.

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

codecov Bot commented Aug 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.231%. Comparing base (ca820e6) to head (b345288).

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           
Files with missing lines Coverage Δ
pymake/utils/_usgs_src_update.py 95.757% <100.000%> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jdhughes-dev
jdhughes-dev merged commit ca83fd6 into develop Aug 18, 2026
35 of 37 checks passed
@jdhughes-dev
jdhughes-dev deleted the pathlib-batch-4 branch August 18, 2026 23:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant