-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsetup.py
More file actions
174 lines (131 loc) · 4.87 KB
/
setup.py
File metadata and controls
174 lines (131 loc) · 4.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import os
import shutil
import subprocess
import sys
from setuptools import find_packages, setup
def _truthy(value: object) -> bool:
if value is None:
return False
if isinstance(value, bool):
return value
if isinstance(value, (int, float)):
return value != 0
if isinstance(value, str):
return value.strip().lower() in {"1", "true", "yes", "y", "on"}
return False
def _auto_install_binaries_enabled() -> bool:
return _truthy(os.environ.get("IPFS_KIT_AUTO_INSTALL_BINARIES"))
def _default_bin_dir() -> str:
override = os.environ.get("IPFS_KIT_BIN_DIR")
if override:
return os.path.expanduser(override)
return os.path.join(os.path.expanduser("~"), ".local", "share", "ipfs_kit_py", "bin")
def _try_install_binaries() -> None:
if not _auto_install_binaries_enabled():
return
bin_dir = _default_bin_dir()
os.makedirs(bin_dir, exist_ok=True)
try:
from ipfs_kit_py.install_ipfs import install_ipfs
if shutil.which("ipfs") is None:
install_ipfs(metadata={"bin_dir": bin_dir}).install_ipfs_daemon()
except Exception as e:
print(f"WARNING: IPFS auto-install during setup failed: {e}", file=sys.stderr)
try:
from ipfs_kit_py.install_lotus import install_lotus
if shutil.which("lotus") is None:
install_lotus(metadata={"bin_dir": bin_dir}).install_lotus_daemon()
except Exception as e:
print(f"WARNING: Lotus auto-install during setup failed: {e}", file=sys.stderr)
def _warn_missing_lotus_packages() -> None:
"""Emit a friendly warning if Lotus system dependencies are missing."""
if os.environ.get("IPFS_KIT_SKIP_LOTUS_CHECK", "").lower() in {"1", "true", "yes"}:
return
if not sys.platform.startswith("linux"):
return
if not shutil.which("dpkg-query"):
return
required_packages = [
"hwloc",
"libhwloc-dev",
"mesa-opencl-icd",
"ocl-icd-opencl-dev",
]
missing_packages = []
for package in required_packages:
try:
result = subprocess.run(
["dpkg-query", "-W", "-f=${Status}", package],
capture_output=True,
text=True,
check=False,
)
except (OSError, subprocess.SubprocessError):
return
if "install ok installed" not in result.stdout:
missing_packages.append(package)
if missing_packages:
install_hint = (
"sudo apt-get update && sudo apt-get install -y "
+ " ".join(required_packages)
)
print(
"WARNING: Lotus prerequisites missing: "
+ ", ".join(missing_packages)
+ f". Install them with: {install_hint}",
file=sys.stderr,
)
_warn_missing_lotus_packages()
# This file is maintained for backwards compatibility
# Most configuration is now in pyproject.toml
def _load_pyproject_metadata() -> tuple[dict, list[str], dict[str, list[str]]]:
"""Load PEP 621 metadata from pyproject.toml.
This keeps legacy setup.py installs aligned with the canonical configuration.
"""
here = os.path.abspath(os.path.dirname(__file__))
pyproject_path = os.path.join(here, "pyproject.toml")
try:
import tomllib # Python 3.11+
with open(pyproject_path, "rb") as f:
data = tomllib.load(f)
except Exception:
return {}, [], {}
project = data.get("project", {})
dependencies = list(project.get("dependencies", []) or [])
optional_dependencies = dict(project.get("optional-dependencies", {}) or {})
return project, dependencies, optional_dependencies
project, install_requires, extras_require = _load_pyproject_metadata()
cmdclass = {}
try:
from setuptools.command.install import install as _install
class install(_install): # noqa: N801 - setuptools cmdclass name
def run(self):
super().run()
_try_install_binaries()
cmdclass["install"] = install
except Exception:
pass
try:
from setuptools.command.develop import develop as _develop
class develop(_develop): # noqa: N801 - setuptools cmdclass name
def run(self):
super().run()
_try_install_binaries()
cmdclass["develop"] = develop
except Exception:
pass
setup(
name='ipfs_kit_py',
version='0.3.0',
description='Python toolkit for IPFS with high-level API, cluster management, tiered storage, and AI/ML integration',
author='Benjamin Barber',
author_email='starworks5@gmail.com',
url='https://github.com/endomorphosis/ipfs_kit_py/',
python_requires='>=3.12',
packages=find_packages(include=["ipfs_kit_py*", "external*"]),
include_package_data=True,
install_requires=install_requires,
extras_require=extras_require,
cmdclass=cmdclass,
# All other configurations come from pyproject.toml
)