Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve code style (PEP8) of {{cookiecutter.repo_name}}/ci scripts. #62

Merged
merged 1 commit into from
Jul 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what tool uses this directive?

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