@@ -40,7 +40,7 @@ def called_from_cmd_args():
4040# Stolen from https://github.com/pydanny/whichcraft/
4141def which (cmd , mode = os .F_OK | os .X_OK , path = None ):
4242 """Find the path which conforms to the given mode on the PATH for a command.
43-
43+
4444 Given a command, mode, and a PATH string, return the path which conforms to the given mode on the PATH, or None if there is no such file.
4545 `mode` defaults to os.F_OK | os.X_OK. `path` defaults to the result of os.environ.get("PATH"), or can be overridden with a custom search path.
4646 Note: This function was backported from the Python 3 source code.
@@ -77,3 +77,61 @@ def _access_check(fn, mode):
7777 name = os .path .join (p , thefile )
7878 if _access_check (name , mode ):
7979 return name
80+
81+
82+ def get_bloodhound_info ():
83+ """
84+ Detect which BloodHound package is installed (regular or CE) and its version.
85+
86+ Returns
87+ -------
88+ tuple: (package_name, version, is_ce)
89+ - package_name: Name of the installed package ('bloodhound', 'bloodhound-ce', or None)
90+ - version: Version string of the installed package (or None if not installed)
91+ - is_ce: Boolean indicating if it's the Community Edition
92+ """
93+ import importlib .metadata
94+ import importlib .util
95+
96+ # First check if any BloodHound package is available to import
97+ if importlib .util .find_spec ("bloodhound" ) is None :
98+ return None , None , False
99+
100+ # Try to get version info from both possible packages
101+ version = None
102+ package_name = None
103+ is_ce = False
104+
105+ # Check for bloodhound-ce first
106+ try :
107+ version = importlib .metadata .version ("bloodhound-ce" )
108+ package_name = "bloodhound-ce"
109+ is_ce = True
110+ except importlib .metadata .PackageNotFoundError :
111+ # Check for regular bloodhound
112+ try :
113+ version = importlib .metadata .version ("bloodhound" )
114+ package_name = "bloodhound"
115+
116+ # Even when installed as 'bloodhound', check if it's actually the CE version
117+ if version and ("ce" in version .lower () or "community" in version .lower ()):
118+ is_ce = True
119+ except importlib .metadata .PackageNotFoundError :
120+ # No bloodhound package found via metadata
121+ pass
122+
123+ # In case we can import it but metadata is not working, check the module itself
124+ if not version :
125+ try :
126+ import bloodhound
127+ version = getattr (bloodhound , "__version__" , "unknown" )
128+ package_name = "bloodhound"
129+
130+ # Check if it's CE based on version string
131+ if "ce" in version .lower () or "community" in version .lower ():
132+ is_ce = True
133+ package_name = "bloodhound-ce"
134+ except ImportError :
135+ pass
136+
137+ return package_name , version , is_ce
0 commit comments