-
Notifications
You must be signed in to change notification settings - Fork 48
/
setup.py
117 lines (96 loc) · 4.56 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
import os
import shutil
import subprocess
from pathlib import Path
import setuptools
from ruamel.yaml import YAML
from VERSION_PYTHON import __version_minimum_python__, __version_maximum_python__
project_root_dir = Path(__file__).parent
version_file = project_root_dir / "VERSION.py"
# noinspection PyBroadException
try:
git_version = subprocess.check_output(["git", "describe", "--tag", "--abbrev=0"]).decode("utf-8").strip()
pypi_version = git_version[1:]
except Exception:
with open(version_file, "r") as vf:
git_version = vf.read().strip().split("=")[-1].strip().replace('"', '')
pypi_version = git_version[1:]
with open(version_file, "w") as vf:
print("Updating \"VERSION.py\" with YFPY version from git tag before packaging...")
vf.write(
f"# DO NOT EDIT - VERSIONING CONTROLLED BY GIT TAGS{os.linesep}__version__ = \"{git_version}\"{os.linesep}")
if Path("build").exists():
print("Removing stale \"build\" directory before packaging...")
shutil.rmtree("build")
if Path("dist").exists():
print("Removing stale \"dist\" directory before packaging...")
shutil.rmtree("dist")
if Path("yfpy.egg-info").exists():
print("Removing stale \"yfpy.egg-info\" directory before packaging...")
shutil.rmtree("yfpy.egg-info")
with open("README.md", "r", encoding="utf8") as docs:
long_description = docs.read()
with open("requirements.txt", "r", encoding="utf8") as reqs:
required = reqs.read().splitlines()
supported_python_major_versions = [
version for version in
range(int(__version_minimum_python__.split(".")[0]), (int(__version_maximum_python__.split(".")[0]) + 1))
]
supported_python_minor_versions = [
version for version in
range(int(__version_minimum_python__.split(".")[-1]), (int(__version_maximum_python__.split(".")[-1]) + 1))
]
docker_compose_yaml_file = project_root_dir / "compose.yaml"
if docker_compose_yaml_file.exists():
print("Updating \"compose.yaml\" with YFPY version from git tag before packaging...")
yaml = YAML(typ="rt")
docker_compose_yaml = yaml.load(docker_compose_yaml_file)
docker_compose_yaml["services"]["package"]["image"] = (
f"{docker_compose_yaml['services']['package']['image'].split(':')[0]}:{git_version.replace('v', '')}"
)
yaml.default_flow_style = False
yaml.dump(docker_compose_yaml, docker_compose_yaml_file)
docker_compose_build_yaml_file = project_root_dir / "compose.build.yaml"
if docker_compose_build_yaml_file.exists():
print("Updating \"compose.build.yaml\" with Python version from .env before packaging...")
yaml = YAML(typ="rt")
docker_compose_build_yaml = yaml.load(docker_compose_build_yaml_file)
updated_build_args = []
for build_arg in docker_compose_build_yaml["services"]["package"]["build"]["args"]:
build_arg_key, build_arg_value = build_arg.split("=")
if build_arg_key == "PYTHON_VERSION_MAJOR":
build_arg_value = supported_python_major_versions[0]
elif build_arg_key == "PYTHON_VERSION_MINOR":
build_arg_value = supported_python_minor_versions[-1]
updated_build_args.append(f"{build_arg_key}={build_arg_value}")
docker_compose_build_yaml["services"]["package"]["build"]["args"] = updated_build_args
yaml.default_flow_style = False
yaml.dump(docker_compose_build_yaml, docker_compose_build_yaml_file)
setuptools.setup(
name="yfpy",
version=pypi_version,
author="Wren J. R.",
author_email="[email protected]",
description="Python API wrapper for the Yahoo Fantasy Sports public API.",
long_description=long_description,
long_description_content_type="text/markdown",
keywords="yahoo fantasy sports api wrapper nfl football nhl hockey mlb baseball nba basketball",
url="https://github.com/uberfastman/yfpy",
download_url=f"https://github.com/uberfastman/yfpy/archive/{git_version}.tar.gz",
packages=setuptools.find_packages(),
classifiers=[
f"Programming Language :: Python :: {supported_python_major_versions[0]}",
*[
f"Programming Language :: Python :: {supported_python_major_versions[0]}.{version}"
for version in supported_python_minor_versions
],
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
"Operating System :: OS Independent",
"Development Status :: 5 - Production/Stable",
"Topic :: Software Development :: Libraries :: Python Modules",
"Environment :: Console",
"Intended Audience :: Developers"
],
python_requires=f">={__version_minimum_python__}",
install_requires=required
)