def test_build_sh_shellcheck_clean(package, repo, testing_workdir, testing_config): api.skeletonize(packages=package, repo=repo, output_dir=testing_workdir, config=testing_config) matches = [] for root, dirnames, filenames in os.walk(testing_workdir): for filename in fnmatch.filter(filenames, "build.sh"): matches.append(os.path.join(root, filename)) build_sh = matches[0] cmd = [ "shellcheck", "--enable=all", # SC2154: var is referenced but not assigned, # see https://github.com/koalaman/shellcheck/wiki/SC2154 "--exclude=SC2154", build_sh, ] p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) sc_stdout, _ = p.communicate() findings = sc_stdout.decode(sys.stdout.encoding).replace( "\r\n", "\n").splitlines() assert findings == [] assert p.returncode == 0
def test_pypi_with_version_arg(testing_workdir): # regression test for https://github.com/conda/conda-build/issues/1442 api.skeletonize('PrettyTable', 'pypi', version='0.7.2') with open('prettytable/meta.yaml') as f: actual = yaml.load(f) assert parse_version( actual['package']['version']) == parse_version("0.7.2")
def test_name_with_version_specified(testing_workdir, test_config): api.skeletonize('sympy', 'pypi', version='0.7.5', config=test_config) with open('{}/test-skeleton/sympy-0.7.5/meta.yaml'.format(thisdir)) as f: expected = yaml.load(f) with open('sympy/meta.yaml') as f: actual = yaml.load(f) assert expected == actual, (expected, actual)
def test_pypi_section_order_preserved(testing_workdir): """ Test whether sections have been written in the correct order. """ from conda_build.render import FIELDS from conda_build.skeletons.pypi import (ABOUT_ORDER, REQUIREMENTS_ORDER, PYPI_META_STATIC) api.skeletonize(packages='sympy', repo='pypi') # Since we want to check the order of items in the recipe (not whether # the metadata values themselves are sensible), read the file as (ordered) # yaml, and check the order. with open('sympy/meta.yaml', 'r') as file: lines = [l for l in file.readlines() if not l.startswith("{%")] # The loader below preserves the order of entries... recipe = ruamel_yaml.load('\n'.join(lines), Loader=ruamel_yaml.RoundTripLoader) major_sections = list(recipe.keys()) # Blank fields are omitted when skeletonizing, so prune any missing ones # before comparing. pruned_fields = [f for f in FIELDS if f in major_sections] assert major_sections == pruned_fields assert list(recipe['about']) == ABOUT_ORDER assert list(recipe['requirements']) == REQUIREMENTS_ORDER for k, v in PYPI_META_STATIC.items(): assert list(v.keys()) == list(recipe[k])
def test_pypi_with_extra_specs(testing_workdir): # regression test for https://github.com/conda/conda-build/issues/1697 api.skeletonize('bigfile', 'pypi', extra_specs=["cython", "mpi4py"], version='0.1.24', python="3.6") m = api.render('bigfile')[0][0] assert parse_version(m.version()) == parse_version("0.1.24") assert any('cython' in req for req in m.meta['requirements']['host']) assert any('mpi4py' in req for req in m.meta['requirements']['host'])
def test_setuptools_test_requirements(testing_workdir): api.skeletonize(packages='hdf5storage', repo='pypi') with open('hdf5storage/meta.yaml') as f: actual = yaml.load(f) assert actual['test']['requires'] == ['nose >=1.0']
def test_name_with_version_specified(testing_workdir, test_config): api.skeletonize(packages='sympy', repo='pypi', version='0.7.5', config=test_config) with open('{}/test-skeleton/sympy-0.7.5/meta.yaml'.format(thisdir)) as f: expected = yaml.load(f) with open('sympy/meta.yaml') as f: actual = yaml.load(f) assert expected == actual, (expected, actual)
def test_name_with_version_specified(testing_workdir, testing_config): api.skeletonize(packages='sympy', repo='pypi', version='0.7.5', config=testing_config) m = api.render('sympy/meta.yaml')[0][0] assert m.version() == "0.7.5"
def test_cran_no_comments(testing_workdir, testing_config): package = "data.table" meta_yaml_comment = ' # This is required to make R link correctly on Linux.' build_sh_comment = '# Add more build steps here, if they are necessary.' build_sh_shebang = '#!/bin/bash' # Check that comments are part of the templates assert meta_yaml_comment in CRAN_META assert build_sh_comment in CRAN_BUILD_SH_SOURCE assert build_sh_shebang in CRAN_BUILD_SH_SOURCE api.skeletonize(packages=package, repo='cran', output_dir=testing_workdir, config=testing_config, no_comments=True) # Check that comments got removed meta_yaml = os.path.join(testing_workdir, 'r-' + package.lower(), 'meta.yaml') with open(meta_yaml) as f: assert meta_yaml_comment not in f.read() build_sh = os.path.join(testing_workdir, 'r-' + package.lower(), 'build.sh') with open(build_sh) as f: build_sh_text = f.read() assert build_sh_comment not in build_sh_text assert build_sh_shebang in build_sh_text
def test_repo(prefix, repo, package, version, testing_workdir, test_config): api.skeletonize(package, output_dir=testing_workdir, repo=repo, config=test_config) try: package_name = "-".join([prefix, package]) if prefix else package assert os.path.isdir(os.path.join(testing_workdir, package_name.lower())) except: print(os.listdir(testing_workdir)) raise
def test_pypi_version_sorting(testing_workdir, test_config): # The package used here must have a numpy dependence for pin-numpy to have # any effect. api.skeletonize("impyla", "pypi") with open('impyla/meta.yaml') as f: actual = yaml.load(f) assert parse_version(actual['package']['version']) >= parse_version("0.13.8")
def test_pypi_with_version_inconsistency(testing_workdir, testing_config): # regression test for https://github.com/conda/conda-build/issues/189 # For mpi4py: testing_config.channel_urls.append('https://repo.anaconda.com/pkgs/free') api.skeletonize('mpi4py_test', 'pypi', extra_specs=["mpi4py"], version='0.0.10', python="3.6", config=testing_config) m = api.render('mpi4py_test')[0][0] assert parse_version(m.version()) == parse_version("0.0.10")
def test_pypi_url(testing_workdir, testing_config): api.skeletonize( 'https://pypi.python.org/packages/source/s/sympy/' 'sympy-0.7.5.tar.gz#md5=7de1adb49972a15a3dd975e879a2bea9', repo='pypi', config=testing_config) m = api.render('sympy/meta.yaml')[0][0] assert m.version() == "0.7.5"
def test_pypi_with_version_inconsistency(testing_workdir): # regression test for https://github.com/conda/conda-build/issues/189 api.skeletonize('mpi4py_test', 'pypi', extra_specs=["mpi4py"], version='0.0.10') m = api.render('mpi4py_test')[0][0] assert parse_version(m.version()) == parse_version("0.0.10")
def test_pypi_version_sorting(testing_workdir, test_config): # The package used here must have a numpy dependence for pin-numpy to have # any effect. api.skeletonize(packages='impyla', repo='pypi', config=test_config) with open('impyla/meta.yaml') as f: actual = yaml.load(f) assert parse_version(actual['package']['version']) >= parse_version("0.13.8")
def test_repo(prefix, repo, package, version, testing_workdir, test_config): api.skeletonize(package, repo, version=version, output_dir=testing_workdir, config=test_config) try: package_name = "-".join([prefix, package]) if prefix else package assert os.path.isdir(os.path.join(testing_workdir, package_name.lower())) except: print(os.listdir(testing_workdir)) raise
def test_cran_os_type(package, skip_text, testing_workdir, testing_config): api.skeletonize(packages=package, repo='cran', output_dir=testing_workdir, config=testing_config) fpath = os.path.join(testing_workdir, 'r-' + package.lower(), 'meta.yaml') with open(fpath) as f: assert skip_text in f.read()
def write_recipe(package, recipe_dir='.', recursive=False, force=False, no_windows=False, **kwargs): """ Call out to to `conda skeleton cran`. Kwargs are accepted for uniformity with `bioconductor_skeleton.write_recipe`; the only one handled here is `recursive`. Parameters ---------- package : str Package name. Can be case-sensitive CRAN name, or sanitized "r-pkgname" conda package name. recipe_dir : str Recipe will be created as a subdirectory in `recipe_dir` recursive : bool Add the `--recursive` argument to `conda skeleton cran` to recursively build CRAN recipes. force : bool If True, then remove the directory `<recipe_dir>/<pkgname>`, where `<pkgname>` the sanitized conda version of the package name, regardless of which format was provided as `package`. no_windows : bool If True, then after creating the skeleton the files are then cleaned of any Windows-related lines and the bld.bat file is removed from the recipe. """ logger.debug('Building skeleton for %s', package) conda_version = package.startswith('r-') if not conda_version: outdir = os.path.join( recipe_dir, 'r-' + package.lower()) else: outdir = os.path.join( recipe_dir, package) if os.path.exists(outdir): if force: logger.warning('Removing %s', outdir) run(['rm', '-r', outdir]) else: logger.warning('%s exists, skipping', outdir) return try: skeletonize( package, repo='cran', output_dir=recipe_dir, version=None, recursive=recursive) clean_skeleton_files( package=os.path.join(recipe_dir, 'r-' + package.lower()), no_windows=no_windows) except NotImplementedError as e: logger.error('%s had dependencies that specified versions: skipping.', package)
def test_pypi_pin_numpy(testing_workdir, testing_config): # The package used here must have a numpy dependence for pin-numpy to have # any effect. api.skeletonize(packages='msumastro', repo='pypi', version='0.9.0', config=testing_config, pin_numpy=True) with open(os.path.join('msumastro', 'meta.yaml')) as f: assert f.read().count('numpy x.x') == 2 with pytest.raises(DependencyNeedsBuildingError): api.build('msumastro')
def test_pypi_url(testing_workdir, test_config): api.skeletonize('https://pypi.python.org/packages/source/s/sympy/' 'sympy-0.7.5.tar.gz#md5=7de1adb49972a15a3dd975e879a2bea9', repo='pypi', config=test_config) with open('{}/test-skeleton/sympy-0.7.5-url/meta.yaml'.format(thisdir)) as f: expected = yaml.load(f) with open('sympy/meta.yaml') as f: actual = yaml.load(f) assert expected == actual, (expected, actual)
def test_pypi_with_extra_specs(testing_workdir): # regression test for https://github.com/conda/conda-build/issues/1697 api.skeletonize('bigfile', 'pypi', extra_specs=["cython", "mpi4py"], version='0.1.24') with open('bigfile/meta.yaml') as f: actual = yaml.load(f) assert parse_version( actual['package']['version']) == parse_version("0.1.24")
def test_pypi_with_version_inconsistency(testing_workdir): # regression test for https://github.com/conda/conda-build/issues/189 api.skeletonize('mpi4py_test', 'pypi', extra_specs=["mpi4py"], version='0.0.10') with open('mpi4py_test/meta.yaml') as f: actual = yaml.load(f) assert parse_version( actual['package']['version']) == parse_version("0.0.10")
def test_repo(prefix, repo, package, version, testing_workdir, testing_config): api.skeletonize(package, repo, version=version, output_dir=testing_workdir, config=testing_config) try: base_package, _ = os.path.splitext(os.path.basename(package)) package_name = "-".join([prefix, base_package]) if prefix else base_package assert os.path.isdir(os.path.join(testing_workdir, package_name.lower())) except: print(os.listdir(testing_workdir)) raise
def execute(args): parser, args = parse_args(args) config = Config(**args.__dict__) if not args.repo: parser.print_help() sys.exit() for package in args.packages: api.skeletonize(package, repo=args.repo, config=config)
def test_pypi_with_extra_specs(testing_workdir, testing_config): # regression test for https://github.com/conda/conda-build/issues/1697 # For mpi4py: testing_config.channel_urls.append('https://repo.anaconda.com/pkgs/free') api.skeletonize('bigfile', 'pypi', extra_specs=["cython", "mpi4py"], version='0.1.24', python="3.6", config=testing_config) m = api.render('bigfile')[0][0] assert parse_version(m.version()) == parse_version("0.1.24") assert any('cython' in req for req in m.meta['requirements']['host']) assert any('mpi4py' in req for req in m.meta['requirements']['host'])
def test_cran_license(package, license_id, license_family, license_file, testing_workdir, testing_config): api.skeletonize(packages=package, repo='cran', output_dir=testing_workdir, config=testing_config) m = api.render(os.path.join(package, 'meta.yaml'))[0][0] m_license_id = m.get_value('about/license') assert m_license_id == license_id m_license_family = m.get_value('about/license_family') assert m_license_family == license_family m_license_file = m.get_value('about/license_file', '') assert os.path.basename(m_license_file) == license_file
def execute(args): parser, args = parse_args(args) config = Config(**args.__dict__) if not args.repo: parser.print_help() sys.exit() api.skeletonize(args.packages, args.repo, output_dir=args.output_dir, recursive=args.recursive, version=args.version, config=config)
def test_pypi_pin_numpy(testing_workdir, test_config): # The package used here must have a numpy dependence for pin-numpy to have # any effect. api.skeletonize("msumastro", "pypi", version='0.9.0', pin_numpy=True) with open('msumastro/meta.yaml') as f: actual = yaml.load(f) assert 'numpy x.x' in actual['requirements']['run'] assert 'numpy x.x' in actual['requirements']['build']
def test_pypi_with_version_inconsistency(testing_workdir, testing_config): # regression test for https://github.com/conda/conda-build/issues/189 # For mpi4py: extra_specs = ['mpi4py'] if not on_win: extra_specs.append('nomkl') testing_config.channel_urls.append('https://repo.anaconda.com/pkgs/free') api.skeletonize('mpi4py_test', 'pypi', extra_specs=extra_specs, version='0.0.10', python="3.6", config=testing_config) m = api.render('mpi4py_test')[0][0] assert parse_version(m.version()) == parse_version("0.0.10")
def test_pypi_with_setup_options(testing_workdir, testing_config): # Use photutils package below because skeleton will fail unless the setup.py is given # the flag --offline because of a bootstrapping a helper file that # occurs by default. # Test that the setup option is used in constructing the skeleton. api.skeletonize(packages='photutils', repo='pypi', version='0.2.2', setup_options='--offline', config=testing_config) # Check that the setup option occurs in bld.bat and build.sh. m = api.render('photutils')[0][0] assert '--offline' in m.meta['build']['script']
def test_pypi_with_setup_options(testing_workdir, test_config): # Use package below because skeleton will fail unless the setup.py is given # the flag --offline because of a bootstrapping a helper file that # occurs by default. # Test that the setup option is used in constructing the skeleton. api.skeletonize('photutils', 'pypi', version="0.2.2", setup_options="--offline") # Check that the setup option occurs in bld.bat and build.sh. for script in ['bld.bat', 'build.sh']: with open('photutils/{}'.format(script)) as f: content = f.read() assert '--offline' in content
def test_repo(prefix, repo, package, version, testing_workdir, testing_config): api.skeletonize(package, repo, version=version, output_dir=testing_workdir, config=testing_config) try: base_package, _ = os.path.splitext(os.path.basename(package)) package_name = "-".join([prefix, base_package]) if prefix else base_package contents = os.listdir(testing_workdir) assert len([content for content in contents if content.startswith(package_name.lower()) and os.path.isdir(os.path.join(testing_workdir, content))]) except: print(os.listdir(testing_workdir)) raise
def test_pypi_with_extra_specs(testing_workdir, testing_config): # regression test for https://github.com/conda/conda-build/issues/1697 # For mpi4py: testing_config.channel_urls.append('https://repo.anaconda.com/pkgs/free') extra_specs = ['cython', 'mpi4py'] if not on_win: extra_specs.append('nomkl') api.skeletonize('bigfile', 'pypi', extra_specs=extra_specs, version='0.1.24', python="3.6", config=testing_config) m = api.render('bigfile')[0][0] assert parse_version(m.version()) == parse_version("0.1.24") assert any('cython' in req for req in m.meta['requirements']['host']) assert any('mpi4py' in req for req in m.meta['requirements']['host'])
def test_pypi_with_setup_options(testing_workdir, test_config): # Use photutils package below because skeleton will fail unless the setup.py is given # the flag --offline because of a bootstrapping a helper file that # occurs by default. # Test that the setup option is used in constructing the skeleton. api.skeletonize(packages='photutils', repo='pypi', version='0.2.2', setup_options='--offline', config=test_config) # Check that the setup option occurs in bld.bat and build.sh. for script in ['bld.bat', 'build.sh']: with open('photutils/{}'.format(script)) as f: content = f.read() assert '--offline' in content
def test_pypi_with_basic_environment_markers(testing_workdir): # regression test for https://github.com/conda/conda-build/issues/1974 api.skeletonize('coconut', 'pypi', version='1.2.2') m = api.render('coconut')[0][0] build_reqs = str(m.meta['requirements']['host']) run_reqs = str(m.meta['requirements']['run']) # should include the right dependencies for the right version assert "futures" not in build_reqs assert "futures" not in run_reqs if sys.version_info >= (2, 7): assert "pygments" in build_reqs assert "pygments" in run_reqs else: assert "pygments" not in build_reqs assert "pygments" not in run_reqs
def test_pypi_with_basic_environment_markers(testing_workdir): # regression test for https://github.com/conda/conda-build/issues/1974 api.skeletonize('coconut', 'pypi', version='1.2.2') with open('coconut/meta.yaml') as f: actual = yaml.load(f) build_reqs = str(actual['requirements']['build']) run_reqs = str(actual['requirements']['run']) # should include the right dependencies for the right version if sys.version_info < (3, ): assert "futures" in build_reqs assert "futures" in run_reqs else: assert "futures" not in build_reqs assert "futures" not in run_reqs if sys.version_info >= (2, 7): assert "pygments" in build_reqs assert "pygments" in run_reqs else: assert "pygments" not in build_reqs assert "pygments" not in run_reqs
def test_pypi_with_basic_environment_markers(testing_workdir): # regression test for https://github.com/conda/conda-build/issues/1974 api.skeletonize('coconut', 'pypi', version='1.2.2') m = api.render('coconut')[0][0] build_reqs = str(m.meta['requirements']['host']) run_reqs = str(m.meta['requirements']['run']) # should include the right dependencies for the right version if sys.version_info < (3,): assert "futures" in build_reqs assert "futures" in run_reqs else: assert "futures" not in build_reqs assert "futures" not in run_reqs if sys.version_info >= (2, 7): assert "pygments" in build_reqs assert "pygments" in run_reqs else: assert "pygments" not in build_reqs assert "pygments" not in run_reqs
def test_pypi_with_basic_environment_markers(testing_workdir): # regression test for https://github.com/conda/conda-build/issues/1974 api.skeletonize('coconut', 'pypi', version='1.2.2') with open('coconut/meta.yaml') as f: actual = yaml.load(f) build_reqs = str(actual['requirements']['build']) run_reqs = str(actual['requirements']['run']) # should include the right dependencies for the right version if sys.version_info < (3,): assert "futures" in build_reqs assert "futures" in run_reqs else: assert "futures" not in build_reqs assert "futures" not in run_reqs if sys.version_info >= (2, 7): assert "pygments" in build_reqs assert "pygments" in run_reqs else: assert "pygments" not in build_reqs assert "pygments" not in run_reqs
def generate_skeleton(package, path): """ Use conda skeleton pypi to generate a recipe for a package and save it to path. Parameters ---------- package: Package The package for which a recipe is to be generated. path: str Path to which the recipe should be written. """ additional_arguments = ['--version', str(package.required_version), '--output-dir', path] additional_arguments = {} if package.include_extras: additional_arguments['all_extras'] = True # Options below ensure an egg is not included in the built package additional_arguments['setup_options'] = [ '--single-version-externally-managed', '--record rec.txt' ] if package.setup_options: additional_arguments['setup_options'].append(package.setup_options) if package.numpy_compiled_extensions: additional_arguments['pin_numpy'] = True skeletonize(package.pypi_name, 'pypi', output_dir=path, version=str(package.required_version), **additional_arguments)
def test_pypi_url(testing_workdir, testing_config): api.skeletonize('https://pypi.python.org/packages/source/s/sympy/' 'sympy-0.7.5.tar.gz#md5=7de1adb49972a15a3dd975e879a2bea9', repo='pypi', config=testing_config) m = api.render('sympy/meta.yaml')[0][0] assert m.version() == "0.7.5"
def test_pypi_with_extra_specs(testing_workdir): # regression test for https://github.com/conda/conda-build/issues/1697 api.skeletonize('bigfile', 'pypi', extra_specs=["cython", "mpi4py"], version='0.1.24') with open('bigfile/meta.yaml') as f: actual = yaml.load(f) assert parse_version(actual['package']['version']) == parse_version("0.1.24")
def test_pypi_with_version_arg(testing_workdir): # regression test for https://github.com/conda/conda-build/issues/1442 api.skeletonize('PrettyTable', 'pypi', version='0.7.2') m = api.render('prettytable')[0][0] assert parse_version(m.version()) == parse_version("0.7.2")
def test_pypi_with_version_inconsistency(testing_workdir): # regression test for https://github.com/conda/conda-build/issues/189 api.skeletonize('mpi4py_test', 'pypi', extra_specs=["mpi4py"], version='0.0.10') with open('mpi4py_test/meta.yaml') as f: actual = yaml.load(f) assert parse_version(actual['package']['version']) == parse_version("0.0.10")
def test_setuptools_test_requirements(testing_workdir): api.skeletonize(packages='hdf5storage', repo='pypi') m = api.render('hdf5storage')[0][0] assert m.meta['test']['requires'] == ['nose >=1.0']
def test_pypi_with_version_inconsistency(testing_workdir): # regression test for https://github.com/conda/conda-build/issues/189 api.skeletonize('mpi4py_test', 'pypi', extra_specs=["mpi4py"], version='0.0.10', python="3.6") m = api.render('mpi4py_test')[0][0] assert parse_version(m.version()) == parse_version("0.0.10")
def test_pypi_version_sorting(testing_workdir, testing_config): # The package used here must have a numpy dependence for pin-numpy to have # any effect. api.skeletonize(packages='impyla', repo='pypi', config=testing_config) m = api.render('impyla')[0][0] assert parse_version(m.version()) >= parse_version("0.13.8")
def test_pypi_with_entry_points(testing_workdir): api.skeletonize('planemo', repo='pypi', python_version="2.7") assert os.path.isdir('planemo')
def test_pypi_with_version_arg(testing_workdir): # regression test for https://github.com/conda/conda-build/issues/1442 api.skeletonize('PrettyTable', 'pypi', version='0.7.2') with open('prettytable/meta.yaml') as f: actual = yaml.load(f) assert parse_version(actual['package']['version']) == parse_version("0.7.2")