Skip to content

Commit

Permalink
Install requirements before toml (#22468)
Browse files Browse the repository at this point in the history
Fixes #22423
  • Loading branch information
karthiknadig authored Nov 13, 2023
1 parent a1fac81 commit 47552a3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
8 changes: 4 additions & 4 deletions pythonFiles/create_venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,15 +236,15 @@ def main(argv: Optional[Sequence[str]] = None) -> None:
download_pip_pyz(args.name)
install_pip(args.name)

if args.toml:
print(f"VENV_INSTALLING_PYPROJECT: {args.toml}")
install_toml(venv_path, args.extras)

requirements = get_requirements_from_args(args)
if requirements:
print(f"VENV_INSTALLING_REQUIREMENTS: {requirements}")
install_requirements(venv_path, requirements)

if args.toml:
print(f"VENV_INSTALLING_PYPROJECT: {args.toml}")
install_toml(venv_path, args.extras)


if __name__ == "__main__":
main(sys.argv[1:])
24 changes: 21 additions & 3 deletions pythonFiles/tests/test_create_venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def add_gitignore(_name):
)


@pytest.mark.parametrize("install_type", ["requirements", "pyproject"])
@pytest.mark.parametrize("install_type", ["requirements", "pyproject", "both"])
def test_install_packages(install_type):
importlib.reload(create_venv)
create_venv.is_installed = lambda _x: True
Expand All @@ -120,16 +120,20 @@ def test_install_packages(install_type):
pip_upgraded = False
installing = None

order = []

def run_process(args, error_message):
nonlocal pip_upgraded, installing
nonlocal pip_upgraded, installing, order
if args[1:] == ["-m", "pip", "install", "--upgrade", "pip"]:
pip_upgraded = True
assert error_message == "CREATE_VENV.UPGRADE_PIP_FAILED"
elif args[1:-1] == ["-m", "pip", "install", "-r"]:
installing = "requirements"
order += ["requirements"]
assert error_message == "CREATE_VENV.PIP_FAILED_INSTALL_REQUIREMENTS"
elif args[1:] == ["-m", "pip", "install", "-e", ".[test]"]:
installing = "pyproject"
order += ["pyproject"]
assert error_message == "CREATE_VENV.PIP_FAILED_INSTALL_PYPROJECT"

create_venv.run_process = run_process
Expand All @@ -138,9 +142,23 @@ def run_process(args, error_message):
create_venv.main(["--requirements", "requirements-for-test.txt"])
elif install_type == "pyproject":
create_venv.main(["--toml", "pyproject.toml", "--extras", "test"])
elif install_type == "both":
create_venv.main(
[
"--requirements",
"requirements-for-test.txt",
"--toml",
"pyproject.toml",
"--extras",
"test",
]
)

assert pip_upgraded
assert installing == install_type
if install_type == "both":
assert order == ["requirements", "pyproject"]
else:
assert installing == install_type


@pytest.mark.parametrize(
Expand Down

0 comments on commit 47552a3

Please sign in to comment.