From d7e04e1e3a52760b27ef8a57f6b9bd8430772300 Mon Sep 17 00:00:00 2001 From: trungleduc Date: Fri, 19 Jan 2024 14:19:23 +0100 Subject: [PATCH] Update build script --- .github/workflows/test.yml | 2 +- CONTRIBUTING.md | 2 +- MANIFEST.in | 5 +++ frontend/package.json | 4 +- frontend/yarn.lock | 14 ++++++- setup.py | 77 +++++++++++++++++++++++++++++++++++++- 6 files changed, 98 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cf118d2..c65da60 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,7 +20,7 @@ jobs: - name: Install node uses: actions/setup-node@v2 with: - node-version: '14.x' + node-version: '18.x' - name: Install configurable-http-proxy run: npm -g install configurable-http-proxy - name: Set up Python ${{ matrix.python-version }} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 20a6176..244b4e9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -13,7 +13,7 @@ Check out the official Docker documentation to know how to install Docker on you Using `mamba` / `conda`: ```bash -mamba create -n tljh-repo2docker -c conda-forge python nodejs +mamba create -n tljh-repo2docker -c conda-forge python nodejs yarn=3 conda activate tljh-repo2docker ``` diff --git a/MANIFEST.in b/MANIFEST.in index 6884e83..84f38f8 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,3 +1,8 @@ recursive-include tljh_repo2docker/templates/ * recursive-include tljh_repo2docker/static/ * recursive-include tljh_repo2docker/tests/ * +recursive-include frontend/ * + +prune frontend/node_modules +prune frontend/lib +prune frontend/.yarn diff --git a/frontend/package.json b/frontend/package.json index 0080b39..418053c 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -8,7 +8,8 @@ "build:prod": "cross-env NODE_ENV=production webpack --config webpack.config.js", "eslint": "eslint --ext .js,.jsx,.ts,.tsx src/", "prettier": "prettier --write \"**/*{.ts,.tsx,.js,.jsx,.css,.json,.md}\"", - "lint": "yarn prettier && yarn eslint" + "lint": "yarn prettier && yarn eslint", + "clean": "rimraf ./lib ../tljh_repo2docker/static/js/react" }, "devDependencies": { "@types/react": "^18.2.0", @@ -26,6 +27,7 @@ "less": "^4.1.3", "less-loader": "11.1.0", "prettier": "^3.0.0", + "rimraf": "^5.0.5", "sass": "^1.55.0", "sass-loader": "^13.1.0", "style-loader": "^3.3.3", diff --git a/frontend/yarn.lock b/frontend/yarn.lock index fd8f4be..a14e2e4 100644 --- a/frontend/yarn.lock +++ b/frontend/yarn.lock @@ -2567,7 +2567,7 @@ __metadata: languageName: node linkType: hard -"glob@npm:^10.2.2, glob@npm:^10.3.10": +"glob@npm:^10.2.2, glob@npm:^10.3.10, glob@npm:^10.3.7": version: 10.3.10 resolution: "glob@npm:10.3.10" dependencies: @@ -4347,6 +4347,17 @@ __metadata: languageName: node linkType: hard +"rimraf@npm:^5.0.5": + version: 5.0.5 + resolution: "rimraf@npm:5.0.5" + dependencies: + glob: ^10.3.7 + bin: + rimraf: dist/esm/bin.mjs + checksum: d66eef829b2e23b16445f34e73d75c7b7cf4cbc8834b04720def1c8f298eb0753c3d76df77325fad79d0a2c60470525d95f89c2475283ad985fd7441c32732d1 + languageName: node + linkType: hard + "run-parallel@npm:^1.1.9": version: 1.2.0 resolution: "run-parallel@npm:1.2.0" @@ -4899,6 +4910,7 @@ __metadata: prettier: ^3.0.0 react: ^18.2.0 react-dom: ^18.2.0 + rimraf: ^5.0.5 sass: ^1.55.0 sass-loader: ^13.1.0 style-loader: ^3.3.3 diff --git a/setup.py b/setup.py index f0d62a7..6cc5148 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,66 @@ -from setuptools import setup, find_packages +import shutil +from pathlib import Path +from subprocess import check_call + +from setuptools import Command, find_packages, setup +from setuptools.command.build_py import build_py +from setuptools.command.develop import develop +from setuptools.command.sdist import sdist + +here = Path(__file__).parent + + +class BaseCommand(Command): + """Copy from https://github.com/jupyterhub/jupyterhub/blob/main/setup.py#L62""" + + user_options = [] + + def initialize_options(self): + pass + + def finalize_options(self): + pass + + def get_inputs(self): + return [] + + def get_outputs(self): + return [] + + +class BuildFrontend(BaseCommand): + description = "build React app" + frontend_dir = str(here / "frontend") + + def run(self): + if not shutil.which("yarn"): + raise Exception("yarn is not installed!") + + check_call( + ["yarn", "install"], + cwd=self.frontend_dir, + ) + + check_call( + ["yarn", "clean"], + cwd=self.frontend_dir, + ) + + check_call( + ["yarn", "run", "build:prod"], + cwd=self.frontend_dir, + ) + + +def command_with_build_frontend(Cls): + class CommandWithBuildFrontend(Cls): + + def run(self): + self.run_command("build_frontend") + + return super().run() + + return CommandWithBuildFrontend setup( name="tljh-repo2docker", @@ -6,5 +68,16 @@ entry_points={"tljh": ["tljh_repo2docker = tljh_repo2docker"]}, packages=find_packages(), include_package_data=True, - install_requires=["dockerspawner~=12.1", "jupyter_client~=6.1", "aiodocker~=0.19", "sqlalchemy<2"], + install_requires=[ + "dockerspawner~=12.1", + "jupyter_client~=6.1", + "aiodocker~=0.19", + "sqlalchemy<2", + ], + cmdclass={ + "build_frontend": BuildFrontend, + "develop": command_with_build_frontend(develop), + 'build_py': command_with_build_frontend(build_py), + 'sdist': command_with_build_frontend(sdist), + }, )