From 73a7aa353c375c06bafe91d5bc96d8e70a173204 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Boulogne?= Date: Tue, 23 Jul 2024 10:53:52 +0200 Subject: [PATCH] read version from lib --- labsw/__init__.py | 1 + setup.py | 21 +++++++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/labsw/__init__.py b/labsw/__init__.py index e69de29..7e6c45a 100644 --- a/labsw/__init__.py +++ b/labsw/__init__.py @@ -0,0 +1 @@ +__version__ == '0.1.2' diff --git a/setup.py b/setup.py index 62fbcf3..fae621f 100644 --- a/setup.py +++ b/setup.py @@ -1,20 +1,29 @@ +import os +import re from setuptools import setup, find_packages -from os import path -# Function to read the requirements from the requirements.txt file +def read_version(name): + with open(os.path.join(os.path.dirname(__file__), name, '__init__.py')) as f: + for line in f: + match = re.match(r"^__version__ = ['\"]([^'\"]*)['\"]", line) + if match: + return match.group(1) + raise RuntimeError("Unable to find version string.") + def parse_requirements(filename): with open(filename, 'r') as file: return file.read().splitlines() # Get the long description from the README file -here = path.abspath(path.dirname(__file__)) -with open(path.join(here, 'README.md'), encoding='utf-8') as f: - long_description = f.read() +here = os.path.abspath(os.path.dirname(__file__)) +with open(os.path.join(here, 'README.md'), encoding='utf-8') as f: + long_description = f.read() + setup( name='labsw', - version='0.1.0', # Required + version = read_version('labsw'), description='A short description of the project', # Optional long_description=long_description, # Optional long_description_content_type='text/markdown', # Optional (see note above)