Skip to content

Fallback to python3 when running az command - #7469

Closed
Robert Fairhead (robertfairhead) wants to merge 21 commits into
Azure:devfrom
robertfairhead:dev
Closed

Robert Fairhead (robertfairhead) wants to merge 21 commits into
Azure:devfrom
robertfairhead:dev

Conversation

@robertfairhead

@robertfairhead Robert Fairhead (robertfairhead) commented Oct 3, 2018 •

Copy link
Copy Markdown

Closes #7367
Closes #1043

This removes the bash script wrapper for the az command that hardcoded python as the python executable, breaking the az cli for python3 users.

In it's place, it uses distutils entry points to have python create its own shim that chooses the correct python executable based on how it was installed, adding python3 support.

The functionality in `azure-cli/azure/cli/main.py was refactored into a main function there to allow for the entry point to work.


This checklist is used to make sure that common guidelines for a pull request are followed.

  • [N/A] The PR has modified HISTORY.rst describing any customer-facing, functional changes. Note that this does not include changes only to help content. (see Modifying change log).

  • I adhere to the Command Guidelines.

@derekbekoe

Derek Bekoe (derekbekoe) commented Oct 4, 2018 •

Copy link
Copy Markdown
Member

Robert Fairhead (@robertfairhead) This shim that entry_points introduces an import from pkg_resources which itself has a large set of other imports. This adds a significant penalty to the start up time for each invocation of az.

This was why we didn't use entry_points in setup.py to begin with.

For example, 3 runs of that import shows the following times on a MacBook Pro with Intel i7 and SSD:

$ time python -c 'import pkg_resources'
real	0m0.547s
user	0m0.244s
sys	0m0.175s

$ time python -c 'import pkg_resources'
real	0m0.317s
user	0m0.231s
sys	0m0.081s

$ time python -c 'import pkg_resources'
real	0m0.317s
user	0m0.230s
sys	0m0.083s

@robertfairhead Robert Fairhead (robertfairhead) changed the title Use distutils entrypoints to add python3 support Fallback to python3 when running az command Oct 4, 2018
@robertfairhead

Robert Fairhead (robertfairhead) commented Oct 4, 2018 •

Copy link
Copy Markdown
Author

Derek Bekoe (@derekbekoe) Fair enough on the start up time. I switched to a test in the bash script that checks if azure is available via the python binary and if so uses that. If not, it fallbacks to trying python3.

That should present no change to the behavior for most users but provide support for those who invoke it as reported in the referenced issues.

@troydai

Copy link
Copy Markdown
Contributor

Assign this to Willie Xu (@williexu)

@troydai

Copy link
Copy Markdown
Contributor

This is indeed an idea we should keep exploring. It should have also carefully considered in the broader discussion around what's the long-term plan as we approaching the end of the Python2 lifecycle. Reassign to Willie Xu (@williexu) as I'm moving out of the project.

@yugangw-msft

Copy link
Copy Markdown
Contributor

//CC Laurent Mazuel (@lmazuel)

@robertfairhead

Copy link
Copy Markdown
Author

I cleared the merge conflicts on this PR so it should be ready for review again. If you'd like to go another direction, that's fine. I can close out the PR. I just used this workaround for myself when using the az cli.

@akx

Copy link
Copy Markdown

FWIW, there's https://pypi.org/project/fastentrypoints/ if you want entrypoints-like behavior without the startup time penalty.

@tjprescott

Copy link
Copy Markdown
Member

Robert Fairhead (@robertfairhead) we are going to investigate some other options but I appreciate you being willing to share what works for you with the project. For now I will close this PR.

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.

10 participants