22
33import contextlib
44import importlib
5+ import importlib .util
56import itertools
67import json
78import operator
1112from pathlib import Path
1213from sysconfig import get_paths , get_python_version , get_scheme_names
1314
14- import pkg_resources
15-
1615import pipenv
1716from pipenv .patched .pip ._internal .commands .install import InstallCommand
1817from pipenv .patched .pip ._internal .index .package_finder import PackageFinder
1918from pipenv .patched .pip ._internal .req .req_uninstall import UninstallPathSet
19+ from pipenv .patched .pip ._vendor import pkg_resources
2020from pipenv .patched .pip ._vendor .packaging .utils import canonicalize_name
2121from pipenv .utils .constants import is_type_checking
2222from pipenv .utils .indexes import prepare_pip_source_args
4141 from pipenv .project import Project , TPipfile , TSource
4242
4343BASE_WORKING_SET = pkg_resources .WorkingSet (sys .path )
44- # TODO: Unittests for this class
4544
4645
4746class Environment :
@@ -863,7 +862,7 @@ def run_activate_this(self):
863862 exec (code , dict (__file__ = activate_this ))
864863
865864 @contextlib .contextmanager
866- def activated (self , include_extras = True , extra_dists = None ):
865+ def activated (self ):
867866 """Helper context manager to activate the environment.
868867
869868 This context manager will set the following variables for the duration
@@ -882,16 +881,8 @@ def activated(self, include_extras=True, extra_dists=None):
882881 to `os.environ["PATH"]` to ensure that calls to `~Environment.run()` use the
883882 environment's path preferentially.
884883 """
885-
886- if not extra_dists :
887- extra_dists = []
888884 original_path = sys .path
889885 original_prefix = sys .prefix
890- parent_path = Path (__file__ ).absolute ().parent
891- vendor_dir = parent_path .joinpath ("vendor" ).as_posix ()
892- patched_dir = parent_path .joinpath ("patched" ).as_posix ()
893- parent_path = parent_path .as_posix ()
894- self .add_dist ("pip" )
895886 prefix = self .prefix .as_posix ()
896887 with vistir .contextmanagers .temp_environ (), vistir .contextmanagers .temp_path ():
897888 os .environ ["PATH" ] = os .pathsep .join (
@@ -914,21 +905,6 @@ def activated(self, include_extras=True, extra_dists=None):
914905 os .environ .pop ("PYTHONHOME" , None )
915906 sys .path = self .sys_path
916907 sys .prefix = self .sys_prefix
917- site .addsitedir (self .base_paths ["purelib" ])
918- pip = self .safe_import ("pip" ) # noqa
919- pip_vendor = self .safe_import ("pip._vendor" )
920- pep517_dir = os .path .join (os .path .dirname (pip_vendor .__file__ ), "pep517" )
921- site .addsitedir (pep517_dir )
922- os .environ ["PYTHONPATH" ] = os .pathsep .join (
923- [os .environ .get ("PYTHONPATH" , self .base_paths ["PYTHONPATH" ]), pep517_dir ]
924- )
925- if include_extras :
926- site .addsitedir (parent_path )
927- sys .path .extend ([parent_path , patched_dir , vendor_dir ])
928- extra_dists = list (self .extra_dists ) + extra_dists
929- for extra_dist in extra_dists :
930- if extra_dist not in self .get_working_set ():
931- extra_dist .activate (self .sys_path )
932908 try :
933909 yield
934910 finally :
0 commit comments