build: drop makefile

It has been a while since we moved to tox. Lets also drop makefile since
it seems to be useless with tox
This commit is contained in:
Evgenii Alekseev 2023-12-16 16:11:11 +02:00
parent b3ce545517
commit 93793b6424
10 changed files with 96 additions and 98 deletions

View File

@ -9,5 +9,4 @@ Put `closes #ISSUE` in case if the pull requests solves one of the opened issues
### Checklist ### Checklist
- [ ] Tests to cover new code - [ ] Tests to cover new code
- [ ] `make check` passed - [ ] `tox` passed
- [ ] `make tests` passed

View File

@ -24,8 +24,13 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }} token: ${{ secrets.GITHUB_TOKEN }}
filter: 'Release \d+\.\d+\.\d+' filter: 'Release \d+\.\d+\.\d+'
- name: Install dependencies
uses: ConorMacBride/install-package@v1.1.0
with:
apt: tox
- name: Create archive - name: Create archive
run: make archive run: tox -e archive
env: env:
VERSION: ${{ steps.version.outputs.VERSION }} VERSION: ${{ steps.version.outputs.VERSION }}
@ -35,7 +40,7 @@ jobs:
body: | body: |
${{ steps.changelog.outputs.compareurl }} ${{ steps.changelog.outputs.compareurl }}
${{ steps.changelog.outputs.changelog }} ${{ steps.changelog.outputs.changelog }}
files: ahriman-*-src.tar.xz files: dist/ahriman-*.tar.gz
fail_on_unmatched_files: true fail_on_unmatched_files: true
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@ -6,33 +6,33 @@ set -ex
[[ $1 = "minimal" ]] && MINIMAL_INSTALL=1 [[ $1 = "minimal" ]] && MINIMAL_INSTALL=1
# install dependencies # install dependencies
echo -e '[arcanisrepo]\nServer = http://repo.arcanis.me/$arch\nSigLevel = Never' | tee -a /etc/pacman.conf echo -e '[arcanisrepo]\nServer = https://repo.arcanis.me/$arch\nSigLevel = Never' | tee -a /etc/pacman.conf
# refresh the image # refresh the image
pacman --noconfirm -Syu pacman -Syu --noconfirm
# main dependencies # main dependencies
pacman --noconfirm -Sy base-devel devtools git pyalpm python-cerberus python-inflection python-passlib python-requests python-srcinfo python-systemd sudo pacman -Sy --noconfirm devtools git pyalpm python-cerberus python-inflection python-passlib python-requests python-srcinfo python-systemd sudo
# make dependencies # make dependencies
pacman --noconfirm -Sy python-build python-flit python-installer python-wheel pacman -Sy --noconfirm python-build python-flit python-installer python-tox python-wheel
# optional dependencies # optional dependencies
if [[ -z $MINIMAL_INSTALL ]]; then if [[ -z $MINIMAL_INSTALL ]]; then
# VCS support # VCS support
pacman --noconfirm -Sy breezy darcs mercurial subversion pacman -Sy --noconfirm breezy darcs mercurial subversion
# web server # web server
pacman --noconfirm -Sy python-aioauth-client python-aiohttp python-aiohttp-apispec-git python-aiohttp-cors python-aiohttp-debugtoolbar python-aiohttp-jinja2 python-aiohttp-security python-aiohttp-session python-cryptography python-jinja pacman -Sy --noconfirm python-aioauth-client python-aiohttp python-aiohttp-apispec-git python-aiohttp-cors python-aiohttp-debugtoolbar python-aiohttp-jinja2 python-aiohttp-security python-aiohttp-session python-cryptography python-jinja
# additional features # additional features
pacman --noconfirm -Sy gnupg python-boto3 rsync pacman -Sy --noconfirm gnupg python-boto3 rsync
fi fi
# FIXME since 1.0.4 devtools requires dbus to be run, which doesn't work now in container # FIXME since 1.0.4 devtools requires dbus to be run, which doesn't work now in container
cp "docker/systemd-nspawn.sh" "/usr/local/bin/systemd-nspawn" cp "docker/systemd-nspawn.sh" "/usr/local/bin/systemd-nspawn"
# create fresh tarball # create fresh tarball
make VERSION=1.0.0 archlinux # well, it does not really matter which version we will put here tox -e archive
# run makepkg # run makepkg
mv ahriman-*-src.tar.xz package/archlinux mv dist/ahriman-*.tar.gz package/archlinux
chmod +777 package/archlinux # because fuck you that's why chmod +777 package/archlinux # because fuck you that's why
cd package/archlinux cd package/archlinux
sudo -u nobody -- makepkg -cf --skipchecksums --noconfirm sudo -u nobody -- makepkg -cf --skipchecksums --noconfirm
pacman --noconfirm -U ahriman-1.0.0-1-any.pkg.tar.zst sudo -u nobody -- makepkg --packagelist | pacman -U --noconfirm -
# create machine-id which is required by build tools # create machine-id which is required by build tools
systemd-machine-id-setup systemd-machine-id-setup

