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 reading resource when packaged in zip #170

Merged
merged 6 commits into from
Feb 11, 2025
Merged

Conversation

hukkin
Copy link
Contributor

@hukkin hukkin commented Feb 1, 2025

Fixes #169

I was unsure of the Traversable type's API, so I checked types with mypy, and made small changes to make it pass. Those changes are also included, but I can remove or separate those changes if that's better.

Copy link

codecov bot commented Feb 1, 2025

Codecov Report

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

Project coverage is 91.40%. Comparing base (75a819a) to head (6c5fd43).
Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
src/em/cli.py 85.71% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #170      +/-   ##
==========================================
- Coverage   92.85%   91.40%   -1.46%     
==========================================
  Files           3        3              
  Lines         126      128       +2     
==========================================
  Hits          117      117              
- Misses          9       11       +2     
Flag Coverage Δ
macos-latest 89.84% <88.23%> (-1.43%) ⬇️
ubuntu-latest 89.84% <88.23%> (-1.43%) ⬇️
windows-latest 89.84% <88.23%> (-1.43%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@hugovk hugovk added the changelog: Fixed For any bug fixes label Feb 4, 2025
.pre-commit-config.yaml Outdated Show resolved Hide resolved
@@ -15,6 +15,6 @@

from __future__ import annotations

from em import _version
from em import _version # type: ignore[attr-defined]
Copy link
Owner

Choose a reason for hiding this comment

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

I don't think this is needed? It passes for me without it:

Suggested change
from em import _version # type: ignore[attr-defined]
from em import _version

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here's a mypy failure in CI without it.

The _version.py file is created dynamically by hatch-vcs. It doesn't exist until the package is built, so before that mypy will fail (without the type: ignore).

Copy link
Owner

@hugovk hugovk Feb 11, 2025

Choose a reason for hiding this comment

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

Ah of course. That reminds me, mypy generally works better on a whole installed project rather than file-by-file via pre-commit, so let's move it to tox.

I realise the following is a bit of scope creep, so I'm also fine leaving it out of pre-commit for now and we can do the tox stuff later.


Please could you add it like here:

https://github.com/hugovk/tinytext/blob/a3300952a281f43480c0b914756c687c956dbc41/tox.ini#L41-L45

And add:

https://github.com/hugovk/tinytext/blob/main/requirements-mypy.txt

And whatever relevant config. We can omit strict for now and add the exclude here:

https://github.com/hugovk/tinytext/blob/a3300952a281f43480c0b914756c687c956dbc41/pyproject.toml#L105-L108

Then run on GitHub Actions:

https://github.com/hugovk/tinytext/blob/a3300952a281f43480c0b914756c687c956dbc41/.github/workflows/lint.yml#L24-L37

Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the clear instructions. The scope creep was my fault, haha, so thought I'd have it fixed here and now.

rev: v1.14.1
hooks:
- id: mypy
files: '^src/em/'
Copy link
Owner

Choose a reason for hiding this comment

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

Let's include tests/ too, perhaps by removing files: and excluding scripts/?

@hugovk hugovk merged commit 292efb7 into hugovk:main Feb 11, 2025
30 of 32 checks passed
@hugovk
Copy link
Owner

hugovk commented Feb 11, 2025

Thank you!

@hukkin hukkin deleted the fix-zip-import branch February 11, 2025 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog: Fixed For any bug fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

A probable bug with zip imports
2 participants