Exemplo n.º 1
0
def test_lock_no_update(
    command_tester_factory: CommandTesterFactory,
    poetry_with_old_lockfile: Poetry,
    repo: TestRepository,
):
    repo.add_package(get_package("sampleproject", "1.3.1"))
    repo.add_package(get_package("sampleproject", "2.0.0"))

    locker = Locker(
        lock=poetry_with_old_lockfile.pyproject.file.path.parent / "poetry.lock",
        local_config=poetry_with_old_lockfile.locker._local_config,
    )
    poetry_with_old_lockfile.set_locker(locker)

    locked_repository = poetry_with_old_lockfile.locker.locked_repository()
    assert (
        poetry_with_old_lockfile.locker.lock_data["metadata"].get("lock-version")
        == "1.0"
    )

    tester = command_tester_factory("lock", poetry=poetry_with_old_lockfile)
    tester.execute("--no-update")

    locker = Locker(
        lock=poetry_with_old_lockfile.pyproject.file.path.parent / "poetry.lock",
        local_config={},
    )
    packages = locker.locked_repository().packages

    assert len(packages) == len(locked_repository.packages)

    assert locker.lock_data["metadata"].get("lock-version") == "1.1"

    for package in packages:
        assert locked_repository.find_packages(package.to_dependency())
Exemplo n.º 2
0
def test_lock_no_update(command_tester_factory, poetry_with_old_lockfile,
                        http):
    http.disable()

    locked_repository = poetry_with_old_lockfile.locker.locked_repository(
        with_dev_reqs=True)
    assert (poetry_with_old_lockfile.locker.lock_data["metadata"].get(
        "lock-version") == "1.0")

    tester = command_tester_factory("lock", poetry=poetry_with_old_lockfile)
    tester.execute("--no-update")

    locker = Locker(
        lock=poetry_with_old_lockfile.pyproject.file.path.parent /
        "poetry.lock",
        local_config={},
    )
    packages = locker.locked_repository(True).packages

    assert len(packages) == len(locked_repository.packages)

    assert locker.lock_data["metadata"].get("lock-version") == "1.1"

    for package in packages:
        assert locked_repository.find_packages(package.to_dependency())
Exemplo n.º 3
0
def test_lock_check_up_to_date(command_tester_factory,
                               poetry_with_up_to_date_lockfile, http):
    http.disable()

    locker = Locker(
        lock=poetry_with_up_to_date_lockfile.pyproject.file.path.parent /
        "poetry.lock",
        local_config=poetry_with_up_to_date_lockfile.locker._local_config,
    )
    poetry_with_up_to_date_lockfile.set_locker(locker)

    tester = command_tester_factory("lock",
                                    poetry=poetry_with_up_to_date_lockfile)
    status_code = tester.execute("--check")

    # exit with an error
    assert status_code == 0
Exemplo n.º 4
0
def test_lock_check_up_to_date(
    command_tester_factory: CommandTesterFactory,
    poetry_with_up_to_date_lockfile: Poetry,
    http: type[httpretty.httpretty],
):
    http.disable()

    locker = Locker(
        lock=poetry_with_up_to_date_lockfile.pyproject.file.path.parent / "poetry.lock",
        local_config=poetry_with_up_to_date_lockfile.locker._local_config,
    )
    poetry_with_up_to_date_lockfile.set_locker(locker)

    tester = command_tester_factory("lock", poetry=poetry_with_up_to_date_lockfile)
    status_code = tester.execute("--check")
    expected = "poetry.lock is consistent with pyproject.toml.\n"
    assert tester.io.fetch_output() == expected

    # exit with an error
    assert status_code == 0
Exemplo n.º 5
0
def test_lock_check_outdated(
    command_tester_factory: "CommandTesterFactory",
    poetry_with_outdated_lockfile: "Poetry",
    http: Type["httpretty.httpretty"],
):
    http.disable()

    locker = Locker(
        lock=poetry_with_outdated_lockfile.pyproject.file.path.parent /
        "poetry.lock",
        local_config=poetry_with_outdated_lockfile.locker._local_config,
    )
    poetry_with_outdated_lockfile.set_locker(locker)

    tester = command_tester_factory("lock",
                                    poetry=poetry_with_outdated_lockfile)
    status_code = tester.execute("--check")

    # exit with an error
    assert status_code == 1
Exemplo n.º 6
0
def test_lock_check_outdated(
    command_tester_factory: CommandTesterFactory,
    poetry_with_outdated_lockfile: Poetry,
    http: type[httpretty.httpretty],
):
    http.disable()

    locker = Locker(
        lock=poetry_with_outdated_lockfile.pyproject.file.path.parent / "poetry.lock",
        local_config=poetry_with_outdated_lockfile.locker._local_config,
    )
    poetry_with_outdated_lockfile.set_locker(locker)

    tester = command_tester_factory("lock", poetry=poetry_with_outdated_lockfile)
    status_code = tester.execute("--check")
    expected = (
        "Error: poetry.lock is not consistent with pyproject.toml. "
        "Run `poetry lock [--no-update]` to fix it.\n"
    )

    assert tester.io.fetch_error() == expected

    # exit with an error
    assert status_code == 1
Exemplo n.º 7
0
    def create(cls, path=None):
        path = path or os.getcwd()
        pyproject_file = Path(path)

        if pyproject_file.name != "pyproject.toml":
            pyproject_file = pyproject_file / "pyproject.toml"

        if not pyproject_file.exists():
            raise RuntimeError(
                "Jetty could not find a pyproject.toml file in {}".format(
                    path))

        local_config = TomlFile(pyproject_file.as_posix()).read()
        tool = local_config.setdefault('tool', {})

        if 'jetty' not in tool and 'poetry' not in tool:
            raise RuntimeError("[tool.jetty] section not found in {}".format(
                pyproject_file.name))

        local_config = merge(tool.get('jetty', {}), tool.get('poetry', {}))

        # Checking validity
        cls.check(local_config)

        # Load package
        name = local_config.get('name', pyproject_file.parent.name)
        version = local_config.get('version', '0')
        package = ProjectPackage(name, version, version)

        if 'dependencies' in local_config:
            for name, constraint in local_config['dependencies'].items():
                if name.lower() == 'python':
                    package.python_versions = constraint
                    continue

                if isinstance(constraint, list):
                    for _constraint in constraint:
                        package.add_dependency(name, _constraint)

                    continue

                package.add_dependency(name, constraint)

        if 'dev-dependencies' in local_config:
            for name, constraint in local_config['dev-dependencies'].items():
                if isinstance(constraint, list):
                    for _constraint in constraint:
                        package.add_dependency(name,
                                               _constraint,
                                               category='dev')

                    continue

                package.add_dependency(name, constraint, category='dev')

        extras = local_config.get("extras", {})
        for extra_name, requirements in extras.items():
            package.extras[extra_name] = []

            # Checking for dependency
            for req in requirements:
                req = Dependency(req, "*")

                for dep in package.requires:
                    if dep.name == req.name:
                        dep.in_extras.append(extra_name)
                        package.extras[extra_name].append(dep)

                        break

        lock = pyproject_file.parent / "poetry.lock"
        locker = Locker(lock, local_config)
        return cls(pyproject_file, local_config, package, locker)