File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55import argparse
66from typing import NoReturn , Optional
77
8- # Version - keep in sync with setup.py
9- __version__ = "2026.2.23"
8+ def get_version () -> str :
9+ """Return the installed package version.
10+
11+ Resolution order:
12+ 1. importlib.metadata — works when installed via pip
13+ 2. setup.py on disk — works when running from source
14+ 3. 'unknown' — last resort fallback
15+ """
16+ try :
17+ from importlib .metadata import version
18+ return version ("docksec" )
19+ except Exception : # package not installed; fall through to source fallback
20+ pass
1021
11- def get_version ():
12- """Get version from setup.py if available, otherwise use hardcoded version."""
1322 try :
1423 import re
1524 setup_path = os .path .join (os .path .dirname (__file__ ), 'setup.py' )
16- if os .path .exists (setup_path ):
17- with open (setup_path , 'r' ) as f :
18- content = f .read ()
19- match = re .search (r'version="([^"]+)"' , content )
20- if match :
21- return match .group (1 )
22- except :
25+ with open (setup_path , 'r' ) as f :
26+ match = re .search (r'version="([^"]+)"' , f .read ())
27+ if match :
28+ return match .group (1 )
29+ except Exception : # setup.py missing or unreadable; fall through to unknown
2330 pass
24- return __version__
31+
32+ return "unknown"
2533
2634def main () -> None :
2735 """
You can’t perform that action at this time.
0 commit comments