Skip to content

Commit

Permalink
remove ruff, reorganize
Browse files Browse the repository at this point in the history
  • Loading branch information
emmyoop committed Jan 24, 2024
1 parent 8a282c6 commit 3cc8d27
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 110 deletions.
30 changes: 2 additions & 28 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,31 +59,5 @@ jobs:
run: |
hatch build
- name: "Show distributions"
run: ls -lh dist/

- name: "Check distribution descriptions"
run: |
twine check dist/*
- name: "Check wheel contents"
run: |
check-wheel-contents dist/*.whl --ignore W007,W008
- name: "Install wheel distributions"
run: |
find ./dist/dbt_common-*.whl -maxdepth 1 -type f | xargs python -m pip install --force-reinstall --find-links=dist/
# TODO: how to validate here? we did dbt --version previously. this checks it's there, but not that it can do anything. maybe it's enough?
- name: "Check wheel distributions"
run: |
pip freeze | grep dbt-common
- name: "Install source distributions"
run: |
find ./dist/dbt_common-*.gz -maxdepth 1 -type f | xargs python -m pip install --force-reinstall --find-links=dist/
# TODO: how to validate here? we did dbt --version previously. this checks it's there, but not that it can do anything. maybe it's enough?
- name: "Check source distributions"
run: |
pip freeze | grep dbt-common
- name: "Check build"
run: hatch run build:check-all
10 changes: 8 additions & 2 deletions dbt_common/clients/_jinja_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ def __init__(self, contents: str) -> None:

class BlockTag:
def __init__(
self, block_type_name: str, block_name: str, contents: Optional[str] = None, full_block: Optional[str] = None
self,
block_type_name: str,
block_name: str,
contents: Optional[str] = None,
full_block: Optional[str] = None,
) -> None:
self.block_type_name = block_type_name
self.block_name = block_name
Expand Down Expand Up @@ -363,4 +367,6 @@ def find_blocks(
def lex_for_blocks(
self, allowed_blocks: Optional[Set[str]] = None, collect_raw_data: bool = True
) -> List[Union[BlockData, BlockTag]]:
return list(self.find_blocks(allowed_blocks=allowed_blocks, collect_raw_data=collect_raw_data))
return list(
self.find_blocks(allowed_blocks=allowed_blocks, collect_raw_data=collect_raw_data)
)
15 changes: 11 additions & 4 deletions dbt_common/clients/jinja.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,13 @@ def _parse(self, source, name, filename):
return MacroFuzzParser(self, source, name, filename).parse()

def _compile(self, source, filename):
"""Override jinja's compilation.
"""
Use to stash the rendered source inside
Override jinja's compilation. Use to stash the rendered source inside
the python linecache for debugging when the appropriate environment
variable is set.
Expand All @@ -115,7 +119,8 @@ def new_context(
# parameters are not used, so enforce that.
if shared or locals:
raise Exception(
"The MacroFuzzTemplate.new_context() override cannot use the shared or locals parameters."
"The MacroFuzzTemplate.new_context() override cannot use the "
"shared or locals parameters."
)

parent = ChainMap(vars, self.globals) if self.globals else vars
Expand Down Expand Up @@ -544,4 +549,6 @@ def extract_toplevel_blocks(
`collect_raw_data` is `True`) `BlockData` objects.
"""
tag_iterator = TagIterator(text)
return BlockIterator(tag_iterator).lex_for_blocks(allowed_blocks=allowed_blocks, collect_raw_data=collect_raw_data)
return BlockIterator(tag_iterator).lex_for_blocks(
allowed_blocks=allowed_blocks, collect_raw_data=collect_raw_data
)
141 changes: 65 additions & 76 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,47 +41,50 @@ dependencies = [
]

[project.urls]
Homepage = "https://github.com/dbt-labs/dbt-common" # TODO: should this be dbt's homepage?
Homepage = "https://github.com/dbt-labs/dbt-common"

Repository = "https://github.com/dbt-labs/dbt-common.git"
Issues = "https://github.com/dbt-labs/dbt-common/issues"
Changelog = "https://github.com/dbt-labs/dbt-common/blob/main/CHANGELOG.md"

[tool.hatch.version]
path = "dbt_common/__about__.py"

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.hatch.build.targets.sdist]
exclude = [
"/.github",
"/.changes",
".changie.yaml",
".gitignore",
".pre-commit-config.yaml",
"CONTRIBUTING.md",
"/tests",
]

[tool.hatch.build.targets.wheel]
packages = ["dbt_common"]
### Default env & scripts

[tool.hatch.envs.default]
description = "Default environment with dependencies for running dbt-common"

[tool.hatch.envs.default.scripts]
proto = "protoc -I=./dbt_common/events --python_out=./dbt_common/events ./dbt_common/events/types.proto"

### Test settings, envs & scripts

[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}"

### Linting settings, envs & scripts

[tool.hatch.envs.lint]
description = "Env for running development commands for linting"
extra-dependencies = [
"black~=23.3",
"flake8",
"Flake8-pyproject",
"flake8-pyproject",
"flake8-docstrings",
"mypy~=1.3",
"pytest~=7.3", # needed for linting tests
"ruff==0.1.11",
"types-Jinja2~=2.11",
"types-jsonschema~=4.17",
"types-protobuf~=4.24.0",
Expand All @@ -99,69 +102,14 @@ all = [
black = "python -m black ."
flake8 = "python -m flake8 ."
mypy = "python -m mypy ."
format = ["black {args:.}", "ruff --fix --exit-non-zero-on-fix {args:.}"]

[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]
line-length = 99
select = [
"E", # Pycodestyle
"F", # Pyflakes
"W", # Whitespace
"D", # Pydocs
]
ignore = [
# Missing docstring in public module -- often docs handled within classes
"D100",
# Missing docstring in public class
"D101",
# Missing docstring in public method
"D102",
# Missing docstring in public function
"D103",
# Missing docstring in public package -- often docs handled within files not __init__.py
"D104",
# Missing docstring in magic method
"D105",
# Missing docstring in public nested class
"D106",
# Missing docstring in __init__
"D107",
]
# Let ruff autofix these errors.
# F401 - Unused imports.
# E501 - Line too long.
# W292 - No newline at end of file.
fixable = ["F401", "E501", "W292"]
exclude = [
"dbt_common/events/types_pb2.py",
"env*",
"third-party-stubs/*",
]

[tool.ruff.pydocstyle]
convention = "google"

[tool.black]
extend-exclude = "dbt_common/events/types_pb2.py"
line-length = 99
target-version = ['py38']

[tool.flake8]
max-line-length = 99
select = ["E", "W", "F"]
ignore = ["E203", "E501", "E741", "W503", "W504"]
exclude = [
Expand All @@ -170,6 +118,7 @@ exclude = [
"env*"
]
per-file-ignores = ["*/__init__.py: F401"]
docstring-convention = "google"

[tool.mypy]
mypy_path = "third-party-stubs/"
Expand All @@ -184,3 +133,43 @@ exclude = [
"env*",
"third-party-stubs/*",
]

### Build settings, envs & scripts

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.hatch.build.targets.sdist]
exclude = [
"/.github",
"/.changes",
".changie.yaml",
".gitignore",
".pre-commit-config.yaml",
"CONTRIBUTING.md",
"/tests",
]

[tool.hatch.build.targets.wheel]
packages = ["dbt_common"]

[tool.hatch.envs.build]
detached = true
features = ["build"]

[tool.hatch.envs.build.scripts]
check-all = [
"- check-wheel",
"- check-sdist",
]
check-wheel = [
"twine check dist/*",
"find ./dist/dbt_common-*.whl -maxdepth 1 -type f | xargs python -m pip install --force-reinstall --find-links=dist/",
"pip freeze | grep dbt-common",
]
check-sdist = [
"check-wheel-contents dist/*.whl --ignore W007,W008",
"find ./dist/dbt_common-*.gz -maxdepth 1 -type f | xargs python -m pip install --force-reinstall --find-links=dist/",
"pip freeze | grep dbt-common",
]

0 comments on commit 3cc8d27

Please sign in to comment.