Store version in project metadata

This commit is contained in:
Pavel Zwerschke 2024-05-11 19:35:14 +02:00
parent 21a266e302
commit f600d682e7
No known key found for this signature in database
GPG key ID: 43E091FBB4E98046
11 changed files with 45 additions and 22 deletions

View file

@ -41,7 +41,9 @@ jobs:
run: git diff --exit-code run: git diff --exit-code
- name: Build - name: Build
run: ./scripts/build run: |
./scripts/build
./dist/pferd${{ matrix.os == 'windows-latest' && '.exe' || '' }} --version
- name: Rename binary - name: Rename binary
# Glob in source location because on windows pyinstaller creates a file # Glob in source location because on windows pyinstaller creates a file

View file

@ -0,0 +1,9 @@
import importlib.metadata
import warnings
try:
__version__ = importlib.metadata.version(__name__)
except importlib.metadata.PackageNotFoundError as e:
warnings.warn(f"Could not determine version of {__name__}."
f"Did you install it correctly?\n{e!s}", stacklevel=2)
__version__ = "unknown"

View file

@ -2,9 +2,9 @@ from typing import Optional, Tuple
import keyring import keyring
from .. import __name__ as NAME
from ..logging import log from ..logging import log
from ..utils import agetpass, ainput from ..utils import agetpass, ainput
from ..version import NAME
from .authenticator import Authenticator, AuthError, AuthSection from .authenticator import Authenticator, AuthError, AuthSection

View file

@ -7,8 +7,18 @@
# importing itself, we get a few linting warnings, which we're disabling as # importing itself, we get a few linting warnings, which we're disabling as
# well. # well.
from . import command_local # noqa: F401 imported but unused from . import command_local
from . import command_ilias_web # noqa: F401 imported but unused from . import command_ilias_web
from . import command_kit_ilias_web # noqa: F401 imported but unused from . import command_kit_ilias_web
from . import command_kit_ipd # noqa: F401 imported but unused from . import command_kit_ipd
from .parser import PARSER, ParserLoadError, load_default_section # noqa: F401 imported but unused from .parser import PARSER, ParserLoadError, load_default_section
__all__ = [
"command_local",
"command_ilias_web",
"command_kit_ilias_web",
"command_kit_ipd",
"PARSER",
"ParserLoadError",
"load_default_section"
]

View file

@ -4,8 +4,9 @@ from argparse import ArgumentTypeError
from pathlib import Path from pathlib import Path
from typing import Any, Callable, List, Optional, Sequence, Union from typing import Any, Callable, List, Optional, Sequence, Union
from .. import __name__ as NAME
from .. import __version__ as VERSION
from ..output_dir import OnConflict, Redownload from ..output_dir import OnConflict, Redownload
from ..version import NAME, VERSION
class ParserLoadError(Exception): class ParserLoadError(Exception):

View file

@ -8,11 +8,12 @@ import aiohttp
import certifi import certifi
from aiohttp.client import ClientTimeout from aiohttp.client import ClientTimeout
from .. import __name__ as NAME
from .. import __version__ as VERSION
from ..auth import Authenticator from ..auth import Authenticator
from ..config import Config from ..config import Config
from ..logging import log from ..logging import log
from ..utils import fmt_real_path from ..utils import fmt_real_path
from ..version import NAME, VERSION
from .crawler import Crawler, CrawlerSection from .crawler import Crawler, CrawlerSection

View file

@ -1,2 +0,0 @@
NAME = "PFERD"
VERSION = "3.5.2"

View file

@ -17,9 +17,7 @@
rec { rec {
default = pkgs.python3Packages.buildPythonApplication rec { default = pkgs.python3Packages.buildPythonApplication rec {
pname = "pferd"; pname = "pferd";
# Performing black magic version = (pkgs.lib.importTOML ./pyproject.toml).package.version;
# Don't worry, I sacrificed enough goats for the next few years
version = (pkgs.lib.importTOML ./PFERD/version.py).VERSION;
format = "pyproject"; format = "pyproject";
src = ./.; src = ./.;

View file

@ -4,6 +4,14 @@ build-backend = "setuptools.build_meta"
[project] [project]
name = "PFERD" name = "PFERD"
version = "3.5.2"
classifiers = [
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]
dependencies = [ dependencies = [
"aiohttp>=3.8.1", "aiohttp>=3.8.1",
"beautifulsoup4>=4.10.0", "beautifulsoup4>=4.10.0",
@ -11,15 +19,11 @@ dependencies = [
"keyring>=23.5.0", "keyring>=23.5.0",
"certifi>=2021.10.8" "certifi>=2021.10.8"
] ]
dynamic = ["version"]
requires-python = ">=3.9" requires-python = ">=3.9"
[project.scripts] [project.scripts]
pferd = "PFERD.__main__:main" pferd = "PFERD.__main__:main"
[tool.setuptools.dynamic]
version = {attr = "PFERD.version.VERSION"}
[tool.flake8] [tool.flake8]
max-line-length = 110 max-line-length = 110

View file

@ -2,4 +2,4 @@
set -e set -e
pyinstaller --onefile pferd.py pyinstaller --onefile --copy-metadata PFERD pferd.py

View file

@ -41,12 +41,12 @@ def extract_changes(lines):
def update_version(version): def update_version(version):
with open("PFERD/version.py") as f: with open("pyproject.toml") as f:
text = f.read() text = f.read()
text = re.sub(r'VERSION = ".*"', f'VERSION = "{version}"', text) text = re.sub(r'version = ".*"', f'version = "{version}"', text)
with open("PFERD/version.py", "w") as f: with open("pyproject.toml", "w") as f:
f.write(text) f.write(text)