forked from apache/paimon-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjava_setuputils.py
More file actions
executable file
·85 lines (66 loc) · 2.72 KB
/
java_setuputils.py
File metadata and controls
executable file
·85 lines (66 loc) · 2.72 KB
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
################################################################################
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
################################################################################
import os
import shutil
import subprocess
from xml.etree import ElementTree
_JAVA_IMPL_MODULE = 'pypaimon/py4j'
_JAVA_DEPS = 'java_dependencies'
_JAVA_BRIDGE = 'paimon-python-java-bridge'
_PYPAIMON_TOX_TEST = '_PYPAIMON_TOX_TEST'
def get_package_data():
is_tox_test = os.environ.get(_PYPAIMON_TOX_TEST)
if is_tox_test and is_tox_test.lower() == "true":
return ['']
setup_java_bridge()
return [os.path.join(_JAVA_DEPS, '*')]
def clean():
java_deps_dir = os.path.join(_find_java_impl_dir(), _JAVA_DEPS)
if os.path.exists(java_deps_dir):
shutil.rmtree(java_deps_dir)
def setup_java_bridge():
java_impl_dir = _find_java_impl_dir()
java_deps_dir = os.path.join(java_impl_dir, _JAVA_DEPS)
if not os.path.exists(java_deps_dir):
os.mkdir(java_deps_dir)
java_bridge_dst = os.path.join(java_deps_dir, _JAVA_BRIDGE + '.jar')
if os.path.exists(java_bridge_dst):
return
java_bridge_module = os.path.join(java_impl_dir, _JAVA_BRIDGE)
subprocess.run(
["mvn", "clean", "package"],
cwd=java_bridge_module,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
shutil.copy(
os.path.join(java_bridge_module, 'target/{}-{}.jar'
.format(_JAVA_BRIDGE, _extract_bridge_version())),
java_bridge_dst
)
def _extract_bridge_version():
pom_path = os.path.join(_find_java_impl_dir(), _JAVA_BRIDGE, 'pom.xml')
return ElementTree.parse(pom_path).getroot().find(
'POM:version',
namespaces={
'POM': 'http://maven.apache.org/POM/4.0.0'
}).text
def _find_java_impl_dir():
this_dir = os.path.abspath(os.path.dirname(__file__))
paimon_python_dir = os.path.dirname(this_dir)
return os.path.join(paimon_python_dir, _JAVA_IMPL_MODULE)