/
setup.py
102 lines (89 loc) · 3.04 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
# -*- coding:utf-8 -*-
import os
import re
import string
from configparser import ConfigParser
from contextlib import contextmanager
from setuptools import setup, find_packages
def get_version(package):
"""
Return package version as listed in `__version__` in `__init__.py`.
"""
init_py = open(os.path.join(package, '__init__.py')).read()
mth = re.search("__version__\s?=\s?['\"]([^'\"]+)['\"]", init_py)
if mth:
return mth.group(1)
else:
raise RuntimeError("Cannot find version!")
def _compact_ver(name, ver):
if ver == '"*"' or ver.startswith("{"):
ver = ""
return '%s%s' % (name, ver.strip('"'))
def install_requires(dev=False):
"""
Return requires in requirements.txt
:return:
"""
try:
cfg = ConfigParser()
cfg.read('Pipfile')
section_name = "%spackages" % ("dev-" if dev else "")
requires = [_compact_ver(name, cfg.get(section_name, name))for name in cfg.options(section_name)]
if not dev:
with open("requirements.txt", "w") as f:
f.write("\n".join(requires))
return requires
except OSError:
return []
try:
LONG_DESCRIPTION = open("README.md").read()
except UnicodeDecodeError:
LONG_DESCRIPTION = open("README.md", encoding="utf-8").read()
@contextmanager
def cfg_manage(cfg_tpl_filename):
if os.path.exists(cfg_tpl_filename):
cfg_file_tpl = open(cfg_tpl_filename)
buffer = cfg_file_tpl.read()
try:
with open(cfg_tpl_filename.rstrip(".tpl"), "w") as cfg_file:
cfg_file.write(string.Template(buffer).substitute(
pwd=os.path.abspath(os.path.dirname(__file__))))
yield
finally:
cfg_file_tpl.close()
else:
yield
with cfg_manage(__file__.replace(".py", ".cfg.tpl")):
setup(
name="structure_spider",
version=get_version("structor"),
description="multi requests to combine a structure item.",
long_description=LONG_DESCRIPTION,
classifiers=[
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Intended Audience :: Developers",
"Operating System :: Unix",
],
long_description_content_type="text/markdown",
keywords="spider",
author="cn",
author_email="cnaafhvk@foxmail.com",
url="https://www.github.com/ShichaoMa/structure_spider",
entry_points={
'console_scripts': [
'feed = structor:feed',
'check = structor:check',
'startproject = structor:start_project',
'createspider = structor:create_spider',
"structure-spider = structor:run"
],
},
license="MIT",
packages=find_packages(exclude=("tests*",)),
install_requires=install_requires(),
include_package_data=True,
zip_safe=True,
setup_requires=["pytest-runner"],
tests_require=install_requires(dev=True)
)