Skip to content

Commit 47552a3

Browse files
authored
Install requirements before toml (#22468)
Fixes #22423
1 parent a1fac81 commit 47552a3

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

pythonFiles/create_venv.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,15 +236,15 @@ def main(argv: Optional[Sequence[str]] = None) -> None:
236236
download_pip_pyz(args.name)
237237
install_pip(args.name)
238238

239-
if args.toml:
240-
print(f"VENV_INSTALLING_PYPROJECT: {args.toml}")
241-
install_toml(venv_path, args.extras)
242-
243239
requirements = get_requirements_from_args(args)
244240
if requirements:
245241
print(f"VENV_INSTALLING_REQUIREMENTS: {requirements}")
246242
install_requirements(venv_path, requirements)
247243

244+
if args.toml:
245+
print(f"VENV_INSTALLING_PYPROJECT: {args.toml}")
246+
install_toml(venv_path, args.extras)
247+
248248

249249
if __name__ == "__main__":
250250
main(sys.argv[1:])

pythonFiles/tests/test_create_venv.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def add_gitignore(_name):
111111
)
112112

113113

114-
@pytest.mark.parametrize("install_type", ["requirements", "pyproject"])
114+
@pytest.mark.parametrize("install_type", ["requirements", "pyproject", "both"])
115115
def test_install_packages(install_type):
116116
importlib.reload(create_venv)
117117
create_venv.is_installed = lambda _x: True
@@ -120,16 +120,20 @@ def test_install_packages(install_type):
120120
pip_upgraded = False
121121
installing = None
122122

123+
order = []
124+
123125
def run_process(args, error_message):
124-
nonlocal pip_upgraded, installing
126+
nonlocal pip_upgraded, installing, order
125127
if args[1:] == ["-m", "pip", "install", "--upgrade", "pip"]:
126128
pip_upgraded = True
127129
assert error_message == "CREATE_VENV.UPGRADE_PIP_FAILED"
128130
elif args[1:-1] == ["-m", "pip", "install", "-r"]:
129131
installing = "requirements"
132+
order += ["requirements"]
130133
assert error_message == "CREATE_VENV.PIP_FAILED_INSTALL_REQUIREMENTS"
131134
elif args[1:] == ["-m", "pip", "install", "-e", ".[test]"]:
132135
installing = "pyproject"
136+
order += ["pyproject"]
133137
assert error_message == "CREATE_VENV.PIP_FAILED_INSTALL_PYPROJECT"
134138

135139
create_venv.run_process = run_process
@@ -138,9 +142,23 @@ def run_process(args, error_message):
138142
create_venv.main(["--requirements", "requirements-for-test.txt"])
139143
elif install_type == "pyproject":
140144
create_venv.main(["--toml", "pyproject.toml", "--extras", "test"])
145+
elif install_type == "both":
146+
create_venv.main(
147+
[
148+
"--requirements",
149+
"requirements-for-test.txt",
150+
"--toml",
151+
"pyproject.toml",
152+
"--extras",
153+
"test",
154+
]
155+
)
141156

142157
assert pip_upgraded
143-
assert installing == install_type
158+
if install_type == "both":
159+
assert order == ["requirements", "pyproject"]
160+
else:
161+
assert installing == install_type
144162

145163

146164
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)