How to use the packit.specfile.Specfile 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 / integration / test_update.py View on Github external
def test_basic_local_update_using_distgit(
    cwd_upstream, api_instance, mock_remote_functionality_upstream
):
    """ basic propose-update test: mock remote API, use local upstream and dist-git """
    u, d, api = api_instance
    mock_spec_download_remote_s(d)

    api.sync_release("master", "0.1.0")

    assert (d / TARBALL_NAME).is_file()
    spec = Specfile(d / "beer.spec")
    assert spec.get_version() == "0.1.0"

    package_section = spec.spec_content.section("%package")

    assert package_section[2] == "# some change"
    assert package_section[4] == "Name:           beer"
    assert package_section[5] == "Version:        0.1.0"
    assert package_section[6] == "Release:        1%{?dist}"
    assert package_section[7] == "Summary:        A tool to make you happy"

    assert (d / "README.packit").is_file()
    # assert that we have changelog entries for both versions
    changelog = "\n".join(spec.spec_content.section("%changelog"))
    assert "0.0.0" in changelog
    assert "0.1.0" in changelog
github packit-service / packit / tests / integration / test_upstream.py View on Github external
def test_get_version(upstream_instance, m_v, exp):
    u, ups = upstream_instance
    flexmock(Specfile, get_upstream_version=lambda **kw: m_v)

    assert ups.get_version() == exp

    u.joinpath("README").write_text("\nEven better now!\n")
    subprocess.check_call(["git", "add", "."], cwd=u)
    subprocess.check_call(["git", "commit", "-m", "More awesome changes"], cwd=u)

    assert ups.get_current_version() == "0.1.0"
github packit-service / packit / tests / integration / test_source_git.py View on Github external
sourcegit_and_remote,
    distgit_and_remote,
    mock_patching,
    mock_remote_functionality_sourcegit,
    api_instance_source_git,
):
    """ propose-update for sourcegit test: mock remote API, use local upstream and dist-git """

    sourcegit, _ = sourcegit_and_remote
    distgit, _ = distgit_and_remote
    mock_spec_download_remote_s(distgit)

    api_instance_source_git.sync_release("master", "0.1.0", upstream_ref="0.1.0")

    assert (distgit / TARBALL_NAME).is_file()
    spec = Specfile(distgit / "beer.spec")
    assert spec.get_version() == "0.1.0"
github packit-service / packit / tests / integration / test_spec.py View on Github external
def test_write_spec_content():
    with open(SPECFILE) as spec:
        content = spec.read()

    data = "new line 1\n"
    spec = Specfile(SPECFILE)
    spec.spec_content.replace_section("%description", [data])
    spec.write_spec_content()

    with open(SPECFILE) as specfile:
        assert "new line 1" in specfile.read()
        spec.spec_content = SpecContent(content)
        spec.write_spec_content()
github packit-service / packit / tests / integration / test_update.py View on Github external
d.joinpath("beer.spec").unlink()
    subprocess.check_call(
        ["git", "commit", "-m", "remove spec", "-a"], cwd=str(d),
    )
    _, distgit_remote = distgit_and_remote
    mock_spec_download_remote_s(d)

    api.sync_release("master", "0.1.0", create_pr=False)

    remote_dir_clone = Path(f"{distgit_remote}-clone")
    subprocess.check_call(
        ["git", "clone", distgit_remote, str(remote_dir_clone)],
        cwd=str(remote_dir_clone.parent),
    )

    spec = Specfile(remote_dir_clone / "beer.spec")
    assert spec.get_version() == "0.1.0"
    assert (remote_dir_clone / "README.packit").is_file()
github packit-service / packit / tests / integration / test_update.py View on Github external
cwd_upstream, api_instance, distgit_and_remote, mock_remote_functionality_upstream
):
    """ basic propose-update test: mock remote API, use local upstream and dist-git """
    u, d, api = api_instance
    _, distgit_remote = distgit_and_remote
    mock_spec_download_remote_s(d)

    api.sync_release("master", "0.1.0", create_pr=False)

    remote_dir_clone = Path(f"{distgit_remote}-clone")
    subprocess.check_call(
        ["git", "clone", distgit_remote, str(remote_dir_clone)],
        cwd=str(remote_dir_clone.parent),
    )

    spec = Specfile(remote_dir_clone / "beer.spec")
    assert spec.get_version() == "0.1.0"
    assert (remote_dir_clone / "README.packit").is_file()
github packit-service / packit / tests / integration / test_update.py View on Github external
def test_basic_local_update(
    cwd_upstream, api_instance, mock_remote_functionality_upstream
):
    """ basic propose-update test: mock remote API, use local upstream and dist-git """
    u, d, api = api_instance
    mock_spec_download_remote_s(d)
    flexmock(api).should_receive("init_kerberos_ticket").at_least().once()

    api.sync_release("master", "0.1.0")

    assert (d / TARBALL_NAME).is_file()
    spec = Specfile(d / "beer.spec")
    assert spec.get_version() == "0.1.0"
    assert (d / "README.packit").is_file()
    # assert that we have changelog entries for both versions
    changelog = "\n".join(spec.spec_content.section("%changelog"))
    assert "0.0.0" in changelog
    assert "0.1.0" in changelog
github packit-service / packit / packit / base_git.py View on Github external
def __init__(self, config: Config, package_config: CommonPackageConfig) -> None:
        """
        :param config: global configuration
        :param package_config: configuration of the upstream project
        """
        self.config = config
        self.package_config = package_config
        self._specfile_path: Optional[Path] = None
        self._specfile: Optional[Specfile] = None
        self.allowed_gpg_keys: Optional[List[str]] = None

        self._handler_kls = None
        self._command_handler: Optional[CommandHandler] = None
github packit-service / packit / packit / upstream.py View on Github external
def get_latest_released_version(self) -> str:
        """
        Return version of the upstream project for the latest official release

        :return: the version string (e.g. "1.0.0")
        """

        version = Specfile.get_upstream_version(
            versioneer=None,
            package_name=self.package_config.downstream_package_name,
            category=None,
        )
        logger.info(f"Version in upstream registries is {version!r}.")
        return version
github packit-service / packit / packit / base_git.py View on Github external
def specfile(self) -> Specfile:
        if self._specfile is None:
            self._specfile = Specfile(
                self.absolute_specfile_path, self.absolute_specfile_dir
            )
        return self._specfile