-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmodules.py
More file actions
66 lines (51 loc) · 1.83 KB
/
Copy pathmodules.py
File metadata and controls
66 lines (51 loc) · 1.83 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import glob
from os.path import join, exists
from shutil import rmtree
from subprocess import run
from os import makedirs, remove
from invoke import task
from tasks.env import PROJ_ROOT, THIRD_PARTY_DIR, FAASM_RUNTIME_ROOT
CPYTHON_SRC = join(THIRD_PARTY_DIR, "cpython")
CPYTHON_INSTALL_DIR = join(CPYTHON_SRC, "install", "wasm")
CROSSENV_WASM_DIR = join(PROJ_ROOT, "cross_venv", "cross")
LIB_SRC_DIR = join(CPYTHON_INSTALL_DIR, "lib", "python3.8")
LIB_DEST_DIR = join(FAASM_RUNTIME_ROOT, "lib", "python3.8")
SITE_PACKAGES_SRC_DIR = join(
CROSSENV_WASM_DIR, "lib", "python3.8", "site-packages"
)
SITE_PACKAGES_DEST_DIR = join(LIB_DEST_DIR, "site-packages")
def _glob_remove(glob_pattern, recursive=False, directory=False):
print("Recursive remove: {}".format(glob_pattern))
for filename in glob.iglob(glob_pattern, recursive=recursive):
print("Removing {}".format(filename))
if directory:
rmtree(filename)
else:
remove(filename)
def _clear_pyc_files(dir_path):
pyc_glob = "{}/**/*.pyc".format(dir_path)
_glob_remove(pyc_glob, recursive=True)
pycache_glob = "{}/**/__pycache__".format(dir_path)
_glob_remove(pycache_glob, recursive=True, directory=True)
@task(default=True)
def install(ctx):
"""
Copies the installed modules into the Faasm runtime root
"""
# Clear out pyc files
print("Clearing out pyc files")
_clear_pyc_files(LIB_SRC_DIR)
_clear_pyc_files(SITE_PACKAGES_SRC_DIR)
# Copy cross-compiled modules
if not exists(SITE_PACKAGES_DEST_DIR):
makedirs(SITE_PACKAGES_DEST_DIR)
print(
"Copying {} to {}".format(
SITE_PACKAGES_SRC_DIR, SITE_PACKAGES_DEST_DIR
)
)
run(
"cp -r {}/* {}/".format(SITE_PACKAGES_SRC_DIR, SITE_PACKAGES_DEST_DIR),
shell=True,
check=True,
)