|
40 | 40 | from poetry.utils._compat import list_to_shell_command
|
41 | 41 | from poetry.utils._compat import subprocess
|
42 | 42 | from poetry.utils.toml_file import TomlFile
|
| 43 | +from virtualenv.seed.wheels.embed import get_embed_wheel |
43 | 44 |
|
44 | 45 |
|
45 | 46 | GET_ENVIRONMENT_INFO = """\
|
@@ -679,19 +680,25 @@ def create_venv(
|
679 | 680 |
|
680 | 681 | @classmethod
|
681 | 682 | def build_venv(
|
682 |
| - cls, path, executable=None |
683 |
| - ): # type: (Union[Path,str], Optional[Union[str, Path]]) -> virtualenv.run.session.Session |
| 683 | + cls, path, executable=None, with_pip=False |
| 684 | + ): # type: (Union[Path,str], Optional[Union[str, Path]], bool) -> virtualenv.run.session.Session |
684 | 685 | if isinstance(executable, Path):
|
685 | 686 | executable = executable.resolve().as_posix()
|
686 |
| - return virtualenv.cli_run( |
687 |
| - [ |
688 |
| - "--no-download", |
689 |
| - "--no-periodic-update", |
690 |
| - "--python", |
691 |
| - executable or sys.executable, |
692 |
| - str(path), |
693 |
| - ] |
694 |
| - ) |
| 687 | + |
| 688 | + opts = [ |
| 689 | + "--no-download", |
| 690 | + "--no-periodic-update", |
| 691 | + "--python", |
| 692 | + executable or sys.executable, |
| 693 | + ] |
| 694 | + |
| 695 | + if not with_pip: |
| 696 | + # we cannot drop setuptools yet because we do editable installs (git, path) in project envs |
| 697 | + opts.extend(["--no-pip", "--no-wheel"]) |
| 698 | + |
| 699 | + opts.append(str(path)) |
| 700 | + |
| 701 | + return virtualenv.cli_run(opts) |
695 | 702 |
|
696 | 703 | @classmethod
|
697 | 704 | def remove_venv(cls, path): # type: (Union[Path,str]) -> None
|
@@ -787,12 +794,21 @@ def marker_env(self):
|
787 | 794 |
|
788 | 795 | return self._marker_env
|
789 | 796 |
|
| 797 | + def get_embedded_wheel(self, distribution): |
| 798 | + return get_embed_wheel( |
| 799 | + distribution, "{}.{}".format(self.version_info[0], self.version_info[1]) |
| 800 | + ).path |
| 801 | + |
790 | 802 | @property
|
791 | 803 | def pip(self): # type: () -> str
|
792 | 804 | """
|
793 | 805 | Path to current pip executable
|
794 | 806 | """
|
795 |
| - return self._bin("pip") |
| 807 | + # we do not use as_posix() here due to issues with windows pathlib2 implementation |
| 808 | + path = self._bin("pip") |
| 809 | + if not Path(path).exists(): |
| 810 | + return str(self.get_embedded_wheel("pip").joinpath("pip")) |
| 811 | + return path |
796 | 812 |
|
797 | 813 | @property
|
798 | 814 | def platform(self): # type: () -> str
|
@@ -1010,7 +1026,7 @@ def get_python_implementation(self): # type: () -> str
|
1010 | 1026 | def get_pip_command(self): # type: () -> List[str]
|
1011 | 1027 | # If we're not in a venv, assume the interpreter we're running on
|
1012 | 1028 | # has a pip and use that
|
1013 |
| - return [sys.executable, "-m", "pip"] |
| 1029 | + return [sys.executable, self.pip] |
1014 | 1030 |
|
1015 | 1031 | def get_paths(self): # type: () -> Dict[str, str]
|
1016 | 1032 | # We can't use sysconfig.get_paths() because
|
@@ -1112,7 +1128,7 @@ def get_python_implementation(self): # type: () -> str
|
1112 | 1128 | def get_pip_command(self): # type: () -> List[str]
|
1113 | 1129 | # We're in a virtualenv that is known to be sane,
|
1114 | 1130 | # so assume that we have a functional pip
|
1115 |
| - return [self._bin("pip")] |
| 1131 | + return [self._bin("python"), self.pip] |
1116 | 1132 |
|
1117 | 1133 | def get_supported_tags(self): # type: () -> List[Tag]
|
1118 | 1134 | file_path = Path(packaging.tags.__file__)
|
@@ -1167,7 +1183,7 @@ def is_venv(self): # type: () -> bool
|
1167 | 1183 |
|
1168 | 1184 | def is_sane(self):
|
1169 | 1185 | # A virtualenv is considered sane if both "python" and "pip" exist.
|
1170 |
| - return os.path.exists(self._bin("python")) and os.path.exists(self._bin("pip")) |
| 1186 | + return os.path.exists(self._bin("python")) |
1171 | 1187 |
|
1172 | 1188 | def _run(self, cmd, **kwargs):
|
1173 | 1189 | with self.temp_environ():
|
@@ -1217,7 +1233,7 @@ def __init__(self, path=None, base=None, execute=False):
|
1217 | 1233 | self.executed = []
|
1218 | 1234 |
|
1219 | 1235 | def get_pip_command(self): # type: () -> List[str]
|
1220 |
| - return [self._bin("python"), "-m", "pip"] |
| 1236 | + return [self._bin("python"), self.pip] |
1221 | 1237 |
|
1222 | 1238 | def _run(self, cmd, **kwargs):
|
1223 | 1239 | self.executed.append(cmd)
|
|
0 commit comments