-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
144 lines (117 loc) · 4.52 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
140
141
142
143
144
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (c) Jason Young (杨郑鑫).
#
# E-Mail: <[email protected]>
# 2020-03-31 22:03
#
# This source code is licensed under the Apache-2.0 license found in the
# LICENSE file in the root directory of this source tree.
import os
import sys
import shutil
import setuptools
# ------------------Package Meta-Data------------------
PACKAGE_INFO = {}
PACKAGE_INFO['Name'] = 'YoungNMT'
PACKAGE_INFO['Version'] = '0.1.1a0'
PACKAGE_INFO['Author'] = 'Jason-Young-AI'
PACKAGE_INFO['EMail'] = '[email protected]'
PACKAGE_INFO['Source_URL'] = 'https://github.com/Jason-Young-AI/YoungNMT.git'
PACKAGE_INFO['Description'] = 'Young Neural Machine Translation System'
# This Package's directory absolute path is set here.
PACKAGE_DIR_ABSOLUTE_PATH = os.path.abspath(os.path.dirname(__file__))
# Long-Description file 'README.md' path is set here
README_ABSOLUTE_PATH = os.path.join(PACKAGE_DIR_ABSOLUTE_PATH, 'README.md')
# Distribution directory 'dist' path is set here.
PACKAGE_DIST_DIR_ABSOLUTE_PATH = os.path.join(PACKAGE_DIR_ABSOLUTE_PATH, 'dist')
# Building directory 'build' path is set here.
PACKAGE_BUILD_DIR_ABSOLUTE_PATH = os.path.join(PACKAGE_DIR_ABSOLUTE_PATH, 'build')
# EggInfo directory 'PACKAGE_NAME.egg-info' path is set here.
PACKAGE_EGGINFO_DIR_ABSOLUTE_PATH = os.path.join(PACKAGE_DIR_ABSOLUTE_PATH, '{}.egg-info'.format(PACKAGE_INFO['Name']))
#[Long Description]
try:
with open(README_ABSOLUTE_PATH, 'r', encoding='utf-8') as readme_file:
PACKAGE_INFO['Long_Description'] = '\n' + readme_file.read()
except FileNotFoundError:
PACKAGE_INFO['Long_Description'] = PACKAGE_INFO['Description']
# Required Packages and Optional Packages
# Required
REQUIRED = [
'numpy',
'torch',
'visdom',
'pyhocon',
'pynvml',
]
# Optional
EXTRAS = {
# '': [''],
}
# Upload command class of the setup.py.
class UploadCommand(setuptools.Command):
"""Let setup.py support the command \'upload\'."""
description = 'Building and Publishing this Package: {}'.format(PACKAGE_INFO['Name'])
user_options = []
@staticmethod
def status(str):
"""Printing things in bold."""
print('\033[1m{}\033[0m'.format(str))
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
try:
self.status('Removing previous dists ...')
shutil.rmtree(PACKAGE_DIST_DIR_ABSOLUTE_PATH)
self.status('Removing previous builds ...')
shutil.rmtree(PACKAGE_BUILD_DIR_ABSOLUTE_PATH)
self.status('Removing previous egg-infos ...')
shutil.rmtree(PACKAGE_EGGINFO_DIR_ABSOLUTE_PATH)
except OSError:
pass
self.status('Building Source and Wheel (universal) distribution ...')
os.system('{} setup.py sdist bdist_wheel'.format(sys.executable))
self.status('Uploading the package to PyPI via Twine ...')
os.system('twine upload --repository-url https://upload.pypi.org/legacy/ dist/*')
self.status('Pushing git tags ...')
os.system('git tag v{}'.format(PACKAGE_INFO['Version']))
os.system('git push --tags')
os.system('git push -u origin master')
sys.exit()
def setup_my_package():
setuptools.setup(
name=PACKAGE_INFO['Name'],
version=PACKAGE_INFO['Version'],
author=PACKAGE_INFO['Author'],
author_email=PACKAGE_INFO['EMail'],
url=PACKAGE_INFO['Source_URL'],
description=PACKAGE_INFO['Description'],
long_description=PACKAGE_INFO['Long_Description'],
long_description_content_type='text/markdown',
packages=setuptools.find_packages(exclude=('tests',)),
install_requires=REQUIRED,
extras_require=EXTRAS,
include_package_data=True,
classifiers=[
'Intended Audience :: Science/Research',
'Programming Language :: Python :: 3',
'License :: OSI Approved :: Apache Software License',
'Operating System :: OS Independent',
'Topic :: Scientific/Engineering :: Artificial Intelligence',
],
cmdclass={
'upload': UploadCommand,
},
entry_points={
'console_scripts': [
'ynmt-preprocess = ynmt_cli.default.preprocess:main',
'ynmt-train = ynmt_cli.default.train:main',
'ynmt-test = ynmt_cli.default.test:main',
],
},
)
if __name__ == '__main__':
setup_my_package()