From f203e998e6cec4215decca2789984f593db59176 Mon Sep 17 00:00:00 2001 From: Colton Padden Date: Mon, 28 Oct 2024 22:09:25 -0400 Subject: [PATCH] ruff; pyright --- .../dagster/dagster/_cli/project.py | 25 +++++++++++-------- .../dagster/dagster/_generate/generate.py | 8 +++--- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/python_modules/dagster/dagster/_cli/project.py b/python_modules/dagster/dagster/_cli/project.py index ffbe87cae7c7d..92868a635a77e 100644 --- a/python_modules/dagster/dagster/_cli/project.py +++ b/python_modules/dagster/dagster/_cli/project.py @@ -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 @@ -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) " @@ -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): @@ -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] @@ -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) @@ -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 " diff --git a/python_modules/dagster/dagster/_generate/generate.py b/python_modules/dagster/dagster/_generate/generate.py index a382ddec3a496..5732d17437061 100644 --- a/python_modules/dagster/dagster/_generate/generate.py +++ b/python_modules/dagster/dagster/_generate/generate.py @@ -1,6 +1,6 @@ import os import posixpath -from typing import List +from typing import List, Optional import click import jinja2 @@ -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}.") @@ -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