-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·134 lines (119 loc) · 4.42 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Setup script for configuring, packaging, distributing and installing this Python package.
#
# Package information
# - Name: kgw
# - Author: Robert Haas
# - Email: [email protected]
# - License: See LICENSE in the package root directory
# - Copyright notice: See NOTICE in the package root directory
#
# References for best practices in creating Python packages
# - Python Packaging User Guide (PyPUG): https://packaging.python.org
# - Python Packaging Authority (PyPA): https://www.pypa.io
# - Python Package Index (PyPI): https://pypi.org
# - Setuptools: https://setuptools.readthedocs.io
# - PEP 440 about versioning: https://www.python.org/dev/peps/pep-0440
# - Semantic Versioning (SemVer): https://semver.org
import re
from codecs import open
from os import path
from setuptools import find_packages, setup
def locate_package_directory():
"""Identify directory of the package and its associated files."""
try:
return path.abspath(path.dirname(__file__))
except Exception:
message = (
"The directory in which the package and its "
"associated files are stored could not be located."
)
raise ValueError(message)
def read_file(filepath):
"""Read content from an UTF-8 encoded text file"""
with open(filepath, "r", encoding="utf-8") as file_handle:
text = file_handle.read()
return text
def load_long_description(pkg_dir):
"""Load long description from file README.rst"""
try:
filepath_readme = path.join(pkg_dir, "README.rst")
return read_file(filepath_readme)
except Exception:
message = "Long description could not be read from README.rst"
raise ValueError(message)
def is_canonical(version):
"""Check if a version string is in canonical format of PEP 440."""
# Source: https://www.python.org/dev/peps/pep-0440
pattern = (
r"^([1-9][0-9]*!)?(0|[1-9][0-9]*)(\.(0|[1-9][0-9]*))"
r"*((a|b|rc)(0|[1-9][0-9]*))?(\.post(0|[1-9][0-9]*))"
r"?(\.dev(0|[1-9][0-9]*))?$"
)
return re.match(pattern, version) is not None
def load_version(pkg_dir, pkg_name):
"""Load version from variable __version__ in file __init__.py"""
try:
# Read file
filepath_init = path.join(pkg_dir, pkg_name, "__init__.py")
file_content = read_file(filepath_init)
# Parse version string with regular expression
re_for_version = re.compile(r"""__version__\s+=\s+['"](.*)['"]""")
match = re_for_version.search(file_content)
version_string = match.group(1)
except Exception:
message = (
"Version could not be read from variable " "__version__ in file __init__.py"
)
raise ValueError(message)
# Check validity
if not is_canonical(version_string):
message = (
'The detected version string "{}" is not in canonical '
"format as defined in PEP 440.".format(version_string)
)
raise ValueError(message)
return version_string
PKG_NAME = "kgw"
PKG_DIR = locate_package_directory()
setup(
# Basic package information
name=PKG_NAME,
version=load_version(PKG_DIR, PKG_NAME),
author="Robert Haas",
author_email="[email protected]",
description="Knowledge Graph Workflows",
long_description=load_long_description(PKG_DIR),
url="https://github.com/robert-haas/kgw",
license="Apache License, Version 2.0",
# Classifiers: available ones listed at https://pypi.org/classifiers
classifiers=[
"Development Status :: 4 - Beta",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: Apache Software License",
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Topic :: Scientific/Engineering",
],
# Included files
# a) auto-detected Python packages
packages=find_packages(),
# b) data files that are specified in the MANIFEST.in file
include_package_data=True,
# Dependencies that need to be fulfilled
python_requires=">=3.6",
# Dependencies that are downloaded by pip on installation
install_requires=[
"bs4",
"gravis",
"luigi",
"networkx",
"orjson",
"requests",
],
# Capability of running in compressed form
zip_safe=False,
)