From d99edadbe93607cb7cd8de1d19bab3ba56d7e96d Mon Sep 17 00:00:00 2001 From: Sean Mackesey Date: Wed, 11 Dec 2024 09:06:32 -0500 Subject: [PATCH] [components] create venv when scaffolding code location (#26348) ## Summary & Motivation Run `uv sync` to generate the virutal environment immediately after scaffolding a code location. This is a more natural place to run it than the first time you try to e.g. list component types. ## How I Tested These Changes Unit tests. --- .../libraries/dagster-dg/dagster_dg/generate.py | 3 +++ .../dagster_dg_tests/cli_tests/test_generate_commands.py | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/python_modules/libraries/dagster-dg/dagster_dg/generate.py b/python_modules/libraries/dagster-dg/dagster_dg/generate.py index c73d44d3aff2e..1ca5c72bad6be 100644 --- a/python_modules/libraries/dagster-dg/dagster_dg/generate.py +++ b/python_modules/libraries/dagster-dg/dagster_dg/generate.py @@ -61,6 +61,9 @@ def generate_code_location(path: str, editable_dagster_root: Optional[str] = Non uv_sources=uv_sources, ) + # Build the venv + execute_code_location_command(Path(path), ("uv", "sync")) + def generate_component_type(root_path: str, name: str) -> None: click.echo(f"Creating a Dagster component type at {root_path}/{name}.py.") diff --git a/python_modules/libraries/dagster-dg/dagster_dg_tests/cli_tests/test_generate_commands.py b/python_modules/libraries/dagster-dg/dagster_dg_tests/cli_tests/test_generate_commands.py index 42872a2c67ca1..776d33f996bff 100644 --- a/python_modules/libraries/dagster-dg/dagster_dg_tests/cli_tests/test_generate_commands.py +++ b/python_modules/libraries/dagster-dg/dagster_dg_tests/cli_tests/test_generate_commands.py @@ -142,6 +142,10 @@ def test_generate_code_location_inside_deployment_success() -> None: assert Path("code_locations/bar/bar_tests").exists() assert Path("code_locations/bar/pyproject.toml").exists() + # Check venv created + assert Path("code_locations/bar/.venv").exists() + assert Path("code_locations/bar/uv.lock").exists() + # Commented out because we are always adding sources right now # with open("code_locations/bar/pyproject.toml") as f: # toml = tomli.loads(f.read()) @@ -162,6 +166,10 @@ def test_generate_code_location_outside_deployment_success() -> None: assert Path("bar/bar_tests").exists() assert Path("bar/pyproject.toml").exists() + # Check venv created + assert Path("bar/.venv").exists() + assert Path("bar/uv.lock").exists() + def _find_git_root(): current = Path.cwd()