Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- data/miniconda3/lib/python3.13/site-packages/anaconda_anon_usage/__pycache__/__init__.cpython-313.pyc +0 -0
- data/miniconda3/lib/python3.13/site-packages/anaconda_anon_usage/__pycache__/_version.cpython-313.pyc +0 -0
- data/miniconda3/lib/python3.13/site-packages/anaconda_anon_usage/__pycache__/heartbeat.cpython-313.pyc +0 -0
- data/miniconda3/lib/python3.13/site-packages/anaconda_anon_usage/__pycache__/patch.cpython-313.pyc +0 -0
- data/miniconda3/lib/python3.13/site-packages/anaconda_anon_usage/__pycache__/plugin.cpython-313.pyc +0 -0
- data/miniconda3/lib/python3.13/site-packages/anaconda_anon_usage/__pycache__/tokens.cpython-313.pyc +0 -0
- data/miniconda3/lib/python3.13/site-packages/anaconda_anon_usage/__pycache__/utils.cpython-313.pyc +0 -0
- data/miniconda3/lib/python3.13/site-packages/anaconda_auth/__pycache__/__init__.cpython-313.pyc +0 -0
- data/miniconda3/lib/python3.13/site-packages/anaconda_auth/__pycache__/__main__.cpython-313.pyc +0 -0
- data/miniconda3/lib/python3.13/site-packages/anaconda_auth/__pycache__/_version.cpython-313.pyc +0 -0
- data/miniconda3/lib/python3.13/site-packages/anaconda_auth/__pycache__/actions.cpython-313.pyc +0 -0
- data/miniconda3/lib/python3.13/site-packages/anaconda_auth/__pycache__/adapters.cpython-313.pyc +0 -0
- data/miniconda3/lib/python3.13/site-packages/anaconda_auth/__pycache__/cli.cpython-313.pyc +0 -0
- data/miniconda3/lib/python3.13/site-packages/anaconda_auth/__pycache__/client.cpython-313.pyc +0 -0
- data/miniconda3/lib/python3.13/site-packages/anaconda_auth/__pycache__/config.cpython-313.pyc +0 -0
- data/miniconda3/lib/python3.13/site-packages/anaconda_auth/__pycache__/device_flow.cpython-313.pyc +0 -0
- data/miniconda3/lib/python3.13/site-packages/anaconda_auth/__pycache__/exceptions.cpython-313.pyc +0 -0
- data/miniconda3/lib/python3.13/site-packages/anaconda_auth/__pycache__/handlers.cpython-313.pyc +0 -0
- data/miniconda3/lib/python3.13/site-packages/anaconda_auth/__pycache__/panel.cpython-313.pyc +0 -0
- data/miniconda3/lib/python3.13/site-packages/anaconda_auth/__pycache__/repo.cpython-313.pyc +0 -0
- data/miniconda3/lib/python3.13/site-packages/anaconda_auth/__pycache__/token.cpython-313.pyc +0 -0
- data/miniconda3/lib/python3.13/site-packages/anaconda_auth/__pycache__/utils.cpython-313.pyc +0 -0
- data/miniconda3/lib/python3.13/site-packages/anaconda_auth/_conda/__init__.py +12 -0
- data/miniconda3/lib/python3.13/site-packages/anaconda_auth/_conda/__pycache__/__init__.cpython-313.pyc +0 -0
- data/miniconda3/lib/python3.13/site-packages/anaconda_auth/_conda/__pycache__/auth_handler.cpython-313.pyc +0 -0
- data/miniconda3/lib/python3.13/site-packages/anaconda_auth/_conda/__pycache__/conda_api.cpython-313.pyc +0 -0
- data/miniconda3/lib/python3.13/site-packages/anaconda_auth/_conda/__pycache__/conda_token.cpython-313.pyc +0 -0
- data/miniconda3/lib/python3.13/site-packages/anaconda_auth/_conda/__pycache__/condarc.cpython-313.pyc +0 -0
- data/miniconda3/lib/python3.13/site-packages/anaconda_auth/_conda/__pycache__/config.cpython-313.pyc +0 -0
- data/miniconda3/lib/python3.13/site-packages/anaconda_auth/_conda/__pycache__/entrypoint.cpython-313.pyc +0 -0
- data/miniconda3/lib/python3.13/site-packages/anaconda_auth/_conda/__pycache__/plugins.cpython-313.pyc +0 -0
- data/miniconda3/lib/python3.13/site-packages/anaconda_auth/_conda/__pycache__/repo_config.cpython-313.pyc +0 -0
- data/miniconda3/lib/python3.13/site-packages/anaconda_auth/_conda/auth_handler.py +165 -0
- data/miniconda3/lib/python3.13/site-packages/anaconda_auth/_conda/conda_api.py +27 -0
- data/miniconda3/lib/python3.13/site-packages/anaconda_auth/_conda/conda_token.py +152 -0
- data/miniconda3/lib/python3.13/site-packages/anaconda_auth/_conda/condarc.py +93 -0
- data/miniconda3/lib/python3.13/site-packages/anaconda_auth/_conda/config.py +152 -0
- data/miniconda3/lib/python3.13/site-packages/anaconda_auth/_conda/entrypoint.py +8 -0
- data/miniconda3/lib/python3.13/site-packages/anaconda_auth/_conda/plugins.py +52 -0
- data/miniconda3/lib/python3.13/site-packages/anaconda_auth/_conda/repo_config.py +549 -0
- data/miniconda3/lib/python3.13/site-packages/archspec/__pycache__/__init__.cpython-313.pyc +0 -0
- data/miniconda3/lib/python3.13/site-packages/archspec/__pycache__/__main__.cpython-313.pyc +0 -0
- data/miniconda3/lib/python3.13/site-packages/archspec/__pycache__/cli.cpython-313.pyc +0 -0
- data/miniconda3/lib/python3.13/site-packages/archspec/cpu/__init__.py +27 -0
- data/miniconda3/lib/python3.13/site-packages/archspec/cpu/__pycache__/__init__.cpython-313.pyc +0 -0
- data/miniconda3/lib/python3.13/site-packages/archspec/cpu/__pycache__/alias.cpython-313.pyc +0 -0
- data/miniconda3/lib/python3.13/site-packages/archspec/cpu/__pycache__/detect.cpython-313.pyc +0 -0
- data/miniconda3/lib/python3.13/site-packages/archspec/cpu/__pycache__/microarchitecture.cpython-313.pyc +0 -0
- data/miniconda3/lib/python3.13/site-packages/archspec/cpu/__pycache__/schema.cpython-313.pyc +0 -0
- data/miniconda3/lib/python3.13/site-packages/archspec/cpu/alias.py +87 -0
data/miniconda3/lib/python3.13/site-packages/anaconda_anon_usage/__pycache__/__init__.cpython-313.pyc
ADDED
|
Binary file (290 Bytes). View file
|
|
|
data/miniconda3/lib/python3.13/site-packages/anaconda_anon_usage/__pycache__/_version.cpython-313.pyc
ADDED
|
Binary file (573 Bytes). View file
|
|
|
data/miniconda3/lib/python3.13/site-packages/anaconda_anon_usage/__pycache__/heartbeat.cpython-313.pyc
ADDED
|
Binary file (7.81 kB). View file
|
|
|
data/miniconda3/lib/python3.13/site-packages/anaconda_anon_usage/__pycache__/patch.cpython-313.pyc
ADDED
|
Binary file (6.88 kB). View file
|
|
|
data/miniconda3/lib/python3.13/site-packages/anaconda_anon_usage/__pycache__/plugin.cpython-313.pyc
ADDED
|
Binary file (1.37 kB). View file
|
|
|
data/miniconda3/lib/python3.13/site-packages/anaconda_anon_usage/__pycache__/tokens.cpython-313.pyc
ADDED
|
Binary file (13.6 kB). View file
|
|
|
data/miniconda3/lib/python3.13/site-packages/anaconda_anon_usage/__pycache__/utils.cpython-313.pyc
ADDED
|
Binary file (10.3 kB). View file
|
|
|
data/miniconda3/lib/python3.13/site-packages/anaconda_auth/__pycache__/__init__.cpython-313.pyc
ADDED
|
Binary file (500 Bytes). View file
|
|
|
data/miniconda3/lib/python3.13/site-packages/anaconda_auth/__pycache__/__main__.cpython-313.pyc
ADDED
|
Binary file (265 Bytes). View file
|
|
|
data/miniconda3/lib/python3.13/site-packages/anaconda_auth/__pycache__/_version.cpython-313.pyc
ADDED
|
Binary file (770 Bytes). View file
|
|
|
data/miniconda3/lib/python3.13/site-packages/anaconda_auth/__pycache__/actions.cpython-313.pyc
ADDED
|
Binary file (11.7 kB). View file
|
|
|
data/miniconda3/lib/python3.13/site-packages/anaconda_auth/__pycache__/adapters.cpython-313.pyc
ADDED
|
Binary file (2.15 kB). View file
|
|
|
data/miniconda3/lib/python3.13/site-packages/anaconda_auth/__pycache__/cli.cpython-313.pyc
ADDED
|
Binary file (11.8 kB). View file
|
|
|
data/miniconda3/lib/python3.13/site-packages/anaconda_auth/__pycache__/client.cpython-313.pyc
ADDED
|
Binary file (14.3 kB). View file
|
|
|
data/miniconda3/lib/python3.13/site-packages/anaconda_auth/__pycache__/config.cpython-313.pyc
ADDED
|
Binary file (17 kB). View file
|
|
|
data/miniconda3/lib/python3.13/site-packages/anaconda_auth/__pycache__/device_flow.cpython-313.pyc
ADDED
|
Binary file (6.78 kB). View file
|
|
|
data/miniconda3/lib/python3.13/site-packages/anaconda_auth/__pycache__/exceptions.cpython-313.pyc
ADDED
|
Binary file (1.91 kB). View file
|
|
|
data/miniconda3/lib/python3.13/site-packages/anaconda_auth/__pycache__/handlers.cpython-313.pyc
ADDED
|
Binary file (8.53 kB). View file
|
|
|
data/miniconda3/lib/python3.13/site-packages/anaconda_auth/__pycache__/panel.cpython-313.pyc
ADDED
|
Binary file (2.78 kB). View file
|
|
|
data/miniconda3/lib/python3.13/site-packages/anaconda_auth/__pycache__/repo.cpython-313.pyc
ADDED
|
Binary file (14.4 kB). View file
|
|
|
data/miniconda3/lib/python3.13/site-packages/anaconda_auth/__pycache__/token.cpython-313.pyc
ADDED
|
Binary file (19.8 kB). View file
|
|
|
data/miniconda3/lib/python3.13/site-packages/anaconda_auth/__pycache__/utils.cpython-313.pyc
ADDED
|
Binary file (2.57 kB). View file
|
|
|
data/miniconda3/lib/python3.13/site-packages/anaconda_auth/_conda/__init__.py
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""This module provides conda plugins.
|
| 2 |
+
|
| 3 |
+
Since conda is not a strict dependency of `anaconda-auth`, the modules here should
|
| 4 |
+
NOT be imported outside of this module. This package is declared as the plugin entrypoint
|
| 5 |
+
inside `pyproject.toml` such that it will be imported and, if conda is installed, the
|
| 6 |
+
plugin definitions will be imported. However, if conda is not installed, no plugins are
|
| 7 |
+
imported into the runtime.
|
| 8 |
+
|
| 9 |
+
As a result, we do not have to spread conditional imports everywhere, but we do need to
|
| 10 |
+
be careful that only the single top-level import of this subpackage is performed.
|
| 11 |
+
|
| 12 |
+
"""
|
data/miniconda3/lib/python3.13/site-packages/anaconda_auth/_conda/__pycache__/__init__.cpython-313.pyc
ADDED
|
Binary file (761 Bytes). View file
|
|
|
data/miniconda3/lib/python3.13/site-packages/anaconda_auth/_conda/__pycache__/auth_handler.cpython-313.pyc
ADDED
|
Binary file (7.13 kB). View file
|
|
|
data/miniconda3/lib/python3.13/site-packages/anaconda_auth/_conda/__pycache__/conda_api.cpython-313.pyc
ADDED
|
Binary file (975 Bytes). View file
|
|
|
data/miniconda3/lib/python3.13/site-packages/anaconda_auth/_conda/__pycache__/conda_token.cpython-313.pyc
ADDED
|
Binary file (6.44 kB). View file
|
|
|
data/miniconda3/lib/python3.13/site-packages/anaconda_auth/_conda/__pycache__/condarc.cpython-313.pyc
ADDED
|
Binary file (4.87 kB). View file
|
|
|
data/miniconda3/lib/python3.13/site-packages/anaconda_auth/_conda/__pycache__/config.cpython-313.pyc
ADDED
|
Binary file (7.31 kB). View file
|
|
|
data/miniconda3/lib/python3.13/site-packages/anaconda_auth/_conda/__pycache__/entrypoint.cpython-313.pyc
ADDED
|
Binary file (284 Bytes). View file
|
|
|
data/miniconda3/lib/python3.13/site-packages/anaconda_auth/_conda/__pycache__/plugins.cpython-313.pyc
ADDED
|
Binary file (1.99 kB). View file
|
|
|
data/miniconda3/lib/python3.13/site-packages/anaconda_auth/_conda/__pycache__/repo_config.cpython-313.pyc
ADDED
|
Binary file (18.7 kB). View file
|
|
|
data/miniconda3/lib/python3.13/site-packages/anaconda_auth/_conda/auth_handler.py
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Defines an auth handler to inject an Authorization header into each request.
|
| 2 |
+
|
| 3 |
+
Tokens are assumed to be installed onto a user's system via a separate CLI command.
|
| 4 |
+
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
from functools import lru_cache
|
| 8 |
+
from typing import Any
|
| 9 |
+
from typing import Optional
|
| 10 |
+
from urllib.parse import urlparse
|
| 11 |
+
|
| 12 |
+
from conda import CondaError
|
| 13 |
+
from conda.plugins.types import ChannelAuthBase
|
| 14 |
+
from requests import PreparedRequest
|
| 15 |
+
from requests import Response
|
| 16 |
+
|
| 17 |
+
from anaconda_auth._conda import repo_config
|
| 18 |
+
from anaconda_auth._conda.config import TOKEN_DOMAIN_MAP
|
| 19 |
+
from anaconda_auth.config import AnacondaAuthConfig
|
| 20 |
+
from anaconda_auth.exceptions import TokenNotFoundError
|
| 21 |
+
from anaconda_auth.token import TokenInfo
|
| 22 |
+
|
| 23 |
+
URI_PREFIX = "/repo/"
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
class AnacondaAuthError(CondaError):
|
| 27 |
+
"""
|
| 28 |
+
A generic error to raise that is a subclass of CondaError so we don't trigger the unhandled exception traceback.
|
| 29 |
+
"""
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
class AnacondaAuthHandler(ChannelAuthBase):
|
| 33 |
+
@staticmethod
|
| 34 |
+
def _load_token_from_keyring(url: str) -> Optional[str]:
|
| 35 |
+
"""Attempt to load an appropriate token from the keyring.
|
| 36 |
+
|
| 37 |
+
We parse the requested URL, extract what may be an organization ID, and first
|
| 38 |
+
attempt to load the token for that specific organization. If that fails, we
|
| 39 |
+
then simply return the first token in the keyring (since this is in all likelihood
|
| 40 |
+
one of the default channels ('main', 'r', etc.).
|
| 41 |
+
|
| 42 |
+
If no token can be found in the keyring, we return None, which means that
|
| 43 |
+
the token will attempt to be read from via conda-token instead.
|
| 44 |
+
|
| 45 |
+
"""
|
| 46 |
+
parsed_url = urlparse(url)
|
| 47 |
+
channel_domain = parsed_url.netloc.lower()
|
| 48 |
+
if channel_domain in TOKEN_DOMAIN_MAP:
|
| 49 |
+
token_domain, is_unified, _ = TOKEN_DOMAIN_MAP[channel_domain]
|
| 50 |
+
else:
|
| 51 |
+
token_domain, is_unified = channel_domain, False
|
| 52 |
+
|
| 53 |
+
try:
|
| 54 |
+
token_info = TokenInfo.load(token_domain)
|
| 55 |
+
except TokenNotFoundError:
|
| 56 |
+
# Fallback to conda-token if the token is not found in the keyring
|
| 57 |
+
return None
|
| 58 |
+
|
| 59 |
+
# Check configuration to use unified api key,
|
| 60 |
+
# otherwise continue and attempt to utilize repo token
|
| 61 |
+
if api_key := token_info.api_key:
|
| 62 |
+
if is_unified:
|
| 63 |
+
return api_key
|
| 64 |
+
try:
|
| 65 |
+
config = AnacondaAuthConfig(domain=token_domain)
|
| 66 |
+
if config.use_unified_repo_api_key:
|
| 67 |
+
return api_key
|
| 68 |
+
except Exception:
|
| 69 |
+
pass
|
| 70 |
+
|
| 71 |
+
path = parsed_url.path
|
| 72 |
+
if path.startswith(URI_PREFIX):
|
| 73 |
+
path = path[len(URI_PREFIX) :]
|
| 74 |
+
maybe_org, _, _ = path.partition("/")
|
| 75 |
+
|
| 76 |
+
# First we attempt to return an organization-specific token
|
| 77 |
+
try:
|
| 78 |
+
return token_info.get_repo_token(maybe_org)
|
| 79 |
+
except TokenNotFoundError:
|
| 80 |
+
pass
|
| 81 |
+
|
| 82 |
+
# Return the first one, assuming this is not an org-specific channel
|
| 83 |
+
try:
|
| 84 |
+
return token_info.repo_tokens[0].token
|
| 85 |
+
except IndexError:
|
| 86 |
+
pass
|
| 87 |
+
|
| 88 |
+
return None
|
| 89 |
+
|
| 90 |
+
@staticmethod
|
| 91 |
+
def _load_token_via_conda_token(url: str) -> Optional[str]:
|
| 92 |
+
domain = urlparse(url).netloc.lower()
|
| 93 |
+
# Try to load the token via conda-token if that is installed
|
| 94 |
+
if repo_config is not None:
|
| 95 |
+
tokens = repo_config.token_list()
|
| 96 |
+
for token_url, token in tokens.items():
|
| 97 |
+
token_netloc = urlparse(token_url).netloc
|
| 98 |
+
if token_netloc.lower() == domain and token is not None:
|
| 99 |
+
return token
|
| 100 |
+
return None
|
| 101 |
+
|
| 102 |
+
@lru_cache
|
| 103 |
+
def _load_token(self, url: str) -> Optional[str]:
|
| 104 |
+
"""Load the appropriate token based on URL matching.
|
| 105 |
+
|
| 106 |
+
First, attempts to load from the keyring. If that fails, we attempt
|
| 107 |
+
to load the legacy repo token via conda-token.
|
| 108 |
+
|
| 109 |
+
Cached for performance.
|
| 110 |
+
|
| 111 |
+
Args:
|
| 112 |
+
url: The URL for the request.
|
| 113 |
+
|
| 114 |
+
Returns:
|
| 115 |
+
The token, if it can be loaded. None, otherwise.
|
| 116 |
+
|
| 117 |
+
"""
|
| 118 |
+
|
| 119 |
+
# First, we try to load the token from the keyring. If it is not found, we fall through
|
| 120 |
+
if token := self._load_token_from_keyring(url):
|
| 121 |
+
return token
|
| 122 |
+
elif token := self._load_token_via_conda_token(url):
|
| 123 |
+
return token
|
| 124 |
+
return None
|
| 125 |
+
|
| 126 |
+
def handle_missing_token(self, response: Response, **_: Any) -> Response:
|
| 127 |
+
"""Raise a nice error message if the authentication token is missing."""
|
| 128 |
+
if response.status_code in {401, 403}:
|
| 129 |
+
raise AnacondaAuthError(
|
| 130 |
+
f"Token not found for {self.channel_name}. Please install token with "
|
| 131 |
+
"`anaconda token install`."
|
| 132 |
+
)
|
| 133 |
+
return response
|
| 134 |
+
|
| 135 |
+
def handle_invalid_token(self, response: Response, **_: Any) -> Response:
|
| 136 |
+
"""Raise a nice error message if the authentication token is invalid (not missing)."""
|
| 137 |
+
if response.status_code in {401, 403}:
|
| 138 |
+
raise AnacondaAuthError(
|
| 139 |
+
f"Received authentication error ({response.status_code}) when "
|
| 140 |
+
f"accessing {self.channel_name}. "
|
| 141 |
+
"If your token is invalid or expired, please re-install with "
|
| 142 |
+
"`anaconda token install`."
|
| 143 |
+
)
|
| 144 |
+
return response
|
| 145 |
+
|
| 146 |
+
def __call__(self, request: PreparedRequest) -> PreparedRequest:
|
| 147 |
+
"""Inject the token as an Authorization header on each request."""
|
| 148 |
+
try:
|
| 149 |
+
token = self._load_token(request.url)
|
| 150 |
+
except Exception:
|
| 151 |
+
# TODO(mattkram): We need to be very resilient about exceptions here for now
|
| 152 |
+
token = None
|
| 153 |
+
|
| 154 |
+
if not token:
|
| 155 |
+
request.register_hook("response", self.handle_missing_token)
|
| 156 |
+
return request
|
| 157 |
+
|
| 158 |
+
request.register_hook("response", self.handle_invalid_token)
|
| 159 |
+
config = AnacondaAuthConfig()
|
| 160 |
+
if config.use_unified_repo_api_key:
|
| 161 |
+
request.headers["Authorization"] = f"Bearer {token}"
|
| 162 |
+
else:
|
| 163 |
+
request.headers["Authorization"] = f"token {token}"
|
| 164 |
+
|
| 165 |
+
return request
|
data/miniconda3/lib/python3.13/site-packages/anaconda_auth/_conda/conda_api.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This is a minimal reimplementation of the deprecated conda.cli.python_api
|
| 2 |
+
# module. It uses the subprocess module to duplicate the fullest extent of
|
| 3 |
+
# the run_command functionality needed for tests. But most of the internal
|
| 4 |
+
# uses of run_command do not require this overhead and are better served
|
| 5 |
+
# working in process. So when subprocess is needed, we do this:
|
| 6 |
+
# from anaconda_auth._conda.conda_api import Commands, run_command
|
| 7 |
+
# and when it is not needed, we do this:
|
| 8 |
+
# from anaconda_auth._conda.conda_api import Commands
|
| 9 |
+
# from conda.cli.main import main as run_command
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
import subprocess
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
class Commands:
|
| 16 |
+
CLEAN = "clean"
|
| 17 |
+
CONFIG = "config"
|
| 18 |
+
INSTALL = "install"
|
| 19 |
+
LIST = "list"
|
| 20 |
+
REMOVE = "remove"
|
| 21 |
+
SEARCH = "search"
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def run_command(*args, use_exception_handler=False): # type: ignore
|
| 25 |
+
args = ("python", "-m", "conda") + args
|
| 26 |
+
proc = subprocess.run(args, capture_output=True, text=True)
|
| 27 |
+
return proc.stdout, proc.stderr, proc.returncode
|
data/miniconda3/lib/python3.13/site-packages/anaconda_auth/_conda/conda_token.py
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
CLI for conda-token.
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
from __future__ import annotations
|
| 6 |
+
|
| 7 |
+
import os
|
| 8 |
+
import sys
|
| 9 |
+
from argparse import ArgumentParser
|
| 10 |
+
from argparse import Namespace
|
| 11 |
+
|
| 12 |
+
from anaconda_auth import __version__
|
| 13 |
+
from anaconda_auth._conda import repo_config
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def token_list(args: Namespace) -> int:
|
| 17 |
+
"""Default function for list subparser."""
|
| 18 |
+
tokens = {
|
| 19 |
+
k: v for k, v in repo_config.token_list().items() if k == repo_config.REPO_URL
|
| 20 |
+
}
|
| 21 |
+
if not tokens:
|
| 22 |
+
print(
|
| 23 |
+
f"No tokens have been configured for {repo_config.REPO_URL}",
|
| 24 |
+
file=sys.stderr,
|
| 25 |
+
)
|
| 26 |
+
return 1
|
| 27 |
+
|
| 28 |
+
for url, token in tokens.items():
|
| 29 |
+
print(url, token)
|
| 30 |
+
|
| 31 |
+
return 0
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def token_set(args: Namespace) -> int:
|
| 35 |
+
try:
|
| 36 |
+
repo_config.validate_token(args.token, no_ssl_verify=args.no_ssl_verify)
|
| 37 |
+
except repo_config.CondaTokenError as e:
|
| 38 |
+
print(e, file=sys.stderr)
|
| 39 |
+
return 1
|
| 40 |
+
|
| 41 |
+
repo_config.token_set(
|
| 42 |
+
args.token,
|
| 43 |
+
args.system,
|
| 44 |
+
args.env,
|
| 45 |
+
args.file,
|
| 46 |
+
args.include_archive_channels,
|
| 47 |
+
args.no_ssl_verify,
|
| 48 |
+
args.enable_signature_verification,
|
| 49 |
+
force=args.force_config_condarc,
|
| 50 |
+
)
|
| 51 |
+
print("Success! Your token was validated and Conda has been configured.")
|
| 52 |
+
return 0
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def token_remove(args: Namespace) -> int:
|
| 56 |
+
repo_config.token_remove()
|
| 57 |
+
return 0
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
def condarc_path_args(parser: ArgumentParser) -> None:
|
| 61 |
+
"""Add condarc path arguments."""
|
| 62 |
+
config_file_location_group = parser.add_argument_group(
|
| 63 |
+
"Config File Location Selection",
|
| 64 |
+
f"Without one of these flags, the user config file at '{repo_config.escaped_user_rc_path}' is used.",
|
| 65 |
+
)
|
| 66 |
+
location = config_file_location_group.add_mutually_exclusive_group()
|
| 67 |
+
location.add_argument(
|
| 68 |
+
"--system",
|
| 69 |
+
action="store_true",
|
| 70 |
+
help=f"Write to the system .condarc file at '{repo_config.escaped_user_rc_path}'.",
|
| 71 |
+
)
|
| 72 |
+
location.add_argument(
|
| 73 |
+
"--env",
|
| 74 |
+
action="store_true",
|
| 75 |
+
help=(
|
| 76 |
+
f"Write to the active conda environment .condarc file ({os.getenv('CONDA_PREFIX', '<no active environment>').replace('%', '%%')}). "
|
| 77 |
+
f"If no environment is active, write to the user config file ({repo_config.escaped_user_rc_path})."
|
| 78 |
+
),
|
| 79 |
+
)
|
| 80 |
+
location.add_argument("--file", action="store", help="Write to the given file.")
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
def cli(argv: list[str] | None = None) -> int:
|
| 84 |
+
parser = ArgumentParser(
|
| 85 |
+
"conda-token",
|
| 86 |
+
usage="conda token",
|
| 87 |
+
description="Configure token access for Anaconda Commercial Edition",
|
| 88 |
+
)
|
| 89 |
+
|
| 90 |
+
parser.add_argument(
|
| 91 |
+
"-V",
|
| 92 |
+
"--version",
|
| 93 |
+
action="version",
|
| 94 |
+
help="Show the conda-token version number and exit.",
|
| 95 |
+
version=f"conda-token {__version__}",
|
| 96 |
+
)
|
| 97 |
+
|
| 98 |
+
subparser = parser.add_subparsers(help="Token commands")
|
| 99 |
+
|
| 100 |
+
subparser_list = subparser.add_parser("list", help="List token if configured.")
|
| 101 |
+
subparser_list.set_defaults(func=token_list)
|
| 102 |
+
|
| 103 |
+
subparser_remove = subparser.add_parser(
|
| 104 |
+
"remove", help="Remove token and revert default_channels."
|
| 105 |
+
)
|
| 106 |
+
condarc_path_args(subparser_remove)
|
| 107 |
+
subparser_remove.set_defaults(func=token_remove)
|
| 108 |
+
|
| 109 |
+
subparser_set = subparser.add_parser(
|
| 110 |
+
"set", help="Set your token and configure default_channels."
|
| 111 |
+
)
|
| 112 |
+
subparser_set.add_argument("token", help="Your token.")
|
| 113 |
+
subparser_set.add_argument(
|
| 114 |
+
"--include-archive-channels",
|
| 115 |
+
choices=repo_config.ARCHIVE_CHANNELS,
|
| 116 |
+
help="Add archived channels to default_channels. "
|
| 117 |
+
"\nAvailable channels are mro, mro-archive, free, and pro.",
|
| 118 |
+
nargs="+",
|
| 119 |
+
default=None,
|
| 120 |
+
metavar="CHANNEL_NAME",
|
| 121 |
+
)
|
| 122 |
+
subparser_set.add_argument(
|
| 123 |
+
"--no-ssl-verify",
|
| 124 |
+
help="Force disabling SSL verification. "
|
| 125 |
+
"By default conda-token will respect your "
|
| 126 |
+
"ssl_verify flag in your Conda settings. "
|
| 127 |
+
"Using this flag will add ssl_verify: false "
|
| 128 |
+
"to your .condarc file. If not already set.",
|
| 129 |
+
action="store_true",
|
| 130 |
+
)
|
| 131 |
+
subparser_set.add_argument(
|
| 132 |
+
"--enable-signature-verification",
|
| 133 |
+
action="store_true",
|
| 134 |
+
help="Enable Conda package signature verification. Default is off.",
|
| 135 |
+
)
|
| 136 |
+
subparser_set.add_argument(
|
| 137 |
+
"--force-config-condarc",
|
| 138 |
+
action="store_true",
|
| 139 |
+
help="Force configuration of .condarc",
|
| 140 |
+
)
|
| 141 |
+
condarc_path_args(subparser_set)
|
| 142 |
+
subparser_set.set_defaults(func=token_set)
|
| 143 |
+
|
| 144 |
+
if len(sys.argv) == 1:
|
| 145 |
+
sys.argv.append("--help")
|
| 146 |
+
|
| 147 |
+
args = parser.parse_args(argv)
|
| 148 |
+
return args.func(args)
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
if __name__ == "__main__":
|
| 152 |
+
cli(sys.argv[1:])
|
data/miniconda3/lib/python3.13/site-packages/anaconda_auth/_conda/condarc.py
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
from typing import Any
|
| 5 |
+
|
| 6 |
+
from ruamel.yaml import YAML
|
| 7 |
+
from ruamel.yaml import YAMLError
|
| 8 |
+
|
| 9 |
+
from anaconda_cli_base import console
|
| 10 |
+
|
| 11 |
+
DEFAULT_CONDARC_PATH = Path("~/.condarc").expanduser()
|
| 12 |
+
|
| 13 |
+
yaml = YAML()
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
class CondaRCError(Exception):
|
| 17 |
+
pass
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
class CondaRC:
|
| 21 |
+
def __init__(self, condarc_path: Path | None = None):
|
| 22 |
+
"""
|
| 23 |
+
Initializes the CondaRC object by attempting to open and load the contents
|
| 24 |
+
of the condarc file found in the user's home directory.
|
| 25 |
+
"""
|
| 26 |
+
self.condarc_path = condarc_path or DEFAULT_CONDARC_PATH
|
| 27 |
+
self._loaded_yaml: dict[str, Any] = {}
|
| 28 |
+
self.load()
|
| 29 |
+
|
| 30 |
+
@property
|
| 31 |
+
def _backup_condarc_path(self) -> Path:
|
| 32 |
+
return self.condarc_path.with_suffix(".bak")
|
| 33 |
+
|
| 34 |
+
def load(self, path: Path | None = None) -> None:
|
| 35 |
+
path = path or self.condarc_path
|
| 36 |
+
try:
|
| 37 |
+
path.touch()
|
| 38 |
+
with path.open("r") as fp:
|
| 39 |
+
contents = fp.read()
|
| 40 |
+
except OSError as exc:
|
| 41 |
+
raise CondaRCError(f"Could not open condarc file: {exc}")
|
| 42 |
+
|
| 43 |
+
try:
|
| 44 |
+
self._loaded_yaml = yaml.load(contents) or {}
|
| 45 |
+
except YAMLError as exc:
|
| 46 |
+
raise CondaRCError(f"Could not parse condarc: {exc}")
|
| 47 |
+
|
| 48 |
+
def update_channel_settings(
|
| 49 |
+
self, channel: str, auth_type: str, username: str | None = None
|
| 50 |
+
) -> None:
|
| 51 |
+
"""
|
| 52 |
+
Update the condarc file's "channel_settings" section
|
| 53 |
+
"""
|
| 54 |
+
if username is None:
|
| 55 |
+
updated_settings = {"channel": channel, "auth": auth_type}
|
| 56 |
+
else:
|
| 57 |
+
updated_settings = {
|
| 58 |
+
"channel": channel,
|
| 59 |
+
"auth": auth_type,
|
| 60 |
+
"username": username,
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
channel_settings = self._loaded_yaml.get("channel_settings", []) or []
|
| 64 |
+
|
| 65 |
+
# Filter out the existing channel's entry if it's there
|
| 66 |
+
filter_settings = [
|
| 67 |
+
settings
|
| 68 |
+
for settings in channel_settings
|
| 69 |
+
if settings.get("channel") != channel
|
| 70 |
+
]
|
| 71 |
+
|
| 72 |
+
# Add the updated settings map
|
| 73 |
+
filter_settings.append(updated_settings)
|
| 74 |
+
|
| 75 |
+
self._loaded_yaml["channel_settings"] = filter_settings
|
| 76 |
+
|
| 77 |
+
def restore(self) -> None:
|
| 78 |
+
console.print(f"Restoring config from {self._backup_condarc_path}")
|
| 79 |
+
self.load(self._backup_condarc_path)
|
| 80 |
+
self.save()
|
| 81 |
+
|
| 82 |
+
def backup(self) -> None:
|
| 83 |
+
console.print(f"Backing up config to {self._backup_condarc_path}")
|
| 84 |
+
self.save(self._backup_condarc_path)
|
| 85 |
+
|
| 86 |
+
def save(self, path: Path | None = None) -> None:
|
| 87 |
+
"""Save the condarc file"""
|
| 88 |
+
path = path or self.condarc_path
|
| 89 |
+
try:
|
| 90 |
+
with path.open("w") as fp:
|
| 91 |
+
yaml.dump(self._loaded_yaml, fp)
|
| 92 |
+
except OSError as exc:
|
| 93 |
+
raise CondaRCError(f"Could not save file: {exc}")
|
data/miniconda3/lib/python3.13/site-packages/anaconda_auth/_conda/config.py
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Configuration manager for the conda plugin.
|
| 2 |
+
|
| 3 |
+
This file is used as a central location to manage global configuration
|
| 4 |
+
settings and deliver them to the locations where they are needed, including
|
| 5 |
+
other modules and YAML configuration files. It is designed to be callable as
|
| 6 |
+
a standalone script or as a module. It can install a conda configuration file
|
| 7 |
+
in the prefix, and to verify its existence and expected behavioral impact.
|
| 8 |
+
These functions are both used by the conda recipe itself.
|
| 9 |
+
|
| 10 |
+
It is imperative that this module not include any other anaconda_auth imports
|
| 11 |
+
so that it can be run during the conda build process
|
| 12 |
+
"""
|
| 13 |
+
|
| 14 |
+
import sys
|
| 15 |
+
from pathlib import Path
|
| 16 |
+
from typing import Any
|
| 17 |
+
from typing import Dict
|
| 18 |
+
from typing import List
|
| 19 |
+
from typing import NamedTuple
|
| 20 |
+
from typing import Set
|
| 21 |
+
from typing import Union
|
| 22 |
+
|
| 23 |
+
__all__ = []
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
PREFIX_CONDARC_PATH = Path(sys.prefix) / "condarc.d" / "anaconda-auth.yml"
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
# This list is now serving THREE purposes. The keys are used in the conda
|
| 30 |
+
# plugin module to determine which hosts should be hardcoded to use
|
| 31 |
+
# anaconda-auth for authentication. The values are used to provide the
|
| 32 |
+
# keyring domain where the legacy token will be stored, as well as
|
| 33 |
+
# whether or not the destination should receive a proper API key.
|
| 34 |
+
# Finally, the list is used to generate the master anaconda-auth.yml
|
| 35 |
+
# configuration for conda.
|
| 36 |
+
class TokenDomainSetting(NamedTuple):
|
| 37 |
+
token_domain: str
|
| 38 |
+
default_use_unified_api_key: bool = True
|
| 39 |
+
autoconfigure_conda_channel_settings: bool = False
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
TOKEN_DOMAIN_MAP = {
|
| 43 |
+
"repo.continuum.io": TokenDomainSetting("anaconda.com"),
|
| 44 |
+
"repo.anaconda.com": TokenDomainSetting("anaconda.com"),
|
| 45 |
+
"repo.anaconda.cloud": TokenDomainSetting("anaconda.com", False, True),
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def _dictify(channel_settings: List[Dict[str, str]]) -> Dict[str, str]:
|
| 50 |
+
"""
|
| 51 |
+
Extract the authentication information for each channel
|
| 52 |
+
for better comparison with expectations.
|
| 53 |
+
"""
|
| 54 |
+
return {c["channel"]: c.get("auth", "") for c in channel_settings}
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def _assert_settings(
|
| 58 |
+
context: Any, expected: Dict[str, str], filtered: bool = False
|
| 59 |
+
) -> None:
|
| 60 |
+
"""
|
| 61 |
+
Compare just the channel authentication information for each
|
| 62 |
+
channel with the expectation, with order independence
|
| 63 |
+
"""
|
| 64 |
+
found = _dictify(context.channel_settings)
|
| 65 |
+
if filtered:
|
| 66 |
+
found = {k: v for k, v in expected.items() if k in expected}
|
| 67 |
+
assert found == expected, f"{found=}, {expected=}"
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
def _build_channel_settings(
|
| 71 |
+
include_defaults: bool = True, include_sites: bool = True
|
| 72 |
+
) -> List[Dict[str, str]]:
|
| 73 |
+
hosts: Set[str] = set()
|
| 74 |
+
if include_defaults:
|
| 75 |
+
hosts.update(
|
| 76 |
+
repo_domain
|
| 77 |
+
for repo_domain, settings in TOKEN_DOMAIN_MAP.items()
|
| 78 |
+
if settings.autoconfigure_conda_channel_settings
|
| 79 |
+
)
|
| 80 |
+
if include_sites:
|
| 81 |
+
# We are delaying this import so this file can be run standalone
|
| 82 |
+
from anaconda_auth.config import AnacondaAuthSitesConfig
|
| 83 |
+
|
| 84 |
+
hosts.update(s.domain for s in AnacondaAuthSitesConfig().sites.root.values())
|
| 85 |
+
return [{"channel": f"https://{host}/*", "auth": "anaconda-auth"} for host in hosts]
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def _build_channel_yaml(
|
| 89 |
+
include_defaults: bool = True, include_sites: bool = True
|
| 90 |
+
) -> str:
|
| 91 |
+
settings = _build_channel_settings(include_defaults, include_sites)
|
| 92 |
+
# Hand-construct the YAML so we can avoid a library dependency, and
|
| 93 |
+
# easily include the warning comment.
|
| 94 |
+
lines = [
|
| 95 |
+
"# DO NOT EDIT THIS FILE.",
|
| 96 |
+
"# This file was generated automatically for anaconda-auth.",
|
| 97 |
+
]
|
| 98 |
+
lines.append("channel_settings:")
|
| 99 |
+
for record in settings:
|
| 100 |
+
pfx = "- "
|
| 101 |
+
for key, value in record.items():
|
| 102 |
+
lines.append(f'{pfx}{key}: "{value}"')
|
| 103 |
+
pfx = " "
|
| 104 |
+
if not settings:
|
| 105 |
+
lines[-1] += " []"
|
| 106 |
+
lines.append("")
|
| 107 |
+
return "\n".join(lines)
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
def _write_channel_settings(
|
| 111 |
+
fpath: Union[Path, str],
|
| 112 |
+
include_defaults: bool = True,
|
| 113 |
+
include_sites: bool = True,
|
| 114 |
+
overwrite: bool = False,
|
| 115 |
+
) -> None:
|
| 116 |
+
with Path(fpath).open(mode="w" if overwrite else "x") as fp:
|
| 117 |
+
fp.write(_build_channel_yaml(include_defaults, include_sites))
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
def _write_condarc_d_settings(overwrite: bool = False) -> None:
|
| 121 |
+
PREFIX_CONDARC_PATH.parent.mkdir(parents=True, exist_ok=True)
|
| 122 |
+
_write_channel_settings(
|
| 123 |
+
PREFIX_CONDARC_PATH, include_sites=False, overwrite=overwrite
|
| 124 |
+
)
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
def _verify_channel_settings(filtered: bool = True) -> None:
|
| 128 |
+
from conda.base.context import context
|
| 129 |
+
|
| 130 |
+
context.__init__()
|
| 131 |
+
expected = _build_channel_settings(include_sites=False)
|
| 132 |
+
_assert_settings(context, _dictify(expected), filtered=filtered)
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
if __name__ == "__main__":
|
| 136 |
+
import sys
|
| 137 |
+
|
| 138 |
+
invalid = [
|
| 139 |
+
x for x in sys.argv[1:] if x not in ("--install", "--verify", "--overwrite")
|
| 140 |
+
]
|
| 141 |
+
if len(sys.argv) == 1 or invalid:
|
| 142 |
+
print(
|
| 143 |
+
f"Usage: {sys.argv[0]} [--install] [--verify] [--overwrite]",
|
| 144 |
+
file=sys.stderr,
|
| 145 |
+
)
|
| 146 |
+
if invalid:
|
| 147 |
+
print(f"Invalid option(s): {' '.join(invalid)}", file=sys.stderr)
|
| 148 |
+
sys.exit(1)
|
| 149 |
+
if "--install" in sys.argv:
|
| 150 |
+
_write_condarc_d_settings(overwrite="--overwrite" in sys.argv)
|
| 151 |
+
if "--verify" in sys.argv:
|
| 152 |
+
_verify_channel_settings()
|
data/miniconda3/lib/python3.13/site-packages/anaconda_auth/_conda/entrypoint.py
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# The plugin entrypoints are loaded via this module as specified in pyproject.toml
|
| 2 |
+
# We do this to be very conservative and catch potential import errors without surfacing to users.
|
| 3 |
+
# Plugins were first introduced in conda=22.11.0
|
| 4 |
+
# The ChannelAuthBase class was introduced in conda=23.7.0
|
| 5 |
+
try:
|
| 6 |
+
from anaconda_auth._conda.plugins import * # noqa: F403
|
| 7 |
+
except ImportError:
|
| 8 |
+
pass
|
data/miniconda3/lib/python3.13/site-packages/anaconda_auth/_conda/plugins.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Definitions for conda plugins.
|
| 2 |
+
|
| 3 |
+
This file should not be imported directly, but instead the parent package will
|
| 4 |
+
conditionally import it in case conda is not installed in the user's environment.
|
| 5 |
+
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
from typing import Iterable
|
| 9 |
+
from typing import Optional
|
| 10 |
+
|
| 11 |
+
from conda import plugins
|
| 12 |
+
from conda.plugins.types import CondaAuthHandler
|
| 13 |
+
from conda.plugins.types import CondaSubcommand
|
| 14 |
+
|
| 15 |
+
from anaconda_auth._conda.auth_handler import AnacondaAuthHandler
|
| 16 |
+
from anaconda_auth._conda.conda_token import cli
|
| 17 |
+
|
| 18 |
+
__all__ = ["conda_subcommands", "conda_auth_handlers"]
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def _cli_wrapper(argv: Optional[list[str]] = None) -> int: # type: ignore
|
| 22 |
+
# If argv is empty tuple, we need to set it back to None
|
| 23 |
+
return cli(argv=argv or None)
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
@plugins.hookimpl
|
| 27 |
+
def conda_subcommands() -> Iterable[CondaSubcommand]:
|
| 28 |
+
"""Defines subcommands into conda itself (not `anaconda` CLI)."""
|
| 29 |
+
yield CondaSubcommand(
|
| 30 |
+
name="token",
|
| 31 |
+
summary="Set repository access token and configure default_channels",
|
| 32 |
+
action=_cli_wrapper, # type: ignore
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
@plugins.hookimpl
|
| 37 |
+
def conda_auth_handlers() -> Iterable[CondaAuthHandler]:
|
| 38 |
+
"""Defines the auth handler that can be used for specific channels.
|
| 39 |
+
|
| 40 |
+
The following shows an example for how to configure a specific channel inside .condarc:
|
| 41 |
+
|
| 42 |
+
```yaml
|
| 43 |
+
channel_settings:
|
| 44 |
+
- channel: https://repo.anaconda.cloud/*
|
| 45 |
+
auth: anaconda-auth
|
| 46 |
+
```
|
| 47 |
+
|
| 48 |
+
"""
|
| 49 |
+
yield CondaAuthHandler(
|
| 50 |
+
name="anaconda-auth",
|
| 51 |
+
handler=AnacondaAuthHandler,
|
| 52 |
+
)
|
data/miniconda3/lib/python3.13/site-packages/anaconda_auth/_conda/repo_config.py
ADDED
|
@@ -0,0 +1,549 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Configure Conda to use Anaconda Commercial Edition.
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
from __future__ import annotations
|
| 6 |
+
|
| 7 |
+
import contextlib
|
| 8 |
+
import io
|
| 9 |
+
import json
|
| 10 |
+
import os
|
| 11 |
+
import sys
|
| 12 |
+
import warnings
|
| 13 |
+
from os.path import abspath
|
| 14 |
+
from os.path import expanduser
|
| 15 |
+
from os.path import join
|
| 16 |
+
from typing import Any
|
| 17 |
+
from urllib.parse import urljoin
|
| 18 |
+
|
| 19 |
+
import conda
|
| 20 |
+
import conda.gateways.logging # noqa: F401
|
| 21 |
+
from conda.base import context as context_module
|
| 22 |
+
from conda.cli import main as conda_main
|
| 23 |
+
from conda.exceptions import CondaKeyError
|
| 24 |
+
from conda.gateways.anaconda_client import read_binstar_tokens
|
| 25 |
+
from conda.gateways.anaconda_client import remove_binstar_token
|
| 26 |
+
from conda.gateways.anaconda_client import set_binstar_token
|
| 27 |
+
from conda.gateways.connection.session import CondaSession
|
| 28 |
+
from conda.models.channel import Channel
|
| 29 |
+
from packaging import version
|
| 30 |
+
from rich.prompt import Confirm
|
| 31 |
+
|
| 32 |
+
from anaconda_auth._conda.conda_api import Commands
|
| 33 |
+
from anaconda_auth._conda.condarc import CondaRC
|
| 34 |
+
from anaconda_auth._conda.config import _build_channel_settings
|
| 35 |
+
from anaconda_cli_base import console
|
| 36 |
+
|
| 37 |
+
CONDA_VERSION = version.parse(conda.__version__)
|
| 38 |
+
|
| 39 |
+
REPO_URL = os.getenv("CONDA_TOKEN_REPO_URL", "https://repo.anaconda.cloud/repo/")
|
| 40 |
+
MAIN_CHANNEL = "main"
|
| 41 |
+
ACTIVE_CHANNELS = ["r", "msys2"]
|
| 42 |
+
ARCHIVE_CHANNELS = ["free", "mro-archive", "pro"]
|
| 43 |
+
|
| 44 |
+
user_rc_path = abspath(expanduser("~/.condarc"))
|
| 45 |
+
escaped_user_rc_path = user_rc_path.replace("%", "%%")
|
| 46 |
+
escaped_sys_rc_path = abspath(join(sys.prefix, ".condarc")).replace("%", "%%")
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def run_command(*args: Any, **kwargs: Any) -> int:
|
| 50 |
+
with warnings.catch_warnings():
|
| 51 |
+
# Ignore PendingDeprecationWarning from any other plugins invoked when calling conda
|
| 52 |
+
warnings.simplefilter("ignore", PendingDeprecationWarning)
|
| 53 |
+
return conda_main(*args, **kwargs)
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
class CondaTokenError(RuntimeError):
|
| 57 |
+
pass
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
class CondaVersionWarning(UserWarning):
|
| 61 |
+
pass
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def _get_condarc_args(
|
| 65 |
+
condarc_system: bool = False,
|
| 66 |
+
condarc_env: bool = False,
|
| 67 |
+
condarc_file: str | None = None,
|
| 68 |
+
) -> list[str]:
|
| 69 |
+
"""Construct conda CLI args related to condarc location."""
|
| 70 |
+
config_args = []
|
| 71 |
+
|
| 72 |
+
if condarc_system:
|
| 73 |
+
config_args.append("--system")
|
| 74 |
+
elif condarc_env:
|
| 75 |
+
config_args.append("--env")
|
| 76 |
+
elif condarc_file:
|
| 77 |
+
config_args.append(f"--file={condarc_file}")
|
| 78 |
+
|
| 79 |
+
return config_args
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
def can_restore_free_channel() -> bool:
|
| 83 |
+
# restore_free_channel was removed in conda 25.9.0
|
| 84 |
+
return CONDA_VERSION >= version.parse("4.7.0") and CONDA_VERSION < version.parse(
|
| 85 |
+
"25.9.0"
|
| 86 |
+
)
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
def clean_index() -> None:
|
| 90 |
+
"""Runs conda clean -i.
|
| 91 |
+
|
| 92 |
+
It is important to remove index cache when
|
| 93 |
+
changing the condarc to ensure that the downloaded
|
| 94 |
+
repodata is correct.
|
| 95 |
+
"""
|
| 96 |
+
run_command(Commands.CLEAN, "-i", "-y", "-q")
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
def validate_token(token: str, no_ssl_verify: bool = False) -> None:
|
| 100 |
+
"""Checks that token can be used with the repository."""
|
| 101 |
+
|
| 102 |
+
# Force ssl_verify: false
|
| 103 |
+
if no_ssl_verify:
|
| 104 |
+
context_module.context.ssl_verify = False # type: ignore
|
| 105 |
+
|
| 106 |
+
# Use CondaSession to be compatible with ssl_verify: truststore
|
| 107 |
+
# https://conda.io/projects/conda/en/latest/user-guide/configuration/settings.html#ssl-verify-ssl-verification
|
| 108 |
+
# Clear metaclass cache to create new session checking ssl_verify
|
| 109 |
+
if hasattr(CondaSession, "cache_clear"):
|
| 110 |
+
# not present in conda < January 2024
|
| 111 |
+
CondaSession.cache_clear()
|
| 112 |
+
else:
|
| 113 |
+
# what cache_clear() does
|
| 114 |
+
try:
|
| 115 |
+
CondaSession._thread_local.sessions.clear() # type: ignore
|
| 116 |
+
except AttributeError:
|
| 117 |
+
# AttributeError: thread's session cache has not been initialized
|
| 118 |
+
pass
|
| 119 |
+
|
| 120 |
+
session = CondaSession()
|
| 121 |
+
|
| 122 |
+
# Ensure the index cache is cleaned first
|
| 123 |
+
clean_index()
|
| 124 |
+
|
| 125 |
+
channel = Channel(urljoin(REPO_URL, "main/noarch/repodata.json"))
|
| 126 |
+
channel.token = token
|
| 127 |
+
token_url = str(channel.url(with_credentials=True))
|
| 128 |
+
|
| 129 |
+
r = session.head(token_url, verify=session.verify)
|
| 130 |
+
if r.status_code != 200:
|
| 131 |
+
raise CondaTokenError(
|
| 132 |
+
"The token could not be validated. Please check that you have typed it correctly."
|
| 133 |
+
)
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
def configure_plugin(should_set_default_channels: bool = False) -> None:
|
| 137 |
+
"""Configure the user's .condarc file with the anaconda-auth plugin.
|
| 138 |
+
|
| 139 |
+
We install the auth-handler plugin by writing the "channel_settings" key and associate
|
| 140 |
+
all premium repo channels with this auth handler.
|
| 141 |
+
|
| 142 |
+
"""
|
| 143 |
+
settings = _build_channel_settings(include_defaults=False)
|
| 144 |
+
if not settings:
|
| 145 |
+
return
|
| 146 |
+
condarc = CondaRC()
|
| 147 |
+
condarc.backup()
|
| 148 |
+
for s in settings:
|
| 149 |
+
condarc.update_channel_settings(s["channel"], s["auth"], username=None)
|
| 150 |
+
condarc.save()
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
def enable_extra_safety_checks(
|
| 154 |
+
condarc_system: bool = False,
|
| 155 |
+
condarc_env: bool = False,
|
| 156 |
+
condarc_file: str | None = None,
|
| 157 |
+
) -> None:
|
| 158 |
+
"""Enable package signature verification.
|
| 159 |
+
|
| 160 |
+
This will set extra_safety_checks: True and
|
| 161 |
+
signing_metadata_url_base in the CondaRC file.
|
| 162 |
+
"""
|
| 163 |
+
if CONDA_VERSION < version.parse("4.10.1"):
|
| 164 |
+
warnings.warn(
|
| 165 |
+
"You need upgrade to at least Conda version 4.10.1 to enable package signature verification.",
|
| 166 |
+
CondaVersionWarning,
|
| 167 |
+
)
|
| 168 |
+
return
|
| 169 |
+
|
| 170 |
+
condarc_file_args = _get_condarc_args(
|
| 171 |
+
condarc_system=condarc_system,
|
| 172 |
+
condarc_env=condarc_env,
|
| 173 |
+
condarc_file=condarc_file,
|
| 174 |
+
)
|
| 175 |
+
|
| 176 |
+
safety_check_args = ["--set", "extra_safety_checks", "true"]
|
| 177 |
+
safety_check_args.extend(condarc_file_args)
|
| 178 |
+
run_command(Commands.CONFIG, *safety_check_args)
|
| 179 |
+
|
| 180 |
+
metadata_url_args = ["--set", "signing_metadata_url_base", REPO_URL.rstrip("/")]
|
| 181 |
+
metadata_url_args.extend(condarc_file_args)
|
| 182 |
+
run_command(Commands.CONFIG, *metadata_url_args)
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
def disable_extra_safety_checks(
|
| 186 |
+
condarc_system: bool = False,
|
| 187 |
+
condarc_env: bool = False,
|
| 188 |
+
condarc_file: str | None = None,
|
| 189 |
+
) -> None:
|
| 190 |
+
"""Disable package signature verification.
|
| 191 |
+
|
| 192 |
+
This will set extra_safety_checks: false and remove
|
| 193 |
+
signing_metadata_url_base in the CondaRC file.
|
| 194 |
+
"""
|
| 195 |
+
|
| 196 |
+
if CONDA_VERSION < version.parse("4.10.1"):
|
| 197 |
+
return
|
| 198 |
+
|
| 199 |
+
condarc_file_args = _get_condarc_args(
|
| 200 |
+
condarc_system=condarc_system,
|
| 201 |
+
condarc_env=condarc_env,
|
| 202 |
+
condarc_file=condarc_file,
|
| 203 |
+
)
|
| 204 |
+
|
| 205 |
+
safety_check_args = ["--set", "extra_safety_checks", "false"]
|
| 206 |
+
safety_check_args.extend(condarc_file_args)
|
| 207 |
+
try:
|
| 208 |
+
run_command(Commands.CONFIG, *safety_check_args)
|
| 209 |
+
except CondaKeyError:
|
| 210 |
+
pass
|
| 211 |
+
|
| 212 |
+
metadata_url_args = ["--remove-key", "signing_metadata_url_base"]
|
| 213 |
+
metadata_url_args.extend(condarc_file_args)
|
| 214 |
+
try:
|
| 215 |
+
run_command(Commands.CONFIG, *metadata_url_args)
|
| 216 |
+
except CondaKeyError:
|
| 217 |
+
pass
|
| 218 |
+
|
| 219 |
+
|
| 220 |
+
def _set_add_anaconda_token(
|
| 221 |
+
condarc_system: bool = False,
|
| 222 |
+
condarc_env: bool = False,
|
| 223 |
+
condarc_file: str | None = None,
|
| 224 |
+
) -> None:
|
| 225 |
+
"""Run conda config --set add_anaconda_token true.
|
| 226 |
+
|
| 227 |
+
Setting this parameter to true ensures that the token
|
| 228 |
+
is used when making requests to the repository.
|
| 229 |
+
"""
|
| 230 |
+
config_args = ["--set", "add_anaconda_token", "true"]
|
| 231 |
+
|
| 232 |
+
condarc_file_args = _get_condarc_args(
|
| 233 |
+
condarc_system=condarc_system,
|
| 234 |
+
condarc_env=condarc_env,
|
| 235 |
+
condarc_file=condarc_file,
|
| 236 |
+
)
|
| 237 |
+
config_args.extend(condarc_file_args)
|
| 238 |
+
|
| 239 |
+
run_command(Commands.CONFIG, *config_args)
|
| 240 |
+
|
| 241 |
+
|
| 242 |
+
def _set_ssl_verify_false(
|
| 243 |
+
condarc_system: bool = False,
|
| 244 |
+
condarc_env: bool = False,
|
| 245 |
+
condarc_file: str | None = None,
|
| 246 |
+
) -> None:
|
| 247 |
+
"""Run conda config --set ssl_verify false.
|
| 248 |
+
|
| 249 |
+
Setting this parameter to false disables all
|
| 250 |
+
SSL verification for conda activities
|
| 251 |
+
"""
|
| 252 |
+
config_args = ["--set", "ssl_verify", "false"]
|
| 253 |
+
|
| 254 |
+
condarc_file_args = _get_condarc_args(
|
| 255 |
+
condarc_system=condarc_system,
|
| 256 |
+
condarc_env=condarc_env,
|
| 257 |
+
condarc_file=condarc_file,
|
| 258 |
+
)
|
| 259 |
+
config_args.extend(condarc_file_args)
|
| 260 |
+
|
| 261 |
+
run_command(Commands.CONFIG, *config_args)
|
| 262 |
+
|
| 263 |
+
|
| 264 |
+
def _unset_restore_free_channel(
|
| 265 |
+
condarc_system: bool = False,
|
| 266 |
+
condarc_env: bool = False,
|
| 267 |
+
condarc_file: str | None = None,
|
| 268 |
+
) -> None:
|
| 269 |
+
"""Runs conda config --set restore_free_channel false.
|
| 270 |
+
|
| 271 |
+
The free channel is provided by Commercial Edition as
|
| 272 |
+
and should be added directly."""
|
| 273 |
+
config_args = ["--set", "restore_free_channel", "false"]
|
| 274 |
+
|
| 275 |
+
condarc_file_args = _get_condarc_args(
|
| 276 |
+
condarc_system=condarc_system,
|
| 277 |
+
condarc_env=condarc_env,
|
| 278 |
+
condarc_file=condarc_file,
|
| 279 |
+
)
|
| 280 |
+
config_args.extend(condarc_file_args)
|
| 281 |
+
|
| 282 |
+
run_command(Commands.CONFIG, *config_args, use_exception_handler=True)
|
| 283 |
+
|
| 284 |
+
|
| 285 |
+
def _set_channel(
|
| 286 |
+
channel: str,
|
| 287 |
+
prepend: bool = True,
|
| 288 |
+
condarc_system: bool = False,
|
| 289 |
+
condarc_env: bool = False,
|
| 290 |
+
condarc_file: str | None = None,
|
| 291 |
+
) -> None:
|
| 292 |
+
"""Adds a named Commercial Edition channel to default_channels."""
|
| 293 |
+
channel_url = urljoin(REPO_URL, channel)
|
| 294 |
+
|
| 295 |
+
config_args = [
|
| 296 |
+
"--prepend" if prepend else "--append",
|
| 297 |
+
"default_channels",
|
| 298 |
+
channel_url,
|
| 299 |
+
]
|
| 300 |
+
|
| 301 |
+
condarc_file_args = _get_condarc_args(
|
| 302 |
+
condarc_system=condarc_system,
|
| 303 |
+
condarc_env=condarc_env,
|
| 304 |
+
condarc_file=condarc_file,
|
| 305 |
+
)
|
| 306 |
+
config_args.extend(condarc_file_args)
|
| 307 |
+
|
| 308 |
+
run_command(Commands.CONFIG, *config_args)
|
| 309 |
+
|
| 310 |
+
|
| 311 |
+
def _get_from_condarc(
|
| 312 |
+
key: str,
|
| 313 |
+
default: Any = None,
|
| 314 |
+
condarc_system: bool = False,
|
| 315 |
+
condarc_env: bool = False,
|
| 316 |
+
condarc_file: str | None = None,
|
| 317 |
+
) -> Any:
|
| 318 |
+
"""Retrieve the existing default_channels from the user's `.condarc` file.
|
| 319 |
+
|
| 320 |
+
If the user does not have a "default_channels" section, an empty list is returned.
|
| 321 |
+
|
| 322 |
+
"""
|
| 323 |
+
config_args = ["--get", key, "--json"]
|
| 324 |
+
|
| 325 |
+
condarc_file_args = _get_condarc_args(
|
| 326 |
+
condarc_system=condarc_system,
|
| 327 |
+
condarc_env=condarc_env,
|
| 328 |
+
condarc_file=condarc_file,
|
| 329 |
+
)
|
| 330 |
+
config_args.extend(condarc_file_args)
|
| 331 |
+
|
| 332 |
+
# Capture the JSON output from stdout
|
| 333 |
+
string_io = io.StringIO()
|
| 334 |
+
with contextlib.redirect_stdout(string_io):
|
| 335 |
+
run_command(Commands.CONFIG, *config_args)
|
| 336 |
+
|
| 337 |
+
try:
|
| 338 |
+
result = json.loads(string_io.getvalue())
|
| 339 |
+
except json.JSONDecodeError:
|
| 340 |
+
result = {}
|
| 341 |
+
|
| 342 |
+
return result.get("get", {}).get(key, default)
|
| 343 |
+
|
| 344 |
+
|
| 345 |
+
def _get_default_channels(
|
| 346 |
+
condarc_system: bool = False,
|
| 347 |
+
condarc_env: bool = False,
|
| 348 |
+
condarc_file: str | None = None,
|
| 349 |
+
) -> list[str]:
|
| 350 |
+
"""Retrieve the existing default_channels from the user's `.condarc` file.
|
| 351 |
+
|
| 352 |
+
If the user does not have a "default_channels" section, an empty list is returned.
|
| 353 |
+
|
| 354 |
+
"""
|
| 355 |
+
return _get_from_condarc(
|
| 356 |
+
"default_channels",
|
| 357 |
+
default=[],
|
| 358 |
+
condarc_system=condarc_system,
|
| 359 |
+
condarc_env=condarc_env,
|
| 360 |
+
condarc_file=condarc_file,
|
| 361 |
+
)
|
| 362 |
+
|
| 363 |
+
|
| 364 |
+
def _remove_default_channels(
|
| 365 |
+
condarc_system: bool = False,
|
| 366 |
+
condarc_env: bool = False,
|
| 367 |
+
condarc_file: str | None = None,
|
| 368 |
+
) -> None:
|
| 369 |
+
"""Runs conda config --remove-key default_channels
|
| 370 |
+
|
| 371 |
+
It is best to remove the default_channels in case they
|
| 372 |
+
are not set at the default values before configuring
|
| 373 |
+
Commercial Edition.
|
| 374 |
+
"""
|
| 375 |
+
config_args = ["--remove-key", "default_channels"]
|
| 376 |
+
|
| 377 |
+
condarc_file_args = _get_condarc_args(
|
| 378 |
+
condarc_system=condarc_system,
|
| 379 |
+
condarc_env=condarc_env,
|
| 380 |
+
condarc_file=condarc_file,
|
| 381 |
+
)
|
| 382 |
+
config_args.extend(condarc_file_args)
|
| 383 |
+
|
| 384 |
+
# We suppress a CondaKeyError below to prevent logging an internal conda error
|
| 385 |
+
# to the terminal.
|
| 386 |
+
err_io = io.StringIO()
|
| 387 |
+
with contextlib.redirect_stderr(err_io):
|
| 388 |
+
try:
|
| 389 |
+
run_command(Commands.CONFIG, *config_args)
|
| 390 |
+
except CondaKeyError:
|
| 391 |
+
pass
|
| 392 |
+
|
| 393 |
+
err_string = err_io.getvalue()
|
| 394 |
+
if "CondaKeyError" not in err_string.strip():
|
| 395 |
+
print(err_string, file=sys.stderr)
|
| 396 |
+
|
| 397 |
+
|
| 398 |
+
def _prompt_to_set_default_channels() -> bool:
|
| 399 |
+
"""Prompt the user for whether they would like to set their default channels."""
|
| 400 |
+
existing_default_channels = _get_default_channels()
|
| 401 |
+
if existing_default_channels:
|
| 402 |
+
console.print("Existing default channels found:")
|
| 403 |
+
for c in existing_default_channels:
|
| 404 |
+
console.print(f"- {c}")
|
| 405 |
+
console.print(
|
| 406 |
+
"This action will override the existing default_channels setting."
|
| 407 |
+
)
|
| 408 |
+
else:
|
| 409 |
+
console.print("Prepared to set default channels in .condarc.")
|
| 410 |
+
|
| 411 |
+
return Confirm.ask("Proceed?", default=False)
|
| 412 |
+
|
| 413 |
+
|
| 414 |
+
def configure_default_channels(
|
| 415 |
+
condarc_system: bool = False,
|
| 416 |
+
condarc_env: bool = False,
|
| 417 |
+
condarc_file: str | None = None,
|
| 418 |
+
include_archive_channels: list[str] | None = None,
|
| 419 |
+
force: bool = False,
|
| 420 |
+
) -> None:
|
| 421 |
+
"""Configure the default_channels to utilize only Commercial Edition.
|
| 422 |
+
|
| 423 |
+
|
| 424 |
+
This function performs the following actions
|
| 425 |
+
1. unset default_channels if it exists in the condarc
|
| 426 |
+
2. unset restore_free_channel if it exists in the condarc
|
| 427 |
+
3. Add the main, r, and msys2 channels to default_channels
|
| 428 |
+
4. Optionally add any of the archive channels:
|
| 429 |
+
free, pro, mro, mro-archive
|
| 430 |
+
"""
|
| 431 |
+
console.print("Configuring your [cyan].condarc[/cyan] file")
|
| 432 |
+
|
| 433 |
+
existing_default_channels = _get_default_channels()
|
| 434 |
+
|
| 435 |
+
existing_default_channels_short_names = [
|
| 436 |
+
c.removeprefix(REPO_URL) for c in existing_default_channels
|
| 437 |
+
]
|
| 438 |
+
if set(existing_default_channels_short_names) == set(
|
| 439 |
+
[MAIN_CHANNEL] + ACTIVE_CHANNELS
|
| 440 |
+
):
|
| 441 |
+
console.print("Default channels already configured, nothing to do.")
|
| 442 |
+
return
|
| 443 |
+
|
| 444 |
+
if not (force or _prompt_to_set_default_channels()):
|
| 445 |
+
return
|
| 446 |
+
|
| 447 |
+
_remove_default_channels(condarc_system, condarc_env, condarc_file)
|
| 448 |
+
|
| 449 |
+
if can_restore_free_channel() and _get_from_condarc(
|
| 450 |
+
"restore_free_channel",
|
| 451 |
+
condarc_system=condarc_system,
|
| 452 |
+
condarc_env=condarc_env,
|
| 453 |
+
condarc_file=condarc_file,
|
| 454 |
+
):
|
| 455 |
+
_unset_restore_free_channel(condarc_system, condarc_env, condarc_file)
|
| 456 |
+
|
| 457 |
+
_set_channel(
|
| 458 |
+
MAIN_CHANNEL,
|
| 459 |
+
prepend=True,
|
| 460 |
+
condarc_system=condarc_system,
|
| 461 |
+
condarc_env=condarc_env,
|
| 462 |
+
condarc_file=condarc_file,
|
| 463 |
+
)
|
| 464 |
+
|
| 465 |
+
for c in ACTIVE_CHANNELS:
|
| 466 |
+
_set_channel(
|
| 467 |
+
c,
|
| 468 |
+
prepend=False,
|
| 469 |
+
condarc_system=condarc_system,
|
| 470 |
+
condarc_env=condarc_env,
|
| 471 |
+
condarc_file=condarc_file,
|
| 472 |
+
)
|
| 473 |
+
|
| 474 |
+
if include_archive_channels is None:
|
| 475 |
+
return
|
| 476 |
+
|
| 477 |
+
for c in include_archive_channels:
|
| 478 |
+
if c in ARCHIVE_CHANNELS:
|
| 479 |
+
_set_channel(
|
| 480 |
+
c,
|
| 481 |
+
prepend=False,
|
| 482 |
+
condarc_system=condarc_system,
|
| 483 |
+
condarc_env=condarc_env,
|
| 484 |
+
condarc_file=condarc_file,
|
| 485 |
+
)
|
| 486 |
+
else:
|
| 487 |
+
raise ValueError(
|
| 488 |
+
f"The archive channel {c} is not one of {', '.join(ARCHIVE_CHANNELS)}"
|
| 489 |
+
)
|
| 490 |
+
|
| 491 |
+
|
| 492 |
+
def token_list() -> dict[str, str]:
|
| 493 |
+
"""Return a dictionary of tokens for all configured repository urls.
|
| 494 |
+
|
| 495 |
+
Note that this function will return tokens configured for non-Commercial Edition
|
| 496 |
+
urls."""
|
| 497 |
+
return read_binstar_tokens()
|
| 498 |
+
|
| 499 |
+
|
| 500 |
+
def token_remove(
|
| 501 |
+
system: bool = False, env: bool = False, file: str | None = None
|
| 502 |
+
) -> None:
|
| 503 |
+
"""Completely remove the Commercial Edition token and default_channels.
|
| 504 |
+
|
| 505 |
+
This function performs three actions.
|
| 506 |
+
1. Remove the token
|
| 507 |
+
2. Remove the custom default_channels in the condarc
|
| 508 |
+
3. Disable package signature verification
|
| 509 |
+
4. Run conda clean -i
|
| 510 |
+
"""
|
| 511 |
+
remove_binstar_token(REPO_URL)
|
| 512 |
+
_remove_default_channels(system, env, file)
|
| 513 |
+
disable_extra_safety_checks(system, env, file)
|
| 514 |
+
clean_index()
|
| 515 |
+
|
| 516 |
+
|
| 517 |
+
def token_set(
|
| 518 |
+
token: str,
|
| 519 |
+
system: bool = False,
|
| 520 |
+
env: bool = False,
|
| 521 |
+
file: str | None = None,
|
| 522 |
+
include_archive_channels: list[str] | None = None,
|
| 523 |
+
no_ssl_verify: bool = False,
|
| 524 |
+
enable_signature_verification: bool = False,
|
| 525 |
+
force: bool = False,
|
| 526 |
+
) -> None:
|
| 527 |
+
"""Set the Commercial Edition token and configure default_channels.
|
| 528 |
+
|
| 529 |
+
|
| 530 |
+
This function performs 4 actions.
|
| 531 |
+
1. Remove previous Commercial Edition token if present.
|
| 532 |
+
2. Add token.
|
| 533 |
+
3. Configure default_channels in the condarc file.
|
| 534 |
+
4. Optionally enable Conda package signature verification
|
| 535 |
+
5. Run conda clean -i
|
| 536 |
+
"""
|
| 537 |
+
remove_binstar_token(REPO_URL)
|
| 538 |
+
|
| 539 |
+
set_binstar_token(REPO_URL, token)
|
| 540 |
+
_set_add_anaconda_token(system, env, file)
|
| 541 |
+
|
| 542 |
+
if no_ssl_verify:
|
| 543 |
+
_set_ssl_verify_false(system, env, file)
|
| 544 |
+
|
| 545 |
+
if enable_signature_verification:
|
| 546 |
+
enable_extra_safety_checks(system, env, file)
|
| 547 |
+
|
| 548 |
+
configure_default_channels(system, env, file, include_archive_channels, force=force)
|
| 549 |
+
clean_index()
|
data/miniconda3/lib/python3.13/site-packages/archspec/__pycache__/__init__.cpython-313.pyc
ADDED
|
Binary file (227 Bytes). View file
|
|
|
data/miniconda3/lib/python3.13/site-packages/archspec/__pycache__/__main__.cpython-313.pyc
ADDED
|
Binary file (327 Bytes). View file
|
|
|
data/miniconda3/lib/python3.13/site-packages/archspec/__pycache__/cli.cpython-313.pyc
ADDED
|
Binary file (2.46 kB). View file
|
|
|
data/miniconda3/lib/python3.13/site-packages/archspec/cpu/__init__.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2019-2020 Lawrence Livermore National Security, LLC and other
|
| 2 |
+
# Archspec Project Developers. See the top-level COPYRIGHT file for details.
|
| 3 |
+
#
|
| 4 |
+
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
|
| 5 |
+
"""The "cpu" package permits to query and compare different
|
| 6 |
+
CPU microarchitectures.
|
| 7 |
+
"""
|
| 8 |
+
from .detect import brand_string, host
|
| 9 |
+
from .microarchitecture import (
|
| 10 |
+
TARGETS,
|
| 11 |
+
InvalidCompilerVersion,
|
| 12 |
+
Microarchitecture,
|
| 13 |
+
UnsupportedMicroarchitecture,
|
| 14 |
+
generic_microarchitecture,
|
| 15 |
+
version_components,
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
__all__ = [
|
| 19 |
+
"brand_string",
|
| 20 |
+
"host",
|
| 21 |
+
"TARGETS",
|
| 22 |
+
"InvalidCompilerVersion",
|
| 23 |
+
"Microarchitecture",
|
| 24 |
+
"UnsupportedMicroarchitecture",
|
| 25 |
+
"generic_microarchitecture",
|
| 26 |
+
"version_components",
|
| 27 |
+
]
|
data/miniconda3/lib/python3.13/site-packages/archspec/cpu/__pycache__/__init__.cpython-313.pyc
ADDED
|
Binary file (602 Bytes). View file
|
|
|
data/miniconda3/lib/python3.13/site-packages/archspec/cpu/__pycache__/alias.cpython-313.pyc
ADDED
|
Binary file (4.01 kB). View file
|
|
|
data/miniconda3/lib/python3.13/site-packages/archspec/cpu/__pycache__/detect.cpython-313.pyc
ADDED
|
Binary file (19.5 kB). View file
|
|
|
data/miniconda3/lib/python3.13/site-packages/archspec/cpu/__pycache__/microarchitecture.cpython-313.pyc
ADDED
|
Binary file (19.2 kB). View file
|
|
|
data/miniconda3/lib/python3.13/site-packages/archspec/cpu/__pycache__/schema.cpython-313.pyc
ADDED
|
Binary file (5.15 kB). View file
|
|
|
data/miniconda3/lib/python3.13/site-packages/archspec/cpu/alias.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2019-2020 Lawrence Livermore National Security, LLC and other
|
| 2 |
+
# Archspec Project Developers. See the top-level COPYRIGHT file for details.
|
| 3 |
+
#
|
| 4 |
+
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
|
| 5 |
+
"""Aliases for microarchitecture features."""
|
| 6 |
+
from .schema import TARGETS_JSON, LazyDictionary
|
| 7 |
+
|
| 8 |
+
_FEATURE_ALIAS_PREDICATE = {}
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class FeatureAliasTest:
|
| 12 |
+
"""A test that must be passed for a feature alias to succeed.
|
| 13 |
+
|
| 14 |
+
Args:
|
| 15 |
+
rules (dict): dictionary of rules to be met. Each key must be a
|
| 16 |
+
valid alias predicate
|
| 17 |
+
"""
|
| 18 |
+
|
| 19 |
+
# pylint: disable=too-few-public-methods
|
| 20 |
+
def __init__(self, rules):
|
| 21 |
+
self.rules = rules
|
| 22 |
+
self.predicates = []
|
| 23 |
+
for name, args in rules.items():
|
| 24 |
+
self.predicates.append(_FEATURE_ALIAS_PREDICATE[name](args))
|
| 25 |
+
|
| 26 |
+
def __call__(self, microarchitecture):
|
| 27 |
+
return all(feature_test(microarchitecture) for feature_test in self.predicates)
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def _feature_aliases():
|
| 31 |
+
"""Returns the dictionary of all defined feature aliases."""
|
| 32 |
+
json_data = TARGETS_JSON["feature_aliases"]
|
| 33 |
+
aliases = {}
|
| 34 |
+
for alias, rules in json_data.items():
|
| 35 |
+
aliases[alias] = FeatureAliasTest(rules)
|
| 36 |
+
return aliases
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
FEATURE_ALIASES = LazyDictionary(_feature_aliases)
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def alias_predicate(func):
|
| 43 |
+
"""Decorator to register a predicate that can be used to evaluate
|
| 44 |
+
feature aliases.
|
| 45 |
+
"""
|
| 46 |
+
name = func.__name__
|
| 47 |
+
|
| 48 |
+
# Check we didn't register anything else with the same name
|
| 49 |
+
if name in _FEATURE_ALIAS_PREDICATE:
|
| 50 |
+
msg = f'the alias predicate "{name}" already exists'
|
| 51 |
+
raise KeyError(msg)
|
| 52 |
+
|
| 53 |
+
_FEATURE_ALIAS_PREDICATE[name] = func
|
| 54 |
+
|
| 55 |
+
return func
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
@alias_predicate
|
| 59 |
+
def reason(_):
|
| 60 |
+
"""This predicate returns always True and it's there to allow writing
|
| 61 |
+
a documentation string in the JSON file to explain why an alias is needed.
|
| 62 |
+
"""
|
| 63 |
+
return lambda x: True
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
@alias_predicate
|
| 67 |
+
def any_of(list_of_features):
|
| 68 |
+
"""Returns a predicate that is True if any of the feature in the
|
| 69 |
+
list is in the microarchitecture being tested, False otherwise.
|
| 70 |
+
"""
|
| 71 |
+
|
| 72 |
+
def _impl(microarchitecture):
|
| 73 |
+
return any(x in microarchitecture for x in list_of_features)
|
| 74 |
+
|
| 75 |
+
return _impl
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
@alias_predicate
|
| 79 |
+
def families(list_of_families):
|
| 80 |
+
"""Returns a predicate that is True if the architecture family of
|
| 81 |
+
the microarchitecture being tested is in the list, False otherwise.
|
| 82 |
+
"""
|
| 83 |
+
|
| 84 |
+
def _impl(microarchitecture):
|
| 85 |
+
return str(microarchitecture.family) in list_of_families
|
| 86 |
+
|
| 87 |
+
return _impl
|