-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup.py
executable file
·105 lines (83 loc) · 2.77 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
#!/usr/bin/env python3
import distutils.command.build as build
import distutils.command.clean as clean
import pathlib
import platform
import setuptools
import shutil
import subprocess
import sys
import tempfile
from typing import List
import os
from setuptools.command import test
from hawk_eye.inference import production_models
__version__ = pathlib.Path("version.txt").read_text()
_MODELS_DIR = pathlib.Path.cwd() / "hawk_eye/core/production_models"
def _get_packages() -> List[str]:
all_deps = pathlib.Path("hawk_eye/setup/requirements.txt").read_text().splitlines()
deps = []
deps_to_export = ["numpy", "pillow", "pyyaml"]
for dep in all_deps:
for export_dep in deps_to_export:
if export_dep in dep:
deps.append(dep)
return deps
class Build(build.build):
def initialize_options(self):
build.build.initialize_options(self)
def finalize_options(self):
build.build.finalize_options(self)
def run(self) -> None:
self.run_command("prepare_models")
build.build.run(self)
class Test(test.test):
def run(self):
self.run_command("prepare_models")
test.test.run(self)
class PrepareModels(build.build):
def run(self):
_MODELS_DIR.mkdir()
models = ["classification_model", "detection_model"]
for model in models:
self._prepare_model(model)
def _prepare_model(self, model_target: str):
bazel_command = ["bazel", "fetch", f"@{model_target}//..."]
if subprocess.call(bazel_command) != 0:
sys.exit(-1)
bazel_external = (
pathlib.Path(
subprocess.check_output(["bazel", "info", "output_base"])
.decode("utf-8")
.strip()
)
/ "external"
)
if "classification" in model_target:
shutil.copytree(
bazel_external
/ model_target
/ production_models._CLASSIFIER["timestamp"],
_MODELS_DIR / production_models._CLASSIFIER["timestamp"],
)
else:
shutil.copytree(
bazel_external
/ model_target
/ production_models._DETECTOR["timestamp"],
_MODELS_DIR / production_models._DETECTOR["timestamp"],
)
try:
setuptools.setup(
name="hawk_eye",
version=__version__,
description=("Find targets"),
author="UAV Austin Image Recognition",
packages=setuptools.find_packages(),
cmdclass={"build": Build, "prepare_models": PrepareModels, "test": Test},
include_package_data=True,
install_requires=_get_packages(),
test_suite="hawk_eye.inference",
)
finally:
shutil.rmtree(_MODELS_DIR)