Skip to content

Commit

Permalink
Merge pull request #62 from tantale/ci-improve
Browse files Browse the repository at this point in the history
Improve code style (PEP8) of ``{{cookiecutter.repo_name}}/ci`` scripts.
  • Loading branch information
ionelmc committed Jul 27, 2016
2 parents 3332b2a + 2621e86 commit a037e14
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
4 changes: 3 additions & 1 deletion {{cookiecutter.repo_name}}/ci/appveyor-bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
with various fixes and improvements that just weren't feasible to implement in PowerShell.
"""
from __future__ import print_function

from os import environ
from os.path import exists
from subprocess import CalledProcessError
from subprocess import check_call

try:
Expand Down Expand Up @@ -67,7 +69,7 @@ def install_python(version, arch, home):
print("Running:", " ".join(cmd))
try:
check_call(cmd)
except Exception as exc:
except CalledProcessError as exc:
print("Failed command", cmd, "with:", exc)
if exists("install.log"):
with open("install.log") as fh:
Expand Down
6 changes: 4 additions & 2 deletions {{cookiecutter.repo_name}}/ci/appveyor-download.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@

import argparse
import os
import requests
import zipfile

import requests


def make_auth_headers():
"""Make the authentication headers needed to use the Appveyor API."""
Expand Down Expand Up @@ -64,7 +65,7 @@ def download_latest_artifacts(account_project, build_id):

def ensure_dirs(filename):
"""Make sure the directories exist for `filename`."""
dirname, _ = os.path.split(filename)
dirname = os.path.dirname(filename)
if dirname and not os.path.exists(dirname):
os.makedirs(dirname)

Expand All @@ -90,6 +91,7 @@ def unpack_zipfile(filename):
ensure_dirs(name)
z.extract(name)


parser = argparse.ArgumentParser(description='Download artifacts from AppVeyor.')
parser.add_argument('--id',
metavar='PROJECT_ID',
Expand Down
20 changes: 9 additions & 11 deletions {{cookiecutter.repo_name}}/ci/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

import os
import sys
from os.path import abspath
from os.path import dirname
from os.path import exists
from os.path import join
from os.path import dirname
from os.path import abspath


if __name__ == "__main__":
Expand All @@ -20,14 +20,16 @@
bin_path = join(env_path, "bin")
if not exists(env_path):
import subprocess

print("Making bootstrap env in: {0} ...".format(env_path))
try:
subprocess.check_call(["virtualenv", env_path])
except Exception:
except subprocess.CalledProcessError:
subprocess.check_call([sys.executable, "-m", "virtualenv", env_path])
print("Installing `jinja2` {% if cookiecutter.test_matrix_configurator == "yes" %}and `matrix` {% endif %}into bootstrap environment ...")
print("Installing `jinja2` {% if cookiecutter.test_matrix_configurator == "yes" %}and `matrix` {% endif %}into bootstrap environment...")
subprocess.check_call([join(bin_path, "pip"), "install", "jinja2"{% if cookiecutter.test_matrix_configurator == "yes" %}, "matrix"{% endif %}])
activate = join(bin_path, "activate_this.py")
# noinspection PyCompatibility
exec(compile(open(activate, "rb").read(), activate, "exec"), dict(__file__=activate))

import jinja2
Expand All @@ -36,7 +38,6 @@
{% else %}
import subprocess
{% endif %}

jinja = jinja2.Environment(
loader=jinja2.FileSystemLoader(join(base_path, "ci", "templates")),
trim_blocks=True,
Expand All @@ -48,27 +49,24 @@
for (alias, conf) in matrix.from_file(join(base_path, "setup.cfg")).items():
python = conf["python_versions"]
deps = conf["dependencies"]
if "coverage_flags" in conf:
cover = {"false": False, "true": True}[conf["coverage_flags"].lower()]
if "environment_variables" in conf:
env_vars = conf["environment_variables"]

tox_environments[alias] = {
"python": "python" + python if "py" not in python else python,
"deps": deps.split(),
}
if "coverage_flags" in conf:
cover = {"false": False, "true": True}[conf["coverage_flags"].lower()]
tox_environments[alias].update(cover=cover)
if "environment_variables" in conf:
env_vars = conf["environment_variables"]
tox_environments[alias].update(env_vars=env_vars.split())
{% else %}
tox_environments = [
line.strip()
# 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']]
{% endif %}

for name in os.listdir(join("ci", "templates")):
with open(join(base_path, name), "w") as fh:
fh.write(jinja.get_template(name).render(tox_environments=tox_environments))
Expand Down

0 comments on commit a037e14

Please sign in to comment.