Skip to content

Commit

Permalink
A bit of template cleanup (a bunch of duplication removed) and fixes …
Browse files Browse the repository at this point in the history
…for the pypy envs. Coveralls can now be enabled for appveyor, coverage submissions will work on pypy3, codacy has a cookiecutter input for the token.
  • Loading branch information
ionelmc committed May 25, 2019
1 parent 33737e2 commit b024f63
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 246 deletions.
2 changes: 2 additions & 0 deletions cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@
"command_line_interface": ["plain", "argparse", "click", "no"],
"command_line_interface_bin_name": "{{ cookiecutter.distribution_name }}",
"coveralls": ["no", "yes"],
"coveralls_token": "Required for Appveyor, take it from https://coveralls.io/github/{{ cookiecutter.github_username }}/{{ cookiecutter.repo_name }}",
"codecov": ["yes", "no"],
"landscape": ["no", "yes"],
"scrutinizer": ["no", "yes"],
"codacy" : ["no", "yes"],
"codacy_projectid" : "Get ID from https://app.codacy.com/app/{{ cookiecutter.github_username }}/{{ cookiecutter.repo_name }}/settings",
"codeclimate" : ["no", "yes"],
"sphinx_docs": ["yes", "no"],
"sphinx_theme": ["sphinx-rtd-theme", "sphinx-py3doc-enhanced-theme"],
Expand Down
52 changes: 25 additions & 27 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,6 @@ def replace_contents(filename, what, replacement):
shutil.rmtree('docs')
{% endif %}

{% if cookiecutter.test_matrix_configurator == "yes" %}
print("""
################################################################################
For your convenience, the test environments are getting configured for the
first time, as you have selected "yes" for `test_matrix_configurator` ...
""")
try:
subprocess.check_call(['tox'])
except Exception:
try:
subprocess.check_call([sys.executable, '-mtox'])
except Exception:
subprocess.check_call([sys.executable, join('ci', 'bootstrap.py')])
{% endif %}

{%- if cookiecutter.command_line_interface == 'no' %}
os.unlink(join('src', '{{ cookiecutter.package_name }}', '__main__.py'))
os.unlink(join('src', '{{ cookiecutter.package_name }}', 'cli.py'))
Expand Down Expand Up @@ -80,19 +64,32 @@ def replace_contents(filename, what, replacement):
os.unlink(join('ci', 'appveyor-bootstrap.py'))
os.unlink(join('ci', 'appveyor-download.py'))
os.unlink(join('ci', 'appveyor-with-compiler.cmd'))
os.unlink('appveyor.yml')
if os.path.exists(join('ci', 'templates', 'appveyor.yml')):
os.unlink(join('ci', 'templates', 'appveyor.yml'))
os.unlink(join('ci', 'templates', 'appveyor.yml'))
if os.path.exists('appveyor.yml'):
os.unlink('appveyor.yml')
{% endif %}

{%- if cookiecutter.travis == 'no' %}
os.unlink('.travis.yml')
if os.path.exists(join('ci', 'templates', '.travis.yml')):
os.unlink(join('ci', 'templates', '.travis.yml'))
os.unlink(join('ci', 'templates', '.travis.yml'))
if os.path.exists('.travis.yml'):
os.unlink('.travis.yml')
{% endif %}

print("""
################################################################################
Generating CI configuration ...
""")
try:
subprocess.check_call(['tox', '-e', 'bootstrap'])
except Exception:
try:
subprocess.check_call([sys.executable, '-mtox', '-e', 'bootstrap'])
except Exception:
subprocess.check_call([sys.executable, join('ci', 'bootstrap.py')])

print("""
################################################################################
################################################################################
You have succesfully created `{{ cookiecutter.repo_name }}`.
Expand All @@ -104,6 +101,8 @@ def replace_contents(filename, what, replacement):
{{ "{0:26}".format(key + ":") }} {{ "{0!r}".format(value).strip("u") }}
{%- endfor %}
See .cookiecutterrc for instructions on regenerating the project.
################################################################################
To get started run these:
Expand All @@ -116,17 +115,16 @@ def replace_contents(filename, what, replacement):
git push -u origin master
{% if cookiecutter.test_matrix_configurator == "yes" %}
To reconfigure your test/CI settings run:
To regenerate your tox.ini, .travis.yml or appveyor.yml run:
{% else %}
To regenerate your .travis.yml or appveyor.yml run:
{% endif %}
tox -e bootstrap
You can also run:
./ci/bootstrap.py
{% else %}
The project doesn't use the test matrix configurator, but in case
you change your mind just edit `setup.cfg` and run `ci/bootstrap.py`.
{% endif %}
""")

command_line_interface_bin_name = '{{ cookiecutter.command_line_interface_bin_name }}'
Expand Down
61 changes: 0 additions & 61 deletions {{cookiecutter.repo_name}}/.travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion {{cookiecutter.repo_name}}/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Overview
:alt: Code Quality Status
{% endif %}
{%- if cookiecutter.codacy == 'yes' %}
.. |codacy| image:: https://img.shields.io/codacy/REPLACE_WITH_PROJECT_ID.svg
.. |codacy| image:: https://img.shields.io/codacy/grade/{{ cookiecutter.codacy_projectid }}.svg
:target: https://www.codacy.com/app/{{ cookiecutter.github_username }}/{{ cookiecutter.repo_name }}
:alt: Codacy Code Quality Status
{% endif %}
Expand Down
71 changes: 0 additions & 71 deletions {{cookiecutter.repo_name}}/appveyor.yml

