question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support PEP 420 -- Implicit Namespace Packages

See original GitHub issue

As Python 2 has been deprecated, we should move away from the pkg_resources approach and use PEP 420 – Implicit Namespace Packages.

Importing pkg_resources will add a 100ms~200ms delay to CLI’s loading time.

$ time python -c "import pkg_resources"

real    0m0.153s
user    0m0.137s
sys     0m0.016s
time python -X importtime -m azure.cli version -h 2>perf.log
tuna perf.log

image

This is discussed at https://github.com/pypa/setuptools/issues/510 which affects many projects but still doesn’t have a proper fix.

Moreover, on Linux, the wrapper ~/env38/bin/az created by Easy Install also requires pkg_resources:

#!/home/admin/env38/bin/python
# EASY-INSTALL-DEV-SCRIPT: 'azure-cli==2.5.1','az'
__requires__ = 'azure-cli==2.5.1'
__import__('pkg_resources').require('azure-cli==2.5.1')
__file__ = '/home/admin/azure-cli/src/azure-cli/az'
with open(__file__) as f:
    exec(compile(f.read(), __file__, 'exec'))

This makes az installed via azdev even slower.

For comparison, directly run azure.cli:

$ time python -m azure.cli version -h

real    0m0.261s
user    0m0.238s
sys     0m0.024s

Run the Easy Install wrapper:

$ time python ~/env38/bin/az version -h

real    0m0.822s
user    0m0.779s
sys     0m0.044s
python -X importtime ~/env38/bin/az version -h 2>perf.log
tuna perf.log

image

In our Linux release, we package our own wrapper src/azure-cli/az, so it doesn’t suffer from the slowness of this Easy Install wrapper.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:19 (18 by maintainers)

github_iconTop GitHub Comments

2reactions
lmazuelcommented, May 16, 2020

Yes, you can kill them now, their only purpose is Python 2, that you don’t handle anymore. Remove them all from everywhere.

1reaction
lmazuelcommented, May 22, 2020

@jiasli

  • On dev environment, you must NOT install any nspkg. For dev, there is no question that you want to leverage PEP420. The nspkg will indeed create trouble to import, at least if you venv is in editable mode.
  • Your production wheel must NOT contains azure\cli\__init__.py,
  • Your github repo should not contain any azure\cli\__init__.py. This file shouldn’t exist.

The debate we have with @zooba is solely about this line, and nothing else, the rest of the recommended guidelines still applies. Once everything else is fixed, and we’re down the decide this, we’ll settle the debate 😃. In the meantime, keep this line since it’s there, but there is many things to still fix it seems.

Read more comments on GitHub >

github_iconTop Results From Across the Web

PEP 420 – Implicit Namespace Packages
Namespace packages are designed to support being split across multiple directories (and hence found via multiple sys.path entries). In this ...
Read more >
PEP 420 - implicit namespace packages - O'Reilly
If you use and target only Python 3, then there is good news for you. PEP 420 (Implicit Namespace Packages) introduced a new...
Read more >
Support for implicit namespace packages PEP 420 : PY-7156
Support for implicit namespace packages PEP 420 ; Included in builds, Not included in builds ; Available in, No available in ; Tester,...
Read more >
pep 420 namespace_packages purpose in setup.py
As you can see, the sample packages using the implicit namespace packages don't use namespace_packages arg in their setup scripts (here is ...
Read more >
flake8-no-pep420 - PyPI
A flake8 plugin to ban PEP-420 implicit namespace packages. Requirements. Python 3.7 to 3.11 supported. Installation. First, install with pip:
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found