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

Replace pkg_resources with importlib_resources #497

Merged
merged 1 commit into from
Apr 1, 2024

Conversation

chuckwondo
Copy link
Collaborator

@chuckwondo chuckwondo commented Mar 19, 2024

Fix "DeprecationWarning: pkg_resources is deprecated as an API." seen when running tests.

In addition:

  • increase test coverage for formatters.py
  • replace deprecated set-output in test.yml workflow
  • remove redundant lines in Makefile
  • make minor grammatical and formatting fixes to CONTRIBUTING.md
  • remove old, redundant "Code of Conduct" section from CONTRIBUTING.md and insert link to CODE_OF_CONDUCT.md
  • fix bare links in CODE_OF_CONDUCT.md

📚 Documentation preview 📚: https://earthaccess--497.org.readthedocs.build/en/497/

@mfisher87
Copy link
Collaborator

These doc fixes are so helpful, thank you for including them!

Makefile Show resolved Hide resolved
mfisher87
mfisher87 previously approved these changes Mar 19, 2024
Makefile Show resolved Hide resolved
earthaccess/formatters.py Show resolved Hide resolved
@mfisher87
Copy link
Collaborator

Woops, didn't notice workflows waiting for approval. 🐌 🚀

@mfisher87
Copy link
Collaborator

@chuckwondo we're just about to start a hack day, hope you'll be joining us again :)

@danielfromearth
Copy link
Collaborator

Just linking this to the other PR that this supersedes: #452, which I think should be closed after this one is merged.

@mfisher87
Copy link
Collaborator

I tried putting Closes #452 in the OP but that didn't seem to work the way I wanted it to. I removed it. Can we close #452 now so we don't have to remember?

@chuckwondo
Copy link
Collaborator Author

@mfisher87, I made a change that should fix the broken python 3.8 build. It also happens to simplify things a bit.

@chuckwondo
Copy link
Collaborator Author

Just linking this to the other PR that this supersedes: #452, which I think should be closed after this one is merged.

@danielfromearth, thanks for making note of this. It totally slipped my mind that I had previously commented on your issue there! This should close the loop on that.

@chuckwondo chuckwondo changed the title Replace pkg_resources with importlib.resources Replace pkg_resources with importlib_resources Mar 19, 2024
@mfisher87
Copy link
Collaborator

And thank you @danielfromearth for your work on this problem!

@chuckwondo
Copy link
Collaborator Author

Ugh! Updated ci/environment-mindeps.yaml to include importlib-resources, which I had added to pyproject.toml. This seems like an accident waiting to happen (it just did). Any idea why the redundancy that forces us to keep these files in sync?

@jhkennedy
Copy link
Collaborator

Ugh! Updated ci/environment-mindeps.yaml to include importlib-resources, which I had added to pyproject.toml. This seems like an accident waiting to happen (it just did). Any idea why the redundancy that forces us to keep these files in sync?

Unfortunately, the environment-* YAMLs are conda environments and dependencies, while the deps in pyproject.toml are Poetry ones that get pulled from PyPI. There's no real way to avoid the duplication due to different package repositories and managers.

And really, even if we went to just poetry environments, there's no way to specify "build an environment from the minimum dependencies" in Poetry, but we could with uv and only use that (dropping conda). Something to add to #374

It's good to have conda env test coverage as well though as many of our users will be using conda.

pyproject.toml Outdated
@@ -44,6 +44,7 @@ multimethod = ">=1.8"
python-dateutil = ">=2.8.2"
kerchunk = { version = ">=0.1.2", optional = true }
dask = { version = ">=2022.1.0", optional = true }
importlib-resources = "^6.3.2"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need to pin down to the patch version here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not necessarily, but I simply used poetry add importlib-resources to add it. There are other deps pinned similarly, but there is certainly no consistency.

This seems to point to a gap in the contributing guide regarding adding dependencies; not only how to add them, but also where to add them (other than pyproject.toml).

I'm happy to add a note in the contributing guide, if you can provide guidance.

Also, happy to adjust the version pin here accordingly, if there's a preference.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Also, a brief explanation of the why (in addition to the how and where) might be good to add to the contributing guide.

Again, happy to add all such details to the contributing guide as part of this PR, if someone can provide a few sentences.

Copy link
Collaborator

@jhkennedy jhkennedy Mar 19, 2024

Choose a reason for hiding this comment

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

There's been a bit of lively discussion around dependencies in #468, but generally, a restrictive top-pin (down to the patch version) like this will force this package to break quickly for users. So we should remove the upper bound if we don't need it.

Suggested change
importlib-resources = "^6.3.2"
importlib-resources = ">=6.3.2"

Similarly, is there a reason for this version being the lower bound?

Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems to point to a gap in the contributing guide regarding adding dependencies; not only how to add them, but also where to add them (other than pyproject.toml).

