From b00214ed5d7404c03bcb8caf61159eac6f53d77e Mon Sep 17 00:00:00 2001 From: Waynerv Date: Fri, 18 Jun 2021 10:18:32 +0800 Subject: [PATCH] centralize tool configurations --- docs/tutorial.md | 12 ++- tests/test_bake_project.py | 2 +- .../.bumpversion.cfg | 12 +++ {{cookiecutter.project_slug}}/.coveragerc | 14 --- {{cookiecutter.project_slug}}/makefile | 2 +- {{cookiecutter.project_slug}}/setup.cfg | 87 ++++++++++++++++--- {{cookiecutter.project_slug}}/tox.ini | 58 ------------- 7 files changed, 93 insertions(+), 94 deletions(-) create mode 100644 {{cookiecutter.project_slug}}/.bumpversion.cfg delete mode 100644 {{cookiecutter.project_slug}}/.coveragerc delete mode 100644 {{cookiecutter.project_slug}}/tox.ini diff --git a/docs/tutorial.md b/docs/tutorial.md index 623b5309..3d23e6ea 100644 --- a/docs/tutorial.md +++ b/docs/tutorial.md @@ -35,7 +35,7 @@ Go to this generated folder, the project layout should look like: ``` . -├── .coveragerc +├── .bumpversion.cfg ├── .editorconfig ├── .github │ ├── ISSUE_TEMPLATE.md @@ -58,17 +58,15 @@ Go to this generated folder, the project layout should look like: │ └── usage.md ├── makefile ├── mkdocs.yml -├── poetry.lock -├── pyproject.toml ├── my_package │ ├── __init__.py │ ├── cli.py │ └── my_package.py +├── pyproject.toml ├── setup.cfg -├── tests -│ ├── __init__.py -│ └── test_my_package.py -└── tox.ini +└── tests + ├── __init__.py + └── test_my_package.py ``` diff --git a/tests/test_bake_project.py b/tests/test_bake_project.py index 24bdd086..19a8289a 100644 --- a/tests/test_bake_project.py +++ b/tests/test_bake_project.py @@ -114,7 +114,7 @@ def test_bake_with_defaults(cookies): found_toplevel_files = [f.basename for f in result.project.listdir()] assert _DEPENDENCY_FILE in found_toplevel_files assert 'python_boilerplate' in found_toplevel_files - assert 'tox.ini' in found_toplevel_files + assert 'setup.cfg' in found_toplevel_files assert 'tests' in found_toplevel_files mkdocs_yml = os.path.join(result._project_dir, "mkdocs.yml") diff --git a/{{cookiecutter.project_slug}}/.bumpversion.cfg b/{{cookiecutter.project_slug}}/.bumpversion.cfg new file mode 100644 index 00000000..49f08edb --- /dev/null +++ b/{{cookiecutter.project_slug}}/.bumpversion.cfg @@ -0,0 +1,12 @@ +[bumpversion] +current_version = {{ cookiecutter.version }} +commit = True +tag = True + +[bumpversion:file:pyproject.toml] +search = version = "{current_version}" +replace = version = "{new_version}" + +[bumpversion:file:{{ cookiecutter.pkg_name }}/__init__.py] +search = __version__ = '{current_version}' +replace = __version__ = '{new_version}' diff --git a/{{cookiecutter.project_slug}}/.coveragerc b/{{cookiecutter.project_slug}}/.coveragerc deleted file mode 100644 index 542217f7..00000000 --- a/{{cookiecutter.project_slug}}/.coveragerc +++ /dev/null @@ -1,14 +0,0 @@ -[run] -# uncomment the following to omit files during running -#omit = -[report] -exclude_lines = - pragma: no cover - def __repr__ - if self.debug: - if settings.DEBUG - raise AssertionError - raise NotImplementedError - if 0: - if __name__ == .__main__.: - def main diff --git a/{{cookiecutter.project_slug}}/makefile b/{{cookiecutter.project_slug}}/makefile index 378536f8..dbf9a859 100644 --- a/{{cookiecutter.project_slug}}/makefile +++ b/{{cookiecutter.project_slug}}/makefile @@ -17,7 +17,7 @@ unittest: pytest coverage: - pytest --cov=$(sources) --cov-append --cov-report=term-missing tests + pytest --cov=$(sources) --cov-branch --cov-report=term-missing tests pre-commit: pre-commit run --all-files diff --git a/{{cookiecutter.project_slug}}/setup.cfg b/{{cookiecutter.project_slug}}/setup.cfg index a8db1264..0b648472 100644 --- a/{{cookiecutter.project_slug}}/setup.cfg +++ b/{{cookiecutter.project_slug}}/setup.cfg @@ -1,16 +1,3 @@ -[bumpversion] -current_version = {{ cookiecutter.version }} -commit = True -tag = True - -[bumpversion:file:pyproject.toml] -search = version = "{current_version}" -replace = version = "{new_version}" - -[bumpversion:file:{{ cookiecutter.pkg_name }}/__init__.py] -search = __version__ = '{current_version}' -replace = __version__ = '{new_version}' - [flake8] max-line-length = 120 max-complexity = 18 @@ -38,3 +25,77 @@ exclude = .git, [mypy] ignore_missing_imports = True {%- endif %} + +[coverage:run] +# uncomment the following to omit files during running +#omit = +[coverage:report] +exclude_lines = + pragma: no cover + def __repr__ + if self.debug: + if settings.DEBUG + raise AssertionError + raise NotImplementedError + if 0: + if __name__ == .__main__.: + def main + +[tox:tox] +isolated_build = true +envlist = py36, py37, py38, py39, format, lint, build + +[gh-actions] +python = + 3.9: py39 + 3.8: py38, format, lint, build + 3.7: py37 + 3.6: py36 + +[testenv] +allowlist_externals = pytest +extras = + test +passenv = * +setenv = + PYTHONPATH = {toxinidir} + PYTHONWARNINGS = ignore +commands = + pytest --cov={{ cookiecutter.pkg_name }} --cov-branch --cov-report=xml --cov-report=term-missing tests + +[testenv:format] +allowlist_externals = + isort + black +extras = + test +commands = + isort {{ cookiecutter.pkg_name }} + black {{ cookiecutter.pkg_name }} tests + +[testenv:lint] +allowlist_externals = + flake8 + {%- if cookiecutter.use_mypy == 'y' %} + mypy + {%- endif %} +extras = + test +commands = + flake8 {{ cookiecutter.pkg_name }} tests + {%- if cookiecutter.use_mypy == 'y' %} + mypy {{ cookiecutter.pkg_name }} tests + {%- endif %} + +[testenv:build] +allowlist_externals = + poetry + mkdocs + twine +extras = + doc + dev +commands = + poetry build + mkdocs build + twine check dist/* diff --git a/{{cookiecutter.project_slug}}/tox.ini b/{{cookiecutter.project_slug}}/tox.ini deleted file mode 100644 index 5e2985fe..00000000 --- a/{{cookiecutter.project_slug}}/tox.ini +++ /dev/null @@ -1,58 +0,0 @@ -[tox] -isolated_build = true -envlist = py36, py37, py38, py39, format, lint, build - -[gh-actions] -python = - 3.9: py39 - 3.8: py38, format, lint, build - 3.7: py37 - 3.6: py36 - -[testenv] -allowlist_externals = pytest -extras = - test -passenv = * -setenv = - PYTHONPATH = {toxinidir} - PYTHONWARNINGS = ignore -commands = - pytest --cov={{ cookiecutter.pkg_name }} --cov-append --cov-report=xml --cov-report=term-missing tests - -[testenv:format] -allowlist_externals = - isort - black -extras = - test -commands = - isort {{ cookiecutter.pkg_name }} - black {{ cookiecutter.pkg_name }} tests - -[testenv:lint] -allowlist_externals = - flake8 - {%- if cookiecutter.use_mypy == 'y' %} - mypy - {%- endif %} -extras = - test -commands = - flake8 {{ cookiecutter.pkg_name }} tests - {%- if cookiecutter.use_mypy == 'y' %} - mypy {{ cookiecutter.pkg_name }} tests - {%- endif %} - -[testenv:build] -allowlist_externals = - poetry - mkdocs - twine -extras = - doc - dev -commands = - poetry build - mkdocs build - twine check dist/*