Skip to content

Commit

Permalink
Adds linting rules
Browse files Browse the repository at this point in the history
  • Loading branch information
jevandezande committed Jul 30, 2024
1 parent ce91cab commit 3440b2b
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ repos:
# Run the linter
- id: ruff
args: [ --fix ]
exclude: '\{\{cookiecutter.package_name\}\}/'
# Run the formatter
- id: ruff-format
exclude: '\{\{cookiecutter.package_name\}\}/'

- repo: local
hooks:
Expand Down
30 changes: 16 additions & 14 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

PROTOCOL = Literal["git", "https"]
GITHUB_PRIVACY_OPTIONS = ["private", "internal", "public"]
MINUMUM_PYTHON_MINOR_VERSION = 12


def call(*inputs: str, **kwargs: Any) -> None:
Expand All @@ -35,7 +36,7 @@ def set_python_version() -> None:
"""Set the python version in pyproject.toml and .github/workflows/test.yml."""
python_version = f"{sys.version_info.major}.{sys.version_info.minor}"
logger.info(f"Settting {python_version=}")
if sys.version_info.minor < 9:
if sys.version_info.minor < MINUMUM_PYTHON_MINOR_VERSION:
logger.warn(f"{python_version=} should be upgraded to the latest avaiable python version.")

file_names = [
Expand Down Expand Up @@ -108,14 +109,13 @@ def process_dependency(dependency: str) -> str:
if not dependency:
raise ValueError("Blank dependency")

if len(split := dependency.split("@")) == 1:
return f'{dependency} = "*"'

if len(split) != 2:
raise ValueError(f"Unable to process {dependency=}")

name, version = split
return f'{name} = "{version}"'
match dependency.split("@"):
case [package]:
return f'{package} = "*"'
case [package, version]:
return f'{package} = "{version}"'
case _:
raise ValueError(f"Unable to process {dependency=}")


def process_dependencies(deps: str) -> str:
Expand Down Expand Up @@ -194,10 +194,12 @@ def github_setup(privacy: str, remote: str) -> None:

try:
call("gh", stdout=subprocess.DEVNULL)
except FileNotFoundError:
raise OSError("The GitHub CLI is not installed; install from https://cli.github.com/")
except subprocess.CalledProcessError:
raise OSError("Issue with GitHub CLI encountered")
except FileNotFoundError as e:
raise OSError(
"The GitHub CLI is not installed; install from https://cli.github.com/"
) from e
except subprocess.CalledProcessError as e:
raise OSError("Issue with GitHub CLI encountered") from e

call(f"gh repo create {{cookiecutter.package_name}} --{privacy} --remote {remote} --source .")
call(f"git branch --set-upstream-to={remote} master")
Expand Down Expand Up @@ -231,7 +233,7 @@ def main() -> None:
git_initial_commit()
git_add_remote("origin", "{{cookiecutter.project_url}}")

if "{{cookiecutter.github_setup}}" != "None": # type: ignore [comparison-overlap]
if "{{cookiecutter.github_setup}}" != "None": # type: ignore [comparison-overlap] # noqa: PLR0133
github_setup("{{cookiecutter.github_setup}}", "origin")

notes()
Expand Down
22 changes: 22 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,33 @@ line-length = 100

[tool.ruff.lint]
select = [
"B", # bugbear
"D", # pydocstyle
"E", # pycodestyle errors
"F", # pyflakes
"I", # isort
"N", # pep8-naming conventions
"W", # pycodestyle warnings
"C4", # comprehensions
"PL", # pylint
"PT", # flake8-pytest-style
"PIE", # misc lints
"PYI", # flake8-pyi
"TID", # tidy imports
"TCH", # type-checking imports
"RUF", # Ruff-specific rules
"RSE", # flake8-raise
"ICN001", # unconventional-import-alias
]
ignore = [
"N806", # Non-lowercase variable in function
"PLR0911", # Too many returns
"PLR0912", # Too many branches
"PLR0913", # Too many arguments to function call
"PLR0914", # Too many locals
"PLR0915", # Too many statements
"PLR1702", # Too many nested-blocks
"PLW2901", # Redifined loop name
]

[tool.ruff.lint.per-file-ignores]
Expand Down
22 changes: 22 additions & 0 deletions {{cookiecutter.package_name}}/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,33 @@ line-length = {{cookiecutter.line_length}}

[tool.ruff.lint]
select = [
"B", # bugbear
"D", # pydocstyle
"E", # pycodestyle errors
"F", # pyflakes
"I", # isort
"N", # pep8-naming conventions
"W", # pycodestyle warnings
"C4", # comprehensions
"PL", # pylint
"PT", # flake8-pytest-style
"PIE", # misc lints
"PYI", # flake8-pyi
"TID", # tidy imports
"TCH", # type-checking imports
"RUF", # Ruff-specific rules
"RSE", # flake8-raise
"ICN001", # unconventional-import-alias
]
ignore = [
"N806", # Non-lowercase variable in function
"PLR0911", # Too many returns
"PLR0912", # Too many branches
"PLR0913", # Too many arguments to function call
"PLR0914", # Too many locals
"PLR0915", # Too many statements
"PLR1702", # Too many nested-blocks
"PLW2901", # Redifined loop name
]

[tool.ruff.lint.per-file-ignores]
Expand Down
1 change: 0 additions & 1 deletion {{cookiecutter.package_name}}/tests/test_stub.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@

def test_stub() -> None:
"""Stub test to ensure the test suite runs."""
pass

0 comments on commit 3440b2b

Please sign in to comment.