From c8b159bb7e7e39d91a60b56989fcab5b4780fdc5 Mon Sep 17 00:00:00 2001 From: Jonah Lawrence Date: Sun, 25 Jun 2023 11:32:16 -0600 Subject: [PATCH 1/3] fix: Add name and version to setup.py --- setup.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/setup.py b/setup.py index b21e3f6..07216b8 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,21 @@ # /usr/bin/env python +import re + from setuptools import setup + +def version(): + version = "" + with open("pyproject.toml") as f: + version = re.search(r'^version = ["\']([^"\']*)["\']', f.read(), re.M) + if not version: + raise RuntimeError("version is not set") + return version.group(1) + + setup( + name="table2ascii", + version=version(), packages=["table2ascii"], package_data={"table2ascii": ["py.typed"]}, ) From 91e30a0e071d62bea9c386c03c6744575e26a9d3 Mon Sep 17 00:00:00 2001 From: Jonah Lawrence Date: Sun, 16 Jul 2023 19:12:18 -0600 Subject: [PATCH 2/3] Get name and deps from pyproject into setup dynamically --- pyproject.toml | 2 +- setup.py | 45 ++++++++++++++++++++++++++++++++++++++------- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index fd814c1..e7343bd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta" [project] name = "table2ascii" -version = "1.1.1" +version = "1.1.2" authors = [{name = "Jonah Lawrence", email = "jonah@freshidea.com"}] description = "Convert 2D Python lists into Unicode/ASCII tables" readme = "README.md" diff --git a/setup.py b/setup.py index 07216b8..efc2302 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,16 @@ from setuptools import setup -def version(): +def get_name(): + name = "" + with open("pyproject.toml") as f: + name = re.search(r'^name = ["\']([^"\']*)["\']', f.read(), re.M) + if not name: + raise RuntimeError("name is not set") + return name.group(1) + + +def get_version(): version = "" with open("pyproject.toml") as f: version = re.search(r'^version = ["\']([^"\']*)["\']', f.read(), re.M) @@ -13,9 +22,31 @@ def version(): return version.group(1) -setup( - name="table2ascii", - version=version(), - packages=["table2ascii"], - package_data={"table2ascii": ["py.typed"]}, -) +def get_dependencies(): + with open("pyproject.toml") as f: + dependency_match = re.search(r"^dependencies = \[([\s\S]*?)\]", f.read(), re.M) + if not dependency_match or not dependency_match.group(1): + return [] + return [ + dependency.strip().strip(",").strip('"') + for dependency in dependency_match.group(1).split("\n") + if dependency + ] + + +try: + # check if pyproject.toml can be used to install dependencies and set the version + setup( + name=get_name(), + packages=[get_name()], + package_data={get_name(): ["py.typed"]}, + ) +except Exception: + # fallback for old versions of pip/setuptools + setup( + name=get_name(), + packages=[get_name()], + package_data={get_name(): ["py.typed"]}, + version=get_version(), + install_requires=get_dependencies(), + ) From c339af8ea3d063553d3f9775f29fd1a0da5ab8ba Mon Sep 17 00:00:00 2001 From: Jonah Lawrence Date: Sun, 16 Jul 2023 19:13:04 -0600 Subject: [PATCH 3/3] Remove name from default setup --- setup.py | 1 - 1 file changed, 1 deletion(-) diff --git a/setup.py b/setup.py index efc2302..9467adb 100644 --- a/setup.py +++ b/setup.py @@ -37,7 +37,6 @@ def get_dependencies(): try: # check if pyproject.toml can be used to install dependencies and set the version setup( - name=get_name(), packages=[get_name()], package_data={get_name(): ["py.typed"]}, )