mindsdb
/
setup.py
175 строк · 5.9 Кб
1import os2import glob3
4from setuptools import find_packages, setup5
6# A special env var that allows us to disable the installation of the default extras for advanced users / containers / etc
7MINDSDB_PIP_INSTALL_DEFAULT_EXTRAS = (8True9if os.getenv("MINDSDB_PIP_INSTALL_DEFAULT_EXTRAS", "true").lower() == "true"10else False11)
12DEFAULT_PIP_EXTRAS = [13line.split("#")[0].rstrip()14for line in open("default_handlers.txt").read().splitlines()15if not line.strip().startswith("#")16]
17
18
19class Deps:20pkgs = []21pkgs_exclude = ["tests", "tests.*"]22new_links = []23extras = {}24
25
26about = {}27with open("mindsdb/__about__.py") as fp:28exec(fp.read(), about)29
30
31with open("README.md", "r", encoding="utf8") as fh:32long_description = fh.read()33
34
35def expand_requirements_links(requirements: list) -> list:36"""Expand requirements that contain links to other requirement files"""37to_add = []38to_remove = []39
40for requirement in requirements:41if requirement.startswith("-r "):42if os.path.exists(requirement.split()[1]):43with open(requirement.split()[1]) as fh:44to_add += expand_requirements_links(45[req.strip() for req in fh.read().splitlines()]46)47to_remove.append(requirement)48
49for req in to_remove:50requirements.remove(req)51for req in to_add:52requirements.append(req)53
54return list(set(requirements)) # Remove duplicates55
56
57def define_deps():58"""Reads requirements.txt requirements-extra.txt files and preprocess it59to be feed into setuptools.
60
61This is the only possible way (we found)
62how requirements.txt can be reused in setup.py
63using dependencies from private github repositories.
64
65Links must be appendend by `-{StringWithAtLeastOneNumber}`
66or something like that, so e.g. `-9231` works as well as
67`1.1.0`. This is ignored by the setuptools, but has to be there.
68
69Warnings:
70to make pip respect the links, you have to use
71`--process-dependency-links` switch. So e.g.:
72`pip install --process-dependency-links {git-url}`
73
74Returns:
75list of packages, extras and dependency links.
76"""
77with open(os.path.normpath('requirements/requirements.txt')) as req_file:78defaults = [req.strip() for req in req_file.read().splitlines()]79
80links = []81requirements = []82for r in defaults:83if 'git+https' in r:84pkg = r.split('#')[-1]85links.append(r + '-9876543210')86requirements.append(pkg.replace('egg=', ''))87else:88requirements.append(r.strip())89
90extra_requirements = {}91full_requirements = []92for fn in os.listdir(os.path.normpath('./requirements')):93extra = []94if fn.startswith('requirements-') and fn.endswith('.txt'):95extra_name = fn.replace('requirements-', '').replace('.txt', '')96with open(os.path.normpath(f"./requirements/{fn}")) as fp:97extra = [req.strip() for req in fp.read().splitlines()]98extra_requirements[extra_name] = extra99full_requirements += extra100
101extra_requirements['all_extras'] = list(set(full_requirements))102
103full_handlers_requirements = []104handlers_dir_path = os.path.normpath('./mindsdb/integrations/handlers')105for fn in os.listdir(handlers_dir_path):106if os.path.isdir(os.path.join(handlers_dir_path, fn)) and fn.endswith(107"_handler"108):109extra = []110for req_file_path in glob.glob(111os.path.join(handlers_dir_path, fn, "requirements*.txt")112):113extra_name = fn.replace("_handler", "")114file_name = os.path.basename(req_file_path)115if file_name != "requirements.txt":116extra_name += "-" + file_name.replace("requirements_", "").replace(117".txt", ""118)119
120# If requirements.txt in our handler folder, import them as our extra's requirements121if os.path.exists(req_file_path):122with open(req_file_path) as fp:123extra = expand_requirements_links(124[req.strip() for req in fp.read().splitlines()]125)126
127extra_requirements[extra_name] = extra128full_handlers_requirements += extra129
130# Even with no requirements in our handler, list the handler as an extra (with no reqs)131else:132extra_requirements[extra_name] = []133
134# If this is a default extra and if we want to install defaults (enabled by default)135# then add it to the default requirements needing to install136if (137MINDSDB_PIP_INSTALL_DEFAULT_EXTRAS
138and extra_name in DEFAULT_PIP_EXTRAS139and extra140):141requirements += extra142
143extra_requirements['all_handlers_extras'] = list(set(full_handlers_requirements))144
145Deps.pkgs = requirements146Deps.extras = extra_requirements147Deps.new_links = links148
149return Deps150
151
152deps = define_deps()153
154setup(155name=about['__title__'],156version=about['__version__'],157url=about['__github__'],158download_url=about['__pypi__'],159license=about['__license__'],160author=about['__author__'],161author_email=about['__email__'],162description=about['__description__'],163long_description=long_description,164long_description_content_type="text/markdown",165packages=find_packages(exclude=deps.pkgs_exclude),166install_requires=deps.pkgs,167dependency_links=deps.new_links,168extras_require=deps.extras,169include_package_data=True,170classifiers=[171"Programming Language :: Python :: 3",172"Operating System :: OS Independent",173],174python_requires=">=3.8,<=3.10",175)
176