forked from ome/pydoop-features
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
103 lines (86 loc) · 2.93 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
# BEGIN_COPYRIGHT
#
# Copyright (C) 2014-2017 Open Microscopy Environment:
# - University of Dundee
# - CRS4
#
# Licensed 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.
#
# END_COPYRIGHT
"""\
Integrate bioimage analysis with Bio-Formats and Hadoop.
"""
import os
import glob
import shutil
import subprocess as sp
from distutils.command.build import build as BaseBuild
from distutils.errors import DistutilsSetupError
from distutils.core import setup
NAME = "pyfeatures"
DESCRIPTION = __doc__
URL = "https://github.com/simleo/pydoop-features.git"
CLASSIFIERS = [
"Programming Language :: Python",
"Topic :: Scientific/Engineering :: Bio-Informatics",
"Intended Audience :: Science/Research",
]
def build_java():
sp.check_call(["mvn", "-B", "clean", "compile", "assembly:single"])
def write_schema_module():
with open(os.path.join("pyfeatures", "schema.py"), "w") as fo:
fo.write("# GENERATED BY setup.py\n")
fnames = glob.glob(os.path.join("src", "main", "avro", "*.avsc"))
if not fnames:
raise DistutilsSetupError("Avro schema files not found!")
for fn in fnames:
name = os.path.basename(os.path.splitext(fn)[0])
with open(fn) as f:
fo.write('\n%s = """\\\n%s"""\n' % (name, f.read()))
def write_config(append=False, **config):
mode = "a" if append else "w"
with open(os.path.join("pyfeatures", "config.py"), mode) as fo:
fo.write("# GENERATED BY setup.py\n")
for k, v in config.iteritems():
fo.write("%s = %r\n" % (k.upper(), v))
class Build(BaseBuild):
def __find_jar(self):
jars = glob.glob("target/pydoop-features-*.jar")
if len(jars) != 1:
raise DistutilsSetupError(
"Exactly one pydoop-features jar expected in target/"
)
return jars[0]
def __add_jar(self, src_path):
bn = os.path.basename(src_path)
dst_path = os.path.join(self.build_lib, "pyfeatures", bn)
shutil.copyfile(src_path, dst_path)
def run(self):
build_java()
jar_path = self.__find_jar()
write_config(jar_name=os.path.basename(jar_path))
write_schema_module()
BaseBuild.run(self)
self.__add_jar(jar_path)
setup(
name=NAME,
description=DESCRIPTION,
url=URL,
classifiers=CLASSIFIERS,
packages=[
"pyfeatures",
"pyfeatures.app",
],
scripts=["scripts/pyfeatures"],
cmdclass={"build": Build}
)