How to use the requirementslib.models.setup_info.ast_parse_file function in requirementslib

To help you get started, we’ve selected a few requirementslib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sarugaku / requirementslib / tests / unit / test_setup_info.py View on Github external
def test_ast_parser_handles_repeated_assignments(setup_py_dir):
    target = setup_py_dir.joinpath(
        "package_with_repeated_assignments/setup.py"
    ).as_posix()
    parsed = ast_parse_setup_py(target)
    analyzer = ast_parse_file(target)
    assert parsed["name"] == "test_package_with_repeated_assignments"
    assert isinstance(parsed["version"], str) is False
    assert parsed["install_requires"] == ["six"]
    analyzer_parsed = analyzer.parse_setup_function()
    # the versions in this instance are AST objects as they come from
    # os.environ and will need to be parsed downstream from here, so
    # equality comparisons will fail
    analyzer_parsed.pop("version")
    parsed.pop("version")
    assert analyzer_parsed == parsed
github sarugaku / requirementslib / tests / unit / test_setup_info.py View on Github external
def test_ast_parser_handles_exceptions(artifact_dir):
    path = artifact_dir.joinpath("git/pyinstaller/setup.py")
    result = ast_parse_setup_py(path.as_posix())
    analyzer = ast_parse_file(path.as_posix())
    assert result is not None
    assert "altgraph" in result["install_requires"]
    for k, v in analyzer.parse_setup_function().items():
        assert k in result
        assert result[k] == v or (
            isinstance(v, dict) and isinstance(list(v.keys())[0], ast.Attribute)
        )
github sarugaku / requirementslib / tests / unit / test_setup_info.py View on Github external
def test_ast_parser_handles_binops(setup_py_dir):
    target = setup_py_dir.joinpath("package_with_setup_from_dict/setup.py").as_posix()
    parsed = ast_parse_setup_py(target)
    analyzer = ast_parse_file(target)
    assert parsed["name"] == "test package"
    assert parsed["version"] == "1.0.0"
    expected = [
        "pytest",
        "flake8",
    ]
    assert list(sorted(parsed["extras_require"]["tests"])) == list(sorted(expected))
    assert analyzer.parse_setup_function() == parsed
github sarugaku / requirementslib / tests / unit / test_setup_info.py View on Github external
def test_ast_parser_finds_fully_qualified_setup(setup_py_dir):
    target = setup_py_dir.joinpath(
        "package_using_fully_qualified_setuptools/setup.py"
    ).as_posix()
    parsed = ast_parse_setup_py(target)
    analyzer = ast_parse_file(target)
    expected = {
        "name": "test_package",
        "version": "1.0.0",
        "description": "The Backend HTTP Server",
        "long_description": "This is a package",
        "install_requires": ["six"],
        "tests_require": ["coverage", "flaky"],
        "extras_require": {"testing": ["coverage", "flaky"]},
        "package_dir": {"": "src"},
        "packages": ["test_package"],
        "include_package_data": True,
        "zip_safe": False,
    }
    for k, v in expected.items():
        assert k in parsed
        if isinstance(v, bool):
github sarugaku / requirementslib / tests / unit / test_setup_info.py View on Github external
def test_ast_parser_finds_variables(setup_py_dir):
    target = setup_py_dir.joinpath("package_with_extras_as_variable/setup.py").as_posix()
    parsed = ast_parse_setup_py(target)
    analyzer = ast_parse_file(target)
    expected = {
        "name": "test_package",
        "version": "1.0.0",
        "description": "The Backend HTTP Server",
        "long_description": "This is a package",
        "install_requires": ["six"],
        "tests_require": ["coverage", "flaky"],
        "extras_require": {"testing": ["coverage", "flaky"]},
        "package_dir": {"": "src"},
        "packages": ["test_package"],
        "include_package_data": True,
        "zip_safe": False,
    }
    for k, v in expected.items():
        assert k in parsed
        if isinstance(v, bool):