auto-semver/setup.py

34 lines
910 B
Python
Raw Normal View History

2023-06-30 23:40:58 +02:00
import re
2023-06-30 23:55:38 +02:00
from pathlib import Path
from typing import List
2018-05-23 21:09:14 +02:00
2023-06-30 23:40:58 +02:00
# To use a consistent encoding
from codecs import open
2018-05-23 21:09:14 +02:00
# Always prefer setuptools over distutils
2023-06-30 23:55:38 +02:00
from setuptools import setup
2018-05-23 21:09:14 +02:00
2023-06-30 23:40:58 +02:00
here = Path(__file__).resolve().parent
2018-05-23 21:09:14 +02:00
# Get the long description from the README file
2023-06-30 23:40:58 +02:00
with open(Path(here, "README.md"), encoding="utf-8") as f:
2018-05-23 21:09:14 +02:00
long_description = f.read()
2023-06-30 23:55:38 +02:00
def find_version(*file_path: List[str]) -> str:
2023-06-30 23:40:58 +02:00
"""
Searches for the semantic version within the given path
:param file_path: Path to the file to search
:return: Semantic version as string
"""
version_file: str = open(Path(here, *file_path), "r").read()
version_match = re.search(r"^version = ['\"]([^'\"]*)['\"]", version_file, re.M)
if not version_match:
raise RuntimeError("Unable to find version string.")
2018-05-23 21:09:14 +02:00
2023-06-30 23:40:58 +02:00
return version_match.group(1)
2018-05-23 21:09:14 +02:00
2023-06-30 23:55:38 +02:00
setup(version=find_version("semver", "__init__.py"))