Commit

Improvements

1. Always use pytest
2. Flit initialization improvements
3. Immediately initialize pipenv
Daniel Moch committed 5 years ago (Tree)

Diffstat

 cookiecutter.json | 2 
 hooks/post_gen_project.py | 11 
 {{cookiecutter.project_slug}}/.gitignore | 4 
 {{cookiecutter.project_slug}}/Makefile | 9 
 {{cookiecutter.project_slug}}/Pipfile | 5 
 {{cookiecutter.project_slug}}/pyproject.toml | 5 
 {{cookiecutter.project_slug}}/tests/__init__.py | 3 
 {{cookiecutter.project_slug}}/tests/test_{{cookiecutter.project_slug}}.py | 26 
 {{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/__init__.py | 16 

cookiecutter.json

8 8 "project_short_description": "Flit Boilerplate contains all the boilerplate you need to create a Python Flit package.",
9 9 "pypi_username": "{{ cookiecutter.github_username }}",
10 10 "version": "0.1.0",
11 - "use_pytest": "y",
12 11 "use_pipenv": "y",
12 + "script_entrypoint": "y",
13 13 "open_source_license": ["MIT license", "BSD license", "ISC license", "Apache Software License 2.0", "GNU General Public License v3", "Not open source"]
14 14 }

hooks/post_gen_project.py

1 -#!/usr/bin/env python
1 +#!/usr/bin/env python3
2 2 import os
3 +import subprocess
3 4
4 5 PROJECT_DIRECTORY = os.path.realpath(os.path.curdir)
5 6
. . .
10 11
11 12 if __name__ == '__main__':
12 13
13 - if '{{ cookiecutter.use_pytest }}' == 'y':
14 - remove_file('tests/__init__.py')
15 - else:
16 - remove_file('pytest.ini')
17 -
18 14 if 'Not open source' == '{{ cookiecutter.open_source_license }}':
19 15 remove_file('LICENSE')
20 16
21 17 if '{{ cookiecutter.use_pipenv }}' == 'n':
22 18 remove_file('Pipfile')
19 + else:
20 + subprocess.run(['pipenv', 'lock', '--dev'])
21 + subprocess.run(['pipenv', 'sync', '--dev'])

{{cookiecutter.project_slug}}/.gitignore (created)

1 +dist/
2 +.coverage
3 +.pytest_cache/
4 +htmlcov/

{{cookiecutter.project_slug}}/Makefile

25 25 export PRINT_HELP_PYSCRIPT
26 26
27 27 BROWSER := python -c "$$BROWSER_PYSCRIPT"
28 +
29 +# Comment out the following line to run outside of Pipenv
28 30 {%- if cookiecutter.use_pipenv == 'y' %}
29 31 PIPENV := pipenv run
30 32 {%- else %}
31 -PIPENV :=
33 +# PIPENV := pipenv run
32 34 {%- endif %}
33 35
34 36 help:
. . .
61 63 $(PIPENV) python -m pytest
62 64
63 65 coverage: ## check code coverage quickly with the default Python
64 - $(PIPENV) coverage run --source {{ cookiecutter.project_slug }} -m pytest
66 + $(PIPENV) python -m pytest
65 67 $(PIPENV) coverage report -m
66 68 $(PIPENV) coverage html
67 69 $(BROWSER) htmlcov/index.html
. . .
75 77
76 78 install: clean ## install the package to the active Python's site-packages
77 79 $(PIPENV) flit install
80 +
81 +debug: install ## debug the package from site packages
82 + $(PIPENV) pudb3 `$(PIPENV) which {{ cookiecutter.project_slug }}` install

{{cookiecutter.project_slug}}/Pipfile

6 6 [packages]
7 7
8 8 [dev-packages]
9 -{%- if cookiecutter.use_pytest == 'y' %}
10 -pytest = "*"
9 +pytest = "<3.7.0"
11 10 pytest-cov = "*"
12 11 pytest-pylint = "*"
13 -{%- endif %}
12 +pudb = "*"
14 13
15 14 [requires]
16 15 python_version = "3.7"

{{cookiecutter.project_slug}}/pyproject.toml

19 19 {% elif cookiecutter.open_source_license == 'GNU General Public License v3' -%}
20 20 classifiers = ["License :: OSI Approved :: GNU General Public License v3 (GPLv3)"]
21 21 {% endif %}
22 +{% if cookiecutter.script_entrypoint == 'y' -%}
23 +
24 +[tool.flit.scripts]
25 +{{ cookiecutter.project_slug }} = "{{cookiecutter.project_slug}}:main"
26 +{% endif %}

{{cookiecutter.project_slug}}/tests/__init__.py (deleted)

1 -# -*- coding: utf-8 -*-
2 -
3 -"""Unit test package for {{ cookiecutter.project_slug }}."""

{{cookiecutter.project_slug}}/tests/test_{{cookiecutter.project_slug}}.py

1 1 # -*- coding: utf-8 -*-
2 2
3 -"""Tests for `{{ cookiecutter.project_slug }}` package."""
3 +"""Tests for {{ cookiecutter.project_slug }} module"""
4 4
5 -{% if cookiecutter.use_pytest == 'y' -%}
6 5 import pytest
7 -{% else %}
8 -import unittest
9 -{%- endif %}
10 6
11 -from {{ cookiecutter.project_slug }} import {{ cookiecutter.project_slug }}
12 -
13 -{%- if cookiecutter.use_pytest == 'y' %}
14 -
7 +import {{ cookiecutter.project_slug }}
15 8
16 9 @pytest.fixture
17 10 def response():
. . .
27 20 """Sample pytest test function with the pytest fixture as an argument."""
28 21 # from bs4 import BeautifulSoup
29 22 # assert 'GitHub' in BeautifulSoup(response.content).title.string
30 -{%- else %}
31 -
32 -
33 -class Test{{ cookiecutter.project_slug|title }}(unittest.TestCase):
34 - """Tests for `{{ cookiecutter.project_slug }}` package."""
35 -
36 - def setUp(self):
37 - """Set up test fixtures, if any."""
38 -
39 - def tearDown(self):
40 - """Tear down test fixtures, if any."""
41 -
42 - def test_000_something(self):
43 - """Test something."""
44 -{%- endif %}

{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/__init__.py

1 1 # -*- coding: utf-8 -*-
2 2
3 3 """{{ cookiecutter.project_short_description }}"""
4 +{% if cookiecutter.script_entrypoint == 'y' -%}
5 +import argparse
6 +
7 +from . import {{ cookiecutter.project_slug }}
8 +{% endif %}
4 9
5 10 __author__ = '{{ cookiecutter.full_name }}'
6 -__email__ = '{{ cookiecutter.email }}'
7 11 __version__ = '{{ cookiecutter.version }}'
8 -__copyright__ = 'Copyright (c) {% now 'local', '%Y' %}, {{ cookiecutter.full_name }}'
12 +{% if cookiecutter.script_entrypoint == 'y' -%}
13 +
14 +def main():
15 + """Main {{ cookiecutter.project_slug }} entrypoint"""
16 + parser = argparse.ArgumentParser()
17 + parser.add_argument(
18 + '-v', action='version',
19 + version='%(prog)s {}'.format(__version__))
20 +{% endif %}