talmolab / sleap

A deep learning framework for multi-animal pose tracking.
https://sleap.ai
Other
435 stars 97 forks source link

Migrate to `importlib_resources` backport #1458

Closed roomrys closed 1 year ago

roomrys commented 1 year ago

Description

While migrating to a pyproject.toml from our setup.py in #1454, we ran across some trouble creating an editable install. Namely, our current method for finding data files included in our editable package (via pkg_resources) was depreciated.

We would get the error:

    f"Cannot locate {shortname} config file at {desired_path} or {package_path}."
FileNotFoundError: Cannot locate shortcuts.yaml config file at None or /home/talmolab/micromamba/envs/env_6/lib/python3.7/site-packages/sleap/config/shortcuts.yaml.

because the editable install did not have a "sleap" folder under site-package when using the pyproject.toml, but rather a "sleap-x.x.x.dist-info" folder: image

The depreciated pkg_resources which we were using did not know about this new structure, but importlib_resources handles it perfectly.

Note that this PR is based off develop which is still on the setup.py configuration (but the changes were tested/initially-created on the liezl/upgrade-pip-wheel branch which uses the pyproject.toml config, so it handles both configs fine).

This PR migrates away from pkg_resources to the importlib_resources backport of importlib.resources.

P.S. we also went a bit crazy with the isort vscode extension. P.S.S. by "we" I mean "I".

Types of changes

Does this address any currently open issues?

[list open issues here]

Outside contributors checklist

Thank you for contributing to SLEAP!

:heart:

codecov[bot] commented 1 year ago

Codecov Report

Merging #1458 (c3a0204) into develop (e0eebb2) will decrease coverage by 0.01%. The diff coverage is 96.93%.

@@             Coverage Diff             @@
##           develop    #1458      +/-   ##
===========================================
- Coverage    73.05%   73.04%   -0.01%     
===========================================
  Files          134      134              
  Lines        23857    23849       -8     
===========================================
- Hits         17429    17421       -8     
  Misses        6428     6428              
Files Changed Coverage Δ
sleap/gui/widgets/video.py 64.34% <94.11%> (ø)
sleap/nn/training.py 75.61% <94.44%> (-0.18%) :arrow_down:
sleap/gui/app.py 75.34% <95.45%> (-0.04%) :arrow_down:
sleap/gui/commands.py 61.39% <100.00%> (ø)
sleap/gui/dialogs/formbuilder.py 90.02% <100.00%> (ø)
sleap/gui/learning/configs.py 69.95% <100.00%> (ø)
sleap/gui/widgets/docks.py 95.07% <100.00%> (ø)
sleap/util.py 92.36% <100.00%> (-0.06%) :arrow_down:

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more