Skip to content

Commit

Permalink
[chore] add UP rule to ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgafni committed Nov 14, 2024
1 parent 691d93e commit 871b1b1
Show file tree
Hide file tree
Showing 1,225 changed files with 6,676 additions and 7,839 deletions.
12 changes: 9 additions & 3 deletions .buildkite/dagster-buildkite/dagster_buildkite/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

from dagster_buildkite.git import GitInfo
from dagster_buildkite.pipelines.dagster_oss_main import build_dagster_oss_main_steps
from dagster_buildkite.pipelines.dagster_oss_nightly_pipeline import build_dagster_oss_nightly_steps
from dagster_buildkite.pipelines.prerelease_package import build_prerelease_package_steps
from dagster_buildkite.pipelines.dagster_oss_nightly_pipeline import (
build_dagster_oss_nightly_steps,
)
from dagster_buildkite.pipelines.prerelease_package import (
build_prerelease_package_steps,
)
from dagster_buildkite.python_packages import PythonPackages
from dagster_buildkite.utils import buildkite_yaml_for_steps

Expand All @@ -23,7 +27,9 @@ def dagster() -> None:
def dagster_nightly() -> None:
PythonPackages.load_from_git(GitInfo(directory=Path(".")))
steps = build_dagster_oss_nightly_steps()
buildkite_yaml = buildkite_yaml_for_steps(steps, custom_slack_channel="eng-buildkite-nightly")
buildkite_yaml = buildkite_yaml_for_steps(
steps, custom_slack_channel="eng-buildkite-nightly"
)
print(buildkite_yaml) # noqa: T201


Expand Down
4 changes: 3 additions & 1 deletion .buildkite/dagster-buildkite/dagster_buildkite/defines.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import packaging.version
import requests

GIT_REPO_ROOT = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "..", "..")
GIT_REPO_ROOT = os.path.join(
os.path.dirname(os.path.abspath(__file__)), "..", "..", ".."
)


def _get_latest_dagster_release() -> str:
Expand Down
10 changes: 8 additions & 2 deletions .buildkite/dagster-buildkite/dagster_buildkite/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@


def get_commit(rev):
return subprocess.check_output(["git", "rev-parse", "--short", rev]).decode("utf-8").strip()
return (
subprocess.check_output(["git", "rev-parse", "--short", rev])
.decode("utf-8")
.strip()
)


def get_commit_message(rev):
return (
subprocess.check_output(["git", "rev-list", "--format=%B", "--max-count=1", rev])
subprocess.check_output(
["git", "rev-list", "--format=%B", "--max-count=1", rev]
)
.decode("utf-8")
.strip()
)
Expand Down
32 changes: 24 additions & 8 deletions .buildkite/dagster-buildkite/dagster_buildkite/package_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ def _infer_package_type(directory: str) -> str:
return "example"
elif directory.startswith("python_modules/libraries/"):
return "extension"
elif directory in _INFRASTRUCTURE_PACKAGES or directory.startswith("integration_tests"):
elif directory in _INFRASTRUCTURE_PACKAGES or directory.startswith(
"integration_tests"
):
return "infrastructure"
else:
return "unknown"
Expand All @@ -62,8 +64,12 @@ def _infer_package_type(directory: str) -> str:
PytestExtraCommandsFunction: TypeAlias = Callable[
[AvailablePythonVersion, Optional[str]], List[str]
]
PytestDependenciesFunction: TypeAlias = Callable[[AvailablePythonVersion, Optional[str]], List[str]]
UnsupportedVersionsFunction: TypeAlias = Callable[[Optional[str]], List[AvailablePythonVersion]]
PytestDependenciesFunction: TypeAlias = Callable[
[AvailablePythonVersion, Optional[str]], List[str]
]
UnsupportedVersionsFunction: TypeAlias = Callable[
[Optional[str]], List[AvailablePythonVersion]
]


@dataclass
Expand Down Expand Up @@ -116,7 +122,9 @@ class PackageSpec:
Union[List[AvailablePythonVersion], UnsupportedVersionsFunction]
] = None
pytest_extra_cmds: Optional[Union[List[str], PytestExtraCommandsFunction]] = None
pytest_step_dependencies: Optional[Union[List[str], PytestDependenciesFunction]] = None
pytest_step_dependencies: Optional[Union[List[str], PytestDependenciesFunction]] = (
None
)
pytest_tox_factors: Optional[List[str]] = None
env_vars: Optional[List[str]] = None
tox_file: Optional[str] = None
Expand Down Expand Up @@ -152,7 +160,9 @@ def build_steps(self) -> List[BuildkiteTopLevelStep]:

