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

DeprecationWarning: Implicit None on return values is deprecated and will raise KeyErrors. #977

Closed
domdfcoding opened this issue Jan 13, 2023 · 11 comments · Fixed by AllenCell/allencell-segmenter-ml#416
Assignees

Comments

@domdfcoding
Copy link

Your Environment

Thank you for taking the time to report an issue.

To more efficiently resolve this issue, we'd like to know some basic information about your system and setup.

  1. Your operating system:

Ubuntu 20.04

  1. Version of python you are running:

Python 3.8.10

  1. How did you install twine? Did you use your operating system's package manager or pip or something else?

pip (via tox)

  1. Version of twine you have installed (include complete output of):
twine --version

twine version 4.0.2 (importlib-metadata: 6.0.0, keyring: 23.13.1, pkginfo: 1.9.6, requests: 2.28.2, requests-toolbelt: 0.10.1, urllib3: 1.26.14)

  1. Which package repository are you targeting?

PyPI

The Issue

Please describe the issue that you are experiencing.

Running twine emits a deprecation warning:

python3 -Walways -m twine --version
venv/lib/python3.8/site-packages/twine/__init__.py:43: DeprecationWarning: Implicit None on return values is deprecated and will raise KeyErrors.
  __license__ = metadata["license"]
twine version 4.0.2 (importlib-metadata: 6.0.0, keyring: 23.13.1, pkginfo: 1.9.6, requests: 2.28.2, requests-toolbelt: 0.10.1, urllib3: 1.26.14)

It appears that twine's metadata does not include the License key. As a result, the metadata "dictionary" twine is getting from importlib_metadata doesn't contain a key license.

The metadata in the wheel uploaded to PyPI can be seen here: https://www.wheelodex.org/projects/twine/#metadata

Steps to Reproduce

If the issue is predictable and consistently reproducible, please list the steps here.

  • Run python3 -Walways -m twine --version
@bhrutledge
Copy link
Contributor

bhrutledge commented Jan 13, 2023

Thanks for the report. This was fixed in #968, and will be included in the next Twine release.

@jaraco
Copy link
Member

jaraco commented Jun 24, 2024

Today I tried to release importlib_metadata 8.0.0, which removes the compatible behavior and begins raising KeyErrors for missing keys. When I did, the release failed with this error:

Successfully built importlib_metadata-8.0.0.tar.gz and importlib_metadata-8.0.0-py3-none-any.whl
release: commands[2]> python -m twine upload 'dist/*'
Traceback (most recent call last):
  File "<frozen runpy>", line 189, in _run_module_as_main
  File "<frozen runpy>", line 148, in _get_module_details
  File "<frozen runpy>", line 112, in _get_module_details
  File "/home/runner/work/importlib_metadata/importlib_metadata/.tox/release/lib/python3.12/site-packages/twine/__init__.py", line 40, in <module>
    __uri__ = metadata["home-page"]
              ~~~~~~~~^^^^^^^^^^^^^
  File "/home/runner/work/importlib_metadata/importlib_metadata/importlib_metadata/_adapters.py", line 54, in __getitem__
    raise KeyError(item)
