-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup.py
139 lines (110 loc) · 3.79 KB
/
setup.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
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# Copyright (C) 2021 Xilinx, Inc
#
# SPDX-License-Identifier: BSD-3-Clause
__author__ = "Mario Ruiz"
__copyright__ = "Copyright 2021, Xilinx"
__email__ = "[email protected]"
import hashlib
import os
import re
import subprocess
import shutil
import tempfile
import urllib.request
from glob import glob
from pynq.utils import build_py
from setuptools import setup, find_packages
# global variables
module_name = "kv260"
board = os.environ["BOARD"]
data_files = []
overlay = {
"KV260": {
"url": "https://www.xilinx.com/bin/public/openDownload?filename=kv260_base_2.7.zip",
"md5sum": "b2a97221b04aead529a6a862d9d691ff",
"format": "zip"
}
}
def find_version(file_path):
"""Parse version number"""
with open(file_path, "r") as fp:
version_file = fp.read()
version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]",
version_file, re.M)
if version_match:
return version_match.group(1)
raise NameError("Version string must be defined in {}.".format(file_path))
# extend package
def extend_package(path):
if os.path.isdir(path):
data_files.extend(
[os.path.join("..", root, f)
for root, _, files in os.walk(path) for f in files]
)
elif os.path.isfile(path):
data_files.append(os.path.join("..", path))
def download_overlay(board, overlay_dest):
"""Download pre-compiled overlay from the Internet"""
if board not in overlay.keys():
return
download_link = overlay[board]["url"]
md5sum = overlay[board].get("md5sum")
archive_format = overlay[board].get("format")
tmp_file = tempfile.mkstemp()[1]
with urllib.request.urlopen(download_link) as response, \
open(tmp_file, "wb") as out_file:
data = response.read()
out_file.write(data)
if md5sum:
file_md5sum = hashlib.md5()
with open(tmp_file, "rb") as out_file:
for chunk in iter(lambda: out_file.read(4096), b""):
file_md5sum.update(chunk)
if md5sum != file_md5sum.hexdigest():
os.remove(tmp_file)
raise ImportWarning("Incorrect checksum for file. The base "
"overlay will not be delivered")
shutil.unpack_archive(tmp_file, overlay_dest, archive_format)
def compile_dtbo(src_path: str, dst_path: str):
"""Compile devicetree overlay"""
sp = subprocess.Popen(["make"], stdout=subprocess.PIPE, cwd=src_path)
p_status = sp.wait()
shutil.copy(src_path + 'base.dtbo', dst_path)
def copy_notebooks(board_folder, module_name):
"""Copy notebooks"""
src_dir = "{}/notebooks".format(board_folder)
if not os.path.exists(src_dir):
return
for folder in glob(src_dir + '/*'):
dst = folder.replace(board_folder, module_name)
if os.path.exists(dst):
shutil.rmtree(dst)
shutil.copytree(folder, dst)
copy_notebooks("kv260/base", module_name)
download_overlay(board, module_name)
compile_dtbo("kv260/base/dts/", module_name)
extend_package(module_name)
pkg_version = find_version("{}/__init__.py".format(module_name))
setup(
name=module_name,
version=pkg_version,
description="KV260-PYNQ Base Overlay",
author="Xilinx PYNQ Development Team",
author_email="[email protected]",
url="https://github.com/Xilinx/Kria-PYNQ",
license="BSD 3-Clause License",
packages=find_packages(),
package_data={
"": data_files,
},
python_requires=">=3.8.0",
install_requires=[
"pynq>=2.7.0"
],
entry_points={
"pynq.notebooks": ["kv260 = {}.notebooks".format(module_name)],
"pynq.overlays": ["kv260 = {}".format(module_name)]
},
cmdclass={"build_py": build_py},
platforms=[board]
)