Skip to content

Commit c4ef719

Browse files
authored
fix: Add name and version to setup.py for older version of pip (#109)
1 parent 92b90b4 commit c4ef719

File tree

2 files changed

+49
-5
lines changed

2 files changed

+49
-5
lines changed

Diff for: pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
55

66
[project]
77
name = "table2ascii"
8-
version = "1.1.1"
8+
version = "1.1.2"
99
authors = [{name = "Jonah Lawrence", email = "[email protected]"}]
1010
description = "Convert 2D Python lists into Unicode/ASCII tables"
1111
readme = "README.md"

Diff for: setup.py

+48-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,51 @@
11
# /usr/bin/env python
2+
import re
3+
24
from setuptools import setup
35

4-
setup(
5-
packages=["table2ascii"],
6-
package_data={"table2ascii": ["py.typed"]},
7-
)
6+
7+
def get_name():
8+
name = ""
9+
with open("pyproject.toml") as f:
10+
name = re.search(r'^name = ["\']([^"\']*)["\']', f.read(), re.M)
11+
if not name:
12+
raise RuntimeError("name is not set")
13+
return name.group(1)
14+
15+
16+
def get_version():
17+
version = ""
18+
with open("pyproject.toml") as f:
19+
version = re.search(r'^version = ["\']([^"\']*)["\']', f.read(), re.M)
20+
if not version:
21+
raise RuntimeError("version is not set")
22+
return version.group(1)
23+
24+
25+
def get_dependencies():
26+
with open("pyproject.toml") as f:
27+
dependency_match = re.search(r"^dependencies = \[([\s\S]*?)\]", f.read(), re.M)
28+
if not dependency_match or not dependency_match.group(1):
29+
return []
30+
return [
31+
dependency.strip().strip(",").strip('"')
32+
for dependency in dependency_match.group(1).split("\n")
33+
if dependency
34+
]
35+
36+
37+
try:
38+
# check if pyproject.toml can be used to install dependencies and set the version
39+
setup(
40+
packages=[get_name()],
41+
package_data={get_name(): ["py.typed"]},
42+
)
43+
except Exception:
44+
# fallback for old versions of pip/setuptools
45+
setup(
46+
name=get_name(),
47+
packages=[get_name()],
48+
package_data={get_name(): ["py.typed"]},
49+
version=get_version(),
50+
install_requires=get_dependencies(),
51+
)

0 commit comments

Comments
 (0)