From 198b6badf120680f3aa721b6c58823c07783c088 Mon Sep 17 00:00:00 2001 From: Emily Rockman Date: Tue, 16 Jan 2024 14:54:35 -0600 Subject: [PATCH] move around hatch envs --- CONTRIBUTING.md | 20 ++++++------ dbt_common/semver.py | 8 ++--- pyproject.toml | 75 ++++++++++++++++++++++++-------------------- 3 files changed, 54 insertions(+), 49 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ea1f0e05..c5120724 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -93,15 +93,17 @@ Once you're able to manually test that your code change is working as expected, See the pyproject.toml for a complete list of custom commands. See the h[atch docs](https://hatch.pypa.io/latest/cli/reference/) for a description of built in commands and flags. These are the most useful custom commands to use while developing. -|Command|Description| -|---|---| -|`hatch run test`|run all tests| -|`hatch run lint-all`|run black, flake8 and mypy checks| -|`hatch run lint-black`|run black| -|`hatch run lint-flake8`|run flake8| -|`hatch run lint-mypy`|run mypy| -|`hatch run format`|run TODO| -|`hatch run proto`|regenerate protobuf definitions| +|Type|Command|Description| +|---|---|---| +|Utility|`hatch run proto`|regenerate protobuf definitions| +|Testing|`hatch run test:unit`|run all tests| +|Testing|`hatch shell test`|Drops you into a shell env set up for manual testing| +|Code Quality|`hatch run lint:all`|run black, flake8 and mypy checks| +|Code Quality|`hatch run lint:black`|run black| +|Code Quality|`hatch run lint:flake8`|run flake8| +|Code Quality|`hatch run lint:mypy`|run mypy| +|Testing|`hatch shell lint`|Drops you into a shell env set up for manualcode quality checks| +|Code Quality|`hatch fmt`|runs ruff on all code| ## Debugging diff --git a/dbt_common/semver.py b/dbt_common/semver.py index 951f4e8e..4b6abe49 100644 --- a/dbt_common/semver.py +++ b/dbt_common/semver.py @@ -36,9 +36,7 @@ class VersionSpecification(dbtClassMixin): (?P{num_no_leading_zeros})\. (?P{num_no_leading_zeros})\. (?P{num_no_leading_zeros}) -""".format( - num_no_leading_zeros=_NUM_NO_LEADING_ZEROS -) +""".format(num_no_leading_zeros=_NUM_NO_LEADING_ZEROS) _VERSION_EXTRA_REGEX = r""" (\-? @@ -47,9 +45,7 @@ class VersionSpecification(dbtClassMixin): (\+ (?P {alpha}(\.{alpha})*))? -""".format( - alpha_no_leading_zeros=_ALPHA_NO_LEADING_ZEROS, alpha=_ALPHA -) +""".format(alpha_no_leading_zeros=_ALPHA_NO_LEADING_ZEROS, alpha=_ALPHA) _VERSION_REGEX_PAT_STR = r""" diff --git a/pyproject.toml b/pyproject.toml index 5330b9f7..a8480cd7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,28 +39,6 @@ dependencies = [ "requests<3.0.0", "typing-extensions~=4.4", ] -[project.optional-dependencies] -lint = [ - "black~=23.3", - "flake8", - "Flake8-pyproject", - "mypy~=1.3", - "ruff==0.1.11", - "types-Jinja2~=2.11", - "types-jsonschema~=4.17", - "types-protobuf~=4.24.0", - "types-python-dateutil~=2.8", - "types-PyYAML~=6.0", - "types-requests<2.31.0" # types-requests 2.31.0.8 requires urllib3>=2, but we pin urllib3 ~= 1.0 because of openssl requirement for requests - -] -test = [ - "pytest~=7.3", - "pytest-xdist~=3.2", - "hypothesis~=6.87" -] -[[tool.hatch.envs.test.matrix]] -python = ["3.8","3.9","3.10", "3.11"] [project.urls] Homepage = "https://github.com/dbt-labs/dbt-common" # TODO: should this be dbt's homepage? @@ -90,22 +68,51 @@ packages = ["dbt_common"] path = "dbt_common/__about__.py" [tool.hatch.envs.default] -description = "Env for running development commands like pytest & linting" -features = ["lint", "test"] +description = "Default environment with dependencies for running dbt-common" -# these are the commands that you run with `hatch run ` for local dev & CI [tool.hatch.envs.default.scripts] -test = "- python -m pytest {args:tests/unit}" -lint-all = [ - "- lint-black", - "- lint-flake8", - "- lint-mypy", +proto = "protoc -I=./dbt_common/events --python_out=./dbt_common/events ./dbt_common/events/types.proto" + +[tool.hatch.envs.lint] +description = "Env for running development commands for linting" +extra-dependencies = [ + "black~=23.3", + "flake8", + "Flake8-pyproject", + "mypy~=1.3", + "ruff==0.1.11", + "types-Jinja2~=2.11", + "types-jsonschema~=4.17", + "types-protobuf~=4.24.0", + "types-python-dateutil~=2.8", + "types-PyYAML~=6.0", + "types-requests<2.31.0" # types-requests 2.31.0.8 requires urllib3>=2, but we pin urllib3 ~= 1.0 because of openssl requirement for requests + ] -lint-black = "python -m black ." -lint-flake8 = "python -m flake8 ." -lint-mypy = "python -m mypy ." + +[tool.hatch.envs.lint.scripts] +all = [ + "- black", + "- flake8", + "- mypy", +] +black = "python -m black ." +flake8 = "python -m flake8 ." +mypy = "python -m mypy ." format = ["black {args:.}", "ruff --fix --exit-non-zero-on-fix {args:.}"] -proto = "protoc -I=./dbt_common/events --python_out=./dbt_common/events ./dbt_common/events/types.proto" + +[tool.hatch.envs.test] +description = "Env for running development commands for testing" +extra-dependencies = [ + "pytest~=7.3", + "pytest-xdist~=3.2", + "hypothesis~=6.87" +] +[[tool.hatch.envs.test.matrix]] +python = ["3.8","3.9","3.10", "3.11"] + +[tool.hatch.envs.test.scripts] +unit = "- python -m pytest {args:tests/unit}" # TODO: should ruff replace flake8? [tool.ruff]