Add --version flag to cli

This commit is contained in:
2026-02-05 00:41:06 +09:00
parent 70b04c0c45
commit b1bb1e556b
6 changed files with 39 additions and 8 deletions

2
.gitignore vendored
View File

@@ -9,3 +9,5 @@ test.db
.ruff_cache
*.qcow2
dibbler/_version.py

View File

@@ -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 '<unknown>'}")
return
if not args.subcommand:
parser.print_help()
sys.exit(1)
load_config(args.config)
engine = create_engine(config_db_string())

View File

@@ -66,6 +66,7 @@
default = self.packages.${system}.dibbler;
dibbler = pkgs.callPackage ./nix/package.nix {
python3Packages = pkgs.python313Packages;
inherit (self) sourceInfo;
};
});
};

View File

@@ -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

View File

@@ -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

1
uv.lock generated
View File

@@ -4,7 +4,6 @@ requires-python = ">=3.11"
[[package]]
name = "dibbler"
version = "1.0.0"
source = { editable = "." }
dependencies = [
{ name = "psycopg2-binary" },