-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsetup.py
executable file
·178 lines (136 loc) · 5.58 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
"""
deadlinks
~~~~~~~~~
deadlinks checker for your static website. It's better keep house clean, right?
"""
import os
from collections import defaultdict
from pathlib import Path
from re import compile as _compile
from re import match
from typing import Dict, List # pylint: disable-msg=W0611
from setuptools import find_packages, setup
# -- Common Functions ----------------------------------------------------------
DUNDER_REGEXP = _compile(r'(__(.*?)__ = "(.*?)")\n')
def read_data() -> Dict[str, str]:
""" Read data from __versions__ py """
init = Path(".").parent / "deadlinks" / "__version__.py"
if not Path(init).is_file():
raise RuntimeError("Can not find source for deadlinks/__version__.py")
values = dict() # type: Dict[str, str]
with open(init) as fh:
content = "".join(fh.readlines())
for str_match in DUNDER_REGEXP.findall(content):
values[str_match[1]] = str_match[2]
return values
def require(section: str = "install") -> List[str]:
""" Requirements txt parser. """
require_txt = Path(".").parent / "requirements.txt"
if not Path(require_txt).is_file():
return []
requires = defaultdict(list) # type: Dict[str, List[str]]
with open(require_txt, "rb") as fh:
key = "" # type: str
for line in fh.read().decode("utf-8").split("\n"):
if not line.strip():
" empty line "
continue
if line[0] == "#":
" section key "
key = line[2:]
continue
# actual package
requires[key].append(line.strip())
return requires[section]
def readme() -> str:
""" different version of readme changed for pypi """
readme = Path(".").parent / "README.md"
if not Path(readme).is_file():
return ""
contents = " "
with open("README.md", encoding="utf8") as f:
contents = f.read()
# cutout first 3 lines (header + PiPy version badge)
contents = "\n".join(contents.split("\n")[3:])
return contents
# ------------------------------------------------------------------------------
# ~~ Version Releases / Start ~~
# PyPi: only releases (x.y.z)
data = read_data()
branch = os.environ.get('DEADLINKS_BRANCH', None)
commit = os.environ.get('DEADLINKS_COMMIT', None)
tagged = os.environ.get('DEADLINKS_TAGGED', None)
VERSION = r'^\d{1,}.\d{1,}.\d{1,}$' # type: str
if os.environ.get('DEADLINKS_VERSION', None) is not None:
data['app_version'] += os.environ.get('DEADLINKS_VERSION', None)
elif tagged and not match(VERSION, tagged) and branch and commit:
dev_version_file = Path(__file__).parent / "deadlinks" / "__develop__.py"
dev_version_str = f".{branch}.{commit}".rstrip("+")
with open(str(dev_version_file), "w") as f:
print(f"version = '{dev_version_str}'", file=f)
data['app_version'] += dev_version_str
# -- Version Releases / End ~~
# -- Setup ---------------------------------------------------------------------
if __name__ == "__main__":
setup(
name=data['app_package'],
version=data['app_version'],
description=data['description'],
long_description=readme(),
long_description_content_type="text/markdown",
keywords=["documentation", "website", "spider", "crawler", "link-checker"],
author=data['author_name'],
author_email=data['author_mail'],
project_urls={
"GitHub: repo": "https://github.com/butuzov/deadlinks",
"Bugtracker": "https://github.com/butuzov/deadlinks/issues",
"Documentation": "http://deadlinks.readthedocs.io/",
"Documentation (latest)": "https://deadlinks.readthedocs.io/en/latest/",
"Dockerized": "https://hub.docker.com/repository/docker/butuzov/deadlinks/",
},
packages=find_packages(exclude=["tests*"]),
install_requires=require("install"),
entry_points='''
[console_scripts]
deadlinks=deadlinks.__main__:main
''',
zip_safe=False,
python_requires='>=3.6',
url=data['app_website'],
license=data['app_license'],
platforms=['MacOS', 'Posix', 'Unix'],
classifiers=[
# Env
"Environment :: Console",
# Status
"Development Status :: 5 - Production/Stable",
# Audience
"Intended Audience :: Developers",
"Intended Audience :: System Administrators",
# Topic
"Topic :: Utilities",
"Topic :: Documentation",
"Topic :: Internet :: WWW/HTTP :: Indexing/Search",
"Topic :: Internet :: WWW/HTTP :: Site Management",
"Topic :: Internet :: WWW/HTTP :: Site Management :: Link Checking",
# Audience and Topic
"Intended Audience :: Developers",
"Intended Audience :: System Administrators",
# Python version
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
# License
"License :: OSI Approved :: Apache Software License",
# Operation System
"Operating System :: MacOS",
"Operating System :: POSIX",
"Operating System :: Unix",
# Language
"Natural Language :: English",
],
)