setup.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #!/usr/bin/env python
  2. # Copyright 2021-2024 Avaiga Private Limited
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
  5. # the License. You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
  10. # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
  11. # specific language governing permissions and limitations under the License.
  12. """The setup script."""
  13. import json
  14. import os
  15. import platform
  16. from pathlib import Path
  17. import subprocess
  18. from setuptools import find_packages, setup
  19. from setuptools.command.build_py import build_py
  20. root_folder = Path(__file__).parent
  21. readme = Path(root_folder / "README.md").read_text("UTF-8")
  22. version_path = os.path.join(root_folder, "taipy/gui/version.json")
  23. setup_requirements = Path("taipy/gui/setup.requirements.txt")
  24. with open(version_path) as version_file:
  25. version = json.load(version_file)
  26. version_string = f'{version.get("major", 0)}.{version.get("minor", 0)}.{version.get("patch", 0)}'
  27. if vext := version.get("ext"):
  28. version_string = f"{version_string}.{vext}"
  29. requirements = [r for r in (setup_requirements).read_text("UTF-8").splitlines() if r]
  30. test_requirements = ["pytest>=3.8"]
  31. extras_require = {
  32. "ngrok": ["pyngrok>=5.1,<6.0"],
  33. "image": [
  34. "python-magic>=0.4.24,<0.5;platform_system!='Windows'",
  35. "python-magic-bin>=0.4.14,<0.5;platform_system=='Windows'",
  36. ],
  37. "arrow": ["pyarrow>=14.0.2,<15.0"],
  38. }
  39. class NPMInstall(build_py):
  40. def run(self):
  41. with_shell = platform.system() == "Windows"
  42. print(f"Building taipy-gui frontend bundle in {root_folder}.")
  43. already_exists = (root_folder / "taipy" / "gui" / "webapp" / "index.html").exists()
  44. if already_exists:
  45. print(f'Found taipy-gui frontend bundle in {root_folder / "taipy" / "gui" / "webapp"}.')
  46. else:
  47. subprocess.run(
  48. ["npm", "ci"], cwd=root_folder / "frontend" / "taipy-gui" / "dom", check=True, shell=with_shell
  49. )
  50. subprocess.run(
  51. ["npm", "ci", "--omit=optional"],
  52. cwd=root_folder / "frontend" / "taipy-gui",
  53. check=True,
  54. shell=with_shell,
  55. )
  56. subprocess.run(
  57. ["npm", "run", "build"], cwd=root_folder / "frontend" / "taipy-gui", check=True, shell=with_shell
  58. )
  59. build_py.run(self)
  60. setup(
  61. author="Avaiga",
  62. author_email="dev@taipy.io",
  63. python_requires=">=3.9",
  64. classifiers=[
  65. "Intended Audience :: Developers",
  66. "License :: OSI Approved :: Apache Software License",
  67. "Natural Language :: English",
  68. "Programming Language :: Python :: 3",
  69. "Programming Language :: Python :: 3.9",
  70. "Programming Language :: Python :: 3.10",
  71. "Programming Language :: Python :: 3.11",
  72. "Programming Language :: Python :: 3.12",
  73. ],
  74. description="Low-code library to create graphical user interfaces on the Web for your Python applications.",
  75. long_description=readme,
  76. long_description_content_type="text/markdown",
  77. install_requires=requirements,
  78. license="Apache License 2.0",
  79. include_package_data=True,
  80. keywords="taipy-gui",
  81. name="taipy-gui",
  82. packages=find_packages(where=root_folder, include=["taipy", "taipy.gui", "taipy.gui.*"]),
  83. test_suite="tests",
  84. tests_require=test_requirements,
  85. url="https://github.com/avaiga/taipy-gui",
  86. version=version_string,
  87. zip_safe=False,
  88. extras_require=extras_require,
  89. cmdclass={"build_py": NPMInstall},
  90. )