Skip to content

Commit

Permalink
Bump ruff, drop autoflake, add darglint back (zenml-io#1279)
Browse files Browse the repository at this point in the history
* bump ruff version

* remove autoflake

* remove unused variable assignment

* remove autoflake

* ignore D401 errors

* add noqa to avoid exceptions

* add darglint back :(

* fix missing docstrings

* add darglint dependencies back

* fix docstring indentation

* Update .github/workflows/docstring.yml

Co-authored-by: Alexej Penner <[email protected]>

* fix linting errors

---------

Co-authored-by: Alexej Penner <[email protected]>
  • Loading branch information
strickvl and AlexejPenner authored Feb 1, 2023
1 parent b6871f3 commit a02769d
Show file tree
Hide file tree
Showing 26 changed files with 252 additions and 54 deletions.
2 changes: 2 additions & 0 deletions .darglint
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[darglint]
docstring_style=google
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,8 @@ jobs:
markdown-link-check:
uses: ./.github/workflows/markdown-link-check.yml

docstring-check:
uses: ./.github/workflows/docstring.yml

spell-check:
uses: ./.github/workflows/spellcheck.yml
25 changes: 25 additions & 0 deletions .github/workflows/docstring.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Docstring Check

on: workflow_call

jobs:
docstring:
name: docstringcheck
runs-on: ubuntu-latest
env:
ZENML_DEBUG: 1
ZENML_ANALYTICS_OPT_IN: false
PYTHONIOENCODING: "utf-8"

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.7
uses: actions/setup-python@v2
with:
python-version: "3.7"
- name: Install Dependencies
run: |
python -m pip install --upgrade pip setuptools
python -m pip install darglint
- name: Docstring Check
run: bash scripts/docstring.sh
2 changes: 1 addition & 1 deletion docs/mkdocstrings_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def generate_docs(
)

integration_file_contents = [INTEGRATION_DOCS_TITLE]
integrations_file_content = create_entity_docs(
create_entity_docs(
api_doc_file_dir=integrations_dev_doc_file_dir,
ignored_modules=["__init__.py", "__pycache__"],
sources_path=path / "integrations",
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@ server = ["fastapi", "uvicorn", "python-multipart", "python-jose", "fastapi-util
black = "^22.3.0"
pytest = "^6.2.4"
mypy = "^0.991"
ruff = "^0.0.223"
ruff = "^0.0.238"
coverage = { extras = ["toml"], version = "^5.5" }
pre-commit = "^2.14.0"
autoflake = "^1.4"
pyment = "^0.3.3"
tox = "^3.24.3"
hypothesis = "^6.43.1"
typing-extensions = ">=3.7.4"
darglint = "^1.8.1"

# pytest dev dependencies
pytest-randomly = "^3.10.1"
Expand Down Expand Up @@ -204,7 +204,7 @@ exclude = [
]
per-file-ignores = {}
select = ["D", "E", "F", "I", "I001", "Q"]
ignore = ["E501", "F401", "F403", "D301", "D403", "D407", "D213", "D203", "S101", "S104", "S105", "S106", "S107"]
ignore = ["E501", "F401", "F403", "D301", "D401", "D403", "D407", "D213", "D203", "S101", "S104", "S105", "S106", "S107"]
src = ["src", "test"]
# use Python 3.7 as the minimum version for autofixing
target-version = "py37"
Expand Down
10 changes: 10 additions & 0 deletions scripts/docstring.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
set -e
set -x

DOCSTRING_SRC=${1:-"src/zenml tests/harness"}

export ZENML_DEBUG=1
export ZENML_ANALYTICS_OPT_IN=false

darglint -v 2 $DOCSTRING_SRC
5 changes: 4 additions & 1 deletion scripts/format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ SRC=${1:-"src/zenml tests examples docs/mkdocstrings_helper.py"}

export ZENML_DEBUG=1
export ZENML_ANALYTICS_OPT_IN=false
autoflake --remove-all-unused-imports --recursive --remove-unused-variables --in-place $SRC --exclude=__init__.py

# autoflake replacement: removes unused imports and variables
ruff $SRC --select F401,F841 --fix --exclude "__init__.py" --isolated

# sorts imports
ruff $SRC --select I --fix --ignore D
black $SRC
4 changes: 2 additions & 2 deletions scripts/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ ruff $SRC_NO_TESTS
# TODO: Fix docstrings in tests and examples and remove the `--extend-ignore D` flag
ruff $TESTS_EXAMPLES --extend-ignore D

# TODO: remove this once ruff implements the feature
autoflake --remove-all-unused-imports --recursive --remove-unused-variables --in-place $SRC --exclude=__init__.py --check | ( grep -v "No issues detected" || true )
# autoflake replacement: checks for unused imports and variables
ruff $SRC --select F401,F841 --exclude "__init__.py" --isolated

black $SRC --check

Expand Down
6 changes: 5 additions & 1 deletion src/zenml/cli/artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ def artifact() -> None:
@cli_utils.list_options(ArtifactFilterModel)
@artifact.command("list", help="List all artifacts.")
def list_artifacts(**kwargs: Any) -> None:
"""List all artifacts."""
"""List all artifacts.
Args:
**kwargs: Keyword arguments to filter artifacts.
"""
cli_utils.print_active_config()
artifacts = Client().list_artifacts(**kwargs)

Expand Down
12 changes: 10 additions & 2 deletions src/zenml/cli/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ def cli_pipeline_run(python_file: str, config_path: str) -> None:
@pipeline.command("list", help="List all registered pipelines.")
@list_options(PipelineFilterModel)
def list_pipelines(**kwargs: Any) -> None:
"""List all registered pipelines."""
"""List all registered pipelines.
Args:
**kwargs: Keyword arguments to filter pipelines.
"""
cli_utils.print_active_config()
client = Client()
with console.status("Listing pipelines...\n"):
Expand Down Expand Up @@ -180,7 +184,11 @@ def runs() -> None:
@runs.command("list", help="List all registered pipeline runs.")
@list_options(PipelineRunFilterModel)
def list_pipeline_runs(**kwargs: Any) -> None:
"""List all registered pipeline runs for the filter."""
"""List all registered pipeline runs for the filter.
Args:
**kwargs: Keyword arguments to filter pipeline runs.
"""
cli_utils.print_active_config()

client = Client()
Expand Down
12 changes: 10 additions & 2 deletions src/zenml/cli/role.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ def role() -> None:
@role.command("list")
@list_options(RoleFilterModel)
def list_roles(**kwargs: Any) -> None:
"""List all roles that fulfill the filter requirements."""
"""List all roles that fulfill the filter requirements.
Args:
**kwargs: Keyword arguments to filter the list of roles.
"""
cli_utils.print_active_config()
client = Client()
with console.status("Listing roles...\n"):
Expand Down Expand Up @@ -287,7 +291,11 @@ def assignment() -> None:
@assignment.command("list")
@list_options(UserRoleAssignmentFilterModel)
def list_role_assignments(**kwargs: Any) -> None:
"""List all user role assignments that fulfill the filter requirements."""
"""List all user role assignments that fulfill the filter requirements.
Args:
kwargs: Keyword arguments.
"""
cli_utils.print_active_config()
client = Client()
with console.status("Listing roles...\n"):
Expand Down
6 changes: 5 additions & 1 deletion src/zenml/cli/stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,11 @@ def rename_stack(
@stack.command("list")
@list_options(StackFilterModel)
def list_stacks(**kwargs: Any) -> None:
"""List all stacks that fulfill the filter requirements."""
"""List all stacks that fulfill the filter requirements.
Args:
kwargs: Keyword arguments to filter the stacks.
"""
client = Client()
with console.status("Listing stacks...\n"):
stacks = client.list_stacks(**kwargs)
Expand Down
6 changes: 5 additions & 1 deletion src/zenml/cli/stack_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,11 @@ def generate_stack_component_list_command(

@list_options(ComponentFilterModel)
def list_stack_components_command(**kwargs: Any) -> None:
"""Prints a table of stack components."""
"""Prints a table of stack components.
Args:
kwargs: Keyword arguments to filter the components.
"""
client = Client()
with console.status(f"Listing {component_type.plural}..."):
kwargs["type"] = component_type
Expand Down
12 changes: 10 additions & 2 deletions src/zenml/cli/user_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ def describe_user(user_name_or_id: Optional[str] = None) -> None:
@user.command("list")
@list_options(UserFilterModel)
def list_users(**kwargs: Any) -> None:
"""List all users."""
"""List all users.
Args:
kwargs: Keyword arguments to filter the list of users.
"""
cli_utils.print_active_config()
client = Client()
with console.status("Listing stacks...\n"):
Expand Down Expand Up @@ -251,7 +255,11 @@ def team() -> None:
@team.command("list")
@list_options(TeamFilterModel)
def list_teams(**kwargs: Any) -> None:
"""List all teams that fulfill the filter requirements."""
"""List all teams that fulfill the filter requirements.
Args:
kwargs: The filter options.
"""
cli_utils.print_active_config()
client = Client()

Expand Down
9 changes: 8 additions & 1 deletion src/zenml/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,11 @@ def warn_unsupported_non_default_workspace() -> None:


def print_page_info(page: Page[T]) -> None:
"""Print all information pertaining to a page to show the amount of items and pages."""
"""Print all page information showing the number of items and pages.
Args:
page: The page to print the information for.
"""
declare(
f"Page `({page.page}/{page.total_pages})`, `{page.total}` items "
f"found for the applied filters."
Expand Down Expand Up @@ -1174,6 +1178,9 @@ def list_options(filter_model: Type[BaseFilterModel]) -> Callable[[F], F]:
Args:
filter_model: The filter model based on which to decorate the function.
Returns:
The inner decorator.
"""

def inner_decorator(func: F) -> F:
Expand Down
6 changes: 5 additions & 1 deletion src/zenml/cli/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ def workspace() -> None:
@workspace.command("list", hidden=True)
@list_options(WorkspaceFilterModel)
def list_workspaces(**kwargs: Any) -> None:
"""List all workspaces."""
"""List all workspaces.
Args:
**kwargs: Keyword arguments to filter the list of workspaces.
"""
warn_unsupported_non_default_workspace()
cli_utils.print_active_config()
client = Client()
Expand Down
11 changes: 5 additions & 6 deletions src/zenml/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,7 @@ def list_teams(
created: Use to filter by time of creation
updated: Use the last updated date for filtering
name: Use the team name for filtering
Returns:
The Team
"""
Expand Down Expand Up @@ -947,6 +948,7 @@ def list_roles(
created: Use to filter by time of creation
updated: Use the last updated date for filtering
name: Use the role name for filtering
Returns:
The Role
"""
Expand Down Expand Up @@ -1073,9 +1075,6 @@ def get_user_role_assignment(
Returns:
The role assignment.
Raises:
RuntimeError: If the role assignment does not exist.
"""
return self.zen_store.get_user_role_assignment(
user_role_assignment_id=role_assignment_id
Expand Down Expand Up @@ -1182,9 +1181,6 @@ def get_team_role_assignment(
Returns:
The role assignment.
Raises:
RuntimeError: If the role assignment does not exist.
"""
return self.zen_store.get_team_role_assignment(
team_role_assignment_id=team_role_assignment_id
Expand Down Expand Up @@ -1362,6 +1358,7 @@ def list_workspaces(
created: Use to filter by time of creation
updated: Use the last updated date for filtering
name: Use the team name for filtering
Returns:
The Team
"""
Expand Down Expand Up @@ -1773,6 +1770,7 @@ def activate_stack(
Raises:
KeyError: If the stack is not registered.
ZenKeyError: If the stack is not registered.
"""
# Make sure the stack is registered
try:
Expand Down Expand Up @@ -2797,6 +2795,7 @@ def list_run_steps(
cache_key: The cache_key of the run to filter by.
status: The name of the run to filter by.
num_outputs: The number of outputs for the step run
Returns:
A page with Pipeline fitting the filter description
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from typing import Any, cast

import great_expectations as ge # type: ignore[import]
import great_expectations as ge # type: ignore[import] # noqa
from great_expectations.checkpoint.types.checkpoint_result import ( # type: ignore[import]
CheckpointResult,
)
Expand Down
2 changes: 1 addition & 1 deletion src/zenml/materializers/pandas_materializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __init__(self, uri: str):
"""
super().__init__(uri)
try:
import pyarrow # type: ignore
import pyarrow # type: ignore # noqa

self.pyarrow_exists = True
except ImportError:
Expand Down
6 changes: 5 additions & 1 deletion src/zenml/models/component_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@ class ComponentFilterModel(ShareableWorkspaceScopedFilterModel):
user_id: Union[UUID, str] = Field(None, description="User of the stack")

def set_scope_type(self, component_type: str) -> None:
"""Set the type of component on which to perform the filtering to scope the response."""
"""Set the type of component on which to perform the filtering to scope the response.
Args:
component_type: The type of component to scope the query to.
"""
self.scope_type = component_type

def generate_filter(
Expand Down
Loading

0 comments on commit a02769d

Please sign in to comment.