def test_get_test_requirements(): config = Configuration(name="ewokscore", version="0.1.0rc5") recipe = GrayskullFactory.create_recipe("pypi", config) assert "pytest" not in recipe["test"]["requires"] assert "pytest --pyargs ewokscore" not in recipe["test"]["commands"] config = Configuration(name="ewokscore", version="0.1.0rc5", extras_require_test="wrongoption") recipe = GrayskullFactory.create_recipe("pypi", config) assert "pytest" not in recipe["test"]["requires"] assert "pytest --pyargs ewokscore" not in recipe["test"]["commands"] # pytest dependency has no version constraints config = Configuration(name="ewokscore", version="0.1.0rc5", extras_require_test="test") recipe = GrayskullFactory.create_recipe("pypi", config) assert "pytest" in recipe["test"]["requires"] assert "pytest --pyargs ewokscore" in recipe["test"]["commands"] # pytest dependency has version constraints config = Configuration(name="ewokscore", version="0.1.0rc8 ", extras_require_test="test") recipe = GrayskullFactory.create_recipe("pypi", config) assert "pytest" in recipe["test"]["requires"] assert "pytest --pyargs ewokscore" in recipe["test"]["commands"]
def test_get_extra_requirements(): config = Configuration(name="pypushflow") data = get_sdist_metadata( "https://pypi.io/packages/source/p/pypushflow/pypushflow-0.3.0rc2.tar.gz", config, ) received = { extra: set(lst) for extra, lst in data["extras_require"].items() } expected = { "mx": {"pymongo >=4, <5"}, "test": { "mongita >=1, <2", "pytest >=7, <8", "psutil >=5.8, <6", "pytest-subtests >=0.4, <1", }, "dev": { "pytest >=7, <8", "black >=22, <23", "psutil >=5.8, <6", "flake8 >=4, <5", "mongita >=1, <2", "pytest-subtests >=0.4, <1", }, } assert received == expected
def test_merge_pypi_sdist_metadata(): config = Configuration(name="gsw", version="3.3.1") pypi_metadata = get_pypi_metadata(config) sdist_metadata = get_sdist_metadata(pypi_metadata["sdist_url"], config) merged_data = merge_pypi_sdist_metadata(pypi_metadata, sdist_metadata, config) assert merged_data["compilers"] == ["c"] assert sorted(merged_data["setup_requires"]) == sorted(["numpy"])
def test_injection_distutils_setup_reqs_ensure_list(): pkg_name, pkg_ver = "pyinstaller-hooks-contrib", "2020.7" config = Configuration(name=pkg_name, version=pkg_ver) data = get_sdist_metadata( f"https://pypi.io/packages/source/p/{pkg_name}/{pkg_name}-{pkg_ver}.tar.gz", config, ) assert data.get("setup_requires") == ["setuptools >= 30.3.0"]
def test_get_compilers(): config = Configuration(name="any_package") assert get_compilers(["pybind11"], {}, config) == ["cxx"] assert get_compilers(["cython"], {}, config) == ["c"] assert sorted(get_compilers(["pybind11", "cython"], {}, config)) == sorted(["cxx", "c"]) assert sorted(get_compilers(["pybind11"], {"compilers": ["c"]}, config)) == sorted(["cxx", "c"])
def test_cythongsl_recipe_build(): recipe = GrayskullFactory.create_recipe( "pypi", Configuration(name="cythongsl", version="0.2.2")) assert recipe["requirements"]["build"] == ["<{ compiler('c') }}"] assert recipe["requirements"]["host"] == ["cython >=0.16", "pip", "python"] assert recipe["build"]["noarch"] is None assert recipe["build"]["number"] == 0
def test_get_pypi_metadata(pypi_metadata): recipe = Recipe(name="pytest") config = Configuration(name="pytest", version="5.3.1", is_strict_cf=True) metadata = get_pypi_metadata(config) PypiStrategy.fetch_data(recipe, config) assert metadata["name"] == "pytest" assert metadata["version"] == "5.3.1" assert "pathlib2 >=2.2.0 # [py<36]" not in recipe["requirements"]["run"]
def test_panel_entry_points(tmpdir): config = Configuration(name="panel", version="0.9.1") recipe = GrayskullFactory.create_recipe("pypi", config) generate_recipe(recipe, config, folder_path=str(tmpdir)) recipe_path = str(tmpdir / "panel" / "meta.yaml") with open(recipe_path, "r") as f: content = f.read() assert "- panel = panel.cli:main" in content
def create_python_recipe(pkg_name, sections_populate=None, **kwargs): config = Configuration(name=pkg_name, **kwargs) return ( GrayskullFactory.create_recipe("pypi", config, sections_populate=sections_populate), config, )
def test_zipp_recipe_tags_on_deps(): config = Configuration(name="zipp", version="3.0.0") recipe = GrayskullFactory.create_recipe("pypi", config) assert recipe["build"]["noarch"] assert recipe["requirements"]["host"] == [ "pip", "python >=3.6", "setuptools-scm >=3.4.1", ]
def test_requests_recipe_extra_deps(capsys, name): CLIConfig().stdout = True name = parse_pkg_name_version(name)[1] config = Configuration(name=name, version="2.22.0") recipe = GrayskullFactory.create_recipe("pypi", config) captured_stdout = capsys.readouterr() assert "win-inet-pton" not in recipe["requirements"]["run"] assert recipe["build"]["noarch"] assert not recipe["build"]["skip"] assert f"{Fore.GREEN}{Style.BRIGHT}python" in captured_stdout.out
def test_pymc_recipe_fortran(): recipe = GrayskullFactory.create_recipe( "pypi", Configuration(name="pymc", version="2.3.6")) assert sorted(recipe["requirements"]["build"]) == sorted( ["<{ compiler('c') }}", "<{ compiler('fortran') }}"]) assert sorted(recipe["requirements"]["host"]) == sorted( ["numpy", "python", "pip"]) assert sorted(recipe["requirements"]["run"]) == sorted( ["<{ pin_compatible('numpy') }}", "python"]) assert not recipe["build"]["noarch"]
def test_ciso_recipe(): recipe = GrayskullFactory.create_recipe( "pypi", Configuration(name="ciso", version="0.1.0")) assert sorted(recipe["requirements"]["host"]) == sorted( ["cython", "numpy", "pip", "python"]) assert sorted(recipe["requirements"]["run"]) == sorted( ["cython", "python", "<{ pin_compatible('numpy') }}"]) assert recipe["test"]["commands"] == ["pip check"] assert recipe["test"]["requires"] == ["pip"] assert recipe["test"]["imports"] == ["ciso"]
def test_run_requirements_sdist(): config = Configuration(name="botocore", version="1.14.17") recipe = GrayskullFactory.create_recipe("pypi", config) assert sorted(recipe["requirements"]["run"]) == sorted([ "docutils >=0.10,<0.16", "jmespath >=0.7.1,<1.0.0", "python", "python-dateutil >=2.1,<3.0.0", "urllib3 >=1.20,<1.26", ])
def test_deps_comments(): config = Configuration(name="kubernetes_asyncio", version="11.2.0") recipe = GrayskullFactory.create_recipe("pypi", config) assert recipe["requirements"]["run"] == [ "aiohttp >=2.3.10,<4.0.0", "certifi >=14.05.14", "python", "python-dateutil >=2.5.3", "pyyaml >=3.12", "setuptools >=21.0.0", "six >=1.9.0", "urllib3 >=1.24.2", ]
def test_injection_distutils(name): config = Configuration(name="hypothesis") data = get_sdist_metadata( "https://pypi.io/packages/source/h/hypothesis/hypothesis-5.5.1.tar.gz", config, ) assert sorted(data["install_requires"]) == sorted( ["attrs>=19.2.0", "sortedcontainers>=2.1.0,<3.0.0"]) assert data["entry_points"] == { "pytest11": ["hypothesispytest = hypothesis.extra.pytestplugin"] } assert data["version"] == "5.5.1" assert data["name"] == "hypothesis" assert not data.get("compilers")
def test_mypy_deps_normalization_and_entry_points(): config = Configuration(name="mypy", version="0.770") recipe = GrayskullFactory.create_recipe("pypi", config) assert "mypy_extensions >=0.4.3,<0.5.0" in recipe["requirements"]["run"] assert "mypy-extensions >=0.4.3,<0.5.0" not in recipe["requirements"][ "run"] assert "typed-ast >=1.4.0,<1.5.0" in recipe["requirements"]["run"] assert "typed_ast <1.5.0,>=1.4.0" not in recipe["requirements"]["run"] assert "typing-extensions >=3.7.4" in recipe["requirements"]["run"] assert "typing_extensions >=3.7.4" not in recipe["requirements"]["run"] assert recipe["build"]["entry_points"] == [ "mypy=mypy.__main__:console_entry", "stubgen=mypy.stubgen:main", "stubtest=mypy.stubtest:main", "dmypy=mypy.dmypy.client:console_entry", ]
def test_injection_distutils_pytest(): config = Configuration(name="pytest", version="5.3.2") data = get_sdist_metadata( "https://pypi.io/packages/source/p/pytest/pytest-5.3.2.tar.gz", config) assert sorted(data["install_requires"]) == sorted([ "py>=1.5.0", "packaging", "attrs>=17.4.0", "more-itertools>=4.0.0", 'atomicwrites>=1.0;sys_platform=="win32"', 'pathlib2>=2.2.0;python_version<"3.6"', 'colorama;sys_platform=="win32"', "pluggy>=0.12,<1.0", 'importlib-metadata>=0.12;python_version<"3.8"', "wcwidth", ]) assert sorted(data["setup_requires"]) == sorted( ["setuptools>=40.0", "setuptools_scm"]) assert not data.get("compilers")
def update_recipe(recipe: Recipe, config: Configuration, all_sections: List[str]): """Update one specific section.""" from souschef.section import Section metadata = get_metadata(recipe, config) for section in all_sections: if metadata.get(section): if section == "package": set_global_jinja_var(recipe, "version", metadata["package"]["version"]) config.version = metadata["package"]["version"] recipe["package"]["version"] = "<{ version }}" elif section in recipe and isinstance(recipe[section], Section): recipe[section].update(metadata[section]) else: recipe.add_section({section: metadata[section]}) if not config.is_arch: recipe["build"]["noarch"] = "python"
def test_part_reload_recipe(tmpdir): recipe = GrayskullFactory.create_recipe( "pypi", Configuration(name="pytest", version="5.3.2") ) host = deepcopy([str(i) for i in recipe["requirements"]["host"]]) run = deepcopy([str(i) for i in recipe["requirements"]["run"]]) recipe["requirements"] = {} recipe["foo"] = "bar" assert not recipe["requirements"].value assert host assert run assert recipe["foo"] == "bar" folder = tmpdir.mkdir("reload_recipe") recipe_path = folder / "recipe.yaml" recipe.save(str(recipe_path)) cli.main(["pypi", str(recipe_path), "--sections", "requirements"]) recipe = Recipe(load_file=str(recipe_path)) assert host == [str(v) for v in recipe["requirements"]["host"] if v] assert run == [str(v) for v in recipe["requirements"]["run"] if v] assert recipe["foo"] == "bar"
def get_all_selectors_pypi(list_extra: List, config: Configuration) -> List: """Get the selectors looking for the pypi data :param list_extra: List of extra requirements from pypi :param config: Configuration instructions for recipe :return: List of extra requirements with the selectors """ result_selector = [] for extra in list_extra: config.is_arch = True selector = parse_extra_metadata_to_selector(extra[1], extra[2], extra[3]) if selector: if extra[0]: result_selector.append(extra[0]) result_selector.append(selector) if extra[4]: result_selector.append(extra[4]) if extra[5]: result_selector.append(extra[5]) if result_selector and result_selector[-1] in ["and", "or"]: del result_selector[-1] return result_selector
def test_importlib_metadata_two_setuptools_scm(): config = Configuration(name="importlib-metadata", version="1.5.0") recipe = GrayskullFactory.create_recipe("pypi", config) assert "setuptools-scm" in recipe["requirements"]["host"] assert "setuptools_scm" not in recipe["requirements"]["host"] assert recipe["about"]["license"] == "Apache-2.0"
def test_generic_py_ver_to(requires_python, expected): config = Configuration(name="abc") assert generic_py_ver_to({"requires_python": requires_python}, config) == expected
def test_config_url_pypi_metadata(): config = Configuration("pytest", url_pypi_metadata="http://url_pypi.com/abc") assert config.url_pypi_metadata == "http://url_pypi.com/abc/{pkg_name}/json"
def test_botocore_recipe_license_name(): config = Configuration(name="botocore", version="1.15.8") recipe = GrayskullFactory.create_recipe("pypi", config) assert recipe["about"]["license"] == "Apache-2.0"
def test_ipytest_recipe_license(): config = Configuration(name="ipytest", version="0.8.0") recipe = GrayskullFactory.create_recipe("pypi", config) assert recipe["about"]["license"] == "MIT"
def test_keyring_host_appearing_twice(): config = Configuration(name="keyring", version="21.1.1") recipe = GrayskullFactory.create_recipe("pypi", config) assert "importlib-metadata" in recipe["requirements"]["run"] assert "importlib_metadata" not in recipe["requirements"]["run"]
def test_python_requires_setup_py(): config = Configuration(name="pygments", version="2.6.1") recipe = GrayskullFactory.create_recipe("pypi", config) assert recipe["build"]["noarch"] assert "python >=3.5" in recipe["requirements"]["host"] assert "python >=3.5" in recipe["requirements"]["run"]
def test_nbdime_license_type(): config = Configuration(name="nbdime", version="2.0.0") recipe = GrayskullFactory.create_recipe("pypi", config) assert recipe["about"]["license"] == "BSD-3-Clause" assert "setupbase" not in recipe["requirements"]["host"]
def test_django_rest_framework_xml_license(): config = Configuration(name="djangorestframework-xml", version="1.4.0") recipe = GrayskullFactory.create_recipe("pypi", config) assert recipe["about"]["license"] == "BSD-3-Clause" assert recipe["about"]["license_file"] == "LICENSE" assert recipe["test"]["imports"][0] == "rest_framework_xml"