generated from iamogbz/oss-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
126 lines (108 loc) · 3.98 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
"""Setup project file"""
import os
import sys
from datetime import datetime
from typing import (
Iterator,
List,
Set,
)
from setuptools import setup
# include nvshim src folder
sys.path.append("./src")
try:
from nvshim import __version__ as PACKAGE_VERSION
from nvshim.utils.constants import SHIMS as shims
finally:
pass
def readme() -> str:
"""Get all lines from read me file"""
return "\n".join(lines("README.md"))
def lines(filepath) -> "Iterator[str]":
"""Lines of a file generator"""
with open(filepath, encoding="UTF-8") as open_file:
while True:
line = open_file.readline()
if line:
yield line.strip()
else:
return
def get_requirements(filepath: str, visited: "List[str]") -> "List[str]":
"""
Get all pip requirements specified by a requirements file
with support for nested requirements files
:param filepath: path to requirements.txt file
:param visited: mutable list of visited requirements.txt files
:return: unordered list of requirements without versions
"""
requirements: "Set[str]" = set()
filepath = os.path.realpath(filepath)
rel_filepath = os.path.relpath(filepath)
if filepath in visited:
print("Skipping requirements:", rel_filepath)
print(visited)
else:
print("Parsing requirements:", rel_filepath)
visited.append(filepath)
req_file_delim = "-r"
req_package_delim = "=="
requirements_dir = os.path.dirname(filepath)
for line in lines(filepath):
if line.startswith("#"):
continue
if line.startswith(req_file_delim):
nested_req_file = line.split(req_file_delim)[1].strip()
nested_req_filepath = os.path.join(requirements_dir, nested_req_file)
requirements.union(get_requirements(nested_req_filepath, visited))
elif req_package_delim in line:
requirements.add(line.split(req_package_delim)[0])
return list(requirements)
def version_scheme(version) -> str:
"""Convert version to version string"""
if not os.getenv("CI"):
return PACKAGE_VERSION
if version.exact:
return version.format_with("{tag}")
return datetime.now().strftime("%Y.%m.%d.%H%M%S%f")
console_scripts = ["nvm=nvshim.core.shim_nvm:main"] + [
f"{s}=nvshim.core.shim:main" for s in shims
]
setup(
author="Emmanuel Ogbizi-Ugbe",
author_email="[email protected]",
classifiers=[
"Development Status :: 4 - Beta",
"Environment :: Console",
"Intended Audience :: Developers",
"Intended Audience :: End Users/Desktop",
"Intended Audience :: System Administrators",
"License :: OSI Approved :: GNU General Public License (GPL)",
"Operating System :: MacOS :: MacOS X",
"Operating System :: Microsoft :: Windows",
"Operating System :: POSIX",
"Programming Language :: Python",
"Topic :: Software Development",
],
description="Automagically use the correct version of node",
entry_points={"console_scripts": console_scripts},
include_package_data=True,
install_requires=get_requirements("requirements/prod.txt", []),
keywords="node nvm node-shim shim shell nvm-shim",
long_description=readme(),
long_description_content_type="text/markdown",
license="GNU",
name="nvshim",
packages=["nvshim", "nvshim.core", "nvshim.utils"],
package_dir={"": "src"},
python_requires=">=3",
setup_requires=["setuptools_scm"],
tests_require=get_requirements("requirements/test.txt", []),
url="http://github.com/iamogbz/nvshim",
# https://pypi.org/project/setuptools-scm/#configuration-parameters
use_scm_version={
"local_scheme": "no-local-version",
"version_scheme": version_scheme,
"write_to": "./src/nvshim/__init__.py",
"write_to_template": '"""Current package version"""\n__version__ = "{version}"\n',
},
)