Skip to content

Commit

Permalink
simplify reading version
Browse files Browse the repository at this point in the history
  • Loading branch information
andgineer committed Mar 30, 2024
1 parent e78c9ea commit 17e4376
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,21 @@
with open("requirements.in") as f:
requirements = f.read().splitlines()

# Solution from https://packaging.python.org/guides/single-sourcing-package-version/
def read(rel_path: str) -> str:
"""Read file."""
here = os.path.abspath(os.path.dirname(__file__))
with codecs.open(os.path.join(here, rel_path), "r") as fp:
return fp.read()


def get_version(rel_path: str) -> str:
def get_version() -> str:
"""Parse version from file content."""
for line in read(rel_path).splitlines():
if line.startswith("VERSION"):
delim = '"' if '"' in line else "'"
return line.split(delim)[1]
with open("src/audiobook_tags/version.py") as f:
version_lines = f.read().splitlines()
for line in version_lines:
if line.startswith("VERSION"):
delim = '"' if '"' in line else "'"
return line.split(delim)[1]
raise RuntimeError("Unable to find version string.")


setuptools.setup(
name="audiobook-tags",
version=get_version("src/audiobook_tags/version.py"),
version=get_version(),
author="Andrey Sorokin",
author_email="andrey@sorokin.engineer",
description="Fix mp3 tags to use in iTunes/iPhone audiobooks",
Expand Down

0 comments on commit 17e4376

Please sign in to comment.