From 1495a52be5d8fd4b05417c2e2aa5fcaed6a4bc26 Mon Sep 17 00:00:00 2001 From: Daniel Bartley Date: Sat, 12 Oct 2024 13:00:37 +1100 Subject: [PATCH] feat(cli.project): enable optional minimalist configuration in templates PEP 621 (Nov 2020) introduced pyproject.toml. Setuptools is fully compatible with pyroject Completes dagster config in project template. Minimalist config to make adopting dagster easy. --- python_modules/dagster/dagster/_cli/project.py | 11 +++++++++-- python_modules/dagster/dagster/_generate/generate.py | 10 +++++++--- .../pyproject.toml.tmpl | 5 ++++- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/python_modules/dagster/dagster/_cli/project.py b/python_modules/dagster/dagster/_cli/project.py index cb37c3f555151..0da4a98967cdc 100644 --- a/python_modules/dagster/dagster/_cli/project.py +++ b/python_modules/dagster/dagster/_cli/project.py @@ -117,7 +117,14 @@ def scaffold_repository_command(name: str): type=click.STRING, help="Name of the new Dagster code location", ) -def scaffold_code_location_command(name: str): +@click.option( + '--skip-files', + multiple=True, + type=click.STRING, + default=[""], + help="exclude file patterns from the project template", +) +def scaffold_code_location_command(name: str, skip_files: list): dir_abspath = os.path.abspath(name) if os.path.isdir(dir_abspath) and os.path.exists(dir_abspath): click.echo( @@ -126,7 +133,7 @@ def scaffold_code_location_command(name: str): ) sys.exit(1) - generate_code_location(dir_abspath) + generate_code_location(dir_abspath, skip_files) click.echo(_styled_success_statement(name, dir_abspath)) diff --git a/python_modules/dagster/dagster/_generate/generate.py b/python_modules/dagster/dagster/_generate/generate.py index 07e336fc58a86..2c0b5489a8e51 100644 --- a/python_modules/dagster/dagster/_generate/generate.py +++ b/python_modules/dagster/dagster/_generate/generate.py @@ -26,7 +26,7 @@ def generate_repository(path: str): click.echo(f"Generated files for Dagster repository in {path}.") -def generate_code_location(path: str): +def generate_code_location(path: str, skip_files: list = []): CODE_LOCATION_NAME_PLACEHOLDER = "CODE_LOCATION_NAME_PLACEHOLDER" click.echo(f"Creating a Dagster code location at {path}.") @@ -38,6 +38,7 @@ def generate_code_location(path: str): project_template_path=os.path.join( os.path.dirname(__file__), "templates", CODE_LOCATION_NAME_PLACEHOLDER ), + skip_files=skip_files, ) click.echo(f"Generated files for Dagster code location in {path}.") @@ -65,7 +66,7 @@ def generate_project(path: str): def _generate_files_from_template( - path: str, name_placeholder: str, project_template_path: str, skip_mkdir: bool = False + path: str, name_placeholder: str, project_template_path: str, skip_mkdir: bool = False, skip_files: list = [] ): normalized_path = os.path.normpath(path) code_location_name = os.path.basename(normalized_path).replace("-", "_") @@ -124,12 +125,15 @@ def _generate_files_from_template( f.write("\n") -def _should_skip_file(path): +def _should_skip_file(path: str, skip_files: list): """Given a file path `path` in a source template, returns whether or not the file should be skipped when generating destination files. Technically, `path` could also be a directory path that should be skipped. """ + if skip_files: # for minimalist dagster projects from templates + IGNORE_PATTERN_LIST.extend(skip_files) + for pattern in IGNORE_PATTERN_LIST: if pattern in path: return True diff --git a/python_modules/dagster/dagster/_generate/templates/CODE_LOCATION_NAME_PLACEHOLDER/pyproject.toml.tmpl b/python_modules/dagster/dagster/_generate/templates/CODE_LOCATION_NAME_PLACEHOLDER/pyproject.toml.tmpl index 18a4302239867..837d3c638bf18 100644 --- a/python_modules/dagster/dagster/_generate/templates/CODE_LOCATION_NAME_PLACEHOLDER/pyproject.toml.tmpl +++ b/python_modules/dagster/dagster/_generate/templates/CODE_LOCATION_NAME_PLACEHOLDER/pyproject.toml.tmpl @@ -11,7 +11,7 @@ dependencies = [ [project.optional-dependencies] dev = [ - "dagster-webserver", + "dagster-webserver", "pytest", ] @@ -19,6 +19,9 @@ dev = [ requires = ["setuptools"] build-backend = "setuptools.build_meta" +[tool.setuptools.packages.find] +exclude=["{{ code_location_name }}_tests"] + [tool.dagster] module_name = "{{ code_location_name }}.definitions" code_location_name = "{{ code_location_name }}"