setup.py 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # Copyright 2021-2024 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 for taipy-gui package"""
  12. import json
  13. import os
  14. import platform
  15. from pathlib import Path
  16. import subprocess
  17. from setuptools import find_packages, setup
  18. from setuptools.command.build_py import build_py
  19. root_folder = Path(__file__).parent
  20. package_desc = Path(root_folder / "package_desc.md").read_text("UTF-8")
  21. version_path = os.path.join(root_folder, "taipy/gui/version.json")
  22. setup_requirements = Path("taipy/gui/setup.requirements.txt")
  23. with open(version_path) as version_file:
  24. version = json.load(version_file)
  25. version_string = f'{version.get("major", 0)}.{version.get("minor", 0)}.{version.get("patch", 0)}'
  26. if vext := version.get("ext"):
  27. version_string = f"{version_string}.{vext}"
  28. requirements = [r for r in (setup_requirements).read_text("UTF-8").splitlines() if r]
  29. test_requirements = ["pytest>=3.8"]
  30. extras_require = {
  31. "ngrok": ["pyngrok>=5.1,<6.0"],
  32. "image": [
  33. "python-magic>=0.4.24,<0.5;platform_system!='Windows'",
  34. "python-magic-bin>=0.4.14,<0.5;platform_system=='Windows'",
  35. ],
  36. "arrow": ["pyarrow>=14.0.2,<15.0"],
  37. }
  38. class NPMInstall(build_py):
  39. def run(self):
  40. with_shell = platform.system() == "Windows"
  41. print(f"Building taipy-gui frontend bundle in {root_folder}.")
  42. already_exists = (root_folder / "taipy" / "gui" / "webapp" / "index.html").exists()
  43. if already_exists:
  44. print(f'Found taipy-gui frontend bundle in {root_folder / "taipy" / "gui" / "webapp"}.')
  45. else:
  46. subprocess.run(
  47. ["npm", "ci"], cwd=root_folder / "frontend" / "taipy-gui" / "dom", check=True, shell=with_shell
  48. )
  49. subprocess.run(
  50. ["npm", "ci", "--omit=optional"],
  51. cwd=root_folder / "frontend" / "taipy-gui",
  52. check=True,
  53. shell=with_shell,
  54. )
  55. subprocess.run(
  56. ["npm", "run", "build"], cwd=root_folder / "frontend" / "taipy-gui", check=True, shell=with_shell
  57. )
  58. build_py.run(self)
  59. setup(
  60. version=version_string,
  61. install_requires=requirements,
  62. packages=find_packages(where=root_folder, include=["taipy", "taipy.gui", "taipy.gui.*"]),
  63. include_package_data=True,
  64. data_files=[("version", [version_path])],
  65. tests_require=test_requirements,
  66. extras_require=extras_require,
  67. cmdclass={"build_py": NPMInstall},
  68. )