-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.py
31 lines (24 loc) · 1.08 KB
/
build.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
import base64
import gzip
from pathlib import Path
def encode_file(path: Path) -> str:
compressed = gzip.compress(path.read_bytes(), compresslevel=9)
return base64.b64encode(compressed).decode('utf-8')
def build_script():
# list all your packages and files here
# use '/' for sub-packages
to_encode = None
packages = ['submission', 'albumentations', 'albumentations/augmentations', 'albumentations/core', 'albumentations/imgaug', 'albumentations/pytorch', 'albumentations/torch', 'utils']
files = ['setup.py', 'reproduceability.py']
for package in packages:
if to_encode is None: to_encode = list(Path(package).glob('*.py'))
else: to_encode = to_encode + list(Path(package).glob('*.py'))
for f in files:
to_encode = to_encode + [Path(f)]
file_data = {str(path): encode_file(path) for path in to_encode}
template = Path('script_template.py').read_text('utf8')
Path('build/script.py').write_text(
template.replace('{file_data}', str(file_data)),
encoding='utf8')
if __name__ == '__main__':
build_script()