12
12
import json
13
13
import os
14
14
from os .path import isdir , isfile , join , splitext
15
+ from itertools import groupby
16
+
15
17
import sys
16
18
import tempfile
17
19
18
20
from constructor .utils import hash_files , filename_dist
19
21
from .conda_interface import (PackageCacheData , PackageCacheRecord , Solver , SubdirData ,
20
- VersionOrder , concatv , conda_context , conda_replace_context_default ,
21
- download , env_vars , groupby , read_paths_json , all_channel_urls ,
22
+ VersionOrder , conda_context , conda_replace_context_default ,
23
+ download , env_vars , read_paths_json , all_channel_urls ,
22
24
cc_platform )
23
25
24
26
@@ -44,11 +46,12 @@ def warn_menu_packages_missing(precs, menu_packages):
44
46
45
47
46
48
def check_duplicates (precs ):
47
- groups = groupby (lambda x : x .name , precs )
48
- for precs in groups .values ():
49
- if len (precs ) > 1 :
50
- sys .exit ("Error: '%s' listed multiple times: %s" %
51
- (precs [0 ].name , ', ' .join (prec .fn for prec in precs )))
49
+ prec_groups = {key : tuple (value ) for key , value in groupby (precs , lambda prec : prec .name )}
50
+
51
+ for name , precs in prec_groups .items ():
52
+ filenames = sorted (prec .fn for prec in precs )
53
+ if len (filenames ) > 1 :
54
+ sys .exit (f"Error: { name } listed multiple times: { ' , ' .join (filenames )} " )
52
55
53
56
54
57
def exclude_packages (precs , exclude = ()):
@@ -57,13 +60,11 @@ def exclude_packages(precs, exclude=()):
57
60
if bad_char in name :
58
61
sys .exit ("Error: did not expect '%s' in package name: %s" % (bad_char , name ))
59
62
60
- groups = groupby (lambda x : x .name in exclude , precs )
61
- excluded_precs = groups .get (True , [])
62
- accepted_precs = groups .get (False , [])
63
- for name in exclude :
64
- if not any (prec .name == name for prec in excluded_precs ):
65
- sys .exit ("Error: no package named '%s' to remove" % name )
66
- return accepted_precs
63
+ unknown_precs = set (exclude ).difference (prec .name for prec in precs )
64
+ if unknown_precs :
65
+ sys .exit (f"Error: no package(s) named { ', ' .join (unknown_precs )} to remove" )
66
+
67
+ return [prec for prec in precs if prec .name not in exclude ]
67
68
68
69
69
70
def _find_out_of_date_precs (precs , channel_urls , platform ):
@@ -245,15 +246,12 @@ def _main(name, version, download_dir, platform, channel_urls=(), channels_remap
245
246
transmute_file_type = '' ):
246
247
# Add python to specs, since all installers need a python interpreter. In the future we'll
247
248
# probably want to add conda too.
248
- specs = list ( concatv ( specs , ( "python" ,)) )
249
+ specs = ( * specs , "python" )
249
250
if verbose :
250
251
print ("specs: %r" % specs )
251
252
252
253
# Append channels_remap srcs to channel_urls
253
- channel_urls = tuple (concatv (
254
- channel_urls ,
255
- (x ['src' ] for x in channels_remap ),
256
- ))
254
+ channel_urls = (* channel_urls , * (x ['src' ] for x in channels_remap ))
257
255
258
256
if environment_file or environment :
259
257
# set conda to be the user's conda (what is in the environment)
0 commit comments