-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsetup.py
141 lines (109 loc) · 3.97 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Note: To use the 'upload' functionality of this file, you must:
# $ pip install twine
import codecs
import os
import sys
from shutil import rmtree
from setuptools import Command, find_packages, setup
from setuptools.command.develop import develop
NAME = 'javac_parser'
DESCRIPTION = 'Exposes the OpenJDK Java parser and scanner to Python'
# Various paths that this script needs to check.
HERE = os.path.dirname(os.path.abspath(__file__))
TEST_PATH = os.path.join(HERE, 'tests')
JAR_NAME = "lex-java-1.0-SNAPSHOT-jar-with-dependencies.jar"
DISTRIBUTABLE_JAR_PATH = os.path.join(HERE, os.path.join(NAME, JAR_NAME))
class UploadCommand(Command):
"""Support setup.py upload."""
description = 'Build and publish the package.'
user_options = []
@staticmethod
def status(s):
"""Prints things in bold."""
print('\033[1m{0}\033[0m'.format(s))
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
try:
self.status('Removing previous builds…')
rmtree(os.path.join(HERE, 'dist'))
except OSError:
pass
assert os.path.isfile(DISTRIBUTABLE_JAR_PATH)
self.status('Building Source and Wheel (universal) distribution…')
os.system('{0} setup.py sdist bdist_wheel --universal'.format(sys.executable))
self.status('Uploading the package to PyPi via Twine…')
os.system('twine upload dist/*')
self.status('Pushing git tags…')
os.system('git tag v{0}'.format(version()))
os.system('git push --tags')
sys.exit()
class PostDevelopCommand(develop):
"""
Post-installation for development mode.
This must occur AFTER py4j is installed.
Generates the JAR file required by the Python module. This should only be
done on a development machine.
"""
def run(self):
# Remove target/ to FORCE the recreation of the JAR files.
rmtree(os.path.join(HERE, 'target'), ignore_errors=True)
from javac_parser import Java
Java._build_jar()
assert os.path.isfile(DISTRIBUTABLE_JAR_PATH)
develop.run(self)
def simple_test_suite():
"""Runs tests from tests/"""
import unittest
test_loader = unittest.TestLoader()
return test_loader.discover(TEST_PATH)
def readme():
with codecs.open('README.md', encoding='UTF-8') as readme_file:
return readme_file.read()
def version():
"""
Load the package's __version__.py module as a dictionary.
Derived from: https://github.com/kennethreitz/setup.py/blob/59cfa99b99d87bf2cb2e9176c6dfcacafb532023/setup.py#L41-L46
"""
about = {}
with open(os.path.join(HERE, NAME, '__version__.py')) as f:
exec(f.read(), about)
return about['__version__']
setup(
name=NAME,
version=version(),
description=DESCRIPTION,
author='Joshua Charles Campbell, Eddie Antonio Santos',
author_email='[email protected], [email protected]',
long_description=readme(),
long_description_content_type='text/markdown',
url='https://github.com/naturalness/javac-parser',
packages=find_packages(exclude=('tests',)),
install_requires=[
'py4j==0.10.6',
'msgpack-python>=0.4.8'
],
package_data={
NAME: [JAR_NAME, 'py.typed', '*.pyi']
},
test_suite='setup.simple_test_suite',
license='AGPL3+',
keywords='java javac parser scanner lexer tokenizer',
classifiers=[
'License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: Implementation :: CPython',
],
cmdclass={
'develop': PostDevelopCommand,
'upload': UploadCommand,
},
)