Skip to content

Commit

Permalink
Improve config path handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ahdamin committed Dec 13, 2024
1 parent 817bd90 commit 826bfec
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion microSALT/utils/referencer.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,17 @@
load_session_token,
)

def resolve_path(path):
"""Resolve environment variables, user shortcuts, and convert to absolute path."""
if path:
path = os.path.expandvars(path)
path = os.path.expanduser(path)
path = os.path.abspath(path)
return path

class Referencer:
def __init__(self, config, log, sampleinfo={}, force=False):
self.config = config
self.config = self.resolve_config_paths(config)
self.logger = log
self.db_access = DB_Manipulator(config, log)
self.updated = list()
Expand Down Expand Up @@ -62,6 +69,19 @@ def __init__(self, config, log, sampleinfo={}, force=False):
if not self.token or not self.secret:
self.token, self.secret = get_new_session_token(default_db)

def resolve_config_paths(self, config):
# Resolve all folder paths
if 'folders' in config:
for key, value in config['folders'].items():
if isinstance(value, str) and '/' in value:
config['folders'][key] = resolve_path(value)

# Resolve pubmlst credentials_files_path if present
if 'pubmlst' in config and 'credentials_files_path' in config['pubmlst']:
config['pubmlst']['credentials_files_path'] = resolve_path(config['pubmlst']['credentials_files_path'])

return config

def identify_new(self, cg_id="", project=False):
"""Automatically downloads pubMLST & NCBI organisms not already downloaded"""
neworgs = list()
Expand Down

0 comments on commit 826bfec

Please sign in to comment.