From 95923405cfb4215710c13b4b02151928aec39db8 Mon Sep 17 00:00:00 2001 From: Iisakki Rotko Date: Thu, 19 Dec 2024 12:22:00 +0100 Subject: [PATCH] build: migrate to pyproject.toml based build process --- .github/workflows/ci_tests.yml | 11 ++- .gitignore | 3 +- ...plot-image-gl.json => bqplot-image-gl.json | 0 js/package.json | 2 +- js/webpack.config.js | 4 +- pyproject.toml | 89 +++++++++++++++++-- setup.py | 85 +----------------- tox.ini | 2 +- 8 files changed, 97 insertions(+), 99 deletions(-) rename etc/jupyter/nbconfig/notebook.d/bqplot-image-gl.json => bqplot-image-gl.json (100%) diff --git a/.github/workflows/ci_tests.yml b/.github/workflows/ci_tests.yml index 4812bc0..0024138 100644 --- a/.github/workflows/ci_tests.yml +++ b/.github/workflows/ci_tests.yml @@ -32,11 +32,11 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install twine wheel jupyter-packaging jupyterlab + pip install hatch - name: Build run: | - python setup.py sdist bdist_wheel + hatch build - name: Upload builds uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3 @@ -93,19 +93,18 @@ jobs: - linux: codestyle coverage: false - - linux: py37-test - runs-on: ubuntu-22.04 - linux: py38-test - linux: py313-test + - macos: py37-test - macos: py310-test - macos: py312-test - windows: py39-test - windows: py311-test - - linux: py37-notebooks + - linux: py38-notebooks runs-on: ubuntu-22.04 - - macos: py38-notebooks + - macos: py37-notebooks runs-on: macos-13 - windows: py39-notebooks diff --git a/.gitignore b/.gitignore index d1878f2..873219b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,10 @@ *.egg-info bqplot_image_gl/static +bqplot_image_gl/labextension +bqplot_image_gl/nbextension dist node_modules .tox .ipynb_checkpoints .tmp __pycache__ -share diff --git a/etc/jupyter/nbconfig/notebook.d/bqplot-image-gl.json b/bqplot-image-gl.json similarity index 100% rename from etc/jupyter/nbconfig/notebook.d/bqplot-image-gl.json rename to bqplot-image-gl.json diff --git a/js/package.json b/js/package.json index 9340c0b..90a7bdf 100644 --- a/js/package.json +++ b/js/package.json @@ -55,7 +55,7 @@ }, "jupyterlab": { "extension": "lib/labplugin", - "outputDir": "../share/jupyter/labextensions/bqplot-image-gl", + "outputDir": "../bqplot_image_gl/labextension", "sharedPackages": { "@jupyter-widgets/base": { "bundled": false, diff --git a/js/webpack.config.js b/js/webpack.config.js index 1a2e8d5..de9d106 100644 --- a/js/webpack.config.js +++ b/js/webpack.config.js @@ -21,7 +21,7 @@ module.exports = [ entry: './lib/extension.js', output: { filename: 'extension.js', - path: path.resolve(__dirname, '../share/jupyter/nbextensions/bqplot-image-gl'), + path: path.resolve(__dirname, '../bqplot_image_gl/nbextension'), libraryTarget: 'amd', devtoolModuleFilenameTemplate: 'webpack://jupyter-widgets/bqplot-image-gl/[resource-path]?[loaders]', publicPath: "", @@ -36,7 +36,7 @@ module.exports = [ entry: './lib/index.js', output: { filename: 'index.js', - path: path.resolve(__dirname, '../share/jupyter/nbextensions/bqplot-image-gl'), + path: path.resolve(__dirname, '../bqplot_image_gl/nbextension'), libraryTarget: 'amd', devtoolModuleFilenameTemplate: 'webpack://jupyter-widgets/bqplot-image-gl/[resource-path]?[loaders]', publicPath: "", diff --git a/pyproject.toml b/pyproject.toml index c3f82ef..d99e940 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,85 @@ [build-system] -requires = ["jupyter_packaging>=0.10.6", - "jupyterlab>=3.6", - "setuptools>=40.8.0", - "wheel"] -build-backend = "setuptools.build_meta" +requires = [ + "jupyterlab>=3.6", + "hatchling", +] +build-backend = "hatchling.build" + +[project] +name = "bqplot-image-gl" +dynamic = ["version"] +description = "An ipywidget image widget for astronomical purposes" +readme = "README.md" +authors = [ + {name = "Maarten A. Breddels", email = "maartenbreddels@gmail.com"}, +] +requires-python = ">=3.7" +keywords = ["ipython", "jupyter", "widgets"] +license = {text = "MIT"} # Add appropriate license +classifiers = [ + "Development Status :: 4 - Beta", + "Framework :: IPython", + "Intended Audience :: Developers", + "Intended Audience :: Science/Research", + "Topic :: Multimedia :: Graphics", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + 'Programming Language :: Python :: 3.11', + 'Programming Language :: Python :: 3.12', + 'Programming Language :: Python :: 3.13', +] +dependencies = [ + "ipywidgets>=7.0.0", + "bqplot>=0.12", + "pillow" +] + +[project.urls] +Homepage = "https://github.com/glue-viz/bqplot-image-gl" + +[tool.hatch.version] +path = "bqplot_image_gl/_version.py" + +[tool.hatch.build.targets.sdist] +exclude = [ + ".github", +] + +[tool.hatch.build.targets.wheel] +include = [ + "bqplot_image_gl", + "etc", + "js", +] + +[tool.hatch.build] +artifacts = [ + "bqplot_image_gl/nbextension", + "bqplot_image_gl/labextension", +] + +[tool.hatch.build.targets.wheel.shared-data] +"bqplot_image_gl/nbextension" = "share/jupyter/nbextensions/bqplot-image-gl" +"bqplot_image_gl/labextension" = "share/jupyter/labextensions/bqplot-image-gl" +"./bqplot-image-gl.json" = "etc/jupyter/nbconfig/notebook.d/bqplot-image-gl.json" + +[tool.hatch.build.hooks.jupyter-builder] +build-function = "hatch_jupyter_builder.npm_builder" +ensured-targets = [ + "bqplot_image_gl/nbextension/index.js", + "bqplot_image_gl/labextension/package.json", +] +skip-if-exists = [ + "bqplot_image_gl/nbextension/index.js", + "bqplot_image_gl/labextension/package.json", +] +dependencies = [ + "hatch-jupyter-builder>=0.5.0", +] + +[tool.hatch.build.hooks.jupyter-builder.build-kwargs] +path = "./js" +build_cmd = "build" \ No newline at end of file diff --git a/setup.py b/setup.py index 9958113..b6c6681 100644 --- a/setup.py +++ b/setup.py @@ -1,83 +1,2 @@ -from __future__ import print_function -from os.path import join as pjoin -from setuptools import setup, find_packages, Command -import os - -from jupyter_packaging import ( - create_cmdclass, - install_npm, - ensure_targets, - combine_commands, - get_version, - skip_if_exists, -) - -LONG_DESCRIPTION = 'An ipywidget image widget for astronomical purposes' -here = os.path.dirname(os.path.abspath(__file__)) -name = 'bqplot-image-gl' -package_name = name.replace('-', '_') -version = get_version(pjoin(package_name, '_version.py')) - -js_dir = pjoin(here, 'js') - -# Representative files that should exist after a successful build -jstargets = [ - pjoin('share', 'jupyter', 'nbextensions', f'{name}', 'index.js'), - # pjoin('share', 'jupyter', 'labextensions', f'{name}', 'package.json'), -] - -data_files_spec = [ - (f'share/jupyter/nbextensions/{name}', f'share/jupyter/nbextensions/{name}', '*.js'), - (f'share/jupyter/labextensions/{name}/', f'share/jupyter/labextensions/{name}/', '**'), - (f'etc/jupyter/nbconfig/notebook.d', f'etc/jupyter/nbconfig/notebook.d', f'{name}.json'), -] - -js_command = combine_commands( - install_npm(js_dir, build_dir='share/jupyter/', source_dir='js/src', build_cmd='build'), ensure_targets(jstargets), -) - -cmdclass = create_cmdclass('jsdeps', data_files_spec=data_files_spec) -is_repo = os.path.exists(os.path.join(here, '.git')) -if is_repo: - cmdclass['jsdeps'] = js_command -else: - cmdclass['jsdeps'] = skip_if_exists(jstargets, js_command) - -setup( - name=name, - version=version, - description='An ipywidget image widget for astronomical purposes', - long_description=LONG_DESCRIPTION, - include_package_data=True, - install_requires=[ - 'ipywidgets>=7.0.0', - 'bqplot>=0.12', - 'pillow', - ], - packages=find_packages(), - zip_safe=False, - cmdclass=cmdclass, - author='Maarten A. Breddels', - author_email='maartenbreddels@gmail.com', - url='https://github.com/glue-viz/bqplot-image-gl', - keywords=[ - 'ipython', - 'jupyter', - 'widgets', - ], - classifiers=[ - 'Development Status :: 4 - Beta', - 'Framework :: IPython', - 'Intended Audience :: Developers', - 'Intended Audience :: Science/Research', - 'Topic :: Multimedia :: Graphics', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: 3.9', - 'Programming Language :: Python :: 3.10', - 'Programming Language :: Python :: 3.11', - 'Programming Language :: Python :: 3.12', - 'Programming Language :: Python :: 3.13', - ], -) +# setup.py shim for use with applications that require it. +__import__("setuptools").setup() diff --git a/tox.ini b/tox.ini index 60fd81a..ba4df46 100644 --- a/tox.ini +++ b/tox.ini @@ -1,7 +1,7 @@ [tox] envlist = py{36,37,38,39,310}-{test,notebooks} requires = pip >= 18.0 - setuptools >= 30.3.0 + hatchling isolated_build = true [testenv]