Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable packit rpm packaging #292

Merged
merged 1 commit into from
Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ __pycache__/
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
Expand All @@ -32,6 +31,8 @@ MANIFEST
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
rpm/*.spec
*.rpm

# Installer logs
pip-log.txt
Expand Down
42 changes: 42 additions & 0 deletions .packit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
# https://packit.dev/docs/configuration/
# Test locally running: packit build locally
# spell-checker:ignore packit specfile copr epel
specfile_path: dist/python-ansible-compat.spec
actions:
create-archive:
# packit.dev service does have these module pre-installed:
- python3 -m build --sdist --outdir dist
- sh -c "ls dist/ansible-compat-*.tar.gz"
get-current-version:
- ./tools/get-version.sh
post-upstream-clone:
- rm -f dist/*.tar.gz || true
- ./tools/update-version.sh
srpm_build_deps:
- python3-build
- python3-setuptools_scm
- python3-pytest
- python3-pytest-mock
jobs:
- job: copr_build
trigger: commit
branch: main
targets:
- fedora-rawhide-x86_64
- fedora-rawhide-aarch64
- fedora-latest-x86_64
- fedora-latest-aarch64
# Missing python3-build see https://bugzilla.redhat.com/show_bug.cgi?id=2129071
# - centos-stream-9-aarch64
# - centos-stream-9-x86_64
- job: tests
trigger: pull_request
branch: main
targets:
- fedora-latest
- fedora-rawhide
# - job: propose_downstream
# trigger: release
# metadata:
# dist-git-branch: master
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ ci:
skip:
# https://github.com/pre-commit-ci/issues/issues/55
- pip-compile
# No docker on pre-commit.ci
- validate-config-in-container
default_language_version:
# Needed in order to make pip-compile output predictable.
python: python3.9
Expand Down Expand Up @@ -111,3 +113,8 @@ repos:
pass_filenames: false
additional_dependencies:
- pip-tools>=6.11.0
- repo: https://github.com/packit/pre-commit-hooks
rev: v1.2.0
hooks:
- id: validate-config-in-container
alias: packit
4 changes: 4 additions & 0 deletions dist/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SRPMS/
*.tar.gz
*-buildrequires
ansible-compat-*/
88 changes: 88 additions & 0 deletions dist/python-ansible-compat.spec.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
%global numcomm @numcomm@
%global alphatag @alphatag@
%global dirty @dirty@

%global srcname ansible-compat
%global pkgname python-ansible-compat

%bcond_without tests

Name: python-ansible-compat
Version: VERSION_PLACEHOLDER
Release: 1%{?dist}
Summary: Ansible python helper functions

License: MIT
URL: https://github.com/ansible/ansible-compat
Source0: %{pypi_source}
BuildArch: noarch

BuildRequires: pyproject-rpm-macros
BuildRequires: ansible-core

%if %{with tests}
BuildRequires: python3-pytest
BuildRequires: python3-pytest-mock
%endif

%global common_description %{expand:
A python package containing functions that help interacting with
various versions of Ansible}

%description %{common_description}

%package -n python-%{srcname}-doc
Summary: %summary

%description -n python-%{srcname}-doc
Documentation for python-ansible-compat

%package -n python3-%{srcname}
Summary: %summary


%description -n python3-%{srcname} %{common_description}

%prep
%autosetup

%generate_buildrequires
%pyproject_buildrequires

%build
%pyproject_wheel

%if %{with doc}
PYTHONPATH=src sphinx-build-3 docs html
rm -rf html/.{doctrees,buildinfo}
%endif

%install
%pyproject_install
%pyproject_save_files ansible_compat

%if %{with tests}
%check
%pytest -vv test -k \
%{shrink:
'
not test_prepare_environment_with_collections
and not test_prerun_reqs_v1
and not test_prerun_reqs_v2
and not test_install_collection_from_disk
and not test_require_collection
'
}
%endif

%files -n python3-%{srcname} -f %{pyproject_files}
%license LICENSE

%if %{with doc}
%files -n python-%{srcname}-doc
%license LICENSE
%doc *.rst
%doc html/
%endif

%changelog
7 changes: 7 additions & 0 deletions tools/get-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
set -e
{
python3 -c "import setuptools_scm" || python3 -m pip install --user setuptools-scm
} 1>&2 # redirect stdout to stderr to avoid polluting the output
python3 -m setuptools_scm | \
sed 's/Guessed Version\([^+]\+\).*/\1/'
7 changes: 7 additions & 0 deletions tools/update-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
DIR=$(dirname "$0")
VERSION=$(./tools/get-version.sh)
mkdir -p "${DIR}/../dist"
sed -e "s/VERSION_PLACEHOLDER/${VERSION}/" \
"${DIR}/../dist/python-ansible-compat.spec.in" \
> "${DIR}/../dist/python-ansible-compat.spec"
7 changes: 7 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@ deps =
{[testenv]deps}
ansible-core>=2.12

[testenv:rpm]
description = Use packit to build RPM (requires RPM based Linux distro)
deps =
packitos
commands =
packit build in-mock

[testenv:docs]
description = Build docs
commands =
Expand Down