Skip to content

fix: Add name and version to setup.py for older version of pip #109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "[email protected]"}]
description = "Convert 2D Python lists into Unicode/ASCII tables"
readme = "README.md"
Expand Down
52 changes: 48 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,51 @@
# /usr/bin/env python
import re

from setuptools import setup

setup(
packages=["table2ascii"],
package_data={"table2ascii": ["py.typed"]},
)

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)
if not version:
raise RuntimeError("version is not set")
return version.group(1)


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(
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(),
)