This repository was archived by the owner on Jul 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsetup.py
88 lines (81 loc) · 3.33 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
try:
from setuptools import setup
except ImportError:
from distutils.core import setup
from distutils.command.build_py import build_py
import glob
import os
import platform
import subprocess
from pathlib import Path
from shutil import copyfile
import sys
class FetchDependencies(build_py):
"""
A command class that fetch Java Dependencies and
add them as files within a python package
"""
def create_stubs(self, project_root, command):
subprocess.run([str((project_root / command).absolute()), 'dependency:copy-dependencies'],
cwd=project_root, check=True)
subprocess.run([str((project_root / command).absolute()), 'dependency:copy-dependencies',
'-Dclassifier=javadoc'], cwd=project_root, check=True)
def run(self):
if not self.dry_run:
project_root = Path(__file__).parent
# Do a mvn clean install
# which is configured to add dependency jars to 'target/dependency'
command = 'mvnw'
if platform.system() == 'Windows':
command = 'mvnw.cmd'
self.create_stubs(project_root, command)
subprocess.run([str((project_root / command).absolute()), 'clean', 'install'], cwd=project_root, check=True)
classpath_jars = []
# Add the main artifact
classpath_jars.extend(glob.glob(os.path.join(project_root, 'target', '*.jar')))
# Add the main artifact's dependencies
classpath_jars.extend(glob.glob(os.path.join(project_root, 'target', 'dependency', '*.jar')))
self.mkpath(os.path.join(self.build_lib, 'jpyinterpreter', 'jars'))
# Copy classpath jars to jpyinterpreter.jars
for file in classpath_jars:
copyfile(file, os.path.join(self.build_lib, 'jpyinterpreter', 'jars', os.path.basename(file)))
# Make jpyinterpreter.jars a Python module
fp = open(os.path.join(self.build_lib, 'jpyinterpreter', 'jars', '__init__.py'), 'w')
fp.close()
build_py.run(self)
this_directory = Path(__file__).parent
setup(
name='jpyinterpreter',
version='0.0.0a0',
license='Apache License Version 2.0',
license_file='LICENSE',
description='A Python bytecode to Java bytecode translator',
classifiers=[
'Development Status :: 1 - Planning',
'Programming Language :: Python :: 3',
'Topic :: Software Development :: Libraries :: Java Libraries',
'License :: OSI Approved :: Apache Software License',
'Operating System :: OS Independent'
],
packages=['jpyinterpreter', 'java-stubs', 'jpype-stubs', 'org-stubs'],
package_dir={
'jpyinterpreter': 'src/main/python',
# Setup tools need a non-empty directory to use as base
# Since these packages are generated during the build,
# we use the src/main/resources package, which does
# not contain any python files and is already included
# in the build
'java-stubs': 'src/main/resources',
'jpype-stubs': 'src/main/resources',
'org-stubs': 'src/main/resources',
},
test_suite='tests',
python_requires='>=3.10',
install_requires=[
'JPype1>=1.5.0',
],
cmdclass={'build_py': FetchDependencies},
package_data={
'jpyinterpreter.jars': ['*.jar'],
},
)