Created
September 9, 2019 00:58
-
-
Save eigenfoo/8b644ca6518041e1742d1a7ca5739266 to your computer and use it in GitHub Desktop.
Template setup.py file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" Template setup.py file """ | |
from os.path import dirname, realpath, join, exists | |
from re import search, M | |
from setuptools import setup, find_packages | |
# TODO: add package details | |
NAME = "" | |
MAINTAINER = "" | |
MAINTAINER_EMAIL = "" | |
DESCRIPTION = "" | |
LICENSE = "" | |
URL = "" | |
PROJECT_URLS = {"Documentation": "", "Issue Tracker": ""} | |
PYTHON_REQUIRES = ">=3.6" | |
# TODO: add package classifiers https://pypi.org/classifiers | |
CLASSIFIERS = ["Natural Language :: English"] | |
# Find and parse README.md, requirements.txt and LICENSE | |
PROJECT_ROOT = dirname(realpath(__file__)) | |
REQUIREMENTS_FILE = join(PROJECT_ROOT, "requirements.txt") | |
README_FILE = join(PROJECT_ROOT, "README.md") | |
try: | |
with open(README_FILE, encoding="utf-8") as f: | |
LONG_DESCRIPTION = "\n" + f.read() | |
LONG_DESCRIPTION_CONTENT_TYPE = "text/markdown" | |
except FileNotFoundError: | |
LONG_DESCRIPTION = DESCRIPTION | |
LONG_DESCRIPTION_CONTENT_TYPE = "text/plain" | |
with open(REQUIREMENTS_FILE) as f: | |
INSTALL_REQUIRES = f.read().splitlines() | |
def get_version(): | |
""" Gets version number from package-level __init__.py through regex. """ | |
version_file = join(NAME, "__init__.py") | |
lines = open(version_file, "rt").readlines() | |
version_regex = r"^__version__ = ['\"]([^'\"]*)['\"]" | |
for line in lines: | |
matches = search(version_regex, line, M) | |
if matches: | |
return matches.group(1) | |
raise RuntimeError("Unable to find version in {}.".format(version_file)) | |
if __name__ == "__main__": | |
setup( | |
name=NAME, | |
version=get_version(), | |
url=URL, | |
project_urls=PROJECT_URLS, | |
maintainer=MAINTAINER, | |
maintainer_email=MAINTAINER_EMAIL, | |
classifiers=CLASSIFIERS, | |
license=LICENSE, | |
description=DESCRIPTION, | |
long_description=LONG_DESCRIPTION, | |
long_description_content_type=LONG_DESCRIPTION_CONTENT_TYPE, | |
packages=find_packages(), | |
python_requires=PYTHON_REQUIRES, | |
install_requires=INSTALL_REQUIRES, | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment