From 9fa63e8f627aa935c8c223d2775027bd2fbe2c5d Mon Sep 17 00:00:00 2001 From: Marcus Christie Date: Thu, 28 Sep 2023 17:18:26 -0400 Subject: [PATCH] Add support for building JS code when installed with pip --- MANIFEST.in | 2 + pyproject.toml | 6 +++ setup.cfg | 26 +++++++++++++ setup.py | 100 ++++++++++++++++++++++++------------------------- 4 files changed, 84 insertions(+), 50 deletions(-) create mode 100644 pyproject.toml diff --git a/MANIFEST.in b/MANIFEST.in index e75367c..99eb00b 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,3 +1,5 @@ recursive-include simccs_maptool/static * recursive-include simccs_maptool/templates * recursive-include simccs_maptool/simccs * +recursive-include frontend * +recursive-exclude frontend/node_modules * diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..374b58c --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,6 @@ +[build-system] +requires = [ + "setuptools>=42", + "wheel" +] +build-backend = "setuptools.build_meta" diff --git a/setup.cfg b/setup.cfg index 2bcd70e..2b58c03 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,2 +1,28 @@ +[metadata] +name = simccs-maptool +version = 0.0.1 +description = SimCCS MapTool plugin to Airavata Django Portal + +[options] +packages = find: +# Include data files as specified in MANIFEST.in +include_package_data = True +install_requires = + django >= 3.2 + cython + pyjnius + pyshp + airavata-django-portal-sdk + djangorestframework + # Pandas 1.2 requires Python 3.7+ and we need less than 1.2 until we drop 3.6 support + pandas < 1.2 + geopandas + +[options.entry_points] +airavata.djangoapp = + simccs_maptool = simccs_maptool.apps:MapToolConfig +airavata.output_view_providers = + cplex-solution-link = simccs_maptool.output_views:SolutionLinkProvider + [flake8] max-line-length = 88 diff --git a/setup.py b/setup.py index dde4ce0..f38dec8 100644 --- a/setup.py +++ b/setup.py @@ -1,58 +1,58 @@ import distutils +import logging import os import subprocess import setuptools -from setuptools.command.develop import develop -from setuptools.command.install import install def build_js(): - subprocess.check_call(["yarn", "install"], cwd=os.path.join(os.getcwd(), "frontend")) - subprocess.check_call(["yarn", "run", "build"], cwd=os.path.join(os.getcwd(), "frontend")) - - -# Build JS code when this package is installed in virtual env -# https://stackoverflow.com/a/36902139 -class BuildJSDevelopCommand(develop): - def run(self): - self.announce("Building JS code", level=distutils.log.INFO) - build_js() - super().run() - - -class BuildJSInstallCommand(install): - def run(self): - self.announce("Building JS code", level=distutils.log.INFO) - build_js() - super().run() - - -setuptools.setup( - name="simccs-maptool", - version="0.0.1", - description="SimCCS MapTool plugin to Airavata Django Portal", - packages=setuptools.find_packages(), - include_package_data=True, - install_requires=[ - 'django>=1.11.16', - 'cython', - 'pyjnius', - 'pyshp', - "airavata-django-portal-sdk", - 'djangorestframework', - # Pandas 1.2 requires Python 3.7+ and our deployments are currently on Python 3.6 - 'pandas<1.2', - 'geopandas' - ], - entry_points=""" -[airavata.djangoapp] -simccs_maptool = simccs_maptool.apps:MapToolConfig -[airavata.output_view_providers] -cplex-solution-link = simccs_maptool.output_views:SolutionLinkProvider -""", - cmdclass={ - 'develop': BuildJSDevelopCommand, - 'install': BuildJSInstallCommand, - } -) + subprocess.check_call(["yarn", "install"], + cwd=os.path.join(os.getcwd(), "frontend")) + subprocess.check_call(["yarn", "run", "build"], + cwd=os.path.join(os.getcwd(), "frontend")) + + +try: + from setuptools.command.build import build as _build + from setuptools.command.editable_wheel import \ + editable_wheel as _editable_wheel + + class build(_build): + def run(self) -> None: + self.announce("Building JS code", level=logging.INFO) + build_js() + super().run() + + class editable_wheel(_editable_wheel): + def run(self) -> None: + self.announce("Building JS code", level=logging.INFO) + build_js() + super().run() + + cmdclass = dict(build=build, editable_wheel=editable_wheel) + +except ImportError: + + # For older versions of setuptools (Python 3.6) + from setuptools.command.develop import develop as _develop + from setuptools.command.install import install as _install + + # Build JS code when this package is installed in virtual env + # https://stackoverflow.com/a/36902139 + + class develop(_develop): + def run(self): + self.announce("Building JS code", level=distutils.log.INFO) + build_js() + super().run() + + class install(_install): + def run(self): + self.announce("Building JS code", level=distutils.log.INFO) + build_js() + super().run() + + cmdclass = dict(develop=develop, install=install) + +setuptools.setup(cmdclass=cmdclass)