support Python 3.12

This commit is contained in:
sebthom
2023-10-14 23:11:02 +02:00
parent 7bcd88cbd6
commit a8ef6818b7
8 changed files with 556 additions and 442 deletions

3
.actrc
View File

@@ -6,5 +6,4 @@
-W .github/workflows/build.yml
-j build
--matrix os:ubuntu-latest
--matrix PYTHON_VERSION:3.11
--matrix PYTHON_VERSION:3.12

View File

@@ -35,18 +35,21 @@ jobs:
include:
- os: macos-latest
PYTHON_VERSION: "3.10"
PUBLISH_RELEASE: true
PUBLISH_RELEASE: false
- os: ubuntu-latest
PYTHON_VERSION: "3.10"
PUBLISH_RELEASE: false
- os: windows-latest
PYTHON_VERSION: "3.10"
PUBLISH_RELEASE: false
- os: macos-latest
PYTHON_VERSION: "3.12"
PUBLISH_RELEASE: true
- os: ubuntu-latest
PYTHON_VERSION: "3.11"
PYTHON_VERSION: "3.12"
PUBLISH_RELEASE: true
- os: windows-latest
PYTHON_VERSION: "3.11"
PYTHON_VERSION: "3.12"
PUBLISH_RELEASE: true
runs-on: ${{ matrix.os }}
@@ -85,9 +88,7 @@ jobs:
python -m pip install --upgrade pip
# pin packaging to 21.3 for now to prevent: packaging.specifiers.InvalidSpecifier: Invalid specifier: '>=3.4.*'
# see https://github.com/pdm-project/pdm/issues/1556
pip install --upgrade pdm packaging==21.3
pip install --upgrade pdm
pdm install -v
@@ -205,7 +206,7 @@ jobs:
steps:
- name: Git checkout
# only required by "hub release create" to prevent "fatal: Not a git repository"
# only required by "gh release create" to prevent "fatal: Not a git repository"
uses: actions/checkout@v4 #https://github.com/actions/checkout
- name: Generate GitHub access token
@@ -227,28 +228,16 @@ jobs:
uses: actions/download-artifact@v3
- name: "Delete previous 'latest' release"
run: |
set -eu
api_base_url="$GITHUB_API_URL/repos/$GITHUB_REPOSITORY"
# delete 'latest' github release
release_id=$(curl -fsL -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/repos/$GITHUB_REPOSITORY/releases | jq -r '.[] | select(.name == "latest") | .id')
if [[ -n $release_id ]]; then
echo "Deleting release [$api_base_url/releases/$release_id]..."
curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -fsSL -X DELETE "$api_base_url/releases/$release_id"
fi
# delete 'latest' git tag
tag_url="$api_base_url/git/refs/tags/latest"
if curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -fsLo /dev/null --head "$tag_url"; then
echo "Deleting tag [$tag_url]..."
curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -fsSL -X DELETE "$tag_url"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_NAME: latest
# https://cli.github.com/manual/gh_release_delete
run: gh release delete "$RELEASE_NAME" --yes --cleanup-tag || true
- name: "Create 'latest' release"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_NAME: latest
run: |
set -eux
@@ -256,13 +245,15 @@ jobs:
mv artifacts-ubuntu-latest/kleinanzeigen-bot kleinanzeigen-bot-linux-amd64
mv artifacts-windows-latest/kleinanzeigen-bot.exe kleinanzeigen-bot-windows-amd64.exe
# https://hub.github.com/hub-release.1.html
hub release create "latest" \
# https://cli.github.com/manual/gh_release_create
gh release create "$RELEASE_NAME" \
--latest \
--prerelease \
--message "latest" \
--attach "kleinanzeigen-bot-darwin-amd64" \
--attach "kleinanzeigen-bot-linux-amd64" \
--attach "kleinanzeigen-bot-windows-amd64.exe"
--target "${{ github.sha }}" \
--notes "$RELEASE_NAME" \
kleinanzeigen-bot-darwin-amd64 \
kleinanzeigen-bot-linux-amd64 \
kleinanzeigen-bot-windows-amd64.exe
- name: "Delete intermediate build artifacts"
uses: geekyeggo/delete-artifact@v2 # https://github.com/GeekyEggo/delete-artifact/

View File

