Skip to content

Commit

Permalink
Add custom configs (#16)
Browse files Browse the repository at this point in the history
* custom lint settings

* Added custom linting configs

* Switch to coveragerc

* Make pytest config

* Reorganized pyproject.toml
  • Loading branch information
turnerm committed Jun 1, 2023
1 parent 66e9930 commit fd42c79
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 105 deletions.
2 changes: 2 additions & 0 deletions .config/black.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[tool.black]
line-length = 79
22 changes: 22 additions & 0 deletions .config/coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[report]
omit =
"*/setup.py"
"*/python?.?/*"
"*/venv/*"
"*/site-packages/*"
"*/tests/*"
"*__init__*"

exclude_lines =
"pragma: no cover" # Have to re-enable the standard pragma
"def __repr__" # Don't complain about missing
"if self.debug" # debug-only code
"raise AssertionError" # Don't complain if tests don't hit
"raise NotImplementedError" # defensive assertion code
"if 0:" # Don't complain if non-runnable code
"if __name__ == .__main__.:" # isn't run

[paths]
source =
"src/hdx"
"*/site-packages/hdx"
3 changes: 2 additions & 1 deletion .config/pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ repos:
rev: 23.3.0
hooks:
- id: black
args: [--config, .config/black.toml]
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.267
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
args: [--config, .config/ruff.toml, --fix, --exit-non-zero-on-fix]
- repo: https://github.com/jazzband/pip-tools
rev: 6.13.0
hooks:
Expand Down
4 changes: 4 additions & 0 deletions .config/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[pytest]
pythonpath = "src"
addopts = "--color=yes"
log_cli = 1
14 changes: 14 additions & 0 deletions .config/ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
line-length = 79
exclude = ["_version.py"]
ignore = [
"E501" # Line too long
]
# List of rules: https://beta.ruff.rs/docs/rules/
select = [
"E", # pycodestyle - default
"F", # pyflakes - default
"I" # isort
]

[isort]
known-local-folder = ["hdx"]
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ To check if your changes pass pre-commit without committing, run:

To run the tests and view coverage, execute:

python -m pytest --cov hdx
pytest -c .config/pytest.ini --cov hdx --cov-config .config/coveragerc

Follow the example set out already in ``api.rst`` as you write the documentation.

Expand Down
154 changes: 54 additions & 100 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,107 +1,11 @@
#########################
# General Configuration #
# Project Configuration #
#########################

# Build

[build-system]
requires = ["hatchling", "hatch-vcs"]
build-backend = "hatchling.build"

# Versioning

[tool.hatch.version]
source = "vcs"

[tool.hatch.version.raw-options]
local_scheme = "no-local-version"
version_scheme = "python-simplified-semver"

# Publishing

[tool.hatch.publish.index]
disable = true

# Linting tools

[tool.black]
line-length = 79

[tool.ruff]
line-length = 79
exclude = ["_version.py"]
ignore = [
"E501" # Line too long
]
# List of rules: https://beta.ruff.rs/docs/rules/
select = [
"E", # pycodestyle - default
"F", # pyflakes - default
"I" # isort
]

[tool.ruff.isort]
known-local-folder = ["hdx"]

# Tests

[tool.pytest.ini_options]
pythonpath = "src"
addopts = "--color=yes"
log_cli = 1

[tool.hatch.envs.test]
features = ["html", "email", "test"]

[tool.hatch.envs.test.scripts]
test = 'pytest --cov=hdx --no-cov-on-fail --junitxml=.tox/test-results.xml --cov-report=xml --cov-report=term-missing'

[[tool.hatch.envs.test.matrix]]
python = ["3.11"]

[tool.hatch.envs.lint]
detached = true
dependencies = [
"black",
"ruff",
]

[tool.hatch.envs.lint.scripts]
style = [
"ruff {args:.}",
"black --check --diff {args:.}",
]
# Not used for anything at the moment
fmt = [
"black {args:.}",
"ruff --fix {args:.}",
]

[tool.coverage.report]
omit = [
"*/setup.py",
"*/python?.?/*",
"*/venv/*",
"*/site-packages/*",
"*/tests/*",
"*__init__*"
]
exclude_lines = [
"pragma: no cover", # Have to re-enable the standard pragma
"def __repr__", # Don't complain about missing
"if self.debug", # debug-only code
"raise AssertionError", # Don't complain if tests don't hit
"raise NotImplementedError", # defensive assertion code
"if 0:", # Don't complain if non-runnable code
"if __name__ == .__main__.:" # isn't run
]

#########################
# Project Configuration #
#########################

# Project

[project]
name = "hdx-python-utilities"
description = "HDX Python Utilities for streaming tabular data, date and time handling and other helpful functions"
Expand Down Expand Up @@ -163,6 +67,11 @@ email = ["email_validator"]
test = ["pytest", "pytest-cov", "pytest-loguru"]
dev = ["pre-commit"]


#########
# Hatch #
#########

# Build

[tool.hatch.build.targets.wheel]
Expand All @@ -171,12 +80,57 @@ packages = ["src/hdx"]
[tool.hatch.build.hooks.vcs]
version-file = "src/hdx/utilities/_version.py"

# Versioning

[tool.hatch.version]
source = "vcs"

[tool.hatch.version.raw-options]
local_scheme = "no-local-version"
version_scheme = "python-simplified-semver"

# Publishing

[tool.hatch.publish.index]
disable = true

# Tests

[tool.coverage.paths]
source = ["src/hdx", "*/site-packages/hdx"]
[tool.hatch.envs.test]
features = ["html", "email", "test"]

[tool.hatch.envs.test.scripts]
test = """
pytest -c .config/pytest.ini --cov=hdx
--cov-config=.config/coveragerc --no-cov-on-fail
--junitxml=.tox/test-results.xml --cov-report=xml
--cov-report=term-missing"
"""

[[tool.hatch.envs.test.matrix]]
python = ["3.11"]

[tool.hatch.envs.lint]
detached = true
dependencies = [
"black",
"ruff",
]

[tool.hatch.envs.lint.scripts]
style = [
"ruff --config .config/ruff.toml {args:.}",
"black --config .config/black.toml --check --diff {args:.}",
]
# Not used for anything at the moment
fmt = [
"black --config .config/black.toml {args:.}",
"ruff --config .config/ruff.toml --fix {args:.}",
]

# Pydoc Markdown - will be moved
##################
# PyDoc Markdown #
##################

[[tool.pydoc-markdown.loaders]]
type = "python"
Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ click==8.1.3
# via typer
colorama==0.4.6
# via typer
coverage[toml]==7.2.6
coverage[toml]==7.2.7
# via pytest-cov
decorator==5.1.1
# via validators
Expand Down Expand Up @@ -127,7 +127,7 @@ rfc3986==2.0.0
# via frictionless
rich==13.3.5
# via typer
ruamel-yaml==0.17.27
ruamel-yaml==0.17.29
# via hdx-python-utilities (pyproject.toml)
ruamel-yaml-clib==0.2.7
# via ruamel-yaml
Expand Down Expand Up @@ -168,7 +168,7 @@ webencodings==0.5.1
# via html5lib
xlrd==2.0.1
# via hdx-python-utilities (pyproject.toml)
xlsxwriter==3.1.1
xlsxwriter==3.1.2
# via tableschema-to-template
xlwt==1.3.0
# via hdx-python-utilities (pyproject.toml)
Expand Down

0 comments on commit fd42c79

Please sign in to comment.