diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index be7821b3..ad36623d 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -9,5 +9,4 @@ Put `closes #ISSUE` in case if the pull requests solves one of the opened issues ### Checklist - [ ] Tests to cover new code -- [ ] `make check` passed -- [ ] `make tests` passed +- [ ] `tox` passed diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b6d4bd40..6168ce89 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -24,8 +24,13 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} filter: 'Release \d+\.\d+\.\d+' + - name: Install dependencies + uses: ConorMacBride/install-package@v1.1.0 + with: + apt: tox + - name: Create archive - run: make archive + run: tox -e archive env: VERSION: ${{ steps.version.outputs.VERSION }} @@ -35,7 +40,7 @@ jobs: body: | ${{ steps.changelog.outputs.compareurl }} ${{ steps.changelog.outputs.changelog }} - files: ahriman-*-src.tar.xz + files: dist/ahriman-*.tar.gz fail_on_unmatched_files: true env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/setup.sh b/.github/workflows/setup.sh index 18e96b56..49112cd5 100755 --- a/.github/workflows/setup.sh +++ b/.github/workflows/setup.sh @@ -6,33 +6,33 @@ set -ex [[ $1 = "minimal" ]] && MINIMAL_INSTALL=1 # 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 -pacman --noconfirm -Syu +pacman -Syu --noconfirm # 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 -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 if [[ -z $MINIMAL_INSTALL ]]; then # VCS support - pacman --noconfirm -Sy breezy darcs mercurial subversion + pacman -Sy --noconfirm breezy darcs mercurial subversion # 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 - pacman --noconfirm -Sy gnupg python-boto3 rsync + pacman -Sy --noconfirm gnupg python-boto3 rsync fi # 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" # 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 -mv ahriman-*-src.tar.xz package/archlinux +mv dist/ahriman-*.tar.gz package/archlinux chmod +777 package/archlinux # because fuck you that's why cd package/archlinux 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 systemd-machine-id-setup diff --git a/.github/workflows/tests.sh b/.github/workflows/tests.sh index 50c6f7cd..36fb8c4c 100755 --- a/.github/workflows/tests.sh +++ b/.github/workflows/tests.sh @@ -4,7 +4,7 @@ set -ex # install dependencies -pacman --noconfirm -Syu base-devel python-setuptools python-tox +pacman --noconfirm -Syu base-devel python-tox # run test and check targets -make check tests +tox diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 793267b3..04e21879 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -19,11 +19,11 @@ There are some strict limitation for suggested pull requests: ### 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 -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. * 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 ```shell -make check tests +tox ``` ### Generate documentation templates ```shell -make specification +tox -e docs ``` ### Create release ```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. diff --git a/Dockerfile b/Dockerfile index 3567bde6..a4d776ad 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,8 +23,9 @@ ENV AHRIMAN_VALIDATE_CONFIGURATION="yes" ## update pacman.conf with multilib RUN echo "[multilib]" >> "/etc/pacman.conf" && \ echo "Include = /etc/pacman.d/mirrorlist" >> "/etc/pacman.conf" -## install minimal required packages -RUN pacman --noconfirm -Syu binutils fakeroot git make sudo +## refresh packages, install sudo and install packages for building +RUN pacman -Syu --noconfirm sudo && \ + pacman -Sy --noconfirm --asdeps fakeroot python-tox ## create build user RUN useradd -m -d "/home/build" -s "/usr/bin/nologin" 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 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 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 \ 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" ## create package archive and install it RUN cd "/home/build/ahriman" && \ - make VERSION=$(python -c "from src.ahriman import __version__; print(__version__)") archlinux && \ - cp ./*-src.tar.xz "package/archlinux" && \ + tox -e archive && \ + cp ./dist/*.tar.gz "package/archlinux" && \ cd "package/archlinux" && \ runuser -u build -- makepkg --noconfirm --install --skipchecksums && \ cd / && rm -r "/home/build/ahriman" diff --git a/Makefile b/Makefile deleted file mode 100644 index 4cc06a12..00000000 --- a/Makefile +++ /dev/null @@ -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 diff --git a/package/archlinux/PKGBUILD b/package/archlinux/PKGBUILD index 15511be2..7f6c4a8a 100644 --- a/package/archlinux/PKGBUILD +++ b/package/archlinux/PKGBUILD @@ -27,7 +27,7 @@ optdepends=('breezy: -bzr packages support' 'python-systemd: journal support' 'rsync: sync by using rsync' '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.tmpfiles') install="$pkgname.install" @@ -35,13 +35,13 @@ backup=('etc/ahriman.ini' 'etc/ahriman.ini.d/logging.ini') build() { - cd "$pkgname" + cd "$pkgname-$pkgver" python -m build --wheel --no-isolation } package() { - cd "$pkgname" + cd "$pkgname-$pkgver" python -m installer --destdir="$pkgdir" "dist/$pkgname-$pkgver-py3-none-any.whl" diff --git a/pyproject.toml b/pyproject.toml index 75a89252..661053f2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -82,3 +82,15 @@ web = [ "cryptography", "requests-unixsocket", # required by unix socket support ] + +[tool.flit.sdist] +include = [ + "AUTHORS", + "CONTRIBUTING.md", + "SECURITY.md", + "package", + "web.png", +] +exclude = [ + "package/archlinux", +] diff --git a/tox.ini b/tox.ini index 02901bc6..abf29904 100644 --- a/tox.ini +++ b/tox.ini @@ -2,6 +2,8 @@ envlist = check, tests dependencies = -e .[journald,pacman,s3,web] project_name = ahriman +labels = + release = version, docs, publish [mypy] 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 spec_test_format = {result} {docstring_summary} -[testenv] +[testenv:archive] +description = Create source files tarball deps = - {[tox]dependencies} + build +commands = + python -m build --sdist [testenv:check] +description = Run common checks like linter, mypy, etc deps = {[tox]dependencies} -e .[check] allowlist_externals = - /bin/bash + bash setenv = MYPYPATH=src commands = @@ -28,34 +34,68 @@ commands = pylint --rcfile=.pylintrc "src/{[tox]project_name}" bandit -c .bandit.yml -r "src/{[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] +description = Generate source files for documentation +depends = + version deps = {[tox]dependencies} -e .[docs] changedir = src allowlist_externals = - /bin/bash + bash + find setenv = SPHINX_APIDOC_OPTIONS=members,no-undoc-members,show-inheritance commands = - /bin/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 bash --prefix ahriman --prog ahriman ahriman.application.ahriman._parser > ../package/share/bash-completion/completions/_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 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 . -[testenv:docs-html] +[testenv:html] +description = Generate html documentation deps = {[tox]dependencies} -e .[docs] +recreate = True 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] +description = Run tests deps = {[tox]dependencies} -e .[tests] commands = 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