def bootstrap(session): del session # Unused jinja = jinja2.Environment( loader=jinja2.FileSystemLoader(os.path.join("ci", "templates")), trim_blocks=True, lstrip_blocks=True, keep_trailing_newline=True, ) nox_environments = {} for (alias, conf) in matrix.from_file("setup.cfg").items(): python = conf["python_versions"] deps = conf["dependencies"] nox_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()] nox_environments[alias].update(cover=cover) if "environment_variables" in conf: env_vars = conf["environment_variables"] nox_environments[alias].update(env_vars=env_vars.split()) for name in os.listdir(os.path.join("ci", "templates")): with open(name, "w") as fh: fh.write( jinja.get_template(name).render( nox_environments=nox_environments)) print("Wrote {}".format(name)) print("DONE.")
def main(): import jinja2 import matrix print("Project path: {0}".format(base_path)) jinja = jinja2.Environment( loader=jinja2.FileSystemLoader(join(base_path, "ci", "templates")), trim_blocks=True, lstrip_blocks=True, keep_trailing_newline=True ) tox_environments = {} for (alias, conf) in matrix.from_file(join(base_path, "setup.cfg")).items(): python = conf["python_versions"] deps = conf["dependencies"] tox_environments[alias] = { "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()) 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)) print("Wrote {}".format(name)) print("DONE.")
def main(): import jinja2 import matrix import yaml jinja = jinja2.Environment(loader=jinja2.FileSystemLoader( join(base_path, "ci", "templates")), trim_blocks=True, lstrip_blocks=True, keep_trailing_newline=True) tox_environments = {} for name in os.listdir(join(base_path, "ci", "envs")): os.unlink(join(base_path, "ci", "envs", name)) for (alias, conf) in matrix.from_file(join(base_path, "ci", "setup.cfg")).items(): tox_environments[alias] = conf conf['repo_name'] = 'python-nameless' conf['package_name'] = 'nameless' conf[ 'c_extension_test_pypi_appveyor_secret'] = 'fDwCnDhQiptm9a4ZcFpgyQ==' conf['c_extension_test_pypi_travis_secret'] = '' conf['codacy'] = 'yes' conf['codacy_projectid'] = '862e7946' conf['eabb4112be6503a667381b71'] = '' conf['codeclimate'] = 'yes' conf['codecov'] = 'yes' conf['coveralls'] = 'yes' conf['coveralls_token'] = 'IoRlAEvnKbwbhBJ2jrWPqzAnE2jobA0I3' conf['landscape'] = 'yes' conf['requiresio'] = 'yes' conf['scrutinizer'] = 'yes' with open(join(base_path, "ci", "envs", alias + '.cookiecutterrc'), "w") as fh: fh.write( yaml.safe_dump( dict(default_context={k: v for k, v in conf.items() if v}), default_flow_style=False)) for name in os.listdir(join(base_path, "ci", "templates")): with open(join(base_path, name), "w") as fh: fh.write( jinja.get_template(name).render( tox_environments=tox_environments)) print("Wrote {}".format(name)) print("DONE.")
def load_matrix(base_path): environments = {} items = list(matrix.from_file(base_path / "setup.cfg").items()) items.insert(0, ("check", {"coverage_flag": "False"})) for alias, conf in items: environments[alias] = conf.copy() pyenv = conf.pop("python_version", "py37") windows = not pyenv.startswith("pypy") python = pyenv if pyenv.startswith("pypy") else "{0[2]}.{0[3]}".format( pyenv) cover = conf.pop("coverage_flag", "true").lower() deps = conf.pop("dependencies", "").split() env_vars = {k.upper(): v for k, v in list(conf.items())} environments[alias].update( windows=windows, python=python, cover=cover == "true", deps=deps, env_vars=env_vars, pyenv=pyenv, ) return environments
subprocess.check_call([join(bin_path, "pip"), "install", "jinja2", "matrix", "pyyaml"]) activate = join(bin_path, "activate_this.py") exec(compile(open(activate, "rb").read(), activate, "exec"), dict(__file__=activate)) import jinja2 import matrix import yaml jinja = jinja2.Environment( loader=jinja2.FileSystemLoader(join("ci", "templates")), trim_blocks=True, lstrip_blocks=True, keep_trailing_newline=True ) tox_environments = {} for name in os.listdir(join("ci", "envs")): os.unlink(join("ci", "envs", name)) for (alias, conf) in matrix.from_file(join("ci", "setup.cfg")).items(): tox_environments[alias] = conf with open(join("ci", "envs", alias + '.cookiecutterrc'), "w") as fh: fh.write(yaml.safe_dump( dict(default_context={k: v for k, v in conf.items() if v}), default_flow_style=False )) for name in os.listdir(join("ci", "templates")): with open(name, "w") as fh: fh.write(jinja.get_template(name).render(tox_environments=tox_environments)) print("Wrote {}".format(name)) print("DONE.")
dict(__file__='.tox/configure/Scripts/activate_this.py')) else: exec( compile( open('.tox/configure/bin/activate_this.py').read(), '.tox/configure/bin/activate_this.py', 'exec'), dict(__file__='.tox/configure/bin/activate_this.py')) import jinja2 import matrix jinja = jinja2.Environment(loader=jinja2.FileSystemLoader('conf'), trim_blocks=True, lstrip_blocks=True, keep_trailing_newline=True) tox_environments = {} for alias, conf in matrix.from_file('setup.cfg').items(): python = conf['python_versions'] deps = conf['dependencies'] cover = {'false': False, 'true': True}[conf['coverage_flags'].lower()] env_vars = conf['environment_variables'] tox_environments[alias] = { 'python': 'python' + python if 'py' not in python else python, 'deps': deps.split(), 'cover': cover, 'env_vars': env_vars.split(), } for name in os.listdir('conf'): with open(name, 'w') as fh: fh.write(
print("Re-executing with: {0}".format(python_executable)) os.execv(python_executable, [python_executable, __file__]) import jinja2 import matrix jinja = jinja2.Environment( loader=jinja2.FileSystemLoader(join(base_path, "ci", "templates")), trim_blocks=True, lstrip_blocks=True, keep_trailing_newline=True ) tox_environments = {} for (alias, conf) in matrix.from_file(join(base_path, "setup.cfg")).items(): python = conf["python_versions"] deps = conf["dependencies"] tox_environments[alias] = { "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()) 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))
if not os.path.samefile(python_executable, sys.executable): print("Re-executing with: {0}".format(python_executable)) os.execv(python_executable, [python_executable, __file__]) import jinja2 import matrix jinja = jinja2.Environment(loader=jinja2.FileSystemLoader( join(base_path, "ci", "templates")), trim_blocks=True, lstrip_blocks=True, keep_trailing_newline=True) tox_environments = {} for (alias, conf) in matrix.from_file(join(base_path, "setup.cfg")).items(): python = conf["python_versions"] deps = conf["dependencies"] tox_environments[alias] = { "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())
exec(compile( open('.tox/configure/bin/activate_this.py').read(), '.tox/configure/bin/activate_this.py', 'exec' ), dict(__file__='.tox/configure/bin/activate_this.py')) import jinja2 import matrix jinja = jinja2.Environment( loader=jinja2.FileSystemLoader(os.path.join('ci', 'templates')), trim_blocks=True, lstrip_blocks=True, keep_trailing_newline=True ) tox_environments = {} for alias, conf in matrix.from_file('setup.cfg').items(): python = conf['python_versions'] deps = conf['dependencies'] cover = {'false': False, 'true': True}[conf['coverage_flags'].lower()] env_vars = conf['environment_variables'] tox_environments[alias] = { 'python': 'python' + python if 'py' not in python else python, 'deps': deps.split(), 'cover': cover, 'env_vars': env_vars.split(), } for name in os.listdir(os.path.join('ci', 'templates')): with open(name, 'w') as fh: fh.write(jinja.get_template(name).render(tox_environments=tox_environments))
exec(compile(open(activate, "rb").read(), activate, "exec"), dict(__file__=activate)) import jinja2 import matrix jinja = jinja2.Environment(loader=jinja2.FileSystemLoader( join(base_path, "ci", "templates")), trim_blocks=True, lstrip_blocks=True, keep_trailing_newline=True) env_names = "" # for (alias, conf) in matrix.from_file(join(base_path, "setup.cfg")).items(): m = matrix.from_file(join(base_path, "setup.cfg")).items() print(m) # python_versions = conf["python_versions"] # coverage_flags = conf["coverage_flags"] python_versions = (conf["python_versions"] for (_, conf) in m) coverage_flags = (conf["coverage_flags"] for (_, conf) in m) alias = (alias for (alias, _) in m) tox_environments = {} for (alias, conf) in m: python = conf["python_versions"] tox_environments[alias] = { "python": "python" + python if "py" not in python else python,
def main(): import jinja2 import matrix import yaml jinja = jinja2.Environment( loader=jinja2.FileSystemLoader(repo_path.joinpath('ci', 'templates')), trim_blocks=True, lstrip_blocks=True) # Load README config for documentation consistency check readme_in_path = repo_path.joinpath('ci', 'readme.json') readme_inputs = readme_conf_loader(readme_in_path) with open(repo_path.joinpath('cookiecutter.json'), 'r') as fh: cc_vars = json.load(fh) # check for keys missing from readme input context = 'Please add them to {}\033[0m\n\033[1;36m or delete it and re-run this script.'.format( readme_in_path) find_missing_keys(cc_vars, readme_inputs['variables_table'], context) # check for extra keys in the readme input context = 'Please remove the extra keys from {}\033[0m\n\033[1;36m or delete it and re-run this script.'.format( readme_in_path) find_missing_keys(readme_inputs["variables_table"], cc_vars, context) # Remove old env configurations tox_envs = {} for old_env in repo_path.joinpath('ci', 'envs').iterdir(): unlink(old_env) # Stages: # 1: default output # 2: single variations from default # 3: matrix of component variations # 4: matrix of deployment variations # define starting point # base_variant = # define table of single changes # define variants from starting point # add variants to the dict # check for duplicates in the matrix default_inputs = {'deployment_display_name': 'Reference', 'deployment_slug': 'Reference'} tox_envs['1-defaults'] = default_inputs write_conf_file('1-defaults', default_inputs) long_inputs_file = {'deployment_display_name': 'Reference', 'deployment_slug': 'Reference', 'component_namespace': 'verylong::silly::naming::space'} tox_envs['2-long-component-namespace'] = long_inputs_file write_conf_file('2-long-component-namespace', long_inputs_file) # Make new cookiecutterrc for each env for (alias, conf) in matrix.from_file(repo_path.joinpath('ci', 'setup.cfg')).items(): alias = '3-{}'.format(alias) tox_envs[alias] = conf if 'deployment_slug' not in conf.keys(): conf['deployment_slug'] = 'MyExample' path_to_dep = conf['deployment_path'] if path_to_dep == '' or path_to_dep == '.': conf['deployment_path_to_project_root'] = '..' else: conf['deployment_path_to_project_root'] = '/'.join( ['..' for k in path_to_dep.split('/')]) write_conf_file(alias, conf) # Constitute templates from bootstrapped configuration for templ in repo_path.joinpath('ci', 'templates').iterdir(): with open(repo_path.joinpath(templ.name), 'w') as fh: fh.write(jinja.get_template(templ.name).render( tox_environments=tox_envs, variables_table=readme_inputs['variables_table'])) print('Generated {}'.format(templ.name)) print('Done.') # Check for boilerplate help strings in the readme without # preventing it from being rendered: bp = [] for key, value in readme_inputs['variables_table'].items(): if value['help'][0] == help_boileplate: bp.append(key) if len(bp) > 0: err_str = ['\n\033[33mWARNING: Boilerplate help strings found for the following variables:\033[0m'] for var in bp: err_str.append('\033[33m * {}\033[0m'.format(var)) raise Exception('\n'.join(err_str))
print("Installing `jinja2` and `matrix` into bootstrap environment ...") subprocess.check_call([join(bin_path, "pip"), "install", "jinja2", "matrix"]) activate = join(bin_path, "activate_this.py") exec(compile(open(activate, "rb").read(), activate, "exec"), dict(__file__=activate)) import jinja2 import matrix jinja = jinja2.Environment( loader=jinja2.FileSystemLoader(join("ci", "templates")), trim_blocks=True, lstrip_blocks=True, keep_trailing_newline=True ) tox_environments = {} for (alias, conf) in matrix.from_file("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: tox_environments[alias].update(cover=cover) if "environment_variables" in conf: tox_environments[alias].update(env_vars=env_vars.split())