Skip to content
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

Fix handling of pathlib.Path objects #143

Merged
merged 4 commits into from
Feb 27, 2024

Conversation

jdavies-st
Copy link
Contributor

@jdavies-st jdavies-st commented Feb 26, 2024

This fixes handling of pathlib.Path objects when used for input files for Step.

It also removes the old, deprecated tmpdir pytest fixture and replaces it with the modern tmp_path equivalent, which provides a pathlib.Path instance.

Resolves #139

@jdavies-st jdavies-st requested a review from a team as a code owner February 26, 2024 11:13
Copy link

codecov bot commented Feb 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 59.25%. Comparing base (8c8bdd2) to head (f9411a9).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #143      +/-   ##
==========================================
- Coverage   59.33%   59.25%   -0.09%     
==========================================
  Files          24       24              
  Lines        1606     1615       +9     
==========================================
+ Hits          953      957       +4     
- Misses        653      658       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -284,9 +284,9 @@ def test_step_list_args(config_file_list_arg_step):
correctly.
"""
config, returned_config_file = ListArgStep.build_config(
"science.fits", config_file=config_file_list_arg_step
"science.fits", config_file=str(config_file_list_arg_step)
Copy link
Collaborator

Choose a reason for hiding this comment

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

As updating build_config to also accept Path seems to match the efforts in this PR would you update that portion of Step to also accept a Path instance:

stpipe/src/stpipe/step.py

Lines 1376 to 1381 in ee5f1ee

if "config_file" in kwargs:
config_file = kwargs["config_file"]
del kwargs["config_file"]
config_from_file = config_parser.load_config_file(config_file)
config_parser.merge_config(config, config_from_file)
config_dir = os.path.dirname(config_file)

That should make this call to str unnecessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This actually fails within ConfigObj unfortunately. It does not fully accept pathlib.Path objects. And since this is now a dependency instead of vendored in extern, not much I can do here. Though perhaps I could modify line 1379 to pass a str() of the path?

Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like config_file is returned by this function and is documented to be a str. So perhaps converting config_file to a str on 1377?

@braingram
Copy link
Collaborator

Thanks for putting this together!

Do the changes in this PR allow us to use -p no:legacypath? (see asdf-format/asdf#1759 for details). If so I'd be all for adding that to pyprojec.toml to guard against future tests using tmpdir.

@jdavies-st
Copy link
Contributor Author

Do the changes in this PR allow us to use -p no:legacypath? (see asdf-format/asdf#1759 for details). If so I'd be all for adding that to pyprojec.toml to guard against future tests using tmpdir.

Good question. I'll give it a try. I too was trying to think of a way to prevent the use of the tmpdir pytest fixture from being reintroduced in testing as well. 👍

pyproject.toml Outdated
@@ -71,7 +71,8 @@ addopts = [
"--strict-config",
"--strict-markers",
"-ra",
"--color=yes"
"--color=yes",
"-p no:legacypath",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Unfortunately it looks like the CI is currently using this config file for pytest runs of downstream (JWST and romancal). As those packages are still using tmpdir this is leading to failures. I would categorize fixing the CI to not use this config as "outside the scope of this PR" (but would not object to a fix for it even if it's included here). So for now my vote is for removing this option and opening an issue about the above config issue (which is preventing us from using no:legacypath).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good. I'll remove this, and I'll open an issue here and in the downstream packages.

@braingram
Copy link
Collaborator

Copy link
Collaborator

@braingram braingram left a comment

Choose a reason for hiding this comment

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

Roman regtests all passed
JWST regtests had 3 failures (all known and random failures for missing log messages that occur likely due to stpipe logger handling).

@braingram braingram merged commit bcb98ec into spacetelescope:main Feb 27, 2024
15 of 16 checks passed
@jdavies-st jdavies-st deleted the fix-pathlib-bug branch February 27, 2024 15:42
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.

Support for pathlib.Path objects?
2 participants