/
context.py
1156 lines (1045 loc) · 49 KB
/
context.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
# -*- coding: utf-8 -*-
# Copyright (C) 2012 Anaconda, Inc
# SPDX-License-Identifier: BSD-3-Clause
from __future__ import absolute_import, division, print_function, unicode_literals
from errno import ENOENT
from logging import getLogger
import os
from os.path import (abspath, basename, expanduser, isdir, isfile, join, normpath,
split as path_split)
from platform import machine
import sys
from .constants import (APP_NAME, DEFAULTS_CHANNEL_NAME, DEFAULT_AGGRESSIVE_UPDATE_PACKAGES,
DEFAULT_CHANNELS, DEFAULT_CHANNEL_ALIAS, DEFAULT_CUSTOM_CHANNELS,
DepsModifier, ERROR_UPLOAD_URL, PLATFORM_DIRECTORIES, PREFIX_MAGIC_FILE,
PathConflict, ROOT_ENV_NAME, SEARCH_PATH, SafetyChecks, UpdateModifier)
from .. import __version__ as CONDA_VERSION
from .._vendor.appdirs import user_data_dir
from .._vendor.auxlib.collection import frozendict
from .._vendor.auxlib.decorators import memoize, memoizedproperty
from .._vendor.auxlib.ish import dals
from .._vendor.boltons.setutils import IndexedSet
from ..common.compat import NoneType, iteritems, itervalues, odict, on_win, string_types
from ..common.configuration import (Configuration, LoadError, MapParameter, PrimitiveParameter,
SequenceParameter, ValidationError)
from ..common.disk import conda_bld_ensure_dir
from ..common.path import expand
from ..common.os.linux import linux_get_libc_version
from ..common.url import has_scheme, path_to_url, split_scheme_auth_token
try:
from cytoolz.itertoolz import concat, concatv, unique
except ImportError: # pragma: no cover
from .._vendor.toolz.itertoolz import concat, concatv, unique
try:
os.getcwd()
except (IOError, OSError) as e:
if e.errno == ENOENT:
# FileNotFoundError can occur when cwd has been deleted out from underneath the process.
# To resolve #6584, let's go with setting cwd to sys.prefix, and see how far we get.
os.chdir(sys.prefix)
else:
raise
log = getLogger(__name__)
_platform_map = {
'linux2': 'linux',
'linux': 'linux',
'darwin': 'osx',
'win32': 'win',
'zos': 'zos',
}
non_x86_linux_machines = {
'armv6l',
'armv7l',
'aarch64',
'ppc64le',
}
_arch_names = {
32: 'x86',
64: 'x86_64',
}
user_rc_path = abspath(expanduser('~/.condarc'))
sys_rc_path = join(sys.prefix, '.condarc')
def channel_alias_validation(value):
if value and not has_scheme(value):
return "channel_alias value '%s' must have scheme/protocol." % value
return True
def default_python_default():
ver = sys.version_info
return '%d.%d' % (ver.major, ver.minor)
def default_python_validation(value):
if value:
if len(value) == 3 and value[1] == '.':
try:
value = float(value)
if 2.0 <= value < 4.0:
return True
except ValueError: # pragma: no cover
pass
else:
# Set to None or '' meaning no python pinning
return True
return "default_python value '%s' not of the form '[23].[0-9]' or ''" % value
def ssl_verify_validation(value):
if isinstance(value, string_types):
if not isfile(value) and not isdir(value):
return ("ssl_verify value '%s' must be a boolean, a path to a "
"certificate bundle file, or a path to a directory containing "
"certificates of trusted CAs." % value)
return True
class Context(Configuration):
add_pip_as_python_dependency = PrimitiveParameter(True)
allow_cycles = PrimitiveParameter(True) # allow cyclical dependencies, or raise
allow_softlinks = PrimitiveParameter(False)
auto_update_conda = PrimitiveParameter(True, aliases=('self_update',))
auto_activate_base = PrimitiveParameter(True)
notify_outdated_conda = PrimitiveParameter(True)
clobber = PrimitiveParameter(False)
changeps1 = PrimitiveParameter(True)
env_prompt = PrimitiveParameter("({default_env}) ")
create_default_packages = SequenceParameter(string_types)
default_python = PrimitiveParameter(default_python_default(),
element_type=string_types + (NoneType,),
validation=default_python_validation)
download_only = PrimitiveParameter(False)
enable_private_envs = PrimitiveParameter(False)
force_32bit = PrimitiveParameter(False)
non_admin_enabled = PrimitiveParameter(True)
pip_interop_enabled = PrimitiveParameter(False)
# Safety & Security
_aggressive_update_packages = SequenceParameter(string_types,
DEFAULT_AGGRESSIVE_UPDATE_PACKAGES,
aliases=('aggressive_update_packages',))
safety_checks = PrimitiveParameter(SafetyChecks.warn)
path_conflict = PrimitiveParameter(PathConflict.clobber)
pinned_packages = SequenceParameter(string_types, string_delimiter='&') # TODO: consider a different string delimiter # NOQA
disallowed_packages = SequenceParameter(string_types, aliases=('disallow',),
string_delimiter='&')
rollback_enabled = PrimitiveParameter(True)
track_features = SequenceParameter(string_types)
use_index_cache = PrimitiveParameter(False)
_root_prefix = PrimitiveParameter("", aliases=('root_dir', 'root_prefix'))
_envs_dirs = SequenceParameter(string_types, aliases=('envs_dirs', 'envs_path'),
string_delimiter=os.pathsep)
_pkgs_dirs = SequenceParameter(string_types, aliases=('pkgs_dirs',))
_subdir = PrimitiveParameter('', aliases=('subdir',))
_subdirs = SequenceParameter(string_types, aliases=('subdirs',))
local_repodata_ttl = PrimitiveParameter(1, element_type=(bool, int))
# number of seconds to cache repodata locally
# True/1: respect Cache-Control max-age header
# False/0: always fetch remote repodata (HTTP 304 responses respected)
# remote connection details
ssl_verify = PrimitiveParameter(True, element_type=string_types + (bool,),
aliases=('verify_ssl',),
validation=ssl_verify_validation)
client_ssl_cert = PrimitiveParameter(None, aliases=('client_cert',),
element_type=string_types + (NoneType,))
client_ssl_cert_key = PrimitiveParameter(None, aliases=('client_cert_key',),
element_type=string_types + (NoneType,))
proxy_servers = MapParameter(string_types + (NoneType,))
remote_connect_timeout_secs = PrimitiveParameter(9.15)
remote_read_timeout_secs = PrimitiveParameter(60.)
remote_max_retries = PrimitiveParameter(3)
add_anaconda_token = PrimitiveParameter(True, aliases=('add_binstar_token',))
# #############################
# channels
# #############################
allow_non_channel_urls = PrimitiveParameter(False)
_channel_alias = PrimitiveParameter(DEFAULT_CHANNEL_ALIAS,
aliases=('channel_alias',),
validation=channel_alias_validation)
channel_priority = PrimitiveParameter(True)
_channels = SequenceParameter(string_types, default=(DEFAULTS_CHANNEL_NAME,),
aliases=('channels', 'channel',)) # channel for args.channel
_custom_channels = MapParameter(string_types, DEFAULT_CUSTOM_CHANNELS,
aliases=('custom_channels',))
_custom_multichannels = MapParameter(list, aliases=('custom_multichannels',))
_default_channels = SequenceParameter(string_types, DEFAULT_CHANNELS,
aliases=('default_channels',))
_migrated_channel_aliases = SequenceParameter(string_types,
aliases=('migrated_channel_aliases',))
migrated_custom_channels = MapParameter(string_types) # TODO: also take a list of strings
override_channels_enabled = PrimitiveParameter(True)
show_channel_urls = PrimitiveParameter(None, element_type=(bool, NoneType))
use_local = PrimitiveParameter(False)
whitelist_channels = SequenceParameter(string_types)
always_softlink = PrimitiveParameter(False, aliases=('softlink',))
always_copy = PrimitiveParameter(False, aliases=('copy',))
always_yes = PrimitiveParameter(None, aliases=('yes',), element_type=(bool, NoneType))
debug = PrimitiveParameter(False)
dry_run = PrimitiveParameter(False)
error_upload_url = PrimitiveParameter(ERROR_UPLOAD_URL)
force = PrimitiveParameter(False)
json = PrimitiveParameter(False)
offline = PrimitiveParameter(False)
quiet = PrimitiveParameter(False)
ignore_pinned = PrimitiveParameter(False)
report_errors = PrimitiveParameter(None, element_type=(bool, NoneType))
shortcuts = PrimitiveParameter(True)
_verbosity = PrimitiveParameter(0, aliases=('verbose', 'verbosity'), element_type=int)
# ######################################################
# ## Solver Configuration ##
# ######################################################
deps_modifier = PrimitiveParameter(DepsModifier.NOT_SET)
update_modifier = PrimitiveParameter(UpdateModifier.UPDATE_SPECS)
# no_deps = PrimitiveParameter(NULL, element_type=(type(NULL), bool)) # CLI-only
# only_deps = PrimitiveParameter(NULL, element_type=(type(NULL), bool)) # CLI-only
#
# freeze_installed = PrimitiveParameter(False)
# update_deps = PrimitiveParameter(False, aliases=('update_dependencies',))
# update_specs = PrimitiveParameter(False)
# update_all = PrimitiveParameter(False)
prune = PrimitiveParameter(False)
force_remove = PrimitiveParameter(False)
force_reinstall = PrimitiveParameter(False)
target_prefix_override = PrimitiveParameter('')
# conda_build
bld_path = PrimitiveParameter('')
anaconda_upload = PrimitiveParameter(None, aliases=('binstar_upload',),
element_type=(bool, NoneType))
_croot = PrimitiveParameter('', aliases=('croot',))
conda_build = MapParameter(string_types, aliases=('conda-build',))
def __init__(self, search_path=None, argparse_args=None):
if search_path is None:
search_path = SEARCH_PATH
if argparse_args:
# This block of code sets CONDA_PREFIX based on '-n' and '-p' flags, so that
# configuration can be properly loaded from those locations
func_name = ('func' in argparse_args and argparse_args.func or '').rsplit('.', 1)[-1]
if func_name in ('create', 'install', 'update', 'remove', 'uninstall', 'upgrade'):
if 'prefix' in argparse_args and argparse_args.prefix:
os.environ['CONDA_PREFIX'] = argparse_args.prefix
elif 'name' in argparse_args and argparse_args.name:
# Currently, usage of the '-n' flag is inefficient, with all configuration
# files being loaded/re-loaded at least two times.
target_prefix = determine_target_prefix(context, argparse_args)
if target_prefix != context.root_prefix:
os.environ['CONDA_PREFIX'] = determine_target_prefix(context,
argparse_args)
super(Context, self).__init__(search_path=search_path, app_name=APP_NAME,
argparse_args=argparse_args)
def post_build_validation(self):
errors = []
if self.client_ssl_cert_key and not self.client_ssl_cert:
error = ValidationError('client_ssl_cert', self.client_ssl_cert, "<<merged>>",
"'client_ssl_cert' is required when 'client_ssl_cert_key' "
"is defined")
errors.append(error)
if self.always_copy and self.always_softlink:
error = ValidationError('always_copy', self.always_copy, "<<merged>>",
"'always_copy' and 'always_softlink' are mutually exclusive. "
"Only one can be set to 'True'.")
errors.append(error)
return errors
@property
def conda_build_local_paths(self):
# does file system reads to make sure paths actually exist
return tuple(unique(full_path for full_path in (
expand(d) for d in (
self._croot,
self.bld_path,
self.conda_build.get('root-dir'),
join(self.root_prefix, 'conda-bld'),
'~/conda-bld',
) if d
) if isdir(full_path)))
@property
def conda_build_local_urls(self):
return tuple(path_to_url(p) for p in self.conda_build_local_paths)
@property
def croot(self):
"""This is where source caches and work folders live"""
if self._croot:
return abspath(expanduser(self._croot))
elif self.bld_path:
return abspath(expanduser(self.bld_path))
elif 'root-dir' in self.conda_build:
return abspath(expanduser(self.conda_build['root-dir']))
elif self.root_writable:
return join(self.root_prefix, 'conda-bld')
else:
return expand('~/conda-bld')
@property
def local_build_root(self):
return self.croot
@property
def src_cache(self):
path = join(self.croot, 'src_cache')
conda_bld_ensure_dir(path)
return path
@property
def git_cache(self):
path = join(self.croot, 'git_cache')
conda_bld_ensure_dir(path)
return path
@property
def hg_cache(self):
path = join(self.croot, 'hg_cache')
conda_bld_ensure_dir(path)
return path
@property
def svn_cache(self):
path = join(self.croot, 'svn_cache')
conda_bld_ensure_dir(path)
return path
@property
def arch_name(self):
m = machine()
if self.platform == 'linux' and m in non_x86_linux_machines:
return m
else:
return _arch_names[self.bits]
@property
def conda_private(self):
return conda_in_private_env()
@property
def platform(self):
return _platform_map.get(sys.platform, 'unknown')
@property
def subdir(self):
if self._subdir:
return self._subdir
m = machine()
if m in non_x86_linux_machines:
return 'linux-%s' % m
elif self.platform == 'zos':
return 'zos-z'
else:
return '%s-%d' % (self.platform, self.bits)
@property
def subdirs(self):
return self._subdirs if self._subdirs else (self.subdir, 'noarch')
@memoizedproperty
def known_subdirs(self):
return frozenset(concatv(PLATFORM_DIRECTORIES, self.subdirs))
@property
def bits(self):
if self.force_32bit:
return 32
else:
return 8 * tuple.__itemsize__
@property
def root_dir(self):
# root_dir is an alias for root_prefix, we prefer the name "root_prefix"
# because it is more consistent with other names
return self.root_prefix
@property
def root_writable(self):
# rather than using conda.gateways.disk.test.prefix_is_writable
# let's shortcut and assume the root prefix exists
path = join(self.root_prefix, PREFIX_MAGIC_FILE)
if isfile(path):
try:
fh = open(path, 'a+')
except (IOError, OSError) as e:
log.debug(e)
return False
else:
fh.close()
return True
return False
@property
def envs_dirs(self):
if self.root_writable:
fixed_dirs = (
join(self.root_prefix, 'envs'),
join(self._user_data_dir, 'envs'),
join('~', '.conda', 'envs'),
)
else:
fixed_dirs = (
join(self._user_data_dir, 'envs'),
join(self.root_prefix, 'envs'),
join('~', '.conda', 'envs'),
)
return tuple(IndexedSet(expand(p) for p in concatv(self._envs_dirs, fixed_dirs)))
@property
def pkgs_dirs(self):
if self._pkgs_dirs:
return tuple(IndexedSet(expand(p) for p in self._pkgs_dirs))
else:
cache_dir_name = 'pkgs32' if context.force_32bit else 'pkgs'
return tuple(IndexedSet(expand(join(p, cache_dir_name)) for p in (
self.root_prefix,
self._user_data_dir,
)))
@memoizedproperty
def trash_dir(self):
# TODO: this inline import can be cleaned up by moving pkgs_dir write detection logic
from ..core.package_cache_data import PackageCacheData
pkgs_dir = PackageCacheData.first_writable().pkgs_dir
trash_dir = join(pkgs_dir, '.trash')
from ..gateways.disk.create import mkdir_p
mkdir_p(trash_dir)
return trash_dir
@property
def _user_data_dir(self):
if on_win:
return user_data_dir(APP_NAME, APP_NAME)
else:
return expand(join('~', '.conda'))
@property
def default_prefix(self):
if self.active_prefix:
return self.active_prefix
_default_env = os.getenv('CONDA_DEFAULT_ENV')
if _default_env in (None, ROOT_ENV_NAME, 'root'):
return self.root_prefix
elif os.sep in _default_env:
return abspath(_default_env)
else:
for envs_dir in self.envs_dirs:
default_prefix = join(envs_dir, _default_env)
if isdir(default_prefix):
return default_prefix
return join(self.envs_dirs[0], _default_env)
@property
def active_prefix(self):
return os.getenv('CONDA_PREFIX')
@property
def shlvl(self):
return int(os.getenv('CONDA_SHLVL', -1))
@property
def aggressive_update_packages(self):
from ..models.match_spec import MatchSpec
return tuple(MatchSpec(s) for s in self._aggressive_update_packages)
@property
def target_prefix(self):
# used for the prefix that is the target of the command currently being executed
# different from the active prefix, which is sometimes given by -p or -n command line flags
return determine_target_prefix(self)
@memoizedproperty
def root_prefix(self):
if self._root_prefix:
return abspath(expanduser(self._root_prefix))
elif conda_in_private_env():
return normpath(join(self.conda_prefix, '..', '..'))
else:
return self.conda_prefix
@property
def conda_prefix(self):
return normpath(sys.prefix)
@property
def conda_exe(self):
bin_dir = 'Scripts' if on_win else 'bin'
exe = 'conda.exe' if on_win else 'conda'
return join(self.conda_prefix, bin_dir, exe)
@memoizedproperty
def channel_alias(self):
from ..models.channel import Channel
location, scheme, auth, token = split_scheme_auth_token(self._channel_alias)
return Channel(scheme=scheme, auth=auth, location=location, token=token)
@property
def migrated_channel_aliases(self):
from ..models.channel import Channel
return tuple(Channel(scheme=scheme, auth=auth, location=location, token=token)
for location, scheme, auth, token in
(split_scheme_auth_token(c) for c in self._migrated_channel_aliases))
@property
def prefix_specified(self):
return (self._argparse_args.get("prefix") is not None or
self._argparse_args.get("name") is not None)
@memoizedproperty
def default_channels(self):
# the format for 'default_channels' is a list of strings that either
# - start with a scheme
# - are meant to be prepended with channel_alias
return self.custom_multichannels[DEFAULTS_CHANNEL_NAME]
@memoizedproperty
def custom_multichannels(self):
from ..models.channel import Channel
reserved_multichannel_urls = odict((
(DEFAULTS_CHANNEL_NAME, self._default_channels),
('local', self.conda_build_local_urls),
))
reserved_multichannels = odict(
(name, tuple(
Channel.make_simple_channel(self.channel_alias, url) for url in urls)
) for name, urls in iteritems(reserved_multichannel_urls)
)
custom_multichannels = odict(
(name, tuple(
Channel.make_simple_channel(self.channel_alias, url) for url in urls)
) for name, urls in iteritems(self._custom_multichannels)
)
all_multichannels = odict(
(name, channels)
for name, channels in concat(map(iteritems, (
custom_multichannels,
reserved_multichannels, # reserved comes last, so reserved overrides custom
)))
)
return all_multichannels
@memoizedproperty
def custom_channels(self):
from ..models.channel import Channel
custom_channels = (Channel.make_simple_channel(self.channel_alias, url, name)
for name, url in iteritems(self._custom_channels))
channels_from_multichannels = concat(channel for channel
in itervalues(self.custom_multichannels))
all_channels = odict((x.name, x) for x in (ch for ch in concatv(
channels_from_multichannels,
custom_channels,
)))
return all_channels
@property
def channels(self):
local_add = ('local',) if self.use_local else ()
if (self._argparse_args and 'override_channels' in self._argparse_args
and self._argparse_args['override_channels']):
if not self.override_channels_enabled:
from ..exceptions import OperationNotAllowed
raise OperationNotAllowed(dals("""
Overriding channels has been disabled.
"""))
elif not (self._argparse_args and 'channel' in self._argparse_args
and self._argparse_args['channel']):
from ..exceptions import CommandArgumentError
raise CommandArgumentError(dals("""
At least one -c / --channel flag must be supplied when using --override-channels.
"""))
else:
return tuple(IndexedSet(concatv(local_add, self._argparse_args['channel'])))
# add 'defaults' channel when necessary if --channel is given via the command line
if self._argparse_args and 'channel' in self._argparse_args:
# TODO: it's args.channel right now, not channels
argparse_channels = tuple(self._argparse_args['channel'] or ())
if argparse_channels and argparse_channels == self._channels:
return tuple(IndexedSet(concatv(local_add, argparse_channels,
(DEFAULTS_CHANNEL_NAME,))))
return tuple(IndexedSet(concatv(local_add, self._channels)))
@property
def binstar_upload(self):
# backward compatibility for conda-build
return self.anaconda_upload
@property
def user_agent(self):
return _get_user_agent(self.platform)
@property
def verbosity(self):
return 2 if self.debug else self._verbosity
@property
def category_map(self):
return odict((
('Channel Configuration', (
'channels',
'channel_alias',
'default_channels',
'override_channels_enabled',
'whitelist_channels',
'custom_channels',
'custom_multichannels',
'migrated_channel_aliases',
'migrated_custom_channels',
'add_anaconda_token',
'allow_non_channel_urls',
)),
('Basic Conda Configuration', ( # TODO: Is there a better category name here?
'env_prompt',
'envs_dirs',
'pkgs_dirs',
)),
('Network Configuration', (
'client_ssl_cert',
'client_ssl_cert_key',
'local_repodata_ttl',
'offline',
'proxy_servers',
'remote_connect_timeout_secs',
'remote_max_retries',
'remote_read_timeout_secs',
'ssl_verify',
)),
('Solver Configuration', (
'aggressive_update_packages',
'auto_update_conda',
'channel_priority',
'create_default_packages',
'disallowed_packages',
'pinned_packages',
'track_features',
'prune',
'force_reinstall',
)),
('Package Linking and Install-time Configuration', (
'allow_softlinks',
'always_copy',
'always_softlink',
'path_conflict',
'rollback_enabled',
'safety_checks',
'shortcuts',
'non_admin_enabled',
)),
('Conda-build Configuration', (
'bld_path',
'croot',
'anaconda_upload',
'conda_build',
)),
('Output, Prompt, and Flow Control Configuration', (
'always_yes',
'auto_activate_base',
'changeps1',
'json',
'notify_outdated_conda',
'quiet',
'report_errors',
'show_channel_urls',
'verbosity',
)),
('CLI-only', (
'deps_modifier',
'update_modifier',
'force',
'force_remove',
'clobber',
'dry_run',
'download_only',
'ignore_pinned',
'use_index_cache',
'use_local',
)),
('Hidden and Undocumented', (
'allow_cycles', # allow cyclical dependencies, or raise
'add_pip_as_python_dependency',
'debug',
'default_python',
'enable_private_envs',
'error_upload_url', # should remain undocumented
'force_32bit',
'pip_interop_enabled', # temporary feature flag
'root_prefix',
'subdir',
'subdirs',
# https://conda.io/docs/config.html#disable-updating-of-dependencies-update-dependencies # NOQA
# I don't think this documentation is correct any longer. # NOQA
'target_prefix_override',
# used to override prefix rewriting, for e.g. building docker containers or RPMs # NOQA
)),
))
def get_descriptions(self):
return self.description_map
@memoizedproperty
def description_map(self):
return frozendict({
'add_anaconda_token': dals("""
In conjunction with the anaconda command-line client (installed with
`conda install anaconda-client`), and following logging into an Anaconda
Server API site using `anaconda login`, automatically apply a matching
private token to enable access to private packages and channels.
"""),
# 'add_pip_as_python_dependency': dals("""
# Add pip, wheel and setuptools as dependencies of python. This ensures pip,
# wheel and setuptools will always be installed any time python is installed.
# """),
'aggressive_update_packages': dals("""
A list of packages that, if installed, are always updated to the latest possible
version.
"""),
'allow_non_channel_urls': dals("""
Warn, but do not fail, when conda detects a channel url is not a valid channel.
"""),
'allow_softlinks': dals("""
When allow_softlinks is True, conda uses hard-links when possible, and soft-links
(symlinks) when hard-links are not possible, such as when installing on a
different filesystem than the one that the package cache is on. When
allow_softlinks is False, conda still uses hard-links when possible, but when it
is not possible, conda copies files. Individual packages can override
this setting, specifying that certain files should never be soft-linked (see the
no_link option in the build recipe documentation).
"""),
'always_copy': dals("""
Register a preference that files be copied into a prefix during install rather
than hard-linked.
"""),
'always_softlink': dals("""
Register a preference that files be soft-linked (symlinked) into a prefix during
install rather than hard-linked. The link source is the 'pkgs_dir' package cache
from where the package is being linked. WARNING: Using this option can result in
corruption of long-lived conda environments. Package caches are *caches*, which
means there is some churn and invalidation. With this option, the contents of
environments can be switched out (or erased) via operations on other environments.
"""),
'always_yes': dals("""
Automatically choose the 'yes' option whenever asked to proceed with a conda
operation, such as when running `conda install`.
"""),
'anaconda_upload': dals("""
Automatically upload packages built with conda build to anaconda.org.
"""),
'auto_activate_base': dals("""
Automatically activate the base environment during shell initialization.
"""),
'auto_update_conda': dals("""
Automatically update conda when a newer or higher priority version is detected.
"""),
'bld_path': dals("""
The location where conda-build will put built packages. Same as 'croot', but
'croot' takes precedence when both are defined. Also used in construction of the
'local' multichannel.
"""),
'changeps1': dals("""
When using activate, change the command prompt ($PS1) to include the
activated environment.
"""),
'channel_alias': dals("""
The prepended url location to associate with channel names.
"""),
'channel_priority': dals("""
When True, the solver is instructed to prefer channel order over package
version. When False, the solver is instructed to give package version
preference over channel priority.
"""),
'channels': dals("""
The list of conda channels to include for relevant operations.
"""),
'client_ssl_cert': dals("""
A path to a single file containing a private key and certificate (e.g. .pem
file). Alternately, use client_ssl_cert_key in conjuction with client_ssl_cert
for individual files.
"""),
'client_ssl_cert_key': dals("""
Used in conjunction with client_ssl_cert for a matching key file.
"""),
# 'clobber': dals("""
# Allow clobbering of overlapping file paths within packages, and suppress
# related warnings. Overrides the path_conflict configuration value when
# set to 'warn' or 'prevent'.
# """),
'conda_build': dals("""
General configuration parameters for conda-build.
"""),
# TODO: add shortened link to docs for conda_build at See https://conda.io/docs/user-guide/configuration/use-condarc.html#conda-build-configuration # NOQA
'create_default_packages': dals("""
Packages that are by default added to a newly created environments.
"""), # TODO: This is a bad parameter name. Consider an alternate.
'croot': dals("""
The location where conda-build will put built packages. Same as 'bld_path', but
'croot' takes precedence when both are defined. Also used in construction of the
'local' multichannel.
"""),
'custom_channels': dals("""
A map of key-value pairs where the key is a channel name and the value is
a channel location. Channels defined here override the default
'channel_alias' value. The channel name (key) is not included in the channel
location (value). For example, to override the location of the 'conda-forge'
channel where the url to repodata is
https://anaconda-repo.dev/packages/conda-forge/linux-64/repodata.json, add an
entry 'conda-forge: https://anaconda-repo.dev/packages'.
"""),
'custom_multichannels': dals("""
A multichannel is a metachannel composed of multiple channels. The two reserved
multichannels are 'defaults' and 'local'. The 'defaults' multichannel is
customized using the 'default_channels' parameter. The 'local'
multichannel is a list of file:// channel locations where conda-build stashes
successfully-built packages. Other multichannels can be defined with
custom_multichannels, where the key is the multichannel name and the value is
a list of channel names and/or channel urls.
"""),
'default_channels': dals("""
The list of channel names and/or urls used for the 'defaults' multichannel.
"""),
# 'default_python': dals("""
# specifies the default major & minor version of Python to be used when
# building packages with conda-build. Also used to determine the major
# version of Python (2/3) to be used in new environments. Defaults to
# the version used by conda itself.
# """),
'disallowed_packages': dals("""
Package specifications to disallow installing. The default is to allow
all packages.
"""),
'download_only': dals("""
Solve an environment and ensure package caches are populated, but exit
prior to unlinking and linking packages into the prefix
"""),
'envs_dirs': dals("""
The list of directories to search for named environments. When creating a new
named environment, the environment will be placed in the first writable
location.
"""),
'env_prompt': dals("""
Template for prompt modification based on the active environment. Currently
supported template variables are '{prefix}', '{name}', and '{default_env}'.
'{prefix}' is the absolute path to the active environment. '{name}' is the
basename of the active environment prefix. '{default_env}' holds the value
of '{name}' if the active environment is a conda named environment ('-n'
flag), or otherwise holds the value of '{prefix}'. Templating uses python's
str.format() method.
"""),
'force_reinstall': dals("""
Ensure that any user-requested package for the current operation is uninstalled
and reinstalled, even if that package already exists in the environment.
"""),
# 'force': dals("""
# Override any of conda's objections and safeguards for installing packages and
# potentially breaking environments. Also re-installs the package, even if the
# package is already installed. Implies --no-deps.
# """),
# 'force_32bit': dals("""
# CONDA_FORCE_32BIT should only be used when running conda-build (in order
# to build 32-bit packages on a 64-bit system). We don't want to mention it
# in the documentation, because it can mess up a lot of things.
# """),
'json': dals("""
Ensure all output written to stdout is structured json.
"""),
'local_repodata_ttl': dals("""
For a value of False or 0, always fetch remote repodata (HTTP 304 responses
respected). For a value of True or 1, respect the HTTP Cache-Control max-age
header. Any other positive integer values is the number of seconds to locally
cache repodata before checking the remote server for an update.
"""),
'migrated_channel_aliases': dals("""
A list of previously-used channel_alias values. Useful when switching between
different Anaconda Repository instances.
"""),
'migrated_custom_channels': dals("""
A map of key-value pairs where the key is a channel name and the value is
the previous location of the channel.
"""),
# 'no_deps': dals("""
# Do not install, update, remove, or change dependencies. This WILL lead to broken
# environments and inconsistent behavior. Use at your own risk.
# """),
'non_admin_enabled': dals("""
Allows completion of conda's create, install, update, and remove operations, for
non-privileged (non-root or non-administrator) users.
"""),
'notify_outdated_conda': dals("""
Notify if a newer version of conda is detected during a create, install, update,
or remove operation.
"""),
'offline': dals("""
Restrict conda to cached download content and file:// based urls.
"""),
'override_channels_enabled': dals("""
Permit use of the --overide-channels command-line flag.
"""),
'path_conflict': dals("""
The method by which conda handle's conflicting/overlapping paths during a
create, install, or update operation. The value must be one of 'clobber',
'warn', or 'prevent'. The '--clobber' command-line flag or clobber
configuration parameter overrides path_conflict set to 'prevent'.
"""),
'pinned_packages': dals("""
A list of package specs to pin for every environment resolution.
This parameter is in BETA, and its behavior may change in a future release.
"""),
'pkgs_dirs': dals("""
The list of directories where locally-available packages are linked from at
install time. Packages not locally available are downloaded and extracted
into the first writable directory.
"""),
'proxy_servers': dals("""
A mapping to enable proxy settings. Keys can be either (1) a scheme://hostname
form, which will match any request to the given scheme and exact hostname, or
(2) just a scheme, which will match requests to that scheme. Values are are
the actual proxy server, and are of the form
'scheme://[user:password@]host[:port]'. The optional 'user:password' inclusion
enables HTTP Basic Auth with your proxy.
"""),
'prune': dals("""
Remove packages that have previously been brought into an environment to satisfy
dependencies of user-requested packages, but are no longer needed.
"""),
'quiet': dals("""
Disable progress bar display and other output.
"""),
'remote_connect_timeout_secs': dals("""
The number seconds conda will wait for your client to establish a connection
to a remote url resource.
"""),
'remote_max_retries': dals("""
The maximum number of retries each HTTP connection should attempt.
"""),
'remote_read_timeout_secs': dals("""
Once conda has connected to a remote resource and sent an HTTP request, the
read timeout is the number of seconds conda will wait for the server to send
a response.
"""),
'report_errors': dals("""
Opt in, or opt out, of automatic error reporting to core maintainers. Error
reports are anonymous, with only the error stack trace and information given
by `conda info` being sent.
"""),
'rollback_enabled': dals("""
Should any error occur during an unlink/link transaction, revert any disk
mutations made to that point in the transaction.
"""),
'safety_checks': dals("""
Enforce available safety guarantees during package installation.
The value must be one of 'enabled', 'warn', or 'disabled'.
"""),
'shortcuts': dals("""
Allow packages to create OS-specific shortcuts (e.g. in the Windows Start
Menu) at install time.
"""),
'show_channel_urls': dals("""
Show channel URLs when displaying what is going to be downloaded.
"""),
'ssl_verify': dals("""
Conda verifies SSL certificates for HTTPS requests, just like a web
browser. By default, SSL verification is enabled, and conda operations will
fail if a required url's certificate cannot be verified. Setting ssl_verify to
False disables certification verification. The value for ssl_verify can also
be (1) a path to a CA bundle file, or (2) a path to a directory containing
certificates of trusted CA.
"""),
'track_features': dals("""
A list of features that are tracked by default. An entry here is similar to
adding an entry to the create_default_packages list.
"""),
'use_index_cache': dals("""
Use cache of channel index files, even if it has expired.
"""),
'verbosity': dals("""
Sets output log level. 0 is warn. 1 is info. 2 is debug. 3 is trace.
"""),
'whitelist_channels': dals("""
The exclusive list of channels allowed to be used on the system. Use of any
other channels will result in an error. If conda-build channels are to be
allowed, along with the --use-local command line flag, be sure to include the
'local' channel in the list. If the list is empty or left undefined, no
channel exclusions will be enforced.
""")
})
def conda_in_private_env():
# conda is located in its own private environment named '_conda_'
envs_dir, env_name = path_split(sys.prefix)
return env_name == '_conda_' and basename(envs_dir) == 'envs'
def reset_context(search_path=SEARCH_PATH, argparse_args=None):
context.__init__(search_path, argparse_args)
from ..models.channel import Channel