Add --version flag to cli
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -9,3 +9,5 @@ test.db
|
||||
.ruff_cache
|
||||
|
||||
*.qcow2
|
||||
|
||||
dibbler/_version.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 '<unknown>'}")
|
||||
return
|
||||
|
||||
if not args.subcommand:
|
||||
parser.print_help()
|
||||
sys.exit(1)
|
||||
|
||||
load_config(args.config)
|
||||
|
||||
engine = create_engine(config_db_string())
|
||||
|
||||
@@ -66,6 +66,7 @@
|
||||
default = self.packages.${system}.dibbler;
|
||||
dibbler = pkgs.callPackage ./nix/package.nix {
|
||||
python3Packages = pkgs.python313Packages;
|
||||
inherit (self) sourceInfo;
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user