for other_factor in tox_factors:
if callable(self.unsupported_python_versions):
unsupported_python_versions = self.unsupported_python_versions(other_factor)
unsupported_python_versions = self.unsupported_python_versions(
other_factor
)
else:
unsupported_python_versions = self.unsupported_python_versions or []

Expand Down Expand Up @@ -183,7 +193,9 @@ def build_steps(self) -> List[BuildkiteTopLevelStep]:
if isinstance(self.pytest_extra_cmds, list):
extra_commands_pre = self.pytest_extra_cmds
elif callable(self.pytest_extra_cmds):
extra_commands_pre = self.pytest_extra_cmds(py_version, other_factor)
extra_commands_pre = self.pytest_extra_cmds(
py_version, other_factor
)
else:
extra_commands_pre = []

Expand All @@ -192,7 +204,9 @@ def build_steps(self) -> List[BuildkiteTopLevelStep]:
if isinstance(self.pytest_step_dependencies, list):
dependencies = self.pytest_step_dependencies
elif callable(self.pytest_step_dependencies):
dependencies = self.pytest_step_dependencies(py_version, other_factor)
dependencies = self.pytest_step_dependencies(
py_version, other_factor
)

steps.append(
build_tox_step(
Expand Down Expand Up @@ -305,7 +319,9 @@ def skip_reason(self) -> Optional[str]:
PythonPackages.walk_dependencies(requirement)
)
if in_scope_changes:
logging.info(f"Building {self.name} because of changes to {in_scope_changes}")
logging.info(
f"Building {self.name} because of changes to {in_scope_changes}"
)
self._should_skip = False
return None

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
)
from dagster_buildkite.steps.docs import build_docs_steps
from dagster_buildkite.steps.trigger import build_trigger_step
from dagster_buildkite.utils import BuildkiteStep, is_release_branch, message_contains, safe_getenv
from dagster_buildkite.utils import (
BuildkiteStep,
is_release_branch,
message_contains,
safe_getenv,
)


def build_dagster_oss_main_steps() -> List[BuildkiteStep]:
Expand Down Expand Up @@ -50,7 +55,8 @@ def build_dagster_oss_main_steps() -> List[BuildkiteStep]:
"DAGSTER_UI_ONLY_OSS_CHANGE": (
"1" if not skip_if_no_dagster_ui_changes() else ""
),
"DAGSTER_CHECKOUT_DEPTH": _get_setting("DAGSTER_CHECKOUT_DEPTH") or "100",
"DAGSTER_CHECKOUT_DEPTH": _get_setting("DAGSTER_CHECKOUT_DEPTH")
or "100",
"OSS_COMPAT_SLIM": "1" if oss_compat_slim else "",
"DAGSTER_FROM_OSS": "1" if pipeline_name == "internal" else "0",
},
Expand Down
19 changes: 16 additions & 3 deletions .buildkite/dagster-buildkite/dagster_buildkite/python_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,16 @@

from dagster_buildkite.git import ChangedFiles, GitInfo

changed_filetypes = [".py", ".cfg", ".toml", ".yaml", ".ipynb", ".yml", ".ini", ".jinja"]
changed_filetypes = [
".py",
".cfg",
".toml",
".yaml",
".ipynb",
".yml",
".ini",
".jinja",
]


def _path_is_relative_to(p: Path, u: Path) -> bool:
Expand All @@ -30,7 +39,9 @@ def __init__(self, setup_path: Path):
# distribution if our setup.py doesn't implement setup() correctly
reload(distutils_core)

distribution = distutils_core.run_setup(str(setup_path / "setup.py"), stop_after="init")
distribution = distutils_core.run_setup(
str(setup_path / "setup.py"), stop_after="init"
)

self._install_requires = distribution.install_requires # type: ignore[attr-defined]
self._extras_require = distribution.extras_require # type: ignore[attr-defined]
Expand Down Expand Up @@ -156,7 +167,9 @@ def load_from_git(cls, git_info: GitInfo) -> None:
continue
processed |= {str(path_dir)}
assert path_dir.is_dir()
if (path_dir / "setup.py").exists() or (path_dir / "pyproject.toml").exists():
if (path_dir / "setup.py").exists() or (
path_dir / "pyproject.toml"
).exists():
try:
packages.append(PythonPackage(path_dir))
except:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,13 @@ def _base_docker_settings(self) -> Dict[str, object]:
"mount-buildkite-agent": True,
}

