From 6188d89c645383eeeb86aad0f508d68048468043 Mon Sep 17 00:00:00 2001
From: Michael Boniface <m.j.boniface@soton.ac.uk>
Date: Thu, 20 Feb 2025 20:53:56 +0000
Subject: [PATCH] added version automatically based on pyproject.toml, called
 acmc --version

---
 acmc/__init__.py | 5 +++++
 acmc/main.py     | 4 +++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/acmc/__init__.py b/acmc/__init__.py
index e69de29..ab83ebf 100644
--- a/acmc/__init__.py
+++ b/acmc/__init__.py
@@ -0,0 +1,5 @@
+try:
+	from importlib.metadata import version
+except ImportError:  # Python <3.8
+	from pkg_resources import get_distribution as version
+__version__ = version("acmc")
diff --git a/acmc/main.py b/acmc/main.py
index 683985e..db75ae2 100644
--- a/acmc/main.py
+++ b/acmc/main.py
@@ -2,6 +2,7 @@ import argparse
 import logging
 from pathlib import Path
 
+import acmc
 from acmc import trud, omop, phen, logging_config as lc
 
 # setup logging
@@ -60,9 +61,9 @@ def phen_diff(args):
 			 args.phen_dir_old)
 
 def main():
-	logger.info("ACMC Tool")	
 	parser = argparse.ArgumentParser(description="ACMC command-line tool")
 	parser.add_argument("--debug", action="store_true", help="Enable debug mode")
+	parser.add_argument("--version", action="version", version=f"acmc {acmc.__version__}")	
 	
     # Top-level commands
 	subparsers = parser.add_subparsers(dest="command", required=True, help="Available commands")
@@ -158,6 +159,7 @@ def main():
 		lc.set_log_level(logging.DEBUG)
 	
 	# Call the function associated with the command
+	logger.info("ACMC Tool")	
 	args.func(args)
 
 if __name__ == "__main__":
-- 
GitLab