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
|
#!/usr/bin/python3
# ruff: noqa
"""The setup and build script for the library named "PACKAGE_NAME"."""
import os
import subprocess
import sys
from distutils.core import Command
PACKAGE_NAME = "recurring_ical_events"
HERE = os.path.abspath(os.path.dirname(__file__))
sys.path.insert(0, HERE) # for package import
__version__ = "3.3.3"
__author__ = "Nicco Kunzmann"
def read_file_named(file_name):
file_path = os.path.join(HERE, file_name)
with open(file_path) as file:
return file.read()
def read_requirements_file(file_name):
content = read_file_named(file_name)
lines = []
for line in content.splitlines():
comment_index = line.find("#")
if comment_index >= 0:
line = line[:comment_index]
line = line.strip()
if not line:
continue
lines.append(line)
return lines
# The base package metadata to be used by both distutils and setuptools
METADATA = dict(
name=PACKAGE_NAME,
version=__version__,
py_modules=[PACKAGE_NAME],
author=__author__,
author_email="niccokunzmann@rambler.ru",
description="Calculate recurrence times of events, todos and journals based on icalendar RFC5545.",
license="LGPL-3.0-or-later",
url="https://github.com/niccokunzmann/python-recurring-ical-events",
keywords="icalendar",
)
# set development status from __version__
DEVELOPMENT_STATES = {
"p": "Development Status :: 1 - Planning",
"pa": "Development Status :: 2 - Pre-Alpha",
"a": "Development Status :: 3 - Alpha",
"b": "Development Status :: 4 - Beta",
"": "Development Status :: 5 - Production/Stable",
"m": "Development Status :: 6 - Mature",
"i": "Development Status :: 7 - Inactive",
}
development_state = DEVELOPMENT_STATES[""]
for ending in DEVELOPMENT_STATES:
if ending and __version__.endswith(ending):
development_state = DEVELOPMENT_STATES[ending]
if not __version__[-1:].isdigit():
METADATA["version"] += "0"
# tag and upload to github to autodeploy with travis
class TagAndDeployCommand(Command):
description = (
"Create a git tag for this version and push it to origin."
"To trigger a travis-ci build and and deploy."
)
user_options = []
name = "tag_and_deploy"
remote = "origin"
branch = "main"
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
if subprocess.call(["git", "--version"]) != 0:
print("ERROR:\n\tPlease install git.")
exit(1)
status_lines = subprocess.check_output(["git", "status"]).splitlines()
current_branch = status_lines[0].strip().split()[-1].decode()
print(f"On branch {current_branch}.")
if current_branch != self.branch:
print(
f'ERROR:\n\tNew tags can only be made from branch "{self.branch}".' ""
)
print(
f'\tYou can use "git checkout {self.branch}" to switch the branch.' ""
)
exit(1)
tags_output = subprocess.check_output(["git", "tag"])
tags = [tag.strip().decode() for tag in tags_output.splitlines()]
tag = "v" + METADATA["version"]
if tag in tags:
print(f"Warning: \n\tTag {tag} already exists.")
print(
"\tEdit the version information in {}".format(
os.path.join(HERE, PACKAGE_NAME, "__init__.py"),
)
)
else:
print(f'Creating tag "{tag}".')
subprocess.check_call(["git", "tag", tag])
print(f'Pushing tag "{tag}" to remote "{self.remote}".')
subprocess.check_call(["git", "push", self.remote, tag])
# Extra package metadata to be used only if setuptools is installed
required_packages = read_requirements_file("requirements.txt")
required_test_packages = read_requirements_file("test-requirements.txt")
SETUPTOOLS_METADATA = dict(
install_requires=required_packages,
tests_require=required_test_packages,
include_package_data=False,
classifiers=[ # https://pypi.python.org/pypi?%3Aaction=list_classifiers
"Intended Audience :: Developers",
"License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Utilities",
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
development_state,
],
zip_safe=True,
cmdclass={
TagAndDeployCommand.name: TagAndDeployCommand,
},
)
def main():
# Build the long_description from the README and CHANGES
METADATA["long_description"] = read_file_named("README.rst")
# Use setuptools if available, otherwise fallback and use distutils
try:
import setuptools
METADATA.update(SETUPTOOLS_METADATA)
setuptools.setup(**METADATA)
except ImportError:
import distutils.core
distutils.core.setup(**METADATA)
if __name__ == "__main__":
main()
|