refactor setup.py for good form

This commit is contained in:
ryanmerolle 2023-02-02 21:53:50 +00:00
parent b782862590
commit 141a146b68

View File

@ -1,21 +1,30 @@
"""
Configuration for setuptools.
"""
import codecs
import os.path
from setuptools import find_packages, setup
here = os.path.abspath(os.path.dirname(__file__))
script_dir = os.path.abspath(os.path.dirname(__file__))
with open(os.path.join(here, "README.md"), encoding="utf-8") as fh:
with open(os.path.join(script_dir, "README.md"), encoding="utf-8") as fh:
long_description = fh.read()
def read(rel_path):
with codecs.open(os.path.join(here, rel_path), "r") as fp:
def read(relative_path):
"""
Read a file and return its contents.
"""
with codecs.open(os.path.join(script_dir, relative_path), "r") as fp:
return fp.read()
def get_version(rel_path):
for line in read(rel_path).splitlines():
def get_version(relative_path):
"""
Extract the version number from a file without importing it.
"""
for line in read(relative_path).splitlines():
if not line.startswith("__version__"):
raise RuntimeError("Unable to find version string.")
delim = '"' if '"' in line else "'"