How to use the packit.utils.cwd function in packit

To help you get started, we’ve selected a few packit 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 packit-service / packit / tests / spellbook.py View on Github external
def call_packit(fnc=None, parameters=None, envs=None, working_dir=None):
    working_dir = working_dir or "."
    fnc = fnc or packit_base
    runner = CliRunner()
    envs = envs or {}
    parameters = parameters or []
    # catch exceptions enables debugger
    with cwd(working_dir):
        return runner.invoke(fnc, args=parameters, env=envs, catch_exceptions=False)
github packit-service / packit / tests / functional / test_srpm.py View on Github external
def test_srpm_command_for_path(upstream_or_distgit_path, tmp_path):
    with cwd(tmp_path):
        call_real_packit(parameters=["--debug", "srpm", str(upstream_or_distgit_path)])
        srpm_path = list(Path.cwd().glob("*.src.rpm"))[0]
        assert srpm_path.exists()
        build_srpm(srpm_path)
github packit-service / packit / tests / integration / test_using_cockpit.py View on Github external
upload_to_lookaside_cache=lambda path: None,
        download_upstream_archive=lambda: "the-archive",
    )
    flexmock(
        PackitAPI,
        push_and_create_pr=lambda pr_title, pr_description, dist_git_branch: None,
    )

    pc = get_local_package_config(str(upstream_path))
    up_lp = LocalProject(working_dir=str(upstream_path))
    c = get_test_config()
    api = PackitAPI(c, pc, up_lp)
    api._dg = DistGit(c, pc)
    api._dg._local_project = LocalProject(working_dir=dist_git_path)

    with cwd(upstream_path):
        api.sync_release(
            "master",
            use_local_content=False,
            version="179",
            force_new_sources=False,
            create_pr=True,
        )
github packit-service / packit / tests / integration / test_source_git.py View on Github external
def test_srpm(mock_remote_functionality_sourcegit, api_instance_source_git):
    sg_path = Path(api_instance_source_git.upstream_local_project.working_dir)
    mock_spec_download_remote_s(sg_path / "fedora")
    create_merge_commit_in_source_git(sg_path)
    with cwd(sg_path):
        api_instance_source_git.create_srpm(upstream_ref="0.1.0")
    srpm_path = list(sg_path.glob("beer-0.1.0-2.*.src.rpm"))[0]
    assert srpm_path.is_file()
    build_srpm(srpm_path)
    branches = subprocess.check_output(
        ["git", "for-each-ref", "--format=%(refname:short)", "refs/heads/"], cwd=sg_path
    ).split(b"\n")
    for b in branches:
        if b and b.startswith(b"packit-patches-"):
            raise AssertionError(
                "packit-patches- branch was found - the history shouldn't have been linearized"
            )
    assert set([x.name for x in sg_path.joinpath("fedora").glob("*.patch")]) == {
        "0001-switching-to-amarillo-hops.patch",
        "0002-actually-let-s-do-citra.patch",
    }
github packit-service / packit / tests / integration / test_generate.py View on Github external
def test_generate_pass(upstream_without_config):
    with cwd(upstream_without_config):
        assert not (upstream_without_config / ".packit.yaml").is_file()

        # This test requires packit on pythonpath
        result = call_packit(parameters=["generate"])

        assert result.exit_code == 0

        assert (upstream_without_config / ".packit.yaml").is_file()
github packit-service / packit / tests / integration / test_using_examples.py View on Github external
def test_srpm_on_example(example_repo):
    c = get_test_config()
    api = get_packit_api(
        config=c, local_project=LocalProject(working_dir=str(example_repo))
    )
    with cwd(example_repo):
        path = api.create_srpm()
    assert path.exists()
    build_srpm(path)
github packit-service / packit / tests / integration / test_using_cockpit.py View on Github external
def test_srpm_on_cockpit_ostree(cockpit_ostree):
    upstream_path, dist_git_path = cockpit_ostree

    pc = get_local_package_config(str(upstream_path))
    up_lp = LocalProject(working_dir=str(upstream_path))
    c = get_test_config()
    api = PackitAPI(c, pc, up_lp)

    with cwd(upstream_path):
        api.create_srpm()
github packit-service / packit / tests / integration / test_copr.py View on Github external
def test_run_copr_build(upstream_n_distgit, copr_project, copr_build, test_copr_client):
    u, d = upstream_n_distgit

    with cwd(u):
        c = get_test_config()

        pc = get_local_package_config(str(u))
        pc.upstream_project_url = str(u)
        pc.downstream_project_url = str(d)
        up_lp = LocalProject(path_or_url=str(u))
        api = PackitAPI(c, pc, up_lp)

        flexmock(Client).should_receive("create_from_config_file").and_return(
            test_copr_client
        )

        # invalid owner + project
        with pytest.raises(PackitInvalidConfigException):
            api.run_copr_build("not-packit", "dummy", [])
github packit-service / packit / packit / distgit.py View on Github external
def download_upstream_archive(self) -> Path:
        """
        Fetch archive for the current upstream release defined in dist-git's spec

        :return: str, path to the archive
        """
        with cwd(self.local_project.working_dir):
            self.specfile.download_remote_sources()
        archive = self.absolute_specfile_dir / self.upstream_archive_name
        if not archive.exists():
            raise PackitException(
                "Upstream archive was not downloaded, something is wrong."
            )
        logger.info(f"Downloaded archive: {archive}")
        return archive
github packit-service / packit / packit / base_git.py View on Github external
def fetch_upstream_archive(self):
        with cwd(self.absolute_specfile_dir):
            self.specfile.download_remote_sources()