setup.BuildPyCommand.run()   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 18
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 18
rs 9.55
c 0
b 0
f 0
cc 2
nop 1
1
import setuptools
2
import setuptools.command.build_py
3
import os
4
import subprocess
5
import pkg_resources
6
7
__version__ = None
8
9
with open("README.md", "r") as fh:
10
    long_description = fh.read()
11
12
with open(os.path.join(os.path.dirname(__file__), 'e2edutch/__version__.py')) as versionpy:
13
    exec(versionpy.read())
14
15
16
class BuildPyCommand(setuptools.command.build_py.build_py):
17
    """Build the tensorflow kernels, and proceed with default build."""
18
19
    def run(self):
20
        try:
21
            import tensorflow as tf
22
        except ImportError:
23
            raise ImportError("This module requires tensorflow to be installed. " +
24
                              "Install it first with `pip install tensorflow`")
25
        args = ["g++", "-std=c++11", "-shared"]
26
        args += [
27
            pkg_resources.resource_filename("e2edutch", "coref_kernels.cc"),
28
            "-o",
29
            pkg_resources.resource_filename("e2edutch", "coref_kernels.so")
30
        ]
31
        args += ["-fPIC"]
32
        args += tf.sysconfig.get_compile_flags() + tf.sysconfig.get_link_flags()
33
        args += ["-O2",
34
                 "-D_GLIBCXX_USE_CXX11_ABI=0"]
35
        subprocess.check_call(args)
36
        setuptools.command.build_py.build_py.run(self)
37
38
39
setuptools.setup(
40
    name="e2e-Dutch",
41
    version=__version__,
42
    author="Dafne van Kuppevelt",
43
    author_email="[email protected]",
44
    description="Coreference resolution with e2e for Dutch",
45
    long_description=long_description,
46
    long_description_content_type="text/markdown",
47
    url="https://github.com/Filter-Bubble/e2e-Dutch",
48
    packages=setuptools.find_packages(),
49
    classifiers=[
50
        "Programming Language :: Python :: 3",
51
        "Development Status :: 4 - Beta",
52
        "Environment :: Console",
53
        "License :: OSI Approved :: Apache Software License",
54
        "Operating System :: OS Independent",
55
    ],
56
    include_package_data=True,
57
    package_data={'e2edutch': ["cfg/*.conf", "coref_kernels.so"]},
58
    cmdclass={
59
        "build_py": BuildPyCommand
60
    },
61
    test_suite='test',
62
    python_requires='>=3.6',
63
    install_requires=[
64
        "tensorflow>=2.0.0",
65
        "h5py",
66
        "pyhocon",
67
        "scipy",
68
        "scikit-learn",
69
        "torch<=1.7.1",
70
        "transformers<=3.5.1",
71
        "KafNafParserPy",
72
        "stanza"
73
    ],
74
    tests_require=[
75
        'pytest',
76
        'pytest-cov',
77
        'pycodestyle',
78
    ],
79
    extras_require={"doc": ["sphinx",
80
                            "m2r2"]}
81
)
82