Yes, agreed, we should add that. Especially since poetry add adds upper bounds to dependencies with ^, which is bad for libraries (and will not change python-poetry/poetry#3427)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Those steps sound right to me. For (1) I'd be inclined to have the users just manually add it to the pyproject.toml instead of having to tell them to effectively manually do it again in (2), but (1) does update the lockfile too.

For 2 we could tell them to use poetry-relax but that should probably be done in isolation with its own PR later.

Cool. Can you provide the "why" in the 2 spots I mentioned? Just a sentence or 2 in each spot to provide context for contributors.

Copy link
Collaborator

Choose a reason for hiding this comment

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

What's "a few versions behind the latest"? If you're referring to importlib-resources, that version is the latest as of earlier today.

Bah, I thought I looked earlier and latest was 7.0.2; no idea what I looked at 😫

Copy link
Collaborator

Choose a reason for hiding this comment

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

@chuckwondo this is getting large -- perhaps we should move the contributing guide discussion to its own issue and subsequent PR?

Copy link
Collaborator

Choose a reason for hiding this comment

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

As for the version, since we're still a poetry project, let's just go with:

importlib-resources = ">=6.3.2"

for now since that's what it decided and the rest were likely added that way.

Copy link
Collaborator

@jhkennedy jhkennedy Mar 20, 2024

Choose a reason for hiding this comment

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

As for the why:

On the line added to pyproject.toml by poetry, change ^ to >= (perhaps add a "why" bit here)

because upper bounds can easily result in unsolvable user environments for Python libraries like Earthaccess. For more information, see the poetry-relax README, especially the references.

Add the same dependency to ci/environment-mindeps.yaml. For a required dep, pin the exact version, but for a testing dep, leave unpinned (again, a "why" comment here might also prove helpful)

I don't actually know the reasoning here... looks like it's because we pip install with --no-deps and only use the dependencies in the conda environment, so we need all dependencies reflected here.
https://github.com/nsidc/earthaccess/blob/main/.github/workflows/test-mindeps.yml

@mfisher87 @betolink got a sentence for this?

ci/environment-mindeps.yaml Outdated Show resolved Hide resolved
Fix "DeprecationWarning: pkg_resources is deprecated as an API." seen
when running tests.

In addition:

- increase test coverage for `formatters.py`
- replace deprecated `set-output` in `test.yml` workflow
- remove redundant lines in `Makefile`
- make minor grammatical and formatting fixes to `CONTRIBUTING.md`
- remove old, redundant "Code of Conduct" section from `CONTRIBUTING.md`
  and insert link to `CODE_OF_CONDUCT.md`
- fix bare links in `CODE_OF_CONDUCT.md`
@chuckwondo
Copy link
Collaborator Author

@jhkennedy and @mfisher87, I believe I addressed the dependency pinning issue. I also added a small "Managing Dependencies" section to the contributing guide. Please let me know if I missed anything.

Copy link
Collaborator

@jhkennedy jhkennedy left a comment

Choose a reason for hiding this comment

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

looks good to me. @mfisher87 did you want to tak another look?

@chuckwondo
Copy link
Collaborator Author

@mfisher87, does this look good?

@chuckwondo
Copy link
Collaborator Author

@jhkennedy can you take a look at how/why one of the checks was cancelled and rerun? I see, "Canceling since a higher priority waiting request for 'refs/pull/497/merge' exists," but can't tell exactly what caused it.

@jhkennedy
Copy link
Collaborator

@jhkennedy can you take a look at how/why one of the checks was cancelled and rerun? I see, "Canceling since a higher priority waiting request for 'refs/pull/497/merge' exists," but can't tell exactly what caused it.

I'm confused by that as well. I believe it's related to the concurrency setting:
https://github.com/nsidc/earthaccess/blob/main/.github/workflows/test-mindeps.yml#L8-L12

But not sure why. I don't have time to dig in right now (it works in some PRs but not others), but I'll open an issue.

For now, I think it's safe to ignore it as the test ran fine in your fork:
https://github.com/chuckwondo/earthaccess/actions/runs/8367002850

@mfisher87
Copy link
Collaborator

Hey, so sorry all for missing your mentions! 👀

Copy link
Collaborator

@mfisher87 mfisher87 left a comment

Choose a reason for hiding this comment

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

LGTM! I have lost some context in my delay to respond to this issue and I apologize for that 😿

@chuckwondo
Copy link
Collaborator Author

Can somebody merge this PR?

@jhkennedy jhkennedy merged commit c140c61 into nsidc:main Apr 1, 2024
10 of 11 checks passed
@jhkennedy
Copy link
Collaborator

@chuckwondo done!

@mfisher87
Copy link
Collaborator

Thanks @jhkennedy . @chuckwondo do you want merge permissions? We don't have any expectations of time commitment for maintainers.

@chuckwondo
Copy link
Collaborator Author

@mfisher87, thanks for the offer for merge permissions. I don't yet feel comfortable being granted such permissions, but perhaps after a few more PRs and "hack days" I'll take you up on the offer.

@mfisher87
Copy link
Collaborator

I'll be sure to ask again later, then! ;)

@chuckwondo chuckwondo deleted the use-importlib-resources branch September 17, 2024 18:07
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.

4 participants