setup.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. # Copyright 2023 Avaiga Private Limited
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
  4. # the License. You may obtain a copy of the License at
  5. #
  6. # http://www.apache.org/licenses/LICENSE-2.0
  7. #
  8. # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
  9. # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
  10. # specific language governing permissions and limitations under the License.
  11. """The setup script."""
  12. import json
  13. import os
  14. import sysconfig
  15. from importlib.util import find_spec
  16. from pathlib import Path
  17. from setuptools import find_namespace_packages, find_packages, setup
  18. from setuptools.command.build_py import build_py
  19. with open("README.md", "rb") as readme_file:
  20. readme = readme_file.read().decode("UTF-8")
  21. with open(f"src{os.sep}taipy{os.sep}version.json") as version_file:
  22. version = json.load(version_file)
  23. version_string = f'{version.get("major", 0)}.{version.get("minor", 0)}.{version.get("patch", 0)}'
  24. if vext := version.get("ext"):
  25. version_string = f"{version_string}.{vext}"
  26. requirements = [
  27. "backports.zoneinfo>=0.2.1,<0.3;python_version<'3.9'",
  28. "cookiecutter>=2.1.1,<2.2",
  29. "taipy-gui>=3.0,<3.1",
  30. "taipy-rest>=3.0,<3.1",
  31. "taipy-templates>=3.0,<3.1",
  32. ]
  33. setup_requirements = [(requirement for requirement in requirements if requirement.startswith("taipy-gui"))]
  34. test_requirements = ["pytest>=3.8"]
  35. extras_require = {
  36. "ngrok": ["pyngrok>=5.1,<6.0"],
  37. "image": [
  38. "python-magic>=0.4.24,<0.5;platform_system!='Windows'",
  39. "python-magic-bin>=0.4.14,<0.5;platform_system=='Windows'",
  40. ],
  41. "rdp": ["rdp>=0.8"],
  42. "arrow": ["pyarrow>=10.0.1,<11.0"],
  43. "mssql": ["pyodbc>=4"],
  44. }
  45. def _build_webapp():
  46. already_exists = Path("./src/taipy/gui_core/lib/taipy-gui-core.js").exists()
  47. if not already_exists:
  48. # default site-packages path is from the current python interpreter
  49. site_packages_path = sysconfig.get_path("purelib")
  50. # taipy-gui should be available through setup_requires option
  51. # taipy-gui at this step is installed in a backend site-packages separated from the one being used by pip
  52. if find_spec("taipy") and find_spec("taipy.gui"):
  53. import taipy
  54. site_packages_path = Path(taipy.__file__).absolute().parent.parent
  55. # Specify the correct path to taipy-gui in gui/.env file
  56. env_file_path = Path(__file__).absolute().parent / "gui" / ".env"
  57. if not os.path.exists(env_file_path):
  58. with open(env_file_path, "w") as env_file:
  59. env_file.write(f"TAIPY_GUI_DIR={site_packages_path}\n")
  60. os.system("cd gui && npm ci && npm run build")
  61. class NPMInstall(build_py):
  62. def run(self):
  63. _build_webapp()
  64. build_py.run(self)
  65. setup(
  66. author="Avaiga",
  67. author_email="dev@taipy.io",
  68. python_requires=">=3.8",
  69. classifiers=[
  70. "Intended Audience :: Developers",
  71. "License :: OSI Approved :: Apache Software License",
  72. "Natural Language :: English",
  73. "Programming Language :: Python :: 3",
  74. "Programming Language :: Python :: 3.8",
  75. "Programming Language :: Python :: 3.9",
  76. "Programming Language :: Python :: 3.10",
  77. "Programming Language :: Python :: 3.11",
  78. ],
  79. description="A 360° open-source platform from Python pilots to production-ready web apps.",
  80. setup_requires=setup_requirements,
  81. install_requires=requirements,
  82. entry_points={
  83. "console_scripts": [
  84. "taipy = taipy._entrypoint:_entrypoint",
  85. ]
  86. },
  87. license="Apache License 2.0",
  88. long_description=readme,
  89. long_description_content_type="text/markdown",
  90. keywords="taipy",
  91. name="taipy",
  92. package_dir={"": "src"},
  93. packages=find_namespace_packages(where="src") + find_packages(include=["taipy"]),
  94. include_package_data=True,
  95. test_suite="tests",
  96. url="https://github.com/avaiga/taipy",
  97. version=version_string,
  98. zip_safe=False,
  99. extras_require=extras_require,
  100. cmdclass={"build_py": NPMInstall},
  101. )