Datasets:
SeanNaren
commited on
Commit
•
da5e8ef
1
Parent(s):
9ec7f28
gzip should be able to handle file handler
Browse files- code_clippy_github.py +25 -23
code_clippy_github.py
CHANGED
@@ -175,29 +175,31 @@ class CodeClippyGithub(datasets.GeneratorBasedBuilder):
|
|
175 |
def _generate_examples(self, files):
|
176 |
key = 0
|
177 |
for file_idx, file in enumerate(files):
|
178 |
-
with xopen(file, "rb") as
|
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 |
def lang_from_name(name):
|
|
|
175 |
def _generate_examples(self, files):
|
176 |
key = 0
|
177 |
for file_idx, file in enumerate(files):
|
178 |
+
with xopen(file, "rb") as file: # download file if in streaming mode
|
179 |
+
with gzip.open(file, "rb") as f:
|
180 |
+
|
181 |
+
uncompressed_data = f.readlines()
|
182 |
+
|
183 |
+
for batch_idx, code_base in enumerate(uncompressed_data):
|
184 |
+
j_dict = json.loads(code_base.decode('utf-8'))
|
185 |
+
|
186 |
+
|
187 |
+
|
188 |
+
lang = lang_from_name(j_dict['path'])
|
189 |
+
license = j_dict["license"]
|
190 |
+
|
191 |
+
if self.config.filter_languages and not lang in self.config.languages:
|
192 |
+
continue
|
193 |
+
if self.config.filter_licenses and not license in self.config.licenses:
|
194 |
+
continue
|
195 |
+
# TODO: Add more features like header comments, filename, and other features useful in a prompt.
|
196 |
+
yield key, {"code_text": j_dict['content'],
|
197 |
+
"repo_name": j_dict['repo_name'],
|
198 |
+
"file_path": j_dict['path'],
|
199 |
+
"license": license,
|
200 |
+
"language": lang,
|
201 |
+
"size": int(j_dict['f0_'])}
|
202 |
+
key += 1
|
203 |
|
204 |
|
205 |
def lang_from_name(name):
|