@@ -199,24 +199,35 @@ def get_package_resource_path(package_name, resource_path, remote=False, resourc
199199 This is the master function that handles all package resource path resolution.
200200
201201 Priority:
202- 1. PyPI install: ~/{base}/share/package/resource_path (e.g., ~/sciflo/share/grq2/)
203- 2. Editable install: ~/{base}/ ops/package/resource_path (e.g., ~/sciflo/ops/grq2/)
202+ 1. PyPI install: Uses sysconfig to find virtualenv, then maps to home directory
203+ 2. Editable install: ops/package/resource_path
204204
205205 :param package_name: Package name (e.g., 'hysds', 'grq2', 'mozart')
206206 :param resource_path: Relative path to resource (e.g., 'scripts/db_create.py', 'configs/settings')
207207 :param remote: If True, check remote host; if False, check local machine
208208 :param resource_type: 'file', 'dir', or 'auto' (auto-detect based on test results)
209209 :return: Full path to resource
210210 """
211- base_map = {'hysds' : 'mozart' , 'grq2' : 'sciflo' , 'pele' : 'sciflo' , 'mozart' : 'mozart' }
212- base = base_map .get (package_name , 'mozart' )
211+ import sysconfig
213212
214213 if remote :
215214 # Check remote host using fabric run()
216215 logger .debug (f'[get_package_resource_path] Called with package={ package_name } , resource={ resource_path } , remote=True, type={ resource_type } ' )
217216
218- # Check PyPI path first: $HOME/{base}/share/{package_name}/{resource_path}
219- pypi_path = f'$HOME/{ base } /share/{ package_name } /{ resource_path } '
217+ # Get the virtualenv data path and extract the base directory name
218+ data_path_cmd = 'python -c "import sysconfig; print(sysconfig.get_path(\' data\' ))"'
219+ data_path_result = run (data_path_cmd , quiet = True )
220+ data_path = data_path_result .strip ()
221+ logger .debug (f'[get_package_resource_path] Remote data path: { data_path } ' )
222+
223+ # Extract base directory name (e.g., 'mozart', 'grq', 'metrics', 'verdi')
224+ # Map 'grq' virtualenv to 'sciflo' home directory
225+ venv_base = data_path .rstrip ('/' ).split ('/' )[- 1 ]
226+ home_base = 'sciflo' if venv_base == 'grq' else venv_base
227+ logger .debug (f'[get_package_resource_path] Virtualenv base: { venv_base } , Home base: { home_base } ' )
228+
229+ # Check PyPI path first: $HOME/{home_base}/share/{package_name}/{resource_path}
230+ pypi_path = f'$HOME/{ home_base } /share/{ package_name } /{ resource_path } '
220231 logger .debug (f'[get_package_resource_path] Checking PyPI path: { pypi_path } ' )
221232
222233 # Determine test command based on resource type
@@ -241,7 +252,7 @@ def get_package_resource_path(package_name, resource_path, remote=False, resourc
241252 logger .debug (f'[get_package_resource_path] Resource not found at PyPI location: { pypi_path } ' )
242253
243254 # Fallback to editable install location
244- fallback_path = f'$HOME/{ base } /ops/{ package_name } /{ resource_path } '
255+ fallback_path = f'$HOME/{ home_base } /ops/{ package_name } /{ resource_path } '
245256 # Expand $HOME to absolute path for Fabric/Jinja2 compatibility
246257 expanded_fallback = run (f'echo { fallback_path } ' , quiet = True ).strip ()
247258 logger .debug (f'[get_package_resource_path] Returning expanded fallback path: { expanded_fallback } ' )
0 commit comments