Skip to content

Commit

Permalink
Rework of build system to use more modern standards (#153)
Browse files Browse the repository at this point in the history
* Replace setup.py with pyproject.toml

This commit will break copr builds for now.

Also removes support for automatically generating man pages, since
it is broken.

* Add support for automatic manpage generation

* Cleanup, use version from pyproject.toml in all other places

* Packaging preparations

Change copr scripts and templated spec file

* Fixup MANIFEST.in file to include templates

* Fix distgen template spec file

* Bump major version, add all authors and cleanup of unused script

* Fix Makefile to use `PYTHON` variable in RPM build

* Replace authors by whole Red Hat team and keep specific maintainer only

* Remove support for different python version from RPM Makefile

* Fix few simple linting errors

* Add changelog entry

Also inform about module API change - removed version file

* Remove AUTHOR file from RPM template

* Set required Python version correctly
  • Loading branch information
SlouchyButton authored Sep 25, 2024
1 parent 1f0c245 commit c09221a
Show file tree
Hide file tree
Showing 22 changed files with 147 additions and 208 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/copr/copr-build-setup
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ PROJECT_PR=praiskup/distgen

build_deps=(
git
distgen
make
python3
python3-setuptools
python3-pip
python3-build
)

for PROJECT in $PROJECT_PR $PROJECT_PUSH; do
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/copr/copr-custom-script
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@ else
RELEASE="PR${3}_${date}_git$short_commit"
fi

python3 -m pip install . --user
cd rpm
make RELEASE="$RELEASE"
32 changes: 0 additions & 32 deletions .github/workflows/copr/script

This file was deleted.

11 changes: 7 additions & 4 deletions .github/workflows/pypi-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,19 @@ jobs:
id-token: write # for trusted publishing

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
submodules: true
- uses: actions/setup-python@v2

- uses: actions/setup-python@v5
with:
python-version: "3.x"

- name: Build a source tarball and a binary wheel
# https://pypa-build.readthedocs.io
run: |
python -m pip install -r requirements.txt
python setup.py sdist
python3 -m pip install build --user
python3 -m build
- name: Publish 📦 to PyPI
# https://github.com/pypa/gh-action-pypi-publish
Expand Down
35 changes: 35 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Read the Docs configuration file for Sphinx projects
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

# Set the OS, Python version and other tools you might need
build:
os: ubuntu-22.04
tools:
python: "3.12"
# You can also specify other tool versions:
# nodejs: "20"
# rust: "1.70"
# golang: "1.20"

# Build documentation in the "docs/" directory with Sphinx
sphinx:
configuration: docs/conf.py
# You can configure Sphinx to use a different builder, for instance use the dirhtml builder for simpler URLs
# builder: "dirhtml"
# Fail on all warnings to avoid broken references
# fail_on_warning: true

# Optionally build your docs in additional formats such as PDF and ePub
# formats:
# - pdf
# - epub

# Optional but recommended, declare the Python requirements required
# to build your documentation
# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
# python:
# install:
# - requirements: docs/requirements.txt
5 changes: 0 additions & 5 deletions AUTHORS

This file was deleted.

11 changes: 0 additions & 11 deletions Dockerfile

This file was deleted.

3 changes: 2 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
include AUTHORS
include dg
include requirements.txt
include LICENSE
include Makefile
Expand All @@ -11,3 +10,5 @@ include docs/Makefile
recursive-include build_manpages *.py
recursive-include tests *.exp *.py *.tpl *.yaml .gitkeep distros container_opt dg-opts
recursive-include tests/unittests/fixtures *
recursive-include distgen/distconf *
recursive-include distgen/templates *
8 changes: 8 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

New in 2.0:

* Complete rewrite of buildsystem to use pyproject.toml
* This removes version file from distgen package
- Use `version()` from `importlib.metadata` instead

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

New in 1.18:

* Added support for Fedora 40, 41, 42
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
Distribution oriented templating system
=======================================

[![Build Status](https://travis-ci.org/devexp-db/distgen.svg?branch=master)](https://travis-ci.org/devexp-db/distgen)
[![Copr package](https://copr.fedorainfracloud.org/coprs/praiskup/distgen/package/distgen/status_image/last_build.png)](https://copr.fedorainfracloud.org/coprs/praiskup/distgen/)
[![Fedora package](https://img.shields.io/fedora/v/distgen)](https://packages.fedoraproject.org/pkgs/distgen/distgen/)
[![Coverage Status](https://coveralls.io/repos/github/devexp-db/distgen/badge.svg)](https://coveralls.io/github/devexp-db/distgen)
[![Documentation Status](https://readthedocs.org/projects/distgen/badge/?version=latest)](https://distgen.readthedocs.io)

Expand Down
15 changes: 0 additions & 15 deletions config.yaml

This file was deleted.

8 changes: 0 additions & 8 deletions dg

This file was deleted.

2 changes: 2 additions & 0 deletions bin/dg → distgen/__main__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/python

"""Main entrypoint for distgen. This module handles CLI interface"""

from __future__ import print_function

import os
Expand Down
28 changes: 17 additions & 11 deletions distgen/cli_parser.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
"""
Separated argument parser. This makes the manual page generator happy because
we don't need any other dependencies installed at build-time. See #149.
"""
"""Module providing an ArgumentParser object to be used by CLI interface."""

from argparse import ArgumentParser, RawDescriptionHelpFormatter

from distgen.version import dg_version
from importlib.metadata import version, PackageNotFoundError

DESCRIPTION = """\
try:
VERSION = version("distgen")
except PackageNotFoundError:
# package is not installed, due to this file being used by manpage generator
# we have to check for this, we do not need valid version during manpage
# generation, but it will crash
VERSION = 0

DESCRIPTION = \
"""
Generate script using predefined metadata about distribution and
templates.
As an example of 'dg' usage, to generate _Dockerfile_ for Fedora
21 64-bit system, you may use command(s):
$ cd project/directory
$ dg --spec docker-data.yaml \\
--template docker.tpl
"""
$ cd project/directory
$ dg --spec docker-data.yaml \\
--template docker.tpl
"""

parser = ArgumentParser(
prog='dg',
Expand All @@ -31,7 +37,7 @@
parser.add_argument(
'--version',
action='version',
version=f"dg (distgen) {dg_version}",
version=f"dg (distgen) {VERSION}"
)

parser.add_argument(
Expand Down
1 change: 0 additions & 1 deletion distgen/version.py

This file was deleted.

12 changes: 5 additions & 7 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
#
import os
import sys
sys.path.insert(0, os.path.abspath('..'))

from distgen.version import dg_version
from importlib.metadata import version as get_version

sys.path.insert(0, os.path.abspath('..'))


# -- General configuration ------------------------------------------------
Expand Down Expand Up @@ -56,9 +57,9 @@
# built documents.
#
# The short X.Y version.
version = dg_version
version = get_version("distgen")
# The full version, including alpha/beta/rc tags.
release = dg_version
release = get_version("distgen")

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down Expand Up @@ -169,6 +170,3 @@
author, 'distgen', 'One line description of project.',
'Miscellaneous'),
]



47 changes: 47 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
[build-system]
requires = ["argparse-manpage[setuptools]"]
build-backend = "setuptools.build_meta"
# requires = ["setuptools>=58.5.0"]
# build-backend = "setuptools.build_meta"

[project]
name = "distgen"
version = "2.0"
dependencies = [
"distro",
"jinja2",
"pyyaml",
"setuptools"
]
requires-python = ">=3.9"
authors = [
{name = "Red Hat Databases team"},
]
maintainers = [
{name = "Ales Nezbeda", email = "anezbeda@redhat.com"}
]
description = "Templating system/generator for distributions"
readme = "README.md"
license = {file = "LICENSE"}
classifiers = [
"Development Status :: 5 - Production/Stable",
"Programming Language :: Python :: 3",
"License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)"
]

[tool.setuptools.cmdclass]
build_py = "build_manpages.build_py"
install = "build_manpages.install"
build_manpages = "build_manpages.build_manpages"

[project.scripts]
dg = "distgen.__main__:main"

[tool.setuptools.packages.find]
where = ["."]
include = ['distgen*']

[tool.build_manpages]
manpages = [
"man/dg.1:object=parser:pyfile=distgen/cli_parser.py",
]
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
distro
jinja2
pyyaml
setuptools
setuptools
build
9 changes: 3 additions & 6 deletions rpm/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
PROJECT = distgen
PYTHON := python3
VERSION := $(shell cd .. ; $(PYTHON) setup.py --version)
VERSION := $(shell python3 -m distgen --version | grep -o '[0-9]*\.[0-9]*')
RELEASE := 1

git_rev = \
Expand All @@ -23,16 +22,14 @@ spec = $(PROJECT).spec
all: $(spec) $(tarball)

$(spec): $(PROJECT).spec.dg
PYTHON="$(PYTHON)" \
../dg --template $< \
python3 -m distgen --template $< \
--distro fedora-rawhide-x86_64 \
--macro "VERSION $(VERSION)" \
--macro "RELEASE $(RELEASE)" \
--output $@

$(tarball):
rm -rf $(tarball)
cd .. && $(PYTHON) setup.py sdist --dist-dir rpm
python3 -m build -o . ..

srpm: $(spec) $(tarball)
rm -rf *.src.rpm
Expand Down
Loading

0 comments on commit c09221a

Please sign in to comment.