diff --git a/.gitignore b/.gitignore index 4e4e580..999539e 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,5 @@ test.db .ruff_cache *.qcow2 + +dibbler/_version.py diff --git a/dibbler/main.py b/dibbler/main.py index b30c810..c7b91ea 100644 --- a/dibbler/main.py +++ b/dibbler/main.py @@ -1,4 +1,5 @@ import argparse +import sys from pathlib import Path from sqlalchemy import create_engine @@ -17,10 +18,17 @@ parser.add_argument( required=False, ) +parser.add_argument( + "-V", + "--version", + help="Show program version", + action="store_true", + default=False, +) + subparsers = parser.add_subparsers( title="subcommands", dest="subcommand", - required=True, ) subparsers.add_parser("loop", help="Run the dibbler loop") subparsers.add_parser("create-db", help="Create the database") @@ -31,6 +39,15 @@ subparsers.add_parser("seed-data", help="Fill with mock data") def main() -> None: args = parser.parse_args() + if args.version: + from ._version import commit_id, version + print(f"Dibbler version {version}, commit {commit_id if commit_id else ''}") + return + + if not args.subcommand: + parser.print_help() + sys.exit(1) + load_config(args.config) engine = create_engine(config_db_string()) diff --git a/flake.nix b/flake.nix index 95621e9..2becd57 100644 --- a/flake.nix +++ b/flake.nix @@ -66,6 +66,7 @@ default = self.packages.${system}.dibbler; dibbler = pkgs.callPackage ./nix/package.nix { python3Packages = pkgs.python313Packages; + inherit (self) sourceInfo; }; }); }; diff --git a/nix/package.nix b/nix/package.nix index 6a3a8a1..bb8cd92 100644 --- a/nix/package.nix +++ b/nix/package.nix @@ -1,4 +1,5 @@ { lib +, sourceInfo , python3Packages , makeWrapper , less @@ -8,7 +9,7 @@ let in python3Packages.buildPythonApplication { pname = pyproject.project.name; - version = pyproject.project.version; + version = "0.1"; src = lib.cleanSource ../.; format = "pyproject"; @@ -17,9 +18,16 @@ python3Packages.buildPythonApplication { # https://github.com/NixOS/nixpkgs/issues/285234 # dontCheckRuntimeDeps = true; + env.SETUPTOOLS_SCM_PRETEND_METADATA = (x: "{${x}}") (lib.concatStringsSep ", " [ + "node=\"${sourceInfo.rev or (lib.substring 0 64 sourceInfo.dirtyRev)}\"" + "node_date=${lib.substring 0 4 sourceInfo.lastModifiedDate}-${lib.substring 4 2 sourceInfo.lastModifiedDate}-${lib.substring 6 2 sourceInfo.lastModifiedDate}" + "dirty=${if sourceInfo ? dirtyRev then "true" else "false"}" + ]); + nativeBuildInputs = with python3Packages; [ - setuptools makeWrapper + setuptools + setuptools-scm ]; propagatedBuildInputs = with python3Packages; [ # brother-ql diff --git a/pyproject.toml b/pyproject.toml index 6bbfdd8..506f421 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,10 +1,13 @@ [build-system] -requires = ["setuptools"] build-backend = "setuptools.build_meta" +requires = [ + "setuptools", + "setuptools-scm", +] [project] name = "dibbler" -version = "1.0.0" +dynamic = ["version"] authors = [ { name = "Programvareverkstedet", email = "projects@pvv.ntnu.no" } ] @@ -21,12 +24,13 @@ dependencies = [ "psycopg2-binary >= 2.8, <2.10", # "python-barcode", ] +scripts.dibbler = "dibbler.main:main" [tool.setuptools.packages.find] include = ["dibbler*"] -[project.scripts] -dibbler = "dibbler.main:main" +[tool.setuptools_scm] +version_file = "dibbler/_version.py" [tool.black] line-length = 100 diff --git a/uv.lock b/uv.lock index 1b58ec1..122da5c 100644 --- a/uv.lock +++ b/uv.lock @@ -4,7 +4,6 @@ requires-python = ">=3.11" [[package]] name = "dibbler" -version = "1.0.0" source = { editable = "." } dependencies = [ { name = "psycopg2-binary" },