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

use importlib.resources instead of pkg_resources #284

Merged
merged 4 commits into from
Jun 17, 2024

Conversation

orbeckst
Copy link
Member

fix #282

@orbeckst orbeckst marked this pull request as draft June 16, 2024 01:04
Copy link

codecov bot commented Jun 16, 2024

Codecov Report

Attention: Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.

Project coverage is 0.00%. Comparing base (4574592) to head (51a1e79).
Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
gromacs/config.py 0.00% 1 Missing ⚠️
gromacs/fileformats/xvg.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #284       +/-   ##
==========================================
- Coverage   69.20%   0.00%   -69.21%     
==========================================
  Files          22      22               
  Lines        3959    3954        -5     
  Branches      717       0      -717     
==========================================
- Hits         2740       0     -2740     
- Misses       1038    3954     +2916     
+ Partials      181       0      -181     

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

@orbeckst
Copy link
Member Author

3.9 - 3.11 runners fail with errors such as

==================================== ERRORS ====================================
______________ ERROR collecting tests/fileformats/test_convert.py ______________
tests/fileformats/test_convert.py:12: in <module>
    from gromacs.fileformats import convert
gromacs/__init__.py:216: in <module>
    from . import config
gromacs/config.py:328: in <module>
    templates = _generate_template_dict("templates")
gromacs/config.py:324: in _generate_template_dict
    for entry in resources.files(__name__).joinpath(dirname).iterdir()
../../../micromamba/envs/gromacs_wrapper/lib/python3.11/importlib/resources/_common.py:22: in files
    return from_package(get_package(package))
../../../micromamba/envs/gromacs_wrapper/lib/python3.11/importlib/resources/_common.py:55: in get_package
    raise TypeError(f'{package!r} is not a package')
E   TypeError: 'gromacs.config' is not a package

Python 3.12 works.

@orbeckst
Copy link
Member Author

In 3.12, we can use a module instead of a package as an anchor for importlib.resources.files

Changed in version 3.12: package parameter was renamed to anchor. anchor can now be a non-package module and if omitted will default to the caller’s module. package is still accepted for compatibility but will raise a DeprecationWarning. Consider passing the anchor positionally or using importlib_resources >= 5.10 for a compatible interface on older Pythons.

@orbeckst orbeckst marked this pull request as ready for review June 17, 2024 06:07
- fix #282
- config.templates
- tests.datafiles
- note: write resources.file() for python 3.9-3.11 (3.12 is nicer)
- ignore some warnings in pytest
- check for some gromacs.UsageWarning explicitly
@orbeckst orbeckst self-assigned this Jun 17, 2024
@orbeckst orbeckst merged commit a5bcc8a into main Jun 17, 2024
17 of 19 checks passed
@orbeckst orbeckst deleted the update-resource-management branch June 17, 2024 06:48
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.

replace pkg_resources everywhere
1 participant