@@ -70,18 +70,14 @@ def get_artifact_checksum(artifact) -> str:
70
70
try :
71
71
with urllib .request .urlopen (possible_url ) as value :
72
72
body = value .read ()
73
- time .sleep (1 )
74
73
return hashlib .sha256 (body ).hexdigest ()
75
74
except urllib .error .HTTPError as e :
76
75
print (f'RESOURCES NOT FOUND: { possible_url } ' )
77
76
78
77
def get_json_dependencies (artifact ) -> List [MavenCoordinates ]:
79
78
with open ('out.json' ) as file :
80
79
data = json .load (file )
81
- for d in data ["dependencies" ]:
82
- if (d ["coord" ] == artifact ):
83
- return get_mavens_coordinates_from_json (d ["directDependencies" ])
84
- return []
80
+ return get_mavens_coordinates_from_json (dependency ["directDependencies" ]) if any ((dependency := d )["coord" ] == artifact for d in data ["dependencies" ]) else []
85
81
86
82
def get_label (coordinate ) -> str :
87
83
if ("org.scala-lang" in coordinate .group or "org.scalatest" in coordinate .group or "org.scalactic" in coordinate .group or "com.twitter" in coordinate .group or "javax.annotation" in coordinate .group ) and "scala-collection" not in coordinate .artifact and "scalap" not in coordinate .artifact :
@@ -109,16 +105,14 @@ def map_to_resolved_artifacts(output) -> List[ResolvedArtifact]:
109
105
def resolve_artifacts_with_checksums_and_direct_dependencies (root_artifacts ) -> List [ResolvedArtifact ]:
110
106
command = f'cs resolve { ' ' .join (root_artifacts )} '
111
107
output = subprocess .run (command , capture_output = True , text = True , shell = True ).stdout .splitlines ()
112
- artifacts = map_to_resolved_artifacts (output )
113
- return artifacts
108
+ return map_to_resolved_artifacts (output )
114
109
115
110
def to_rules_scala_compatible_dict (artifacts , version ) -> Dict [str , Dict ]:
116
111
temp = {}
117
112
118
113
for a in artifacts :
119
114
label = get_label (a .coordinates ).replace ('scala3_' , 'scala_' ).replace ('scala_tasty_core' , 'scala_scala_tasty_core' )
120
- deps = ['@' + get_label (dep ) for dep in a .direct_dependencies ]
121
- deps = list (map (lambda dep : dep .replace ('scala_library' , 'scala_library_2' ), deps )) if "scala3-library_3" in a .coordinates .artifact else deps
115
+ deps = [f'@{ get_label (dep )} _2' if "scala3-library_3" in a .coordinates .artifact else f'@{ get_label (dep )} ' for dep in a .direct_dependencies ]
122
116
123
117
temp [label ] = {
124
118
"artifact" : f"{ a .coordinates .coordinate } " ,
@@ -161,9 +155,7 @@ def write_to_file(artifact_dict, version, file):
161
155
with file .open ('w' ) as data :
162
156
data .write (f'scala_version = "{ version } "\n ' )
163
157
data .write ('\n artifacts = ' )
164
- written = get_with_trailing_commas (json .dumps (artifact_dict , indent = 4 ).replace ('true' , 'True' ).replace ('false' , 'False' ))
165
- data .write (written )
166
- data .write ('\n ' )
158
+ data .write (f'{ get_with_trailing_commas (json .dumps (artifact_dict , indent = 4 ).replace ('true' , 'True' ).replace ('false' , 'False' ))} \n ' )
167
159
168
160
def create_file (version ):
169
161
path = os .getcwd ().replace ('/scripts' , '/third_party/repositories' )
@@ -172,11 +164,11 @@ def create_file(version):
172
164
if not file .exists ():
173
165
file_to_copy = Path (sorted (glob .glob (f'{ path } /*.bzl' ))[- 1 ])
174
166
with file .open ('w+' ) as data , file_to_copy .open ('r' ) as data_to_copy :
175
- for line_number , line in enumerate (data_to_copy ):
176
- if line_number > 1 :
177
- data .write (line )
167
+ for line in data_to_copy :
168
+ data .write (line )
178
169
179
170
with file .open ('r+' ) as data :
171
+ excluded_artifacts = ["org.scala-lang.modules:scala-parser-combinators_2.11:1.0.4" ]
180
172
root_artifacts = select_root_artifacts (version )
181
173
read_data = data .read ()
182
174
replaced_data = read_data [read_data .find ('{' ):]
@@ -189,14 +181,12 @@ def create_file(version):
189
181
generated_labels = generated_artifact_dict .keys ()
190
182
191
183
for label in labels :
192
- if label in generated_labels and generated_artifact_dict [label ]["artifact" ] != "org.scala-lang.modules:scala-parser-combinators_2.11:1.0.4" :
184
+ if label in generated_labels and generated_artifact_dict [label ]["artifact" ] not in excluded_artifacts :
193
185
artifact = generated_artifact_dict [label ]["artifact" ]
194
186
sha = generated_artifact_dict [label ]["sha256" ]
195
187
deps = generated_artifact_dict [label ]["deps:" ] if "deps:" in generated_artifact_dict [label ] else []
196
-
197
188
original_artifact_dict [label ]["artifact" ] = artifact
198
189
original_artifact_dict [label ]["sha256" ] = sha
199
-
200
190
if deps :
201
191
dependencies = [d for d in deps if d [1 :] in labels and "runtime" not in d and "runtime" not in artifact ]
202
192
if dependencies :
0 commit comments