Overview
Migrate all source code and workspaces from os.path.* (notably os.path.join)
to pathlib.Path. The codebase already uses pathlib extensively in newer code,
but ~99 legacy os.path.* references remain across 10 repos. This is a
mechanical refactor for consistency — no behaviour changes.
Plan
- Replace
os.path.join(a, b) with Path(a) / b
- Replace
os.path.exists / isdir / isfile with Path equivalents
- Replace
os.path.dirname(os.path.realpath(__file__)) with Path(__file__).parent.resolve()
- Replace
os.path.basename / split / splitext with .name / .parent / .suffix
- Wrap with
str(...) only where a downstream API requires a string
- Drop now-unused
import os lines
- Verify per-repo with unit tests; verify workspaces with
/smoke_test
Detailed implementation plan
Affected Repositories
- PyAutoFit (primary)
- PyAutoConf
- PyAutoArray
- PyAutoGalaxy
- PyAutoLens
- autogalaxy_workspace
- autolens_workspace
- autolens_workspace_developer
- autofit_workspace_developer
- euclid_strong_lens_modeling_pipeline
Work Classification
Both (libraries first, workspaces follow)
Branch Survey
| Repository |
Current Branch |
Dirty? |
| PyAutoConf |
main |
clean |
| PyAutoFit |
main |
clean |
| PyAutoArray |
main |
clean |
| PyAutoGalaxy |
main |
clean |
| PyAutoLens |
main |
clean |
| autogalaxy_workspace |
main |
88 changed (unrelated dataset regen by smoke-test-optimization) |
| autolens_workspace |
main |
148 changed (unrelated dataset regen by smoke-test-optimization) |
| autolens_workspace_developer |
main |
TBD |
| autofit_workspace_developer |
main |
TBD |
| euclid_strong_lens_modeling_pipeline |
main |
TBD |
Suggested branch: feature/use-pathlib
Worktree root: ~/Code/PyAutoLabs-wt/use-pathlib/ (created later by /start_library)
Implementation Steps
- Refactor each library in dependency order: PyAutoConf → PyAutoFit → PyAutoArray → PyAutoGalaxy → PyAutoLens. Run unit tests after each.
- Refactor workspaces: autogalaxy_workspace, autolens_workspace, autolens_workspace_developer, autofit_workspace_developer, euclid_strong_lens_modeling_pipeline. Run
/smoke_test to validate.
- Resolve workspace dirty state in autogalaxy_workspace and autolens_workspace before cutting workspace branches (coordinate with smoke-test-optimization task).
- Ship via
/ship_library then /ship_workspace.
Key Files
PyAutoConf/autoconf/directory_config.py — os.path.isdir checks
PyAutoConf/autoconf/setup_colab.py — os.path.join for workspace paths
PyAutoConf/autoconf/json_prior/generate.py — os.path.exists
PyAutoConf/test_autoconf/test_fitsable.py — many os.path.join in test data
PyAutoFit/autofit/non_linear/paths/directory.py — os.path.exists/isfile
PyAutoFit/autofit/non_linear/paths/abstract.py — os.path.exists
PyAutoFit/autofit/non_linear/search/**/search.py — checkpoint file checks
PyAutoFit/autofit/mapper/model_mapper.py — os.path.dirname(os.path.realpath(__file__))
PyAutoFit/autofit/tools/util.py — os.path.join, os.path.split, os.path.exists
PyAutoFit/autofit/database/__init__.py — os.path.exists
PyAutoArray/autoarray/util/dataset_util.py, autoarray/plot/utils.py, 4 test files
PyAutoGalaxy/autogalaxy/plot/plot_utils.py, autogalaxy/util/plot_utils.py, 1 test file
PyAutoLens/... — 19 references (largest by count)
autolens_workspace/scripts/imaging/features/advanced/subhalo/sensitivity/slam_source_*.py
autolens_workspace/scripts/interferometer/casa_reduction.py
- All
docs/conf.py (sphinx boilerplate sys.path.insert(0, os.path.abspath(".")) — converted too, per "no more os.path")
Risks / edge cases
- External libraries that may need str (some FITS readers in older versions) — wrap with
str() where needed.
os.path.realpath resolves symlinks; Path.resolve() is equivalent in Python 3.6+.
- Test fixtures: pytest's
tmp_path is already a Path, aligns naturally.
- The 88 + 148 dirty files in autogalaxy_workspace / autolens_workspace are dataset binaries from in-progress smoke-test-optimization — handle separately at workspace-phase time.
Original Prompt
Click to expand starting prompt
Most examples now use Pathlib, but there are still some os.path.join uses from
legacy.
Can you update all source code and workspaces to not use path.join at all
and always use Pathlib?
This should aspan all source code, workspaces, etc, no more os.path!
Overview
Migrate all source code and workspaces from
os.path.*(notablyos.path.join)to
pathlib.Path. The codebase already usespathlibextensively in newer code,but ~99 legacy
os.path.*references remain across 10 repos. This is amechanical refactor for consistency — no behaviour changes.
Plan
os.path.join(a, b)withPath(a) / bos.path.exists / isdir / isfilewithPathequivalentsos.path.dirname(os.path.realpath(__file__))withPath(__file__).parent.resolve()os.path.basename / split / splitextwith.name / .parent / .suffixstr(...)only where a downstream API requires a stringimport oslines/smoke_testDetailed implementation plan
Affected Repositories
Work Classification
Both (libraries first, workspaces follow)
Branch Survey
Suggested branch:
feature/use-pathlibWorktree root:
~/Code/PyAutoLabs-wt/use-pathlib/(created later by/start_library)Implementation Steps
/smoke_testto validate./ship_librarythen/ship_workspace.Key Files
PyAutoConf/autoconf/directory_config.py—os.path.isdirchecksPyAutoConf/autoconf/setup_colab.py—os.path.joinfor workspace pathsPyAutoConf/autoconf/json_prior/generate.py—os.path.existsPyAutoConf/test_autoconf/test_fitsable.py— manyos.path.joinin test dataPyAutoFit/autofit/non_linear/paths/directory.py—os.path.exists/isfilePyAutoFit/autofit/non_linear/paths/abstract.py—os.path.existsPyAutoFit/autofit/non_linear/search/**/search.py— checkpoint file checksPyAutoFit/autofit/mapper/model_mapper.py—os.path.dirname(os.path.realpath(__file__))PyAutoFit/autofit/tools/util.py—os.path.join,os.path.split,os.path.existsPyAutoFit/autofit/database/__init__.py—os.path.existsPyAutoArray/autoarray/util/dataset_util.py,autoarray/plot/utils.py, 4 test filesPyAutoGalaxy/autogalaxy/plot/plot_utils.py,autogalaxy/util/plot_utils.py, 1 test filePyAutoLens/...— 19 references (largest by count)autolens_workspace/scripts/imaging/features/advanced/subhalo/sensitivity/slam_source_*.pyautolens_workspace/scripts/interferometer/casa_reduction.pydocs/conf.py(sphinx boilerplatesys.path.insert(0, os.path.abspath("."))— converted too, per "no more os.path")Risks / edge cases
str()where needed.os.path.realpathresolves symlinks;Path.resolve()is equivalent in Python 3.6+.tmp_pathis already aPath, aligns naturally.Original Prompt
Click to expand starting prompt
Most examples now use Pathlib, but there are still some os.path.join uses from
legacy.
Can you update all source code and workspaces to not use path.join at all
and always use Pathlib?
This should aspan all source code, workspaces, etc, no more os.path!