Skip to content

Commit b178d4f

Browse files
authored
Merge pull request #48 from HEPData/data-file-size-limit
Added file size limit for data files
2 parents 73536c0 + a52e621 commit b178d4f

File tree

5 files changed

+400028
-8
lines changed

5 files changed

+400028
-8
lines changed

hepdata_validator/full_submission_validator.py

+11
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
from .data_file_validator import DataFileValidator
1616

1717

18+
INDIVIDUAL_FILE_SIZE_LIMIT = 10485760
19+
1820
class SchemaType(Enum):
1921
SUBMISSION = 'submission'
2022
SINGLE_YAML = 'single file'
@@ -313,6 +315,15 @@ def _check_doc(self, doc):
313315
)
314316
return is_valid_submission_doc
315317

318+
file_size = os.path.getsize(data_file_path)
319+
if file_size > INDIVIDUAL_FILE_SIZE_LIMIT: # 10MB limit for each file
320+
self._add_validation_message(
321+
file=data_file_path,
322+
message=f"Size of data_file '{doc['data_file']}' ({file_size} bytes) is bigger than the limit of " \
323+
f"{INDIVIDUAL_FILE_SIZE_LIMIT} bytes. Try adding the file as an additional_resource instead."
324+
)
325+
return is_valid_submission_doc
326+
316327
user_data_file_path = self.submission_file_path if self.single_yaml_file else data_file_path
317328
user_data_file_path = self._remove_temp_directory(user_data_file_path)
318329

testsuite/test_data/TestHEPSubmission_invalid/data10.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ dependent_variables:
3030
errors:
3131
- {label: stat, symerror: 100}
3232
- {label: 'sys,detector', symerror: 10}
33-
- {label: 'sys,background', symerror: 1}
33+
- {label: 'sys,background', symerror: 1}

0 commit comments

Comments
 (0)