Created
September 23, 2022 22:05
-
-
Save tsibley/5e43d370e76809c62db302b25bd13bc2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/nextstrain/cli/runner/managed_conda.py b/nextstrain/cli/runner/managed_conda.py | |
| index c970f32..14602fd 100644 | |
| --- a/nextstrain/cli/runner/managed_conda.py | |
| +++ b/nextstrain/cli/runner/managed_conda.py | |
| @@ -16,7 +16,7 @@ from ..types import RunnerSetupStatus, RunnerTestResults, RunnerUpdateStatus | |
| from ..util import capture_output, exec_or_return, user_app_data_dir, warn | |
| -USER_APP_DATA_DIR = user_app_data_dir() | |
| +USER_APP_DATA_DIR = user_app_data_dir(avoid_spaces = True) | |
| PREFIX = USER_APP_DATA_DIR / "runtimes/managed-conda" | |
| PREFIX_BIN = PREFIX / "bin" | |
| diff --git a/nextstrain/cli/util.py b/nextstrain/cli/util.py | |
| index 14f4034..a05f501 100644 | |
| --- a/nextstrain/cli/util.py | |
| +++ b/nextstrain/cli/util.py | |
| @@ -505,13 +505,19 @@ def glob_match(path: Union[str, Path], patterns: Union[str, Sequence[str]]) -> b | |
| return globmatch(path, patterns, flags = GLOBSTAR | BRACE | EXTGLOB | MATCHBASE | NEGATE) | |
| -def user_app_data_dir() -> Path: | |
| +def user_app_data_dir(avoid_spaces: bool = False) -> Path: | |
| """ | |
| Determines the appropriate directory for our user-specific application | |
| data for the current user. | |
| Supports macOS- and Windows-specific paths and follows the XDG spec for | |
| all other systems (Linux and other Unixes). | |
| + | |
| + If *avoid_spaces* is true and the path to the data dir would contain spaces | |
| + (e.g. on macOS under :filename:`~/Library/Application | |
| + Support/nextstrain/`), then the returned path will go thru a | |
| + :filename:`~/.nextstrain/user-data` symlink to avoid the appearance of | |
| + spaces. This symlink is automatically created as necessary. | |
| """ | |
| system = platform.system() | |
| @@ -531,7 +537,30 @@ def user_app_data_dir() -> Path: | |
| except KeyError: | |
| user_data = Path.home() / ".local/share" | |
| - return user_data / "nextstrain/cli/" | |
| + # An umbrella Nextstrain data dir within the user data dir, e.g. could be | |
| + # used by Augur, etc. as well as us. | |
| + nextstrain_user_data = user_data / "nextstrain/" | |
| + nextstrain_user_data.mkdir(exist_ok = True) | |
| + | |
| + # XXX FIXME comment on this | |
| + if avoid_spaces and " " in str(nextstrain_user_data): | |
| + symlink = Path.home() / ".nextstrain/user-data" | |
| + symlink.parent.mkdir(exist_ok = True) | |
| + | |
| + if symlink.resolve(strict = False) != nextstrain_user_data.resolve(strict = False): | |
| + symlink.unlink(missing_ok = True) | |
| + | |
| + try: | |
| + target = nextstrain_user_data.relative_to(symlink.parent) | |
| + except ValueError: | |
| + target = nextstrain_user_data | |
| + | |
| + symlink.symlink_to(target, target_is_directory = True) | |
| + | |
| + nextstrain_user_data = symlink | |
| + | |
| + # An app-specific dir within the Nextstrain user data dir | |
| + return nextstrain_user_data / "cli/" | |
| def runner_tests_ok(tests: RunnerTestResults) -> bool: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment