@@ -5,12 +5,13 @@ workflow configs.
55import os
66import sys
77import yaml
8+ from augur .config import resolve_filepath
89from collections .abc import Callable
910from typing import Optional
1011from textwrap import dedent , indent
1112
1213
13- # Set search paths for Augur
14+ # Set search paths
1415if "AUGUR_SEARCH_PATHS" in os .environ :
1516 print (dedent (f"""\
1617 Using existing search paths in AUGUR_SEARCH_PATHS:
@@ -46,27 +47,23 @@ else:
4647
4748 search_paths = [path .resolve () for path in search_paths if path .is_dir ()]
4849
50+ # For simplicity, ensure search paths are unique (e.g. often the CWD == workflow.basedir)
51+ search_paths = [p for idx ,p in enumerate (search_paths ) if search_paths .index (p )== idx ]
52+
4953 os .environ ["AUGUR_SEARCH_PATHS" ] = ":" .join (map (str , search_paths ))
5054
5155
5256class InvalidConfigError (Exception ):
5357 pass
5458
5559
56- def resolve_config_path (path : str , defaults_dir : Optional [ str ] = None ) -> Callable :
60+ def resolve_config_path (path : str ) -> Callable :
5761 """
5862 Resolve a relative *path* given in a configuration value. Will always try to
5963 resolve *path* after expanding wildcards with Snakemake's `expand` functionality.
6064
61- Returns the path for the first existing file, checked in the following order:
62- 1. relative to the analysis directory or workdir, usually given by ``--directory`` (``-d``)
63- 2. relative to *defaults_dir* if it's provided
64- 3. relative to the workflow's ``defaults/`` directory if *defaults_dir* is _not_ provided
65-
66- This behaviour allows a default configuration value to point to a default
67- auxiliary file while also letting the file used be overridden either by
68- setting an alternate file path in the configuration or by creating a file
69- with the conventional name in the workflow's analysis directory.
65+ Returns the path for the first existing file found relative to directories
66+ defined by the AUGUR_SEARCH_PATHS environment variable.
7067 """
7168 global workflow
7269
@@ -88,31 +85,26 @@ def resolve_config_path(path: str, defaults_dir: Optional[str] = None) -> Callab
8885 and that the rule actually uses the wildcard name.
8986 """ .lstrip ("\n " ).rstrip ()).format (path = repr (path ), available_wildcards = available_wildcards ), " " * 4 ))
9087
91- if os .path .exists (expanded_path ):
92- return expanded_path
93-
94- if defaults_dir :
95- defaults_path = os .path .join (defaults_dir , expanded_path )
96- else :
97- # Special-case defaults/… for backwards compatibility with older
98- # configs. We could achieve the same behaviour with a symlink
99- # (defaults/defaults → .) but that seems less clear.
100- if path .startswith ("defaults/" ):
101- defaults_path = os .path .join (workflow .basedir , expanded_path )
102- else :
103- defaults_path = os .path .join (workflow .basedir , "defaults" , expanded_path )
104-
105- if os .path .exists (defaults_path ):
106- return defaults_path
107-
108- raise InvalidConfigError (indent (dedent (f"""\
109- Unable to resolve the config-provided path { path !r} ,
110- expanded to { expanded_path !r} after filling in wildcards.
111- The workflow does not include the default file { defaults_path !r} .
112-
113- Hint: Check that the file { expanded_path !r} exists in your analysis
114- directory or remove the config param to use the workflow defaults.
115- """ ), " " * 4 ))
88+ search_paths = [Path (p ) for p in os .environ ["AUGUR_SEARCH_PATHS" ].split (":" )]
89+ try :
90+ return str (resolve_filepath (Path (expanded_path ), search_paths ))
91+ except Exception as error :
92+ raise InvalidConfigError (
93+ indent (
94+ dedent (f"""
95+ Unable to resolve the config-provided path { path !r} ,
96+ expanded to { expanded_path !r} after filling in wildcards.
97+
98+ """ )
99+ + str (error )
100+ + dedent (f"""
101+
102+ Hint: Check that the file { expanded_path !r} exists in your analysis
103+ directory or remove the config param to use the workflow defaults.
104+ """ ),
105+ " " * 4 ,
106+ )
107+ )
116108
117109 return _resolve_config_path
118110
0 commit comments