__main__.py 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. import os
  2. import sys
  3. import warnings
  4. # Remove '' and current working directory from the first entry
  5. # of sys.path, if present to avoid using current directory
  6. # in pip commands check, freeze, install, list and show,
  7. # when invoked as python -m pip <command>
  8. if sys.path[0] in ("", os.getcwd()):
  9. sys.path.pop(0)
  10. # If we are running from a wheel, add the wheel to sys.path
  11. # This allows the usage python pip-*.whl/pip install pip-*.whl
  12. if __package__ == "":
  13. # __file__ is pip-*.whl/pip/__main__.py
  14. # first dirname call strips of '/__main__.py', second strips off '/pip'
  15. # Resulting path is the name of the wheel itself
  16. # Add that to sys.path so we can import pip
  17. path = os.path.dirname(os.path.dirname(__file__))
  18. sys.path.insert(0, path)
  19. if __name__ == "__main__":
  20. # Work around the error reported in #9540, pending a proper fix.
  21. # Note: It is essential the warning filter is set *before* importing
  22. # pip, as the deprecation happens at import time, not runtime.
  23. warnings.filterwarnings(
  24. "ignore", category=DeprecationWarning, module=".*packaging\\.version"
  25. )
  26. from pip._internal.cli.main import main as _main
  27. sys.exit(_main())