summaryrefslogtreecommitdiff
path: root/download_dependencies.py
diff options
context:
space:
mode:
authorRichard Burton <richard.burton@arm.com>2022-03-17 10:54:26 +0000
committerRichard <richard.burton@arm.com>2022-03-17 15:19:16 +0000
commit17069628a7f28198652a296ac16dc83529c7eaae (patch)
treeadff78b64954e67dc4e29f6f039c63c8c18cde2c /download_dependencies.py
parent624dafd2a206d88da979453442fe5a8d4c05ad51 (diff)
downloadml-embedded-evaluation-kit-17069628a7f28198652a296ac16dc83529c7eaae.tar.gz
MLECO-3036: Update to use Pathlib in Python scripts
* Pathlib used in Python scripts over os * Bug fix for build_default.py * Minor code style updates Signed-off-by: Richard Burton <richard.burton@arm.com> Change-Id: I5fc2e582a84443c3fb79250eb711b960d63ed8fd
Diffstat (limited to 'download_dependencies.py')
-rwxr-xr-xdownload_dependencies.py44
1 files changed, 20 insertions, 24 deletions
diff --git a/download_dependencies.py b/download_dependencies.py
index c02d98f..b62c9b1 100755
--- a/download_dependencies.py
+++ b/download_dependencies.py
@@ -15,20 +15,20 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-# The script does effectively the same as "git submodule update --init" command.
-
+"""This script does effectively the same as "git submodule update --init" command."""
import logging
-import os
import sys
import tarfile
import tempfile
from urllib.request import urlopen
from zipfile import ZipFile
+from pathlib import Path
+
+TF = "https://github.com/tensorflow/tflite-micro/archive/1a0287fc5fa81fa6aa1dcfb0c5b2e01f74164393.zip"
+CMSIS = "https://github.com/ARM-software/CMSIS_5/archive/9b5df640c777563919affb4e9201c96c657adbb2.zip"
+ETHOS_U_CORE_DRIVER = "https://git.mlplatform.org/ml/ethos-u/ethos-u-core-driver.git/snapshot/ethos-u-core-driver-22.02.tar.gz"
+ETHOS_U_CORE_PLATFORM = "https://git.mlplatform.org/ml/ethos-u/ethos-u-core-platform.git/snapshot/ethos-u-core-platform-22.02.tar.gz"
-tf = "https://github.com/tensorflow/tflite-micro/archive/1a0287fc5fa81fa6aa1dcfb0c5b2e01f74164393.zip"
-cmsis = "https://github.com/ARM-software/CMSIS_5/archive/9b5df640c777563919affb4e9201c96c657adbb2.zip"
-ethos_u_core_driver = "https://git.mlplatform.org/ml/ethos-u/ethos-u-core-driver.git/snapshot/ethos-u-core-driver-22.02.tar.gz"
-ethos_u_core_platform = "https://git.mlplatform.org/ml/ethos-u/ethos-u-core-platform.git/snapshot/ethos-u-core-platform-22.02.tar.gz"
def download(url_file: str, post_process=None):
with urlopen(url_file) as response, tempfile.NamedTemporaryFile() as temp:
@@ -46,10 +46,10 @@ def unzip(file, to_path):
archive_path.filename = archive_path.filename[archive_path.filename.find("/") + 1:]
if archive_path.filename:
z.extract(archive_path, to_path)
- target_path = os.path.join(to_path, archive_path.filename)
+ target_path = to_path / archive_path.filename
attr = archive_path.external_attr >> 16
if attr != 0:
- os.chmod(target_path, attr)
+ target_path.chmod(attr)
def untar(file, to_path):
@@ -63,29 +63,25 @@ def untar(file, to_path):
z.extract(archive_path, to_path)
-def main(dependencies_path: str):
+def main(dependencies_path: Path):
- download(cmsis,
- lambda file: unzip(file.name,
- to_path=os.path.join(dependencies_path, "cmsis")))
- download(ethos_u_core_driver,
- lambda file: untar(file.name,
- to_path=os.path.join(dependencies_path, "core-driver")))
- download(ethos_u_core_platform,
- lambda file: untar(file.name,
- to_path=os.path.join(dependencies_path, "core-platform")))
- download(tf,
- lambda file: unzip(file.name,
- to_path=os.path.join(dependencies_path, "tensorflow")))
+ download(CMSIS,
+ lambda file: unzip(file.name, to_path=dependencies_path / "cmsis"))
+ download(ETHOS_U_CORE_DRIVER,
+ lambda file: untar(file.name, to_path=dependencies_path / "core-driver"))
+ download(ETHOS_U_CORE_PLATFORM,
+ lambda file: untar(file.name, to_path=dependencies_path / "core-platform"))
+ download(TF,
+ lambda file: unzip(file.name, to_path=dependencies_path / "tensorflow"))
if __name__ == '__main__':
logging.basicConfig(filename='download_dependencies.log', level=logging.DEBUG, filemode='w')
logging.getLogger().addHandler(logging.StreamHandler(sys.stdout))
- download_dir = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "dependencies"))
+ download_dir = Path(__file__).parent.resolve() / "dependencies"
- if os.path.isdir(download_dir):
+ if download_dir.is_dir():
logging.info(f'{download_dir} exists. Skipping download.')
else:
main(download_dir)