From 141a146b68fa906c01c15bc5586706bc4f00fb3d Mon Sep 17 00:00:00 2001 From: ryanmerolle Date: Thu, 2 Feb 2023 21:53:50 +0000 Subject: [PATCH] refactor setup.py for good form --- setup.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/setup.py b/setup.py index 50d4055..5059faa 100644 --- a/setup.py +++ b/setup.py @@ -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 "'"