Skip to content

Commit

Permalink
feat(cli): deprecate project scaffold-code-location
Browse files Browse the repository at this point in the history
Eliminated code duplication between `dagster project scaffold` and 
`dagster project scaffold-code-location`. Turns out the only difference is that 
scaffold-code-location excludes the readme. This confused me for hours.
  • Loading branch information
dbrtly authored Oct 19, 2024
1 parent e6d4a96 commit e916af9
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 29 deletions.
34 changes: 15 additions & 19 deletions python_modules/dagster/dagster/_cli/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def project_cli():
)

scaffold_code_location_command_help_text = (
"(DEPRECATED; Use `dagster project scaffold --excludes README.md` instead) "
"Create a folder structure with a single Dagster code location, in the current directory. "
"This CLI helps you to scaffold a new Dagster code location within a folder structure that "
"includes multiple Dagster code locations."
Expand Down Expand Up @@ -74,6 +75,7 @@ def check_if_pypi_package_conflict_exists(project_name: str) -> PackageConflictC

return PackageConflictCheckResult(request_error_msg=None, conflict_exists=False)

# start deprecated commands

@project_cli.command(
name="scaffold-repository",
Expand Down Expand Up @@ -117,24 +119,10 @@ def scaffold_repository_command(name: str):
type=click.STRING,
help="Name of the new Dagster code location",
)
@click.option(
"--excludes",
multiple=True,
type=click.STRING,
default=[],
help="Exclude file patterns from the project template",
)
def scaffold_code_location_command(name: str, excludes: list):
dir_abspath = os.path.abspath(name)
if os.path.isdir(dir_abspath) and os.path.exists(dir_abspath):
click.echo(
click.style(f"The directory {dir_abspath} already exists. ", fg="red")
+ "\nPlease delete the contents of this path or choose another location."
)
sys.exit(1)
def scaffold_code_location_command(name: str):
scaffold_command(name, excludes="README.md")

generate_code_location(dir_abspath, excludes)
click.echo(_styled_success_statement(name, dir_abspath))
# end deprecated commands


def _check_and_error_on_package_conflicts(project_name: str) -> None:
Expand Down Expand Up @@ -177,13 +165,21 @@ def _check_and_error_on_package_conflicts(project_name: str) -> None:
type=click.STRING,
help="Name of the new Dagster project",
)
@click.option(
"--excludes",
multiple=True,
type=click.STRING,
default=[],
help="Exclude file patterns from the project template",
)
@click.option(
"--ignore-package-conflict",
is_flag=True,
default=False,
help="Controls whether the project name can conflict with an existing PyPI package.",
)
def scaffold_command(name: str, ignore_package_conflict: bool):
def scaffold_command(name: str, excludes: Union[Tuple, list], ignore_package_conflict: bool=False):
excludes = list(excludes)
dir_abspath = os.path.abspath(name)
if os.path.isdir(dir_abspath) and os.path.exists(dir_abspath):
click.echo(
Expand All @@ -195,7 +191,7 @@ def scaffold_command(name: str, ignore_package_conflict: bool):
if not ignore_package_conflict:
_check_and_error_on_package_conflicts(name)

generate_project(dir_abspath)
generate_project(dir_abspath, excludes)
click.echo(_styled_success_statement(name, dir_abspath))


Expand Down
1 change: 1 addition & 0 deletions python_modules/dagster/dagster/_generate/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"deploy_ecs",
"deploy_k8s",
"development_to_production",
"etl_tutorial",
"feature_graph_backed_assets",
"getting_started_etl_tutorial",
"project_analytics",
Expand Down
10 changes: 4 additions & 6 deletions python_modules/dagster/dagster/_generate/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from dagster.version import __version__ as dagster_version

IGNORE_PATTERN_LIST : list[str] = [
IGNORE_PATTERN_LIST: list[str] = [
"__pycache__",
".pytest_cache",
"*.egg-info",
Expand All @@ -18,6 +18,7 @@


def generate_repository(path: str):
"""Part of the deprecated scaffold-repository command"""
REPO_NAME_PLACEHOLDER = "REPO_NAME_PLACEHOLDER"

click.echo(f"Creating a Dagster repository at {path}.")
Expand Down Expand Up @@ -80,6 +81,7 @@ def _generate_files_from_template(
skip_mkdir: bool = False,
excludes: list[str] = [],
):
"""Renders Jinja2 templates to the dagster project."""
normalized_path = os.path.normpath(path)
code_location_name = os.path.basename(normalized_path).replace("-", "_")

Expand Down Expand Up @@ -145,8 +147,4 @@ def _should_skip_file(path: str, excludes: list[str] = IGNORE_PATTERN_LIST):
Technically, `path` could also be a directory path that should be skipped.
"""
for pattern in excludes:
if pattern in path:
return True

return False
return any(pattern in path for pattern in excludes)
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,14 @@ def test_scaffold_code_location_command_exclude_succeeds():
with runner.isolated_filesystem():
result = runner.invoke(
scaffold_code_location_command,
["--name", "my_dagster_code", "--excludes", "setup*", "--excludes", "tests"],
["--name", "diet_dagster", "--excludes", "setup", "--excludes", "tests"],
)
assert result.exit_code == 0
assert not os.path.exists("my_dagster_code/setup.cfg")
assert not os.path.exists("my_dagster_code/setup.py")
assert not os.path.exists("my_dagster_code/tests/")
assert os.path.exists("diet_dagster/pyproject.toml")
assert os.path.exists("diet_dagster/README.md")
assert not os.path.exists("diet_dagster/diet_dagster_tests/")
assert not os.path.exists("diet_dagster/setup.cfg")
assert not os.path.exists("diet_dagster/setup.py")


def test_from_example_command_fails_when_example_not_available():
Expand Down

0 comments on commit e916af9

Please sign in to comment.