KeyError: 'home-page'
release: exit 1 (0.08 seconds) /home/runner/work/importlib_metadata/importlib_metadata> python -m twine upload 'dist/*' pid=1994
  release: FAIL code 1 (18.00=setup[12.88]+cmd[0.03,5.01,0.08] seconds)
  evaluation failed :( (18.21 seconds)

It looks like twine is still reliant on the deprecated behavior.

I'm unsure if we should re-open this issue or start a new one, since the concerns are very closely related.

@jaraco jaraco reopened this Jun 24, 2024
@jaraco
Copy link
Member

jaraco commented Jun 25, 2024

When running the current test suite, I see that the DeprecationWarnings were apparent:

 twine main @ .tox/py/bin/pytest --collect-only -qq
tests/test_auth.py: 19
tests/test_check.py: 13
tests/test_cli.py: 2
tests/test_commands.py: 5
tests/test_main.py: 3
tests/test_package.py: 32
tests/test_register.py: 6
tests/test_repository.py: 25
tests/test_settings.py: 16
tests/test_upload.py: 36
tests/test_utils.py: 35
tests/test_wheel.py: 10

================================================================ warnings summary ================================================================
twine/__init__.py:40
  /Users/jaraco/code/pypa/twine/twine/__init__.py:40: DeprecationWarning: Implicit None on return values is deprecated and will raise KeyErrors.
    __uri__ = metadata["home-page"]

twine/__init__.py:42
  /Users/jaraco/code/pypa/twine/twine/__init__.py:42: DeprecationWarning: Implicit None on return values is deprecated and will raise KeyErrors.
    __author__ = metadata["author"]

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html

@qqiao2024
Copy link

qqiao2024 commented Jun 25, 2024

same error got from gitlab-ci.
The same code is working fine on my laptop.

twine 5.1.0

$ python -m twine check dist/*
Traceback (most recent call last):
  File "/py/lib/python3.8/runpy.py", line 185, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/py/lib/python3.8/runpy.py", line 144, in _get_module_details
    return _get_module_details(pkg_main_name, error)
  File "/py/lib/python3.8/runpy.py", line 111, in _get_module_details
    __import__(pkg_name)
  File "/venv/lib/python3.8/site-packages/twine/__init__.py", line 40, in <module>
    __uri__ = metadata["home-page"]
  File "/venv/lib/python3.8/site-packages/importlib_metadata/_adapters.py", line 54, in __getitem__
    raise KeyError(item)
KeyError: 'home-page'

@RenaudLN
Copy link

RenaudLN commented Jun 25, 2024

I had a build succeed 3h ago with twine 5.1.0 then fail 5mn ago with that same version.

Working
image

Not working
image

@yym68686
Copy link

yym68686 commented Jun 25, 2024

This command fixed the issue.

pip install importlib_metadata==7.2.1

Add this line to github action

name: Publish Python 🐍 distributions 📦 to PyPI

on:
  push:
    tags:
      - '*'
    branches:
      - main

jobs:
  build-n-publish:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Set up Python
      uses: actions/setup-python@v2
      with:
        python-version: '3.x'
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install setuptools wheel twine
+      pip install importlib_metadata==7.2.1
    - name: Build and publish
      env:
        TWINE_USERNAME: __token__
        TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
      run: |
        python setup.py sdist bdist_wheel
        twine upload dist/*

@qqiao2024
Copy link

This command fixed the issue.

pip install importlib_metadata==7.2.1

yes, the bug happens with importlib_metadata 8.0.0

@Erotemic
Copy link

Ah, release season is so fun!

The amount of hair I've pulled out where something that was working an hour ago is no longer working... Glad to know the issue is being tracked!

@henryiii
Copy link
Contributor

5.1.0 reverted the (fixed) reliance on this behavior.

@JohnVillalovos
Copy link

FYI: A PR to fix this KeyError issue is at #1115

@JohnVillalovos
Copy link

The twine issue was resolved in 5.1.1 and is published on PyPI: https://pypi.org/project/twine/

kylebgorman added a commit to mmcauliffe/wikipron that referenced this issue Jul 11, 2024
kylebgorman added a commit to CUNY-CL/wikipron that referenced this issue Jul 11, 2024
* Fix dialect xpath selector

* Update changelog

* Fix bug with "ib-content" classes not using contains specifier

* Updates requirements to fix Twine issue

For context, see: pypa/twine#977

---------

Co-authored-by: Kyle Gorman <kylebgorman@gmail.com>
Gallaecio added a commit to scrapinghub/web-poet that referenced this issue Jul 12, 2024
sjwiesman added a commit to sjwiesman/materialize that referenced this issue Jul 19, 2024
Twine is the library used to deploy dbt-materialize to PyPi. Recent
versions are broken with missing metadata keys. The issue has been
resolved in the latest release.

Example failure: https://buildkite.com/materialize/deploy/builds/15079#0190cc52-c16a-4ea4-8020-e1df5daed947
Twine issue: pypa/twine#977
sjwiesman added a commit to sjwiesman/materialize that referenced this issue Jul 19, 2024
Twine is the library used to deploy dbt-materialize to PyPi. Recent
versions are broken with missing metadata keys. The issue has been
resolved in the latest release.

Example failure: https://buildkite.com/materialize/deploy/builds/15079#0190cc52-c16a-4ea4-8020-e1df5daed947
Twine issue: pypa/twine#977
sjwiesman added a commit to MaterializeInc/materialize that referenced this issue Jul 20, 2024
Twine is the library used to deploy dbt-materialize to PyPi. Recent
versions are broken with missing metadata keys. The issue has been
resolved in the latest release.

Example failure:
https://buildkite.com/materialize/deploy/builds/15079#0190cc52-c16a-4ea4-8020-e1df5daed947
Twine issue: pypa/twine#977

<!--
Describe the contents of the PR briefly but completely.

If you write detailed commit messages, it is acceptable to copy/paste
them
here, or write "see commit messages for details." If there is only one
commit
in the PR, GitHub will have already added its commit message above.
-->

### Motivation

<!--
Which of the following best describes the motivation behind this PR?

  * This PR fixes a recognized bug.

    [Ensure issue is linked somewhere.]

  * This PR adds a known-desirable feature.

    [Ensure issue is linked somewhere.]

  * This PR fixes a previously unreported bug.

    [Describe the bug in detail, as if you were filing a bug report.]

  * This PR adds a feature that has not yet been specified.

[Write a brief specification for the feature, including justification
for its inclusion in Materialize, as if you were writing the original
     feature specification.]

   * This PR refactors existing code.

[Describe what was wrong with the existing code, if it is not obvious.]
-->

### Tips for reviewer

<!--
Leave some tips for your reviewer, like:

    * The diff is much smaller if viewed with whitespace hidden.
    * [Some function/module/file] deserves extra attention.
* [Some function/module/file] is pure code movement and only needs a
skim.

Delete this section if no tips.
-->

### Checklist

- [ ] This PR has adequate test coverage / QA involvement has been duly
considered. ([trigger-ci for additional test/nightly
runs](https://trigger-ci.dev.materialize.com/))
- [ ] This PR has an associated up-to-date [design
doc](https://github.com/MaterializeInc/materialize/blob/main/doc/developer/design/README.md),
is a design doc
([template](https://github.com/MaterializeInc/materialize/blob/main/doc/developer/design/00000000_template.md)),
or is sufficiently small to not require a design.
  <!-- Reference the design in the description. -->
- [ ] If this PR evolves [an existing `$T ⇔ Proto$T`
mapping](https://github.com/MaterializeInc/materialize/blob/main/doc/developer/command-and-response-binary-encoding.md)
(possibly in a backwards-incompatible way), then it is tagged with a
`T-proto` label.
- [ ] If this PR will require changes to cloud orchestration or tests,
there is a companion cloud PR to account for those changes that is
tagged with the release-blocker label
([example](MaterializeInc/cloud#5021)).
<!-- Ask in #team-cloud on Slack if you need help preparing the cloud
PR. -->
- [ ] This PR includes the following [user-facing behavior
changes](https://github.com/MaterializeInc/materialize/blob/main/doc/developer/guide-changes.md#what-changes-require-a-release-note):
- <!-- Add release notes here or explicitly state that there are no
user-facing behavior changes. -->
nicholaslourie added a commit to nicholaslourie/opda that referenced this issue Aug 1, 2024
Packaging opda with importlib_metadata 8.0.0 and twine 4.0.2 raises
an exception: "KeyError: 'license'". The exception results from a
change in importlib_metadata where requesting missing metadata used
to return None but now raises a KeyError. Upgrading twine to 5.1.1
resolves the issue.

For more information, see pypa/twine#977
which discusses the missing license metadata in twine 4.0.2, and
see pypa/twine#1125 for how the release
of importlib_metadata 8.0.0 triggered the issue.
oyvindio added a commit to fiaas/publish that referenced this issue Oct 3, 2024
The pinned version of twine appears to be incompatible with the version
of importlib-metadata it pulls in transitively
( pypa/twine#977 )
Upgrade twine to 5.1.1 where this issue should be fixed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
9 participants