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

Don't use pkg_resources.declare_namespace(__name__) #766

Closed
DanielNoord opened this issue Apr 7, 2023 · 12 comments
Closed

Don't use pkg_resources.declare_namespace(__name__) #766

DanielNoord opened this issue Apr 7, 2023 · 12 comments
Assignees
Labels
bug Something isn't working triage New issue; requires attention

Comments

@DanielNoord
Copy link

Describe the bug:

Importing after building the package with setuptools 67.3 and later will raise a DeprecationWarning because of the deprecation of pkg_resources.declare_namespace: https://setuptools.pypa.io/en/latest/history.html#v67-3-0

Steps to Reproduce:

Expected behavior:

Remove this line from __init__.py and use the method as described in PEP 420.

@DanielNoord DanielNoord added bug Something isn't working triage New issue; requires attention labels Apr 7, 2023
@BenRKarl BenRKarl self-assigned this Apr 11, 2023
@BenRKarl
Copy link
Contributor

@DanielNoord thank you for pointing this out, we'll get it updated in a future release.

@BenRKarl
Copy link
Contributor

@DanielNoord I'm having trouble reproducing the deprecation warning, could you add some details as to how you're able to get it to appear? What I've tried so far is installing setuptools==67.3.1 and installing the library into a clean virtual environment, both from my local repository and from PyPI.

@DanielNoord
Copy link
Author

Have you also updated pip? I'm not behind a computer right now but know that it this is somewhere in the interaction between pip and setuptools

@BenRKarl
Copy link
Contributor

Yes, same result when using pip version 23.1.1

Which version of Python are you using?

@DanielNoord
Copy link
Author

I could reproduce on 3.10.

@DanielNoord
Copy link
Author

https://discuss.python.org/t/announcement-pip-23-1-release/25844/6

This might be related. Can you reproduce with 23.1.2?

@BenRKarl
Copy link
Contributor

@DanielNoord I'm still unable to reproduce with Python 3.10.5 and pip==23.1.2...

It would be useful to get more specifics about your environment. When you have a moment, could you run the below commands in order, capturing the output that shows the deprecation warning?

python -V
python -m venv <path to venv>
source <path to venv>/bin/activate
python -m pip list
python -m pip install -U pip setuptools
python -m pip list
cd to google-ads-python
python -m pip install .
python -m pip list

@DanielNoord
Copy link
Author

I could reproduce with:

python3.11 -m virtualenv .venv
source .venv/bin/activate
python -m pip install pip==23.1
python -m pip install setuptools==67.3.1
python -m pip install google-ads
python -m pip install pytest
vim test.py
python -m pytest test.py
cat test.py
from google.ads.googleads.client import GoogleAdsClient

def test():
    assert False

Output:

python -m pytest test.py
============================= test session starts ==============================
platform linux -- Python 3.11.3, pytest-7.3.1, pluggy-1.0.0
rootdir: /tmp
collected 1 item                                                               

test.py F                                                                [100%]

=================================== FAILURES ===================================
_____________________________________ test _____________________________________

    def test():
>       assert False
E       assert False

test.py:4: AssertionError
=============================== warnings summary ===============================
.venv/lib/python3.11/site-packages/pkg_resources/__init__.py:2803
.venv/lib/python3.11/site-packages/pkg_resources/__init__.py:2803
.venv/lib/python3.11/site-packages/pkg_resources/__init__.py:2803
.venv/lib/python3.11/site-packages/pkg_resources/__init__.py:2803
.venv/lib/python3.11/site-packages/pkg_resources/__init__.py:2803
.venv/lib/python3.11/site-packages/pkg_resources/__init__.py:2803
  /tmp/.venv/lib/python3.11/site-packages/pkg_resources/__init__.py:2803: DeprecationWarning: Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
    declare_namespace(pkg)

.venv/lib/python3.11/site-packages/pkg_resources/__init__.py:2308
.venv/lib/python3.11/site-packages/pkg_resources/__init__.py:2308
.venv/lib/python3.11/site-packages/pkg_resources/__init__.py:2308
  /tmp/.venv/lib/python3.11/site-packages/pkg_resources/__init__.py:2308: DeprecationWarning: Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
    declare_namespace(parent)

.venv/lib/python3.11/site-packages/google/rpc/__init__.py:20
  /tmp/.venv/lib/python3.11/site-packages/google/rpc/__init__.py:20: DeprecationWarning: Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
    pkg_resources.declare_namespace(__name__)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=========================== short test summary info ============================
FAILED test.py::test - assert False
======================== 1 failed, 10 warnings in 0.14s ========================

Running with ``python -m pytest test.py -Werror` shows that the errors originate from imports in this package.

@BenRKarl
Copy link
Contributor

BenRKarl commented May 1, 2023

Thanks @DanielNoord I was able to reproduce the warning using those steps. What I found was that if I remove the declare_namespace statements from our library, deprecation warnings get raised from other external libraries such as grpcio. I'm going to coordinate internally to see if there can be a shared approach to this, since we share the same namespace as other Google libraries. I'll try to post an update here as soon as possible.

@DanielNoord
Copy link
Author

Thanks for the update @BenRKarl!

Do let me know if I can help out with testing anything!

@BenRKarl
Copy link
Contributor

This PR will resolve this issue: #830

@BenRKarl
Copy link
Contributor

This is resolved in version 23.0.0, you should longer see any warnings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage New issue; requires attention
Projects
None yet
Development

No branches or pull requests

2 participants