diff options
author | Joseph Hunkeler <jhunkeler@users.noreply.github.com> | 2019-05-16 15:44:53 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-16 15:44:53 -0400 |
commit | 28c26653e86b01dd707c50b72da5de524aad3fe5 (patch) | |
tree | 8941385204e9db22fbbb19bca32e50ef57ab4b2f | |
parent | 5c3adc2fbaebaca2324d1ff86f19e23a3fabd012 (diff) | |
parent | fbb81b10ba8baff236ab9b60c170866dc7a7a067 (diff) | |
download | delivery_merge-28c26653e86b01dd707c50b72da5de524aad3fe5.tar.gz |
Merge pull request #3 from astroconda/codecov
Codecov
-rw-r--r-- | .coveragerc | 16 | ||||
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | azure-pipelines.yml | 7 | ||||
-rw-r--r-- | delivery_merge/cli/merge.py | 3 | ||||
-rw-r--r-- | delivery_merge/conda.py | 32 | ||||
-rw-r--r-- | delivery_merge/merge.py | 40 | ||||
-rw-r--r-- | delivery_merge/utils.py | 3 | ||||
-rw-r--r-- | setup.py | 2 |
8 files changed, 82 insertions, 23 deletions
diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000..5f51efe --- /dev/null +++ b/.coveragerc @@ -0,0 +1,16 @@ +[run] +branch = True +source = delivery_merge + +[report] +exclude_lines = + if self.debug: + pragma: no cover + raise NotImplementedError + if __name__ == .__main__.: +ignore_errors = True +omit = + conftest.py + setup.py + tests/* + delivery_merge/tests/* @@ -8,3 +8,5 @@ results src miniconda* anaconda* +.coverage +coverage.xml diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 2afca99..ba3ad70 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -25,6 +25,9 @@ steps: displayName: 'Install dependencies' - script: | - python -m pip install pytest pytest-azurepipelines - pytest -v + python -m pip install pytest pytest-azurepipelines pytest-cov codecov + pytest -v --cov=delivery_merge --cov-report=xml tests + codecov -t $codecov_token + env: + codecov_token: $(CODECOV_TOKEN) displayName: 'pytest' diff --git a/delivery_merge/cli/merge.py b/delivery_merge/cli/merge.py index 45adf64..a9b94b4 100644 --- a/delivery_merge/cli/merge.py +++ b/delivery_merge/cli/merge.py @@ -1,5 +1,5 @@ import os -from ..conda import conda, conda_installer, conda_init_path +from ..conda import conda, conda_installer, conda_init_path, ei_touch from ..merge import ( env_combine, testable_packages, @@ -44,6 +44,7 @@ def main(): prefix = conda_installer(args.installer_version) conda_init_path(prefix) + ei_touch() if not os.path.exists(os.path.join(prefix, 'envs', name)): print(f"Creating environment {name}...") diff --git a/delivery_merge/conda.py b/delivery_merge/conda.py index cc265f1..6dd29b1 100644 --- a/delivery_merge/conda.py +++ b/delivery_merge/conda.py @@ -13,6 +13,22 @@ class BadPlatform(Exception): pass +def ei_touch(): + py_version = sh('python', '--version').stdout.decode().strip().split()[1] + py_version = '.'.join(py_version.split('.')[:2]) + root = run("python -c 'import sys; print(sys.prefix)'", + capture_output=True, + shell=True, + env=os.environ).stdout.decode().strip() + libsp = ['lib', f'python{py_version}', 'site-packages'] + site_packages = os.path.join(root, *libsp) + pthfile = os.path.join(site_packages, 'easy-install.pth') + + print('PTHFILE = {}'.format(pthfile)) + if not os.path.exists(pthfile): + open(pthfile, 'w+').write('') + + def conda_installer(ver, prefix='./miniconda3'): """ Install miniconda into a user-defined prefix and return its path @@ -59,7 +75,7 @@ def conda_installer(ver, prefix='./miniconda3'): os.chmod(installer, 0o755) # Perform installation - run(install_command).check_returncode() + run(install_command, env=os.environ).check_returncode() return prefix @@ -78,6 +94,17 @@ def conda_init_path(prefix): os.environ['PATH']]) +def conda_site(): + """ Retrieve current environment's site-packages path + """ + result = run("python -c 'import site; print(site.getsitepackages()[-1])'", + capture_output=True, + shell=True, + env=os.environ) + result.check_returncode() + return result.stdout.decode().strip() + + def conda_activate(env_name): """ Activate a conda environment @@ -90,7 +117,8 @@ def conda_activate(env_name): """ proc = run(f". activate {env_name} && env", capture_output=True, - shell=True) + shell=True, + env=os.environ) proc.check_returncode() return getenv(proc.stdout.decode()).copy() diff --git a/delivery_merge/merge.py b/delivery_merge/merge.py index f99c542..c58da77 100644 --- a/delivery_merge/merge.py +++ b/delivery_merge/merge.py @@ -1,7 +1,7 @@ import os import re import sys -from .conda import conda, conda_env_load, conda_cmd_channels +from .conda import conda, conda_env_load, conda_cmd_channels, ei_touch from .utils import comment_find, git, pushd, sh from configparser import ConfigParser from glob import glob @@ -74,15 +74,19 @@ def env_combine(filename, conda_env, conda_channels=[]): packages.append(f"'{record['fullspec']}'") packages_result = ' '.join([x for x in packages]) - proc = conda('install', '-q', '-y', - '-n', conda_env, - conda_cmd_channels(conda_channels), - packages_result) - if proc.stderr: - print(proc.stderr.decode()) + with conda_env_load(conda_env): + ei_touch() + # Perform package installation + proc = conda('install', '-q', '-y', + '-n', conda_env, + conda_cmd_channels(conda_channels), + packages_result) - proc.check_returncode() + if proc.stderr: + print(proc.stderr.decode()) + + proc.check_returncode() def testable_packages(filename, prefix): @@ -159,29 +163,33 @@ def integration_test(pkg_data, conda_env, results_root='.'): force_xunit2() with conda_env_load(conda_env): + ei_touch() results = os.path.abspath(os.path.join(results_root, repo_root, 'result.xml')) - proc_pip_install = sh("pip", "install --upgrade pip") + + conda("uninstall", "-y", repo_root) + + proc_pip_install = sh("python", "-m pip install --upgrade pip pytest ci-watson") if proc_pip_install.returncode: print(proc_pip_install.stdout.decode()) print(proc_pip_install.stderr.decode()) - proc_pip = sh("pip", "install -v -e .[test] pytest ci_watson") + proc_pip = sh("python", "-m pip install -v .[test]") proc_pip_stderr = proc_pip.stderr.decode() if proc_pip.returncode: print(proc_pip.stdout.decode()) print(proc_pip.stderr.decode()) - # Setuptools is busted in conda. Ignore errors related to - # easy_install.pth - if 'easy-install.pth' not in proc_pip_stderr: - proc_pip.check_returncode() - if 'consider upgrading' not in proc_pip_stderr: proc_pip.check_returncode() - proc_pytest = sh("pytest", f"-v --basetemp=.tmp --junitxml={results}") + proc_egg = sh("python", "setup.py egg_info") + if proc_egg.returncode: + print(proc_egg.stdout.decode()) + print(proc_egg.stderr.decode()) + + proc_pytest = sh("python", "-m pytest", f"-v --basetemp=.tmp --junitxml={results}") print(proc_pytest.stdout.decode()) if proc_pytest.returncode: print(proc_pytest.stderr.decode()) diff --git a/delivery_merge/utils.py b/delivery_merge/utils.py index 705eaf2..e3d43c0 100644 --- a/delivery_merge/utils.py +++ b/delivery_merge/utils.py @@ -32,7 +32,7 @@ def sh(prog, *args): command += tmp print(f'Running: {" ".join(command)}') - return run(command, capture_output=True) + return run(command, capture_output=True, env=os.environ) def git(*args): @@ -70,4 +70,3 @@ def pushd(path): yield finally: os.chdir(last) - @@ -16,6 +16,8 @@ setup( extras_require={ 'test': [ 'pytest', + 'pytest-cov', + 'codecov', ], } ) |