def test(): """Run the unit tests.""" # Run the tests in each of the virtual environments defined in Project.test_python_versions # or if not defined, then in Project.wheel_python_versions. If neither are defined, then # run the test in the current environment. venvs = VirtualenvInfo('test_python_versions', 'wheel_python_versions') coverage = '--cov-report term-missing --cov={package}'.format(package=Project.package) reports = '--junitxml={quality}/tests.xml'.format(quality=Project.quality_dir) mkdir_p(Project.tests_dir) if not venvs.in_virtualenv and venvs.defined: for venv_info in venvs.infos(): info('Running unit tests using the {venv} virtual environment.'.format(venv=venv_info.venv)) venv_info.run('py.test {coverage} {reports} {tests_dir}'.format(coverage=coverage, reports=reports, tests_dir=Project.tests_dir), verbose=True) else: with LocalShell() as local: info('Running unit tests using the current python environment') local.run("py.test {coverage} {reports} {tests_dir}".format(coverage=coverage, reports=reports, tests_dir=Project.tests_dir), verbose=True)
def pdf(): """Generate PDF API documents""" venvs = VirtualenvInfo("doc_python_version") if not venvs.in_virtualenv and venvs.defined: for venv_info in venvs.infos(): venv_info.run("{herring} doc::pdf_generate".format(herring=Project.herring)) else: info("Generating documentation using the current python environment") task_execute("doc::pdf_generate")
def watch(): """generate project documentation""" venvs = VirtualenvInfo('doc_python_version') info("venvs: {venvs}".format(venvs=repr(venvs.__dict__))) if not venvs.in_virtualenv and venvs.defined: for venv_info in venvs.infos(): venv_info.run('{herring} doc::watcher --python-tag py{ver}'.format(herring=Project.herring, ver=venv_info.ver)) else: info('Watching documentation using the current python environment') task_execute('doc::watcher')
def slides(): """generate project slides""" venvs = VirtualenvInfo('docs_venv') info("venvs: {venvs}".format(venvs=repr(venvs.__dict__))) if not venvs.in_virtualenv and venvs.defined: for venv_info in venvs.infos(): venv_info.run('{herring} doc::hieroglyph_slides --python-tag py{ver}'.format(herring=Project.herring, ver=venv_info.ver)) else: info('Generating slides using the current python environment') task_execute('doc::hieroglyph_slides')
def doc_no_api(): """generate project documentation without the api""" venvs = VirtualenvInfo('docs_venv') info("venvs: {venvs}".format(venvs=repr(venvs.__dict__))) if not venvs.in_virtualenv and venvs.defined: for venv_info in venvs.infos(): venv_info.run('{herring} doc::generate_no_api --python-tag py{ver}'.format(herring=Project.herring, ver=venv_info.ver)) else: info('Generating documentation using the current python environment') task_execute('doc::generate_no_api')
def doc(): """generate project documentation""" venvs = VirtualenvInfo("doc_python_version") info("venvs: {venvs}".format(venvs=repr(venvs.__dict__))) if not venvs.in_virtualenv and venvs.defined: for venv_info in venvs.infos(): venv_info.run( "{herring} doc::generate --python-tag py{ver}".format(herring=Project.herring, ver=venv_info.ver) ) else: info("Generating documentation using the current python environment") task_execute("doc::generate")
def sdist(): """ build source distribution""" info('') info("=" * 70) info('building source distribution') venvs = VirtualenvInfo('sdist_python_version') if not venvs.in_virtualenv and venvs.defined: for venv_info in venvs.infos(): info('Building sdist using {venv} virtual environment'.format(venv=venv_info.venv)) venv_info.run('python setup.py sdist') else: with LocalShell() as local: info("Building sdist using default environment") local.system("python setup.py sdist")
def metrics(): """ Quality metrics """ # Run the metrics in each of the virtual environments defined in Project.metrics_python_versions # or if not defined, then in Project.wheel_python_versions. If neither are defined, then # run the test in the current environment. venvs = VirtualenvInfo('metrics_python_versions', 'wheel_python_versions') if not venvs.in_virtualenv and venvs.defined: for venv_info in venvs.infos(): info('Running metrics using the {venv} virtual environment.'.format(venv=venv_info.venv)) venv_info.run('herring metrics::all_metrics') else: info('Running metrics using the current python environment') task_execute('metrics::all_metrics')
def environment(): """ Display project environment """ venvs = VirtualenvInfo('python_versions') site_packages_cmdline = "python -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())'" project_env = {} if not venvs.in_virtualenv and venvs.defined: for venv_info in venvs.infos(): site_packages = venv_info.run(site_packages_cmdline).strip().splitlines()[2] project_env[venv_info.venv + ': site-packages'] = site_packages else: with LocalShell() as local: site_packages = local.system(site_packages_cmdline).strip() project_env['site-packages'] = site_packages info(pformat(project_env)) return project_env
def behave(): """Run the behavior tests.""" # Run the features in each of the virtual environments defined in Project.test_python_versions # or if not defined, then in Project.wheel_python_versions. If neither are defined, then # run the test in the current environment. venvs = VirtualenvInfo('test_python_versions', 'wheel_python_versions') if not venvs.in_virtualenv and venvs.defined: for venv_info in venvs.infos(): info('Running features using the {venv} virtual environment.'.format(venv=venv_info.venv)) venv_info.run('behave {features_dir}'.format(features_dir=Project.features_dir), verbose=True) else: with LocalShell() as local: info('Running features using the current python environment') local.run("behave {features_dir}".format(features_dir=Project.features_dir), verbose=True)
def wheels(): """build wheels""" info('') info("=" * 70) info('building wheels') venvs = VirtualenvInfo('wheel_python_versions') if not venvs.in_virtualenv and venvs.defined: value = setup_cfg_value(section='wheel', key='universal') if value is None or value != '0': warning('To use wheels, you must disable universal in setup.cfg:\n [wheel]\n universal=0\n') return for venv_info in venvs.infos(): venv_info.run('{herring} build::wheel --python-tag py{ver}'.format(herring=Project.herring, ver=venv_info.ver)) else: info("To build wheels, in your herringfile you must set Project.wheel_python_versions to a list" "of compact version, for example: ['27', '33', '34'] will build wheels for " "python 2.7, 3.3, and 3.4") return
def deploy(): """ copy latest sdist tar ball to server """ info('') info("=" * 70) info('deploying source distribution') if getattr(Project, 'pypiserver', None) is not None and Project.pypiserver: venvs = VirtualenvInfo('deploy_python_version') if not venvs.in_virtualenv and venvs.defined: for venv_info in venvs.infos(): info('Switching to deploy_python_version ({venv}) virtual environment'.format(venv=venv_info.venv)) venv_info.run("python setup.py sdist upload -r {server}".format(server=Project.pypiserver), verbose=True) else: with LocalShell() as local: info("Deploying sdist using default environment") local.run("python setup.py sdist upload -r {server}".format(server=Project.pypiserver), verbose=True) else: version = Project.version project_version_name = "{name}-{version}.tar.gz".format(name=Project.base_name, version=version) project_latest_name = "{name}-latest.tar.gz".format(name=Project.base_name) pypi_dir = Project.pypi_path dist_host = Project.dist_host # dist_dir = '{dir}/{name}'.format(dir=pypi_dir, name=Project.base_name) dist_dir = pypi_dir dist_version = '{dir}/{file}'.format(dir=dist_dir, file=project_version_name) dist_latest = '{dir}/{file}'.format(dir=dist_dir, file=project_latest_name) dist_file = os.path.join(Project.herringfile_dir, 'dist', project_version_name) dist_wheels = _dist_wheels(dist_dir=dist_dir) dist_wheel_files = _dist_wheel_files() password = Project.dist_password if password is None and Project.dist_host_prompt_for_sudo_password: password = getpass("password for {user}@{host}: ".format(user=Project.user, host=Project.dist_host)) Project.dist_password = password with RemoteShell(user=Project.user, password=Project.dist_password, host=dist_host, verbose=True) as remote: remote.run('mkdir -p {dir}'.format(dir=dist_dir)) remote.run('sudo chown www-data:www-data {dest}'.format(dest=dist_dir), accept_defaults=True, timeout=10) remote.run('sudo chmod 777 {dest}'.format(dest=dist_dir), accept_defaults=True, timeout=10) remote.run('rm {path}'.format(path=dist_latest)) remote.run('rm {path}'.format(path=dist_version)) for dist_wheel in dist_wheels: remote.run('rm {path}'.format(path=dist_wheel)) remote.put(dist_file, dist_dir) for dist_wheel_file in dist_wheel_files: remote.put(dist_wheel_file, dist_dir) remote.run('ln -s {src} {dest}'.format(src=dist_version, dest=dist_latest)) remote.run('sudo chown www-data:www-data {dest}'.format(dest=dist_version), accept_defaults=True, timeout=10) remote.run('sudo chown www-data:www-data {dest}'.format(dest=dist_latest), accept_defaults=True, timeout=10) remote.run('sudo chmod 777 {dest}'.format(dest=dist_version), accept_defaults=True, timeout=10) remote.run('sudo chmod 777 {dest}'.format(dest=dist_latest), accept_defaults=True, timeout=10) for dist_wheel in dist_wheels: remote.run('sudo chown www-data:www-data {dest}'.format(dest=dist_wheel), accept_defaults=True, timeout=10) remote.run('sudo chmod 777 {dest}'.format(dest=dist_wheel), accept_defaults=True, timeout=10)