-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathexceptions.py
1299 lines (1061 loc) · 41 KB
/
exceptions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright (C) 2012 Anaconda, Inc
# SPDX-License-Identifier: BSD-3-Clause
"""Conda exceptions."""
from __future__ import annotations
import json
import os
import sys
from datetime import timedelta
from logging import getLogger
from os.path import join
from textwrap import dedent
from traceback import format_exception, format_exception_only
from typing import TYPE_CHECKING
from requests.exceptions import JSONDecodeError
from . import CondaError, CondaExitZero, CondaMultiError
from .auxlib.entity import EntityEncoder
from .auxlib.ish import dals
from .auxlib.logz import stringify
from .base.constants import COMPATIBLE_SHELLS, PathConflict, SafetyChecks
from .common.compat import on_win
from .common.io import dashlist
from .common.iterators import groupby_to_dict as groupby
from .common.signals import get_signal_name
from .common.url import join_url, maybe_unquote
from .deprecations import DeprecatedError # noqa: F401
from .exception_handler import ExceptionHandler, conda_exception_handler # noqa: F401
from .models.channel import Channel
if TYPE_CHECKING:
import requests
log = getLogger(__name__)
# TODO: for conda-build compatibility only
# remove in conda 4.4
class ResolvePackageNotFound(CondaError):
def __init__(self, bad_deps):
# bad_deps is a list of lists
# bad_deps should really be named 'invalid_chains'
self.bad_deps = tuple(dep for deps in bad_deps for dep in deps if dep)
formatted_chains = tuple(
" -> ".join(map(str, bad_chain)) for bad_chain in bad_deps
)
self._formatted_chains = formatted_chains
message = "\n" + "\n".join(
(f" - {bad_chain}") for bad_chain in formatted_chains
)
super().__init__(message)
NoPackagesFound = NoPackagesFoundError = ResolvePackageNotFound
class LockError(CondaError):
def __init__(self, message):
msg = f"{message}"
super().__init__(msg)
class ArgumentError(CondaError):
return_code = 2
def __init__(self, message, **kwargs):
super().__init__(message, **kwargs)
class Help(CondaError):
pass
class ActivateHelp(Help):
def __init__(self):
message = dals(
"""
usage: conda activate [-h] [--[no-]stack] [env_name_or_prefix]
Activate a conda environment.
Options:
positional arguments:
env_name_or_prefix The environment name or prefix to activate. If the
prefix is a relative path, it must start with './'
(or '.\\' on Windows).
optional arguments:
-h, --help Show this help message and exit.
--stack Stack the environment being activated on top of the
previous active environment, rather replacing the
current active environment with a new one. Currently,
only the PATH environment variable is stacked. This
may be enabled implicitly by the 'auto_stack'
configuration variable.
--no-stack Do not stack the environment. Overrides 'auto_stack'
setting.
"""
)
super().__init__(message)
class DeactivateHelp(Help):
def __init__(self):
message = dals(
"""
usage: conda deactivate [-h]
Deactivate the current active conda environment.
Options:
optional arguments:
-h, --help Show this help message and exit.
"""
)
super().__init__(message)
class GenericHelp(Help):
def __init__(self, command):
message = f"help requested for {command}"
super().__init__(message)
class CondaSignalInterrupt(CondaError):
def __init__(self, signum):
signal_name = get_signal_name(signum)
super().__init__(
"Signal interrupt %(signal_name)s", signal_name=signal_name, signum=signum
)
class TooManyArgumentsError(ArgumentError):
def __init__(
self, expected, received, offending_arguments, optional_message="", *args
):
self.expected = expected
self.received = received
self.offending_arguments = offending_arguments
self.optional_message = optional_message
suffix = "s" if received - expected > 1 else ""
msg = "{} Got {} argument{} ({}) but expected {}.".format(
optional_message,
received,
suffix,
", ".join(offending_arguments),
expected,
)
super().__init__(msg, *args)
class ClobberError(CondaError):
def __init__(self, message, path_conflict, **kwargs):
self.path_conflict = path_conflict
super().__init__(message, **kwargs)
def __repr__(self):
clz_name = (
"ClobberWarning"
if self.path_conflict == PathConflict.warn
else "ClobberError"
)
return f"{clz_name}: {self}\n"
class BasicClobberError(ClobberError):
def __init__(self, source_path, target_path, context):
message = dals(
"""
Conda was asked to clobber an existing path.
source path: %(source_path)s
target path: %(target_path)s
"""
)
if context.path_conflict == PathConflict.prevent:
message += (
"Conda no longer clobbers existing paths without the use of the "
"--clobber option\n."
)
super().__init__(
message,
context.path_conflict,
target_path=target_path,
source_path=source_path,
)
class KnownPackageClobberError(ClobberError):
def __init__(
self, target_path, colliding_dist_being_linked, colliding_linked_dist, context
):
message = dals(
"""
The package '%(colliding_dist_being_linked)s' cannot be installed due to a
path collision for '%(target_path)s'.
This path already exists in the target prefix, and it won't be removed by
an uninstall action in this transaction. The path appears to be coming from
the package '%(colliding_linked_dist)s', which is already installed in the prefix.
"""
)
if context.path_conflict == PathConflict.prevent:
message += (
"If you'd like to proceed anyway, re-run the command with "
"the `--clobber` flag.\n."
)
super().__init__(
message,
context.path_conflict,
target_path=target_path,
colliding_dist_being_linked=colliding_dist_being_linked,
colliding_linked_dist=colliding_linked_dist,
)
class UnknownPackageClobberError(ClobberError):
def __init__(self, target_path, colliding_dist_being_linked, context):
message = dals(
"""
The package '%(colliding_dist_being_linked)s' cannot be installed due to a
path collision for '%(target_path)s'.
This path already exists in the target prefix, and it won't be removed
by an uninstall action in this transaction. The path is one that conda
doesn't recognize. It may have been created by another package manager.
"""
)
if context.path_conflict == PathConflict.prevent:
message += (
"If you'd like to proceed anyway, re-run the command with "
"the `--clobber` flag.\n."
)
super().__init__(
message,
context.path_conflict,
target_path=target_path,
colliding_dist_being_linked=colliding_dist_being_linked,
)
class SharedLinkPathClobberError(ClobberError):
def __init__(self, target_path, incompatible_package_dists, context):
message = dals(
"""
This transaction has incompatible packages due to a shared path.
packages: %(incompatible_packages)s
path: '%(target_path)s'
"""
)
if context.path_conflict == PathConflict.prevent:
message += (
"If you'd like to proceed anyway, re-run the command with "
"the `--clobber` flag.\n."
)
super().__init__(
message,
context.path_conflict,
target_path=target_path,
incompatible_packages=", ".join(str(d) for d in incompatible_package_dists),
)
class CommandNotFoundError(CondaError):
def __init__(self, command):
activate_commands = {
"activate",
"deactivate",
"run",
}
conda_commands = {
"clean",
"config",
"create",
"--help", # https://github.com/conda/conda/issues/11585
"info",
"install",
"list",
"package",
"remove",
"search",
"uninstall",
"update",
"upgrade",
}
build_commands = {
"build",
"convert",
"develop",
"index",
"inspect",
"metapackage",
"render",
"skeleton",
}
from .cli.main import init_loggers
init_loggers()
if command in activate_commands:
# TODO: Point users to a page at conda-docs, which explains this context in more detail
builder = [
"Your shell has not been properly configured to use 'conda %(command)s'."
]
if on_win:
builder.append(
dals(
"""
If using 'conda %(command)s' from a batch script, change your
invocation to 'CALL conda.bat %(command)s'.
"""
)
)
builder.append(
dals(
"""
To initialize your shell, run
$ conda init <SHELL_NAME>
Currently supported shells are:%(supported_shells)s
See 'conda init --help' for more information and options.
IMPORTANT: You may need to close and restart your shell after running 'conda init'.
"""
)
% {
"supported_shells": dashlist(COMPATIBLE_SHELLS),
}
)
message = "\n".join(builder)
elif command in build_commands:
message = "To use 'conda %(command)s', install conda-build."
else:
from difflib import get_close_matches
from .cli.find_commands import find_commands
message = "No command 'conda %(command)s'."
choices = (
activate_commands
| conda_commands
| build_commands
| set(find_commands())
)
close = get_close_matches(command, choices)
if close:
message += f"\nDid you mean 'conda {close[0]}'?"
super().__init__(message, command=command)
class PathNotFoundError(CondaError, OSError):
def __init__(self, path):
message = "%(path)s"
super().__init__(message, path=path)
class DirectoryNotFoundError(CondaError):
def __init__(self, path):
message = "%(path)s"
super().__init__(message, path=path)
class EnvironmentLocationNotFound(CondaError):
def __init__(self, location):
message = "Not a conda environment: %(location)s"
super().__init__(message, location=location)
class EnvironmentNameNotFound(CondaError):
def __init__(self, environment_name):
message = dals(
"""
Could not find conda environment: %(environment_name)s
You can list all discoverable environments with `conda info --envs`.
"""
)
super().__init__(message, environment_name=environment_name)
class NoBaseEnvironmentError(CondaError):
def __init__(self):
message = dals(
"""
This conda installation has no default base environment. Use
'conda create' to create new environments and 'conda activate' to
activate environments.
"""
)
super().__init__(message)
class DirectoryNotACondaEnvironmentError(CondaError):
def __init__(self, target_directory):
message = dals(
"""
The target directory exists, but it is not a conda environment.
Use 'conda create' to convert the directory to a conda environment.
target directory: %(target_directory)s
"""
)
super().__init__(message, target_directory=target_directory)
class CondaEnvironmentError(CondaError, EnvironmentError):
def __init__(self, message, *args):
msg = f"{message}"
super().__init__(msg, *args)
class DryRunExit(CondaExitZero):
def __init__(self):
msg = "Dry run. Exiting."
super().__init__(msg)
class CondaSystemExit(CondaExitZero, SystemExit):
def __init__(self, *args):
msg = " ".join(str(arg) for arg in self.args)
super().__init__(msg)
class PaddingError(CondaError):
def __init__(self, dist, placeholder, placeholder_length):
msg = (
"Placeholder of length '%d' too short in package %s.\n"
"The package must be rebuilt with conda-build > 2.0."
% (placeholder_length, dist)
)
super().__init__(msg)
class LinkError(CondaError):
def __init__(self, message):
super().__init__(message)
class CondaOSError(CondaError, OSError):
def __init__(self, message, **kwargs):
msg = f"{message}"
super().__init__(msg, **kwargs)
class ProxyError(CondaError):
def __init__(self):
message = dals(
"""
Conda cannot proceed due to an error in your proxy configuration.
Check for typos and other configuration errors in any '.netrc' file in your home directory,
any environment variables ending in '_PROXY', and any other system-wide proxy
configuration settings.
"""
)
super().__init__(message)
class CondaIOError(CondaError, IOError):
def __init__(self, message, *args):
msg = f"{message}"
super().__init__(msg)
class CondaFileIOError(CondaIOError):
def __init__(self, filepath, message, *args):
self.filepath = filepath
msg = f"'{filepath}'. {message}"
super().__init__(msg, *args)
class CondaKeyError(CondaError, KeyError):
def __init__(self, key, message, *args):
self.key = key
self.msg = f"{key!r}: {message}"
super().__init__(self.msg, *args)
class ChannelError(CondaError):
pass
class ChannelNotAllowed(ChannelError):
warning = "Channel not included in allowlist"
def __init__(self, channel):
channel_name = channel.name
channel_url = maybe_unquote(channel.base_url)
message = dals(
"""
%(warning)s:
channel name: %(channel_name)s
channel url: %(channel_url)s
"""
)
super().__init__(
message,
channel_url=channel_url,
channel_name=channel_name,
warning=self.warning,
)
class ChannelDenied(ChannelNotAllowed):
warning = "Channel included in denylist"
class UnavailableInvalidChannel(ChannelError):
status_code: str | int
def __init__(
self, channel, status_code, response: requests.models.Response | None = None
):
# parse channel
channel = Channel(channel)
channel_name = channel.name
channel_url = maybe_unquote(channel.base_url)
# define hardcoded/default reason/message
reason = getattr(response, "reason", None)
message = dals(
"""
The channel is not accessible or is invalid.
You will need to adjust your conda configuration to proceed.
Use `conda config --show channels` to view your configuration's current state,
and use `conda config --show-sources` to view config file locations.
"""
)
if channel.scheme == "file":
url = join_url(channel.location, channel.name)
message += dedent(
f"""
As of conda 4.3, a valid channel must contain a `noarch/repodata.json` and
associated `noarch/repodata.json.bz2` file, even if `noarch/repodata.json` is
empty. Use `conda index {url}`, or create `noarch/repodata.json`
and associated `noarch/repodata.json.bz2`.
"""
)
# if response includes a valid json body we prefer the reason/message defined there
try:
body = response.json()
except (AttributeError, JSONDecodeError):
body = {}
else:
reason = body.get("reason", None) or reason
message = body.get("message", None) or message
# standardize arguments
status_code = status_code or "000"
reason = reason or "UNAVAILABLE OR INVALID"
if isinstance(reason, str):
reason = reason.upper()
self.status_code = status_code
super().__init__(
f"HTTP {status_code} {reason} for channel {channel_name} <{channel_url}>\n\n{message}",
channel_name=channel_name,
channel_url=channel_url,
status_code=status_code,
reason=reason,
response_details=stringify(response, content_max_len=1024) or "",
json=body,
)
class OperationNotAllowed(CondaError):
def __init__(self, message):
super().__init__(message)
class CondaImportError(CondaError, ImportError):
def __init__(self, message):
msg = f"{message}"
super().__init__(msg)
class ParseError(CondaError):
def __init__(self, message):
msg = f"{message}"
super().__init__(msg)
class CouldntParseError(ParseError):
def __init__(self, reason):
self.reason = reason
super().__init__(self.args[0])
class ChecksumMismatchError(CondaError):
def __init__(
self,
url,
target_full_path,
checksum_type,
expected_checksum,
actual_checksum,
partial_download=False,
):
message = dals(
"""
Conda detected a mismatch between the expected content and downloaded content
for url '%(url)s'.
download saved to: %(target_full_path)s
expected %(checksum_type)s: %(expected_checksum)s
actual %(checksum_type)s: %(actual_checksum)s
"""
)
url = maybe_unquote(url)
super().__init__(
message,
url=url,
target_full_path=target_full_path,
checksum_type=checksum_type,
expected_checksum=expected_checksum,
actual_checksum=actual_checksum,
partial_download=partial_download,
)
class PackageNotInstalledError(CondaError):
def __init__(self, prefix, package_name):
message = dals(
"""
Package is not installed in prefix.
prefix: %(prefix)s
package name: %(package_name)s
"""
)
super().__init__(message, prefix=prefix, package_name=package_name)
class CondaHTTPError(CondaError):
def __init__(
self,
message,
url,
status_code,
reason,
elapsed_time,
response=None,
caused_by=None,
):
# if response includes a valid json body we prefer the reason/message defined there
try:
body = response.json()
except (AttributeError, JSONDecodeError):
body = {}
else:
reason = body.get("reason", None) or reason
message = body.get("message", None) or message
# standardize arguments
url = maybe_unquote(url)
status_code = status_code or "000"
reason = reason or "CONNECTION FAILED"
if isinstance(reason, str):
reason = reason.upper()
elapsed_time = elapsed_time or "-"
if isinstance(elapsed_time, timedelta):
elapsed_time = str(elapsed_time).split(":", 1)[-1]
# extract CF-RAY
try:
cf_ray = response.headers["CF-RAY"]
except (AttributeError, KeyError):
cf_ray = ""
else:
cf_ray = f"CF-RAY: {cf_ray}\n"
super().__init__(
dals(
f"""
HTTP {status_code} {reason} for url <{url}>
Elapsed: {elapsed_time}
{cf_ray}
"""
)
# since message may include newlines don't include in f-string/dals above
+ message,
url=url,
status_code=status_code,
reason=reason,
elapsed_time=elapsed_time,
response_details=stringify(response, content_max_len=1024) or "",
json=body,
caused_by=caused_by,
)
class CondaSSLError(CondaError):
pass
class AuthenticationError(CondaError):
pass
class PackagesNotFoundError(CondaError):
def __init__(self, packages, channel_urls=()):
format_list = lambda iterable: " - " + "\n - ".join(str(x) for x in iterable)
if channel_urls:
message = dals(
"""
The following packages are not available from current channels:
%(packages_formatted)s
Current channels:
%(channels_formatted)s
To search for alternate channels that may provide the conda package you're
looking for, navigate to
https://anaconda.org
and use the search bar at the top of the page.
"""
)
from .base.context import context
if context.use_only_tar_bz2:
message += dals(
"""
Note: 'use_only_tar_bz2' is enabled. This might be omitting some
packages from the index. Set this option to 'false' and retry.
"""
)
packages_formatted = format_list(packages)
channels_formatted = format_list(channel_urls)
else:
message = dals(
"""
The following packages are missing from the target environment:
%(packages_formatted)s
"""
)
packages_formatted = format_list(packages)
channels_formatted = ()
super().__init__(
message,
packages=packages,
packages_formatted=packages_formatted,
channel_urls=channel_urls,
channels_formatted=channels_formatted,
)
class UnsatisfiableError(CondaError):
"""An exception to report unsatisfiable dependencies.
Args:
bad_deps: a list of tuples of objects (likely MatchSpecs).
chains: (optional) if True, the tuples are interpreted as chains
of dependencies, from top level to bottom. If False, the tuples
are interpreted as simple lists of conflicting specs.
Returns:
Raises an exception with a formatted message detailing the
unsatisfiable specifications.
"""
def _format_chain_str(self, bad_deps):
chains = {}
for dep in sorted(bad_deps, key=len, reverse=True):
dep1 = [s.partition(" ") for s in dep[1:]]
key = (dep[0],) + tuple(v[0] for v in dep1)
vals = ("",) + tuple(v[2] for v in dep1)
found = False
for key2, csets in chains.items():
if key2[: len(key)] == key:
for cset, val in zip(csets, vals):
cset.add(val)
found = True
if not found:
chains[key] = [{val} for val in vals]
for key, csets in chains.items():
deps = []
for name, cset in zip(key, csets):
if "" not in cset:
pass
elif len(cset) == 1:
cset.clear()
else:
cset.remove("")
cset.add("*")
if name[0] == "@":
name = "feature:" + name[1:]
deps.append(
"{} {}".format(name, "|".join(sorted(cset))) if cset else name
)
chains[key] = " -> ".join(deps)
return [chains[key] for key in sorted(chains.keys())]
def __init__(self, bad_deps, chains=True, strict=False):
from .models.match_spec import MatchSpec
messages = {
"python": dals(
"""
The following specifications were found
to be incompatible with the existing python installation in your environment:
Specifications:\n{specs}
Your python: {ref}
If python is on the left-most side of the chain, that's the version you've asked for.
When python appears to the right, that indicates that the thing on the left is somehow
not available for the python version you are constrained to. Note that conda will not
change your python version to a different minor version unless you explicitly specify
that.
"""
),
"request_conflict_with_history": dals(
"""
The following specifications were found to be incompatible with a past
explicit spec that is not an explicit spec in this operation ({ref}):\n{specs}
"""
),
"direct": dals(
"""
The following specifications were found to be incompatible with each other:
"""
),
"virtual_package": dals(
"""
The following specifications were found to be incompatible with your system:\n{specs}
Your installed version is: {ref}
"""
),
}
msg = ""
self.unsatisfiable = []
if len(bad_deps) == 0:
msg += """
Did not find conflicting dependencies. If you would like to know which
packages conflict ensure that you have enabled unsatisfiable hints.
conda config --set unsatisfiable_hints True
"""
else:
for class_name, dep_class in bad_deps.items():
if dep_class:
_chains = []
if class_name == "direct":
msg += messages["direct"]
last_dep_entry = {d[0][-1].name for d in dep_class}
dep_constraint_map = {}
for dep in dep_class:
if dep[0][-1].name in last_dep_entry:
if not dep_constraint_map.get(dep[0][-1].name):
dep_constraint_map[dep[0][-1].name] = []
dep_constraint_map[dep[0][-1].name].append(dep[0])
msg += "\nOutput in format: Requested package -> Available versions"
for dep, chain in dep_constraint_map.items():
if len(chain) > 1:
msg += f"\n\nPackage {dep} conflicts for:\n"
msg += "\n".join(
[" -> ".join([str(i) for i in c]) for c in chain]
)
self.unsatisfiable += [
tuple(entries) for entries in chain
]
else:
for dep_chain, installed_blocker in dep_class:
# Remove any target values from the MatchSpecs, convert to strings
dep_chain = [
str(MatchSpec(dep, target=None)) for dep in dep_chain
]
_chains.append(dep_chain)
if _chains:
_chains = self._format_chain_str(_chains)
else:
_chains = [", ".join(c) for c in _chains]
msg += messages[class_name].format(
specs=dashlist(_chains), ref=installed_blocker
)
if strict:
msg += (
"\nNote that strict channel priority may have removed "
"packages required for satisfiability."
)
super().__init__(msg)
class RemoveError(CondaError):
def __init__(self, message):
msg = f"{message}"
super().__init__(msg)
class DisallowedPackageError(CondaError):
def __init__(self, package_ref, **kwargs):
from .models.records import PackageRecord
package_ref = PackageRecord.from_objects(package_ref)
message = (
"The package '%(dist_str)s' is disallowed by configuration.\n"
"See 'conda config --show disallowed_packages'."
)
super().__init__(
message, package_ref=package_ref, dist_str=package_ref.dist_str(), **kwargs
)
class SpecsConfigurationConflictError(CondaError):
def __init__(self, requested_specs, pinned_specs, prefix):
message = dals(
"""
Requested specs conflict with configured specs.
requested specs: {requested_specs_formatted}
pinned specs: {pinned_specs_formatted}
Use 'conda config --show-sources' to look for 'pinned_specs' and 'track_features'
configuration parameters. Pinned specs may also be defined in the file
{pinned_specs_path}.
"""
).format(
requested_specs_formatted=dashlist(requested_specs, 4),
pinned_specs_formatted=dashlist(pinned_specs, 4),
pinned_specs_path=join(prefix, "conda-meta", "pinned"),
)
super().__init__(
message,
requested_specs=requested_specs,
pinned_specs=pinned_specs,
prefix=prefix,
)
class CondaIndexError(CondaError, IndexError):
def __init__(self, message):
msg = f"{message}"
super().__init__(msg)
class CondaValueError(CondaError, ValueError):
def __init__(self, message, *args, **kwargs):
super().__init__(message, *args, **kwargs)
class CyclicalDependencyError(CondaError, ValueError):
def __init__(self, packages_with_cycles, **kwargs):
from .models.records import PackageRecord
packages_with_cycles = tuple(
PackageRecord.from_objects(p) for p in packages_with_cycles
)
message = f"Cyclic dependencies exist among these items: {dashlist(p.dist_str() for p in packages_with_cycles)}"
super().__init__(message, packages_with_cycles=packages_with_cycles, **kwargs)
class CorruptedEnvironmentError(CondaError):
def __init__(self, environment_location, corrupted_file, **kwargs):
message = dals(
"""
The target environment has been corrupted. Corrupted environments most commonly
occur when the conda process is force-terminated while in an unlink-link
transaction.
environment location: %(environment_location)s
corrupted file: %(corrupted_file)s
"""
)
super().__init__(
message,
environment_location=environment_location,
corrupted_file=corrupted_file,
**kwargs,
)
class CondaHistoryError(CondaError):
def __init__(self, message):
msg = f"{message}"
super().__init__(msg)
class CondaUpgradeError(CondaError):
def __init__(self, message):
msg = f"{message}"
super().__init__(msg)
class CondaVerificationError(CondaError):