def on_python_image(self, image: str, env: Optional[List[str]] = None) -> "CommandStepBuilder":
def on_python_image(
self, image: str, env: Optional[List[str]] = None
) -> "CommandStepBuilder":
settings = self._base_docker_settings()
settings["image"] = f"{AWS_ACCOUNT_ID}.dkr.ecr.{AWS_ECR_REGION}.amazonaws.com/{image}"
settings["image"] = (
f"{AWS_ACCOUNT_ID}.dkr.ecr.{AWS_ECR_REGION}.amazonaws.com/{image}"
)
# Mount the Docker socket so we can run Docker inside of our container
# Mount /tmp from the host machine to /tmp in our container. This is
# useful if you need to mount a volume when running a Docker container;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ def build_graphql_python_client_backcompat_steps() -> List[CommandStep]:
"dagster-graphql-client query check",
)
.with_skip(
skip_graphql_if_no_changes_to_dependencies(["dagster", "dagster-graphql", "automation"])
skip_graphql_if_no_changes_to_dependencies(
["dagster", "dagster-graphql", "automation"]
)
)
.build()
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,7 @@ def build_dagster_ui_core_steps() -> List[CommandStep]:


def skip_if_no_dagster_ui_changes():
return skip_if_no_dagster_ui_components_changes() or skip_if_no_dagster_ui_core_changes()
return (
skip_if_no_dagster_ui_components_changes()
or skip_if_no_dagster_ui_core_changes()
)
11 changes: 9 additions & 2 deletions .buildkite/dagster-buildkite/dagster_buildkite/steps/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ def build_docs_steps() -> List[BuildkiteStep]:
# To fix this, run 'make mdx-format' in the /docs directory to update the snapshots.
# Be sure to check the diff to make sure the literalincludes are as you expect them."
CommandStepBuilder("docs code snippets")
.run("cd docs", "make next-dev-install", "make mdx-format", "git diff --exit-code")
.run(
"cd docs",
"make next-dev-install",
"make mdx-format",
"git diff --exit-code",
)
.with_skip(skip_if_no_docs_changes())
.on_test_image(AvailablePythonVersion.get_default())
.build(),
Expand Down Expand Up @@ -55,7 +60,9 @@ def build_docs_steps() -> List[BuildkiteStep]:
.on_test_image(AvailablePythonVersion.get_default())
.build(),
# Verify screenshot integrity.
build_tox_step("docs", "audit-screenshots", skip_reason=skip_if_no_docs_changes()),
build_tox_step(
"docs", "audit-screenshots", skip_reason=skip_if_no_docs_changes()
),
]

steps += [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ def build_celery_k8s_suite_steps() -> List[BuildkiteTopLevelStep]:
"-default",
"-markredis",
]
directory = os.path.join("integration_tests", "test_suites", "celery-k8s-test-suite")
directory = os.path.join(
"integration_tests", "test_suites", "celery-k8s-test-suite"
)
return build_integration_suite_steps(
directory,
pytest_tox_factors,
Expand All @@ -153,7 +155,9 @@ def build_daemon_suite_steps():

def build_auto_materialize_perf_suite_steps():
pytest_tox_factors = None
directory = os.path.join("integration_tests", "test_suites", "auto_materialize_perf_tests")
directory = os.path.join(
"integration_tests", "test_suites", "auto_materialize_perf_tests"
)
return build_integration_suite_steps(
directory,
pytest_tox_factors,
Expand Down Expand Up @@ -233,15 +237,19 @@ def build_integration_suite_steps(
).build_steps()


def k8s_integration_suite_pytest_extra_cmds(version: AvailablePythonVersion, _) -> List[str]:
def k8s_integration_suite_pytest_extra_cmds(
version: AvailablePythonVersion, _
) -> List[str]:
return [
"export DAGSTER_DOCKER_IMAGE_TAG=$${BUILDKITE_BUILD_ID}-" + version.value,
'export DAGSTER_DOCKER_REPOSITORY="$${AWS_ACCOUNT_ID}.dkr.ecr.us-west-2.amazonaws.com"',
"aws ecr get-login --no-include-email --region us-west-2 | sh",
]


def celery_k8s_integration_suite_pytest_extra_cmds(version: AvailablePythonVersion, _) -> List[str]:
def celery_k8s_integration_suite_pytest_extra_cmds(
version: AvailablePythonVersion, _
) -> List[str]:
cmds = [
'export AIRFLOW_HOME="/airflow"',
"mkdir -p $${AIRFLOW_HOME}",
Expand Down
Loading

0 comments on commit 871b1b1

Please sign in to comment.