Skip to content

Commit

Permalink
ruff; pyright
Browse files Browse the repository at this point in the history
  • Loading branch information
cmpadden committed Oct 29, 2024
1 parent a12248f commit f203e99
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
25 changes: 14 additions & 11 deletions python_modules/dagster/dagster/_cli/project.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import sys
from typing import NamedTuple, Optional, Sequence
from typing import List, NamedTuple, Optional, Sequence, Union

import click
import requests
Expand All @@ -11,14 +11,14 @@


@click.group(name="project")
def project_cli():
def project_cli() -> None:
"""Commands for bootstrapping new Dagster projects and code locations."""


# Keywords to flag in package names. When a project name contains one of these keywords, we check
# if a conflicting PyPI package exists.
FLAGGED_PACKAGE_KEYWORDS = ["dagster", "dbt"]
VALID_EXCLUDES: list[str] = ["readme.md", "setup", "tests"] # all lower case
VALID_EXCLUDES: List[str] = ["readme.md", "setup", "tests"] # all lower case

scaffold_repository_command_help_text = (
"(DEPRECATED; Use `dagster project scaffold --excludes README.md` instead) "
Expand Down Expand Up @@ -180,7 +180,9 @@ def scaffold_code_location_command(context, name: str):
help="Controls whether the project name can conflict with an existing PyPI package.",
)
def scaffold_command(
name: str, excludes: list[str] | tuple | None = None, ignore_package_conflict: bool = False
name: str,
excludes: Optional[Union[List[str], tuple]] = None,
ignore_package_conflict: bool = False,
) -> None:
dir_abspath = os.path.abspath(name)
if os.path.isdir(dir_abspath) and os.path.exists(dir_abspath):
Expand All @@ -189,7 +191,7 @@ def scaffold_command(
+ "\nPlease delete the contents of this path or choose another location."
)
sys.exit(1)

if isinstance(excludes, tuple):
excludes = list(excludes)
excludes = [] if not excludes else [item for item in excludes]
Expand All @@ -198,13 +200,14 @@ def scaffold_command(
if invalid_excludes:
click.echo(
click.style(
f"The following strings are invalid options for the excludes tag: {invalid_excludes}",
fg="red")
+ f"Choose from {VALID_EXCLUDES}. Case-insensitive. "
f"The following strings are invalid options for the excludes tag: {invalid_excludes}",
fg="red",
)
+ f"Choose from {VALID_EXCLUDES}. Case-insensitive. "
)
sys.exit(1)
excludes = [item.lower() for item in excludes if item in VALID_EXCLUDES]
excludes = [item.lower() for item in excludes if item in VALID_EXCLUDES]

if not ignore_package_conflict:
check_pypi_package_conflict(name)

Expand Down Expand Up @@ -271,7 +274,7 @@ def _styled_list_examples_prints(examples: Sequence[str]) -> str:
return "\n".join([f"* {name}" for name in examples])


def _styled_success_statement(name: str, path: str) -> None:
def _styled_success_statement(name: str, path: str) -> str:
return (
click.style("Success!", fg="green")
+ " Created "
Expand Down
8 changes: 4 additions & 4 deletions python_modules/dagster/dagster/_generate/generate.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import posixpath
from typing import List
from typing import List, Optional

import click
import jinja2
Expand Down Expand Up @@ -37,11 +37,11 @@ def generate_repository(path: str):

def generate_project(
path: str,
excludes: List[str] | None = None,
excludes: Optional[List[str]] = None,
name_placeholder: str = PROJECT_NAME_PLACEHOLDER,
templates_path: str = PROJECT_NAME_PLACEHOLDER,
):
excludes: list[str] = DEFAULT_EXCLUDES if not excludes else DEFAULT_EXCLUDES + excludes
excludes = DEFAULT_EXCLUDES if not excludes else DEFAULT_EXCLUDES + excludes

click.echo(f"Creating a Dagster project at {path}.")

Expand Down Expand Up @@ -77,7 +77,7 @@ def generate_project(

# For each file in the source template, render a file in the destination.
for filename in files:
src_file_path: posixpath = os.path.join(root, filename)
src_file_path = os.path.join(root, filename)
if _should_skip_file(src_file_path, excludes):
continue

Expand Down

0 comments on commit f203e99

Please sign in to comment.