From 3bfe1ad1313579117bb10921400da68a55a76e0d Mon Sep 17 00:00:00 2001 From: Corey Oordt Date: Sun, 5 Dec 2021 08:34:15 -0600 Subject: [PATCH] Added pre-commit configuration and configuration for the tools. --- .pre-commit-config.yaml | 51 +++++++++++++++++++++++++ README.md | 1 + pyproject.toml | 82 +++++++++++++++++++++++++++++++++++++++++ requirements.txt | 4 +- setup.cfg | 36 ++++++++++++++++++ setup.py | 70 +++++++++++++++++++++++------------ 6 files changed, 218 insertions(+), 26 deletions(-) create mode 100644 .pre-commit-config.yaml create mode 100644 pyproject.toml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..9e54b49 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,51 @@ +repos: + - repo: https://github.com/timothycrosley/isort + rev: 5.10.1 + hooks: + - id: isort + additional_dependencies: [toml] + - repo: https://github.com/python/black + rev: 21.11b1 + hooks: + - id: black + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.0.1 + hooks: + - id: check-added-large-files + - id: check-case-conflict + - id: check-executables-have-shebangs + - id: check-json + - id: check-merge-conflict + - id: check-shebang-scripts-are-executable + - id: check-symlinks + - id: check-toml + - id: check-yaml + - id: debug-statements + - id: end-of-file-fixer + exclude: "^tests/resources/" + - id: fix-byte-order-marker + - id: fix-encoding-pragma + args: ["--remove"] + - id: requirements-txt-fixer + - repo: https://gitlab.com/pycqa/flake8 + rev: 3.9.2 + hooks: + - id: flake8 + - repo: https://github.com/pycqa/pydocstyle + rev: 6.1.1 + hooks: + - id: pydocstyle + exclude: test.* + additional_dependencies: [toml] + - repo: https://github.com/terrencepreilly/darglint + rev: v1.8.1 + hooks: + - id: darglint + args: + - -v 2 + - "--message-template={path}:{line} in `{obj}`:\n {msg_id}: {msg}" + - --strictness=short + - repo: https://github.com/econchick/interrogate + rev: 1.5.0 # or master if you're bold + hooks: + - id: interrogate diff --git a/README.md b/README.md index 7386fca..0f8741b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # Django Categories [![Jazzband](https://jazzband.co/static/img/badge.svg)](https://jazzband.co/) +[![codecov](https://codecov.io/gh/jazzband/django-categories/branch/master/graph/badge.svg?token=rW8mpdZqWQ)](https://codecov.io/gh/jazzband/django-categories) Django Categories grew out of our need to provide a basic hierarchical taxonomy management system that multiple applications could use independently or in concert. diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..126de67 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,82 @@ +[build-system] +requires = [ + "setuptools >= 40.9.0", + "wheel", +] +build-backend = "setuptools.build_meta" + +[tool.coverage.run] +branch = true +omit = ["**/test_*.py"] + +[tool.coverage.report] +omit = [ + "*site-packages*", + "*tests*", + "*.tox*", +] +show_missing = true +exclude_lines = [ + "raise NotImplementedError", + "pragma: no-coverage", +] + +[tool.interrogate] +ignore-init-method = true +ignore-init-module = false +ignore-magic = true +ignore-semiprivate = false +ignore-private = false +ignore-property-decorators = false +ignore-module = false +ignore-nested-functions = true +ignore-nested-classes = true +ignore-setters = false +fail-under = 95 +exclude = ["setup.py", "docs", "build", "test"] +ignore-regex = ["^get$", "^mock_.*", ".*BaseClass.*"] +verbose = 0 +quiet = false +whitelist-regex = [] +color = true + +[tool.isort] +py_version = "38" +force_grid_wrap = 0 +use_parentheses = true +line_length = 88 +known_typing = ["typing", "types", "typing_extensions", "mypy", "mypy_extensions"] +sections = ["FUTURE", "TYPING", "STDLIB", "THIRDPARTY", "FIRSTPARTY", "LOCALFOLDER"] +include_trailing_comma = true +profile = "black" +multi_line_output = 3 +indent = 4 +color_output = true + +[tool.pydocstyle] +convention = "google" +add-ignore = ["D107", "D200", "D212"] +match = "(?!test_).*\\.py" + +[tool.black] +line-length = 119 +target-version = ['py38', 'py39'] +include = '\.pyi?$' +exclude = ''' +/( + \.eggs + | \.git + | \.hg + | \.mypy_cache + | \.tox + | \.venv + | _build + | buck-out + | build + | dist + # The following are specific to Black, you probably don't want those. + | blib2to3 + | tests/data + | profiling +)/ +''' diff --git a/requirements.txt b/requirements.txt index 0d767c5..b0a4601 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ -django-mptt==0.11.0 -unicode-slugify==0.1.3 +django-mptt +unicode-slugify diff --git a/setup.cfg b/setup.cfg index 2a9acf1..bfc227d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,2 +1,38 @@ +[metadata] +name = django-categories +description = A way to handle one or more hierarchical category trees in django. +long_description = file:README.md +long_description_content_type = "text/markdown" +author = Corey Oordt +author_email = coreyoordt@gmail.com +url = http://github.com/jazzband/django-categories +classifiers = + Framework :: Django + +[options] +zip_safe=False +include_package_data=True + +[options.packages.find] +exclude = + example* + docs + build +include = categories + +[flake8] +ignore = D203,W503,E501 +exclude = + .git + .tox + docs + build + dist + doc_src +max-line-length = 119 + +[darglint] +ignore=DAR402 + [bdist_wheel] universal = 1 diff --git a/setup.py b/setup.py index 834ce3c..da41c03 100644 --- a/setup.py +++ b/setup.py @@ -1,31 +1,53 @@ -from setuptools import setup, find_packages +"""The setup script.""" + +from pathlib import Path + +from setuptools import setup + import categories -import os -try: - long_description = open('README.md').read() -except IOError: - long_description = '' -try: - reqs = open(os.path.join(os.path.dirname(__file__), 'requirements.txt')).read() -except (IOError, OSError): - reqs = '' +def parse_reqs(filepath: str) -> list: + """ + Parse a file path containing requirements and return a list of requirements. + + Will properly follow ``-r`` and ``--requirements`` links like ``pip``. This + means nested requirements will be returned as one list. + + Other ``pip``-specific lines are excluded. + + Args: + filepath: The path to the requirements file + + Returns: + All the requirements as a list. + """ + path = Path(filepath) + reqstr = path.read_text() + reqs = [] + for line in reqstr.splitlines(): + line = line.strip() + if line == "": + continue + elif not line or line.startswith("#"): + # comments are lines that start with # only + continue + elif line.startswith("-r") or line.startswith("--requirement"): + _, new_filename = line.split() + new_file_path = path.parent / new_filename + reqs.extend(parse_reqs(new_file_path)) + elif line.startswith("-f") or line.startswith("-i") or line.startswith("--"): + continue + elif line.startswith("-Z") or line.startswith("--always-unzip"): + continue + else: + reqs.append(line) + return reqs + + +requirements = parse_reqs("requirements.txt") setup( - name='django-categories', version=categories.get_version(), - description='A way to handle one or more hierarchical category trees in django.', - long_description=long_description, - long_description_content_type="text/markdown", - author='Corey Oordt', - author_email='coreyoordt@gmail.com', - include_package_data=True, - url='http://github.com/jazzband/django-categories', - packages=find_packages(exclude=['example*', ]), - classifiers=[ - 'Framework :: Django', - ], - install_requires=reqs, - dependency_links=[] + install_requires=requirements, )