forked from Angel-ML/SNIP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
110 lines (90 loc) · 2.55 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
#! /usr/bin/env python
# -*- encoding: utf-8 -*-
#
# Copyright 2022 the deepx authors.
# Author: Chuan Cheng ([email protected])
#
import os
import shutil
import subprocess
from collections import namedtuple
from textwrap import dedent
from setuptools import Command, find_packages, setup
from setuptools.command.sdist import sdist as _sdist
TOP_DIR = os.path.realpath(os.path.dirname(__file__))
SRC_DIR = TOP_DIR
# delete file by folder
def remove_files_by_folder(folder_path):
folder_list = list()
for folder in os.listdir(folder_path):
folder_list.append(folder)
for file in folder_list:
rm_path = os.path.join(folder_path, file)
print(rm_path)
shutil.rmtree(rm_path)
#delete remain setup file
if os.path.exists("./build"):
remove_files_by_folder("./build")
# try to get git_version
try:
git_version = (
subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=TOP_DIR)
.decode("ascii")
.strip()
)
except (OSError, subprocess.CalledProcessError):
git_version = None
# open local file version.txt
# read version
with open(os.path.join(TOP_DIR, "version.txt"), "rb") as version_file:
VersionInfo = namedtuple(
"VersionInfo", ["version", "git_version"]
)(
version=version_file.read().decode("ascii").strip(),
git_version=git_version,
)
# creat version for setup
class create_version(Command):
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
with open(os.path.join(SRC_DIR, "version.py"), "w") as f:
f.write(
dedent(
"""\
# This file is generated by setup.py. DO NOT EDIT!
__version__ = '{version}'
__git_version__ = '{git_version}'
""".format(
**dict(VersionInfo._asdict())
)
)
)
class sdist(_sdist):
def run(self):
self.run_command("create_version")
return _sdist.run(self)
def configure_console_scripts():
return [
]
# begin setup
# checkout version.txt
setup(
name="Auto48X",
version=VersionInfo.version,
description="A platform to do qat and distil",
setup_requires=[],
data_files=[(".", ["version.txt"])],
packages=find_packages(),
package_data = {
# If any package contains *.txt or *.rst files, include them:
'': ['*.json', '*.txt']
},
url="/Auto48X",
python_requires=">=3.8",
install_requires=[
],
)