diff --git a/.github/workflows/copr/copr-build-setup b/.github/workflows/copr/copr-build-setup index b5b0510..610a8fb 100755 --- a/.github/workflows/copr/copr-build-setup +++ b/.github/workflows/copr/copr-build-setup @@ -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 diff --git a/.github/workflows/copr/copr-custom-script b/.github/workflows/copr/copr-custom-script index b5298bc..a076f5b 100644 --- a/.github/workflows/copr/copr-custom-script +++ b/.github/workflows/copr/copr-custom-script @@ -42,5 +42,6 @@ else RELEASE="PR${3}_${date}_git$short_commit" fi +python3 -m pip install . --user cd rpm make RELEASE="$RELEASE" diff --git a/.github/workflows/copr/script b/.github/workflows/copr/script deleted file mode 100755 index 7c12e2a..0000000 --- a/.github/workflows/copr/script +++ /dev/null @@ -1,32 +0,0 @@ -#! /bin/bash - -# Used by .travis.yml. - -set -e -if test -n "$COPR_BUILD"; then - curl -o copr-build https://raw.githubusercontent.com/praiskup/copr-ci-tooling/main/copr-travis-submit - export COPR_PR_WEBHOOK="https://copr.fedorainfracloud.org/webhooks/custom/18597/341df2dc-df8d-4d15-bded-cdd23ffdd077/distgen/" - exec bash copr-build -fi - -set -x - -test -n "$TRAVIS_PYTHON_VERSION" -case $TRAVIS_PYTHON_VERSION in - *-dev) TRAVIS_PYTHON_VERSION=${TRAVIS_PYTHON_VERSION%%-dev} ;; -esac -export PYTHON="python$TRAVIS_PYTHON_VERSION" - -make check \ - PYTHON="$PYTHON" \ - COVERAGE=true - -make test-sdist-check \ - PYTHON="$PYTHON" - -make test-git-archive-check \ - PYTHON="$PYTHON" - -make test-lint - -"$PYTHON" setup.py install --root "$PWD/i" diff --git a/.github/workflows/pypi-publish.yml b/.github/workflows/pypi-publish.yml index 49d6c9b..064000e 100644 --- a/.github/workflows/pypi-publish.yml +++ b/.github/workflows/pypi-publish.yml @@ -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 diff --git a/.readthedocs.yaml b/.readthedocs.yaml new file mode 100644 index 0000000..124910a --- /dev/null +++ b/.readthedocs.yaml @@ -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 \ No newline at end of file diff --git a/AUTHORS b/AUTHORS deleted file mode 100644 index ef3be05..0000000 --- a/AUTHORS +++ /dev/null @@ -1,5 +0,0 @@ -Main contributors (alphabetical) --------------------------------- -Pavel Raiskup (original author) -Slávek Kabrda (current maintainer) -Tomáš Tomeček diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 3388207..0000000 --- a/Dockerfile +++ /dev/null @@ -1,11 +0,0 @@ -FROM fedora:26 -LABEL maintainer="bkabrda@redhat.com" - -RUN mkdir -p /var/dgdir -WORKDIR /var/dgdir - -RUN dnf install python3-pip && dnf clean all -COPY . /tmp/distgen -RUN cd /tmp/distgen && pip3 install . - -ENTRYPOINT ["/usr/bin/dg"] diff --git a/MANIFEST.in b/MANIFEST.in index 73b97fe..1f9f03b 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,5 +1,4 @@ include AUTHORS -include dg include requirements.txt include LICENSE include Makefile @@ -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 * \ No newline at end of file diff --git a/NEWS b/NEWS index 79c6c10..f4caa0b 100644 --- a/NEWS +++ b/NEWS @@ -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 diff --git a/README.md b/README.md index 38004eb..98b23ef 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/config.yaml b/config.yaml deleted file mode 100644 index 3ddb7a5..0000000 --- a/config.yaml +++ /dev/null @@ -1,15 +0,0 @@ -default: - commands: - pkginstall: - pkgs: - - postgresql-server - pkgreinstall: - pkgs: - - glibc-common - -distros: - fedora: - 20: - pkginstall: - rhel: - diff --git a/dg b/dg deleted file mode 100755 index 79eaa6e..0000000 --- a/dg +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh - -proj_cli_dir="$(dirname "$(readlink -f "$0")")" - -export PYTHON=${PYTHON:-`which python3`} -export PYTHONPATH="$proj_cli_dir${PYTHONPATH+:$PYTHONPATH}" - -$PYTHON $proj_cli_dir/bin/dg "$@" diff --git a/bin/dg b/distgen/__main__.py similarity index 97% rename from bin/dg rename to distgen/__main__.py index 2124c5a..fc1e5c2 100755 --- a/bin/dg +++ b/distgen/__main__.py @@ -1,5 +1,7 @@ #!/bin/python +"""Main entrypoint for distgen. This module handles CLI interface""" + from __future__ import print_function import os diff --git a/distgen/cli_parser.py b/distgen/cli_parser.py index d83c214..676f1ac 100644 --- a/distgen/cli_parser.py +++ b/distgen/cli_parser.py @@ -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', @@ -31,7 +37,7 @@ parser.add_argument( '--version', action='version', - version=f"dg (distgen) {dg_version}", + version=f"dg (distgen) {VERSION}" ) parser.add_argument( diff --git a/distgen/version.py b/distgen/version.py deleted file mode 100644 index 595d2eb..0000000 --- a/distgen/version.py +++ /dev/null @@ -1 +0,0 @@ -dg_version = "1.18" diff --git a/docs/conf.py b/docs/conf.py index 9fc7c0c..19f40fe 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -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 ------------------------------------------------ @@ -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. @@ -169,6 +170,3 @@ author, 'distgen', 'One line description of project.', 'Miscellaneous'), ] - - - diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..e90bb5a --- /dev/null +++ b/pyproject.toml @@ -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", +] diff --git a/requirements.txt b/requirements.txt index a318f8f..cb59127 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ distro jinja2 pyyaml -setuptools \ No newline at end of file +setuptools +build \ No newline at end of file diff --git a/rpm/Makefile b/rpm/Makefile index f50e6c4..5eda13f 100644 --- a/rpm/Makefile +++ b/rpm/Makefile @@ -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 = \ @@ -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 diff --git a/rpm/distgen.spec.dg b/rpm/distgen.spec.dg index 73a8ea3..aeb8640 100644 --- a/rpm/distgen.spec.dg +++ b/rpm/distgen.spec.dg @@ -1,17 +1,5 @@ # vim: ft=spec -%global pybin %{?fedora:%{__python3}}%{!?fedora:%{__python2}} -%global pylib %{?fedora:%{python3_sitelib}}%{!?fedora:%{python2_sitelib}} -%global pypkg %{?fedora:python3}%{!?fedora:python} -%global meh_pypkg %{?fedora:%{pypkg}-} - -%if 0%{?rhel} >= 8 -%global pybin %__python3 -%global pylib %python3_sitelib -%global pypkg python3 -%global meh_pypkg python3- -%endif - Name: distgen Summary: Templating system/generator for distributions @@ -21,21 +9,9 @@ License: GPLv2+ URL: https://github.com/devexp-db/distgen BuildArch: noarch -Requires: %{pypkg}-jinja2 -Requires: %{pypkg}-distro -Requires: %{meh_pypkg}PyYAML - -BuildRequires: make -BuildRequires: %{pypkg}-devel -BuildRequires: %{pypkg}-distro -BuildRequires: %{pypkg}-jinja2 -BuildRequires: %{meh_pypkg}pytest -%if 0%{?rhel} && 0%{?rhel} < 8 -BuildRequires: %{pypkg}-mock -BuildRequires: %{pypkg}-pytest-catchlog -%endif -BuildRequires: %{meh_pypkg}PyYAML -BuildRequires: %{pypkg}-setuptools +BuildRequires: python3-devel +BuildRequires: pyproject-rpm-macros +BuildRequires: python3-pytest Source0: https://pypi.org/packages/source/d/%name/%name-%version.tar.gz @@ -47,29 +23,28 @@ file and preexisting distribution metadata generate output file. %prep %autosetup -p1 +%generate_buildrequires +%pyproject_buildrequires -x pytest,pytest-catchlog,pytest-cov,coverage,flake8 + %build -%{pybin} setup.py build +%pyproject_wheel %install -%{pybin} setup.py install --root=%{buildroot} -mkdir -p %{buildroot}%{_datadir}/distgen -mv %{buildroot}%{pylib}/distgen/{distconf,templates} %{buildroot}%{_datadir}/distgen +%pyproject_install +%pyproject_save_files distgen %check -make PYTHON=%{pybin} check +%pytest tests/unittests/ -%files +%files -f %{pyproject_files} %license LICENSE -%doc AUTHORS NEWS +%doc NEWS %doc docs/ %{_bindir}/dg -%{pylib}/distgen -%{pylib}/%{name}-*.egg-info -%{_datadir}/%{name} %{_mandir}/man1/* diff --git a/setup.cfg b/setup.cfg index 2b13372..acd96a0 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,9 +1,6 @@ -[build_manpages] -manpages = - man/dg.1:object=parser:pyfile=distgen/cli_parser.py - [flake8] ignore= # E402 module level import not at top of file - E402 + E402, + C0116 max-complexity=15 diff --git a/setup.py b/setup.py deleted file mode 100644 index 7d9408e..0000000 --- a/setup.py +++ /dev/null @@ -1,61 +0,0 @@ -import sys - -from setuptools import setup -from distgen.version import dg_version -from os import listdir, path, getcwd - -project = "distgen" -datadir = "share" -pkgdatadir = datadir + "/" + project -tpldir = pkgdatadir + "/templates" -distconfdir = pkgdatadir + "/distconf" - -from setuptools.command.build_py import build_py -from setuptools.command.install import install - -try: - sys.path = [path.join(getcwd(), 'build_manpages')] + sys.path - from build_manpages.build_manpages import ( - build_manpages, get_build_py_cmd, get_install_cmd) -except: - print("=======================================") - print("Use 'git submodule update --init' first") - print("=======================================") - raise - - -def get_requirements(): - with open('requirements.txt') as f: - return f.read().splitlines() - -def get_long_description(): - with open('README.md') as f: - return "\n".join(l for l in f.read().splitlines() if not l.startswith('[![')) - -setup( - name='distgen', - version=dg_version, - description='Templating system/generator for distributions', - long_description=get_long_description(), - long_description_content_type='text/markdown', - author='Pavel Raiskup (see AUTHORS)', - author_email='praiskup@redhat.com', - maintainer='Bohuslav Kabrda', - maintainer_email='bkabrda@redhat.com', - license='GPLv2+', - url='https://github.com/devexp-db/distgen', - platforms=['any'], - packages=['distgen'], - # this is bit impractical, but I see no better way to include subdirs properly - package_data={'distgen': - ['distconf/*.yaml', 'distconf/**/*.yaml', - 'templates/*.tpl', 'templates/**/*.tpl', 'templates/**/**/*.tpl'] - }, - scripts=['bin/dg'], - install_requires=get_requirements(), - cmdclass={ - 'build_manpages': build_manpages, - 'build_py': get_build_py_cmd(build_py), - 'install': get_install_cmd(install), - }, -)