@@ -24,7 +24,7 @@ defaults:
shell: bash
env:
PYTHON_VERSION: "3.11"
PYTHON_VERSION: "3.11" # TODO don't upgrade to 3.12 yet, see https://github.com/github/codeql-action/issues/1933
jobs:
analyze:

View File

@@ -16,7 +16,7 @@ defaults:
shell: bash
env:
PYTHON_VERSION: "3.11"
PYTHON_VERSION: "3.12"
jobs:
@@ -68,7 +68,7 @@ jobs:
set -euo pipefail
exec 5>&1
updates=$(pdm update 2>&1 |tee /dev/fd/5)
updates=$(pdm update --update-all 2>&1 |tee /dev/fd/5)
if git diff --exit-code pdm.lock; then
echo "updates=" >> "$GITHUB_OUTPUT"

View File

@@ -1,3 +1,7 @@
#syntax=docker/dockerfile:1.4
# see https://docs.docker.com/build/dockerfile/frontend/#dockerfile-frontend
# see https://github.com/moby/buildkit/blob/master/frontend/dockerfile/docs/reference.md#syntax
# see https://docs.docker.com/engine/reference/builder/#syntax
#
# Copyright (C) 2022 Sebastian Thomschke and contributors
# SPDX-License-Identifier: AGPL-3.0-or-later
@@ -8,45 +12,59 @@
######################
FROM debian:stable-slim as runtime-base-image
LABEL maintainer="Sebastian Thomschke"
ARG DEBIAN_FRONTEND=noninteractive
ARG LC_ALL=C
RUN set -eu \
#
&& apt-get update -y \
&& echo "#################################################" \
&& echo "Install Chromium + Driver..." \
&& echo "#################################################" \
&& apt-get install --no-install-recommends -y chromium chromium-driver \
#
&& rm -rf \
SHELL ["/bin/bash", "-euo", "pipefail", "-c"]
RUN <<EOF
apt-get update
echo "#################################################"
echo "Install Chromium + Driver..."
echo "#################################################"
apt-get install --no-install-recommends -y chromium chromium-driver
apt-get clean autoclean
apt-get autoremove --purge -y
rm -rf \
/var/cache/{apt,debconf} \
/var/lib/apt/lists/* \
/var/log/{apt,alternatives.log,bootstrap.log,dpkg.log} \
/tmp/* /var/tmp/*
EOF
######################
# build image
######################
# https://hub.docker.com/_/python?tab=tags&name=3-slim
FROM python:3-slim AS build-image
# https://hub.docker.com/_/python/tags?name=3-slim
FROM python:3.12-slim AS build-image
ARG DEBIAN_FRONTEND=noninteractive
ARG LC_ALL=C
SHELL ["/bin/bash", "-euo", "pipefail", "-c"]
RUN <<EOF
apt-get update
RUN apt-get update \
# install required libraries
&& apt-get install --no-install-recommends -y \
apt-get install --no-install-recommends -y \
binutils `# required by pyinstaller` \
build-essential `# required by transitive dependency "wrapt"` \
git `# required by pdm to generate app version` \
#
# upgrade pip
&& python -m pip install --upgrade pip \
#
python -m pip install --upgrade pip \
# install pdm
&& pip install pdm
pip install pdm
EOF
ENV PATH="/opt/upx:${PATH}"
@@ -54,12 +72,16 @@ COPY kleinanzeigen_bot /opt/app/kleinanzeigen_bot
COPY .git /opt/app/.git
COPY README.md pdm.lock pyinstaller.spec pyproject.toml /opt/app/
RUN cd /opt/app \
&& ls -la . \
&& pdm install -v \
&& ls -la kleinanzeigen_bot \
&& pdm run compile \
&& ls -l dist
RUN <<EOF
cd /opt/app
ls -la .
pdm install -v
ls -la kleinanzeigen_bot
pdm run compile
ls -l dist
EOF
RUN /opt/app/dist/kleinanzeigen-bot --help
@@ -76,10 +98,16 @@ ARG GIT_COMMIT_DATE
ARG GIT_REPO_URL
LABEL \
maintainer="Sebastian Thomschke" \
org.label-schema.schema-version="1.0" \
org.label-schema.build-date=$BUILD_DATE \
org.label-schema.vcs-ref=$GIT_COMMIT_HASH \
org.label-schema.vcs-url=$GIT_REPO_URL
org.label-schema.vcs-url=$GIT_REPO_URL \
org.opencontainers.image.authors="Sebastian Thomschke" \
org.opencontainers.image.vendor="Sebastian Thomschke" \
org.opencontainers.image.licenses="AGPL-3.0" \
org.opencontainers.image.title="kleinanzeigen-bot" \
org.opencontainers.image.description="CLI application to ease publishing of ads to kleinanzeigen.de"
# https://stackoverflow.com/a/59812588/5116073
ENV PYTHONUNBUFFERED=1

784
pdm.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -41,44 +41,52 @@ from sys import platform
if platform != "darwin":
excluded_modules.append("_osx_support")
block_cipher = None
# https://github.com/pyinstaller/pyinstaller/blob/e7c252573f424ad9b79169ab01229d27599004b1/PyInstaller/building/build_main.py#L318
analysis = Analysis(
['kleinanzeigen_bot/__main__.py'],
pathex = [],
binaries = [],
# pathex = [],
# binaries = [],
datas = datas,
hiddenimports = ['pkg_resources'],
hookspath = [],
hooksconfig = {},
runtime_hooks = [],
# hookspath = [],
# hooksconfig = {},
excludes = excluded_modules,
win_no_prefer_redirects = False,
win_private_assemblies = False,
cipher = block_cipher,
noarchive = False
# runtime_hooks = [],
# noarchive = False,
# module_collection_mode = None
)
pyz = PYZ(analysis.pure, analysis.zipped_data, cipher = block_cipher)
# https://github.com/pyinstaller/pyinstaller/blob/e7c252573f424ad9b79169ab01229d27599004b1/PyInstaller/building/api.py#L51
pyz = PYZ(
analysis.pure, # tocs
analysis.zipped_data,
# name = None
)
import shutil
# https://github.com/pyinstaller/pyinstaller/blob/e7c252573f424ad9b79169ab01229d27599004b1/PyInstaller/building/api.py#L338
exe = EXE(pyz,
analysis.scripts,
analysis.binaries,
analysis.zipfiles,
analysis.datas,
[],
# bootloader_ignore_signals = False,
# console = True,
# disable_windowed_traceback = False,
# debug = False,
name = 'kleinanzeigen-bot',
debug = False,
bootloader_ignore_signals = False,
# exclude_binaries = False,
# icon = None,
# version = None,
# uac_admin = False,
# uac_uiaccess = False,
# argv_emulation = None,
# target_arch = None,
# codesign_identity = None,
# entitlements_file = None,
# contents_directory = "_internal",
strip = shutil.which("strip") is not None,
upx = shutil.which("upx") is not None,
upx_exclude = [],
runtime_tmpdir = None,
console = True,
disable_windowed_traceback = False,
target_arch = None,
codesign_identity = None,
entitlements_file = None
)

View File

@@ -24,14 +24,14 @@ classifiers = [ # https://pypi.org/classifiers/
"License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)",
"Programming Language :: Python :: 3.10"
]
requires-python = ">=3.10,<3.12" # <3.12 required for pyinstaller
requires-python = ">=3.10,<3.13" # <3.12 required for pyinstaller
dependencies = [
"coloredlogs~=15.0",
"inflect~=7.0",
"overrides~=7.4",
"ruamel.yaml~=0.17",
"pywin32==303; sys_platform == 'win32'",
"selenium~=4.12",
"pywin32==306; sys_platform == 'win32'",
"selenium~=4.13",
"selenium_stealth~=1.0",
"wcmatch~=8.5",
"webdriver_manager~=4.0"
@@ -56,12 +56,12 @@ dev = [
"bandit~=1.7",
"toml", # required by bandit
"tomli", # required by bandit
"pydantic~=1.10", # inflect depends on pydantic > 1.9 which results in pydantic 2 being loaded, which however is not compatible with pyinstaller, so pinning to 1.x
"pydantic~=2.4",
"pytest~=7.4",
"pyinstaller~=5.13",
"pyinstaller~=6.0",
"psutil",
"pylint~=2.17",
"mypy~=1.5.1",
"pylint~=3.0",
"mypy~=1.5",
]
[tool.pdm.scripts]