diff --git a/flake.nix b/flake.nix index 9742aea..e6416c1 100644 --- a/flake.nix +++ b/flake.nix @@ -105,20 +105,27 @@ default = self.packages.${system}.worblehat; worblehat = let inherit (pkgs) python3Packages; + inherit (self) sourceInfo; pyproject = lib.pipe ./pyproject.toml [ builtins.readFile builtins.fromTOML ]; in python3Packages.buildPythonApplication { pname = pyproject.project.name; - version = pyproject.project.version; + version = "0.1"; src = lib.cleanSource ./.; format = "pyproject"; - build-system = with python3Packages; [ hatchling ]; + build-system = with python3Packages; [ setuptools setuptools-scm ]; dependencies = deps pkgs.python3Packages; + 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"}" + ]); + meta.mainProgram = "worblehat"; }; }); diff --git a/pyproject.toml b/pyproject.toml index 2067fda..3913f22 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "worblehat" -version = "0.1.0" +dynamic = ["version"] description = "Worblehat is a simple library management system written specifically for Programvareverkstedet" authors = [ { name = "Programvareverkstedet", email = "projects@pvv.ntnu.no" } @@ -55,6 +55,9 @@ include = ["worblehat*"] [tool.setuptools.package-dir] "" = "src" +[tool.setuptools_scm] +version_file = "src/worblehat/_version.py" + [tool.poe.tasks] clean = """ rm -rf diff --git a/src/worblehat/main.py b/src/worblehat/main.py index 844e6c0..3438997 100644 --- a/src/worblehat/main.py +++ b/src/worblehat/main.py @@ -18,14 +18,10 @@ from .services import ( def _print_version() -> None: - from importlib.metadata import PackageNotFoundError, version + from ._version import commit_id, version - try: - __version__ = version("worblehat") - except PackageNotFoundError: - __version__ = "unknown" - - print(f"Worblehat version {__version__}") + print(f"Worblehat version {version}, commit {commit_id if commit_id else ''}") + return def _connect_to_database(**engine_args) -> Session: @@ -43,6 +39,11 @@ def _connect_to_database(**engine_args) -> Session: def main() -> None: args = arg_parser.parse_args() + + if args.version: + _print_version() + exit(0) + Config.load_configuration(vars(args)) if Config["logging.debug"]: @@ -50,10 +51,6 @@ def main() -> None: else: logging.basicConfig(encoding="utf-8", level=logging.INFO) - if args.version: - _print_version() - exit(0) - if args.print_config: print(f"Configuration:\n{pformat(vars(args))}") exit(0) diff --git a/uv.lock b/uv.lock index c2a9295..9157eac 100644 --- a/uv.lock +++ b/uv.lock @@ -750,7 +750,6 @@ wheels = [ [[package]] name = "worblehat" -version = "0.1.0" source = { editable = "." } dependencies = [ { name = "alembic" },