This file was deleted.

2 changes: 1 addition & 1 deletion {{cookiecutter.repo_name}}/ci/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
# WARNING: 'tox' must be installed globally or in the project's virtualenv
for line in subprocess.check_output(['tox', '--listenvs'], universal_newlines=True).splitlines()
]
tox_environments = [line for line in tox_environments if line not in ['clean', 'report', 'docs', 'check']]
tox_environments = [line for line in tox_environments if line.startswith('py')]
{% endif %}
for name in os.listdir(join("ci", "templates")):
with open(join(base_path, name), "w") as fh:
Expand Down
77 changes: 31 additions & 46 deletions {{cookiecutter.repo_name}}/ci/templates/.travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,53 +15,38 @@ matrix:
- TOXENV=docs
{%- endif %}
{% if cookiecutter.test_matrix_configurator == "yes" -%}
{% raw -%}
{%- for env, config in tox_environments|dictsort %}{{ '' }}
{% if env.startswith("pypy3") %}
- python: 'pypy3.5-6.0'
{% elif env.startswith("pypy") %}
- python: 'pypy2.7-6.0'
{% else %}
- python: '{{ "{0[2]}.{0[3]}".format(env) }}'
{% endif %}
env:
- TOXENV={{ env }}{% if config.cover %},report{% endraw %}
{%- if cookiecutter.coveralls == 'yes' -%}
{%- if cookiecutter.c_extension_support != "no" %},extension-coveralls{% endif %},coveralls
{%- endif -%}
{%- if cookiecutter.codecov == 'yes' %},codecov{% endif -%}
{%- raw %}{% endif -%}
{% endfor %}
{%- endraw %}
{% else %}
{%- raw -%}
{%- for env in tox_environments %}{{ '' }}
{% if env.startswith("pypy3") %}
- python: 'pypy3.5-6.0'
{% elif env.startswith("pypy") %}
- python: 'pypy2.7-6.0'
{% else %}
- python: '{{ "{0[2]}.{0[3]}".format(env) }}'
{% endif %}
env:
- TOXENV={{ env }}{% endraw -%}
{%- if cookiecutter.test_matrix_separate_coverage == 'yes' %}{% raw -%}
{% if 'cover' in env %},report{% endraw %}
{%- if cookiecutter.coveralls == 'yes' -%}
{%- if cookiecutter.c_extension_support != "no" %},extension-coveralls{% endif %},coveralls
{%- endif -%}
{%- if cookiecutter.codecov == 'yes' %},codecov{% endif -%}
{%- raw %}{% endif -%}{% endraw %}
{%- else %},report
{%- if cookiecutter.coveralls == 'yes' %}
{%- if cookiecutter.c_extension_support != "no" %},extension-coveralls{% endif %},coveralls
{%- endif %}
{%- if cookiecutter.codecov == 'yes' %},codecov{% endif %}
{%- endif %}
{%- raw %}
{%- endfor %}{{ '' }}
{%- endraw %}
{{ "{%- for env, config in tox_environments|dictsort %}{{ '' }}" }}
{%- else -%}
{{ "{%- for env in tox_environments %}{{ '' }}" }}
{%- endif %}
- env:
- TOXENV={{ "{{ env }}" }}
{%- if cookiecutter.test_matrix_configurator == "yes" -%}
{{ "{% if config.cover %}" }}
{%- else %}
{%- if cookiecutter.test_matrix_separate_coverage == 'yes' %}{{ "{% if 'cover' in env %}" }}{% endif %}
{%- endif %}
{%- if cookiecutter.coveralls == 'yes' %}
{%- if cookiecutter.c_extension_support != "no" %},extension-coveralls{% endif -%}
,coveralls
{%- endif %}
{%- if cookiecutter.codecov == 'yes' -%}
,codecov
{%- endif %}
{%- if cookiecutter.test_matrix_configurator == "yes" -%}
{{ "{% endif %}" }}
{%- else %}
{%- if cookiecutter.test_matrix_separate_coverage == 'yes' -%}{{ "{% endif %}" }}{%- endif %}
{%- endif %}
{{ "{%- if env.startswith('pypy3') %}{{ '' }}" }}
- TOXPYTHON=pypy3
python: 'pypy3.5-6.0'
{{ "{%- elif env.startswith('pypy') %}{{ '' }}" }}
python: 'pypy2.7-6.0'
{{ "{%- else %}{{ '' }}" }}
python: {{ "'{{ '{0[2]}.{0[3]}'.format(env) }}'" }}
{{ "{%- endif %}" }}
{{ "{%- endfor %}{{ '' }}" }}
before_install:
- python --version
- uname -a
Expand Down
Loading

0 comments on commit b024f63

Please sign in to comment.