From 47552a31f88a74c83874982675291018de7cd62a Mon Sep 17 00:00:00 2001 From: Karthik Nadig Date: Mon, 13 Nov 2023 12:33:48 -0800 Subject: [PATCH] Install requirements before toml (#22468) Fixes https://github.com/microsoft/vscode-python/issues/22423 --- pythonFiles/create_venv.py | 8 ++++---- pythonFiles/tests/test_create_venv.py | 24 +++++++++++++++++++++--- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/pythonFiles/create_venv.py b/pythonFiles/create_venv.py index 68f21a38b980..092286f986cf 100644 --- a/pythonFiles/create_venv.py +++ b/pythonFiles/create_venv.py @@ -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:]) diff --git a/pythonFiles/tests/test_create_venv.py b/pythonFiles/tests/test_create_venv.py index 772fc02708f8..446d6da8bc55 100644 --- a/pythonFiles/tests/test_create_venv.py +++ b/pythonFiles/tests/test_create_venv.py @@ -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 @@ -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 @@ -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(