Skip to content

Commit

Permalink
read version from file
Browse files Browse the repository at this point in the history
  • Loading branch information
andgineer committed Mar 30, 2024
1 parent 3d68e06 commit f1d128d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@
# This includes the license file(s) in the wheel.
# https://wheel.readthedocs.io/en/stable/user_guide.html#including-license-files-in-the-generated-wheel-file
license_files = LICENSE.txt
version = attr: audiobook_tags.version.VERSION
20 changes: 20 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import codecs
import os

import setuptools

with open("README.md", "r", encoding="utf-8") as f:
Expand All @@ -6,9 +9,26 @@
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:
"""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]
raise RuntimeError("Unable to find version string.")


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

0 comments on commit f1d128d

Please sign in to comment.