View File

@ -4,7 +4,7 @@
set -ex set -ex
# install dependencies # install dependencies
pacman --noconfirm -Syu base-devel python-setuptools python-tox pacman --noconfirm -Syu base-devel python-tox
# run test and check targets # run test and check targets
make check tests tox

View File

@ -19,11 +19,11 @@ There are some strict limitation for suggested pull requests:
### Code formatting ### Code formatting
In order to resolve all difficult cases the `autopep8` is used. You can perform formatting at any time by running `make check` or running `autopep8` command directly. In order to resolve all difficult cases the `autopep8` is used. You can perform formatting at any time by running `tox` or running `autopep8` command directly.
### Code style ### Code style
Again, the most checks can be performed by `make check` command, though some additional guidelines must be applied: Again, the most checks can be performed by `tox` command, though some additional guidelines must be applied:
* Every class, every function (including private and protected), every attribute must be documented. The project follows [Google style documentation](https://google.github.io/styleguide/pyguide.html). The only exception is local functions. * Every class, every function (including private and protected), every attribute must be documented. The project follows [Google style documentation](https://google.github.io/styleguide/pyguide.html). The only exception is local functions.
* Correct way to document function (if a section is empty, e.g. no notes or there are no args, it should be omitted) is the following: * Correct way to document function (if a section is empty, e.g. no notes or there are no args, it should be omitted) is the following:
@ -231,19 +231,19 @@ The projects also uses typing checks (provided by `mypy`) and some linter checks
### Run automated checks ### Run automated checks
```shell ```shell
make check tests tox
``` ```
### Generate documentation templates ### Generate documentation templates
```shell ```shell
make specification tox -e docs
``` ```
### Create release ### Create release
```shell ```shell
make VERSION=x.y.z check tests release tox -m release -- x.y.z
``` ```
The command above will also run checks first and will generate documentation, tags, etc., and will push them to GitHub. Other things will be handled by GitHub workflows automatically. The command above will generate documentation, tags, etc., and will push them to GitHub. Other things will be handled by GitHub workflows automatically.

View File

@ -23,8 +23,9 @@ ENV AHRIMAN_VALIDATE_CONFIGURATION="yes"
## update pacman.conf with multilib ## update pacman.conf with multilib
RUN echo "[multilib]" >> "/etc/pacman.conf" && \ RUN echo "[multilib]" >> "/etc/pacman.conf" && \
echo "Include = /etc/pacman.d/mirrorlist" >> "/etc/pacman.conf" echo "Include = /etc/pacman.d/mirrorlist" >> "/etc/pacman.conf"
## install minimal required packages ## refresh packages, install sudo and install packages for building
RUN pacman --noconfirm -Syu binutils fakeroot git make sudo RUN pacman -Syu --noconfirm sudo && \
pacman -Sy --noconfirm --asdeps fakeroot python-tox
## create build user ## create build user
RUN useradd -m -d "/home/build" -s "/usr/bin/nologin" build && \ RUN useradd -m -d "/home/build" -s "/usr/bin/nologin" build && \
echo "build ALL=(ALL) NOPASSWD: ALL" > "/etc/sudoers.d/build" echo "build ALL=(ALL) NOPASSWD: ALL" > "/etc/sudoers.d/build"
@ -33,7 +34,7 @@ COPY "docker/install-aur-package.sh" "/usr/local/bin/install-aur-package"
## darcs is not installed by reasons, because it requires a lot haskell packages which dramatically increase image size ## darcs is not installed by reasons, because it requires a lot haskell packages which dramatically increase image size
RUN pacman -Sy --noconfirm --asdeps devtools git pyalpm python-cerberus python-inflection python-passlib python-requests python-srcinfo && \ RUN pacman -Sy --noconfirm --asdeps devtools git pyalpm python-cerberus python-inflection python-passlib python-requests python-srcinfo && \
pacman -Sy --noconfirm --asdeps python-build python-flit python-installer python-wheel && \ pacman -Sy --noconfirm --asdeps python-build python-flit python-installer python-wheel && \
pacman -Sy --noconfirm --asdeps breezy mercurial python-aiohttp python-aiohttp-cors python-boto3 python-cryptography python-jinja python-requests-unixsocket python-systemd rsync subversion && \ pacman -Sy --noconfirm --asdeps breezy git mercurial python-aiohttp python-aiohttp-cors python-boto3 python-cryptography python-jinja python-requests-unixsocket python-systemd rsync subversion && \
runuser -u build -- install-aur-package python-aioauth-client python-aiohttp-apispec-git python-aiohttp-jinja2 \ runuser -u build -- install-aur-package python-aioauth-client python-aiohttp-apispec-git python-aiohttp-jinja2 \
python-aiohttp-debugtoolbar python-aiohttp-session python-aiohttp-security python-aiohttp-debugtoolbar python-aiohttp-session python-aiohttp-security
@ -45,8 +46,8 @@ COPY "docker/systemd-nspawn.sh" "/usr/local/bin/systemd-nspawn"
COPY --chown=build . "/home/build/ahriman" COPY --chown=build . "/home/build/ahriman"
## create package archive and install it ## create package archive and install it
RUN cd "/home/build/ahriman" && \ RUN cd "/home/build/ahriman" && \
make VERSION=$(python -c "from src.ahriman import __version__; print(__version__)") archlinux && \ tox -e archive && \
cp ./*-src.tar.xz "package/archlinux" && \ cp ./dist/*.tar.gz "package/archlinux" && \
cd "package/archlinux" && \ cd "package/archlinux" && \
runuser -u build -- makepkg --noconfirm --install --skipchecksums && \ runuser -u build -- makepkg --noconfirm --install --skipchecksums && \
cd / && rm -r "/home/build/ahriman" cd / && rm -r "/home/build/ahriman"

View File

@ -1,59 +0,0 @@
.PHONY: archive archlinux check clean directory html release specification tests version
.DEFAULT_GOAL := archlinux
PROJECT := ahriman
FILES := AUTHORS CONTRIBUTING.md COPYING README.md SECURITY.md package pyproject.toml src web.png
TARGET_FILES := $(addprefix $(PROJECT)/, $(FILES))
IGNORE_FILES := package/archlinux src/.mypy_cache
$(TARGET_FILES) : $(addprefix $(PROJECT), %) : $(addprefix ., %) directory version
@cp -rp $< $@
archive: archive_directory
tar cJf "$(PROJECT)-$(VERSION)-src.tar.xz" "$(PROJECT)"
rm -rf "$(PROJECT)"
archive_directory: $(TARGET_FILES)
rm -fr $(addprefix $(PROJECT)/, $(IGNORE_FILES))
find "$(PROJECT)" -type f -name "*.pyc" -delete
find "$(PROJECT)" -depth -type d -name "__pycache__" -execdir rm -rf {} +
find "$(PROJECT)" -depth -type d -name "*.egg-info" -execdir rm -rf {} +
archlinux: archive
sed -i "s/pkgver=.*/pkgver=$(VERSION)/" package/archlinux/PKGBUILD
check: clean
tox -e check
clean:
find . -type f -name "$(PROJECT)-*-src.tar.xz" -delete
rm -rf "$(PROJECT)"
directory: clean
mkdir "$(PROJECT)"
html: specification
rm -rf docs/html
tox -e docs-html
release: specification archlinux
git add package/archlinux/PKGBUILD src/ahriman/__init__.py docs/ahriman-architecture.svg package/share/man/man1/ahriman.1 package/share/bash-completion/completions/_ahriman package/share/zsh/site-functions/_ahriman
git commit -m "Release $(VERSION)"
git tag "$(VERSION)"
git push
git push --tags
specification:
# make sure that old files are removed
find docs -type f -name "$(PROJECT)*.rst" -delete
tox -e docs
tests: clean
tox -e tests
version:
ifndef VERSION
$(error VERSION is required, but not set)
endif
sed -i 's/^__version__ = .*/__version__ = "$(VERSION)"/' src/ahriman/__init__.py

View File

@ -27,7 +27,7 @@ optdepends=('breezy: -bzr packages support'
'python-systemd: journal support' 'python-systemd: journal support'
'rsync: sync by using rsync' 'rsync: sync by using rsync'
'subversion: -svn packages support') 'subversion: -svn packages support')
source=("https://github.com/arcan1s/ahriman/releases/download/$pkgver/$pkgname-$pkgver-src.tar.xz" source=("https://github.com/arcan1s/ahriman/releases/download/$pkgver/$pkgname-$pkgver.tar.gz"
'ahriman.sysusers' 'ahriman.sysusers'
'ahriman.tmpfiles') 'ahriman.tmpfiles')
install="$pkgname.install" install="$pkgname.install"
@ -35,13 +35,13 @@ backup=('etc/ahriman.ini'
'etc/ahriman.ini.d/logging.ini') 'etc/ahriman.ini.d/logging.ini')
build() { build() {
cd "$pkgname" cd "$pkgname-$pkgver"
python -m build --wheel --no-isolation python -m build --wheel --no-isolation
} }
package() { package() {
cd "$pkgname" cd "$pkgname-$pkgver"
python -m installer --destdir="$pkgdir" "dist/$pkgname-$pkgver-py3-none-any.whl" python -m installer --destdir="$pkgdir" "dist/$pkgname-$pkgver-py3-none-any.whl"

View File

@ -82,3 +82,15 @@ web = [
"cryptography", "cryptography",
"requests-unixsocket", # required by unix socket support "requests-unixsocket", # required by unix socket support
] ]
[tool.flit.sdist]
include = [
"AUTHORS",
"CONTRIBUTING.md",
"SECURITY.md",
"package",
"web.png",
]
exclude = [
"package/archlinux",
]

58
tox.ini
View File

@ -2,6 +2,8 @@
envlist = check, tests envlist = check, tests
dependencies = -e .[journald,pacman,s3,web] dependencies = -e .[journald,pacman,s3,web]
project_name = ahriman project_name = ahriman
labels =
release = version, docs, publish
[mypy] [mypy]
flags = --implicit-reexport --strict --allow-untyped-decorators --allow-subclassing-any flags = --implicit-reexport --strict --allow-untyped-decorators --allow-subclassing-any
@ -11,16 +13,20 @@ addopts = --cov=ahriman --cov-report=term-missing:skip-covered --no-cov-on-fail
asyncio_mode = auto asyncio_mode = auto
spec_test_format = {result} {docstring_summary} spec_test_format = {result} {docstring_summary}
[testenv] [testenv:archive]
description = Create source files tarball
deps = deps =
{[tox]dependencies} build
commands =
python -m build --sdist
[testenv:check] [testenv:check]
description = Run common checks like linter, mypy, etc
deps = deps =
{[tox]dependencies} {[tox]dependencies}
-e .[check] -e .[check]
allowlist_externals = allowlist_externals =
/bin/bash bash
setenv = setenv =
MYPYPATH=src MYPYPATH=src
commands = commands =
@ -28,34 +34,68 @@ commands =
pylint --rcfile=.pylintrc "src/{[tox]project_name}" pylint --rcfile=.pylintrc "src/{[tox]project_name}"
bandit -c .bandit.yml -r "src/{[tox]project_name}" bandit -c .bandit.yml -r "src/{[tox]project_name}"
bandit -c .bandit-test.yml -r "tests/{[tox]project_name}" bandit -c .bandit-test.yml -r "tests/{[tox]project_name}"
/bin/bash -c 'mypy {[mypy]flags} -p "{[tox]project_name}" --install-types --non-interactive || mypy {[mypy]flags} -p "{[tox]project_name}"' bash -c 'mypy {[mypy]flags} -p "{[tox]project_name}" --install-types --non-interactive || mypy {[mypy]flags} -p "{[tox]project_name}"'
[testenv:docs] [testenv:docs]
description = Generate source files for documentation
depends =
version
deps = deps =
{[tox]dependencies} {[tox]dependencies}
-e .[docs] -e .[docs]
changedir = src changedir = src
allowlist_externals = allowlist_externals =
/bin/bash bash
find
setenv = setenv =
SPHINX_APIDOC_OPTIONS=members,no-undoc-members,show-inheritance SPHINX_APIDOC_OPTIONS=members,no-undoc-members,show-inheritance
commands = commands =
/bin/bash -c 'shtab --shell bash --prefix ahriman --prog ahriman ahriman.application.ahriman._parser > ../package/share/bash-completion/completions/_ahriman' bash -c 'shtab --shell bash --prefix ahriman --prog ahriman ahriman.application.ahriman._parser > ../package/share/bash-completion/completions/_ahriman'
/bin/bash -c 'shtab --shell zsh --prefix ahriman --prog ahriman ahriman.application.ahriman._parser > ../package/share/zsh/site-functions/_ahriman' bash -c 'shtab --shell zsh --prefix ahriman --prog ahriman ahriman.application.ahriman._parser > ../package/share/zsh/site-functions/_ahriman'
argparse-manpage --module ahriman.application.ahriman --function _parser --author "ahriman team" --project-name ahriman --author-email "" --url https://github.com/arcan1s/ahriman --output ../package/share/man/man1/ahriman.1 argparse-manpage --module ahriman.application.ahriman --function _parser --author "ahriman team" --project-name ahriman --author-email "" --url https://github.com/arcan1s/ahriman --output ../package/share/man/man1/ahriman.1
pydeps ahriman -o ../docs/ahriman-architecture.svg --no-config --no-show --cluster pydeps ahriman -o ../docs/ahriman-architecture.svg --no-config --no-show --cluster
# remove autogenerated modules rst files
find ../docs -type f -name "{[tox]project_name}*.rst" -delete
sphinx-apidoc -o ../docs . sphinx-apidoc -o ../docs .
[testenv:docs-html] [testenv:html]
description = Generate html documentation
deps = deps =
{[tox]dependencies} {[tox]dependencies}
-e .[docs] -e .[docs]
recreate = True
commands = commands =
sphinx-build -b html -a -j auto -W docs docs/html sphinx-build -b html -a -j auto -W docs {envtmpdir}{/}html
[testenv:publish]
description = Create and publish release to Github
depends =
docs
allowlist_externals =
git
commands =
git add package/archlinux/PKGBUILD src/ahriman/__init__.py docs/ahriman-architecture.svg package/share/man/man1/ahriman.1 package/share/bash-completion/completions/_ahriman package/share/zsh/site-functions/_ahriman
git commit -m "Release {posargs}"
git tag "{posargs}"
git push
git push --tags
[testenv:tests] [testenv:tests]
description = Run tests
deps = deps =
{[tox]dependencies} {[tox]dependencies}
-e .[tests] -e .[tests]
commands = commands =
pytest {posargs} pytest {posargs}
[testenv:version]
description = Bump package version
deps =
packaging
allowlist_externals =
sed
commands =
# check if version is set and validate it
{envpython} -c 'from packaging.version import Version; Version("{posargs}")'
sed -i 's/^__version__ = .*/__version__ = "{posargs}"/' src/ahriman/__init__.py
sed -i "s/pkgver=.*/pkgver={posargs}/" package/archlinux/PKGBUILD