From 76e3bd6e24e0e3bc4f95df47ca87feb6f8881905 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Fri, 13 May 2022 06:57:30 -0500 Subject: [PATCH 1/5] Switch to hatch backend --- .flake8 | 17 ++++++++++ hatch_build.py | 26 +++++++++++++++ ipykernel/kernelspec.py | 5 ++- pyproject.toml | 66 +++++++++++++++++++++++++++++++------ setup.cfg | 63 ++++++++++++++++++++++++++---------- setup.py | 72 ++++++++++++++--------------------------- 6 files changed, 173 insertions(+), 76 deletions(-) create mode 100644 .flake8 create mode 100644 hatch_build.py diff --git a/.flake8 b/.flake8 new file mode 100644 index 000000000..6792947f9 --- /dev/null +++ b/.flake8 @@ -0,0 +1,17 @@ +[flake8] +ignore = E501, W503, E402 +builtins = c, get_config +exclude = + .cache, + .github, + docs, + setup.py +enable-extensions = G +extend-ignore = + G001, G002, G004, G200, G201, G202, + # black adds spaces around ':' + E203, +per-file-ignores = + # B011: Do not call assert False since python -O removes these calls + # F841 local variable 'foo' is assigned to but never used + ipykernel/tests/*: B011, F841 diff --git a/hatch_build.py b/hatch_build.py new file mode 100644 index 000000000..31be2ff1e --- /dev/null +++ b/hatch_build.py @@ -0,0 +1,26 @@ +import os +import shutil +import sys + +from hatchling.builders.hooks.plugin.interface import BuildHookInterface + + +class CustomHook(BuildHookInterface): + def initialize(self, version, build_data): + + here = os.path.abspath(os.path.dirname(__file__)) + sys.path.insert(0, here) + from ipykernel.kernelspec import make_ipkernel_cmd, write_kernel_spec + + # When building a standard wheel, the executable specified in the kernelspec is simply 'python'. + if version == "standard": + argv = make_ipkernel_cmd(executable="python") + + # When installing an editable wheel, the full `sys.executable` can be used. + else: + argv = make_ipkernel_cmd() + + dest = os.path.join(here, "data_kernelspec") + if os.path.exists(dest): + shutil.rmtree(dest) + write_kernel_spec(dest, overrides={"argv": argv}) diff --git a/ipykernel/kernelspec.py b/ipykernel/kernelspec.py index 585d87127..ac2594d78 100644 --- a/ipykernel/kernelspec.py +++ b/ipykernel/kernelspec.py @@ -13,7 +13,10 @@ from jupyter_client.kernelspec import KernelSpecManager -from .debugger import _is_debugpy_available +try: + from .debugger import _is_debugpy_available +except ImportError: + _is_debugpy_available = False pjoin = os.path.join diff --git a/pyproject.toml b/pyproject.toml index 4da63a645..ed9630e77 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,16 +1,62 @@ [build-system] -build-backend = "setuptools.build_meta" -requires=[ - "setuptools", - "wheel", - "debugpy", - "ipython>=5", - "jupyter_core>=4.2", - "jupyter_client", +requires = ["hatchling", "jupyter_client"] +build-backend = "hatchling.build" + +[project] +name = "ipykernel" +authors = [{name = "IPython Development Team", email = "ipython-dev@scipy.org"}] +license = {text = "BSD"} +description = "IPython Kernel for Jupyter" +keywords = ["Interactive", "Interpreter", "Shell", "Web"] +classifiers = [ + "Intended Audience :: Developers", + "Intended Audience :: System Administrators", + "Intended Audience :: Science/Research", + "License :: OSI Approved :: BSD License", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", +] +urls = {Homepage = "https://ipython.org"} +requires-python = ">=3.7" +dependencies = [ + "debugpy>=1.0", + "ipython>=7.23.1", + "traitlets>=5.1.0", + "jupyter_client>=6.1.12", + "tornado>=6.1", + "matplotlib-inline>=0.1", + 'appnope;platform_system=="Darwin"', + "psutil", + "nest_asyncio", + "packaging", +] +dynamic = ["version"] + +[project.optional-dependencies] +test = [ + "pytest>=6.0", + "pytest-cov", + "flaky", + "ipyparallel", + "pre-commit", + "pytest-timeout", ] -[tool.check-manifest] -ignore = [] +# Used to call hatch_build.py +[tool.hatch.build.targets.wheel.hooks.custom] + +[tool.hatch.build.targets.wheel.shared-data] +"data_kernelspec" = "share/jupyter/kernels/python3" + +[tool.hatch.build] +include = ["ipykernel/**", "ipykernel_launcher.py"] + +[tool.hatch.version] +path = "ipykernel/_version.py" [tool.jupyter-releaser] skip = ["check-links"] diff --git a/setup.cfg b/setup.cfg index 2ee9451f5..f91a2d114 100644 --- a/setup.cfg +++ b/setup.cfg @@ -5,21 +5,50 @@ universal=0 [metadata] license_file = COPYING.md version = attr: ipykernel._version.__version__ +name = ipykernel +author = IPython Development Team +author_email = ipython-dev@scipy.org +license = BSD +description = IPython Kernel for Jupyter +keywords = Interactive, Interpreter, Shell, Web +url = https://ipython.org +long_description_content_type = text/markdown +classifiers = + Intended Audience :: Developers + Intended Audience :: System Administrators + Intended Audience :: Science/Research + License :: OSI Approved :: BSD License + Programming Language :: Python + Programming Language :: Python :: 3 + Programming Language :: Python :: 3.7 + Programming Language :: Python :: 3.8 + Programming Language :: Python :: 3.9 + Programming Language :: Python :: 3.10 +platforms = Linux,, Mac, OS, X,, Windows -[flake8] -ignore = E501, W503, E402 -builtins = c, get_config -exclude = - .cache, - .github, - docs, - setup.py -enable-extensions = G -extend-ignore = - G001, G002, G004, G200, G201, G202, - # black adds spaces around ':' - E203, -per-file-ignores = - # B011: Do not call assert False since python -O removes these calls - # F841 local variable 'foo' is assigned to but never used - ipykernel/tests/*: B011, F841 +[options] +py_modules = ipykernel_launcher +install_requires = + debugpy>=1.0 + ipython>=7.23.1 + traitlets>=5.1.0 + jupyter_client>=6.1.12 + tornado>=6.1 + matplotlib-inline>=0.1 + appnope;platform_system=="Darwin" + psutil + nest_asyncio + packaging +python_requires = >=3.7 +scripts = + +[options.extras_require] +test = + pytest>=6.0 + pytest-cov + flaky + ipyparallel + pre-commit + pytest-timeout + +[options.package_data] diff --git a/setup.py b/setup.py index 9bb5e05ce..4740bb89b 100644 --- a/setup.py +++ b/setup.py @@ -10,46 +10,22 @@ from typing import Dict from setuptools import setup -from setuptools.command.bdist_egg import bdist_egg # the name of the package name = "ipykernel" -class bdist_egg_disabled(bdist_egg): - """Disabled version of bdist_egg - - Prevents setup.py install from performing setuptools' default easy_install, - which it should never ever do. - """ - - def run(self): - sys.exit("Aborting implicit building of eggs. Use `pip install .` to install from source.") - - -pjoin = os.path.join -here = os.path.abspath(os.path.dirname(__file__)) -pkg_root = pjoin(here, name) - -packages = [] -for d, _, _ in os.walk(pjoin(here, name)): - if os.path.exists(pjoin(d, "__init__.py")): - packages.append(d[len(here) + 1 :].replace(os.path.sep, ".")) +from os.path import join as pjoin package_data = { "ipykernel": ["resources/*.*", "py.typed"], } -with open(pjoin(here, "README.md")) as fid: - LONG_DESCRIPTION = fid.read() setup_args: Dict[str, object] = dict( name=name, - cmdclass={ - "bdist_egg": bdist_egg if "bdist_egg" in sys.argv else bdist_egg_disabled, - }, scripts=glob(pjoin("scripts", "*")), - packages=packages, + # packages=packages, py_modules=["ipykernel_launcher"], package_data=package_data, description="IPython Kernel for Jupyter", @@ -58,7 +34,7 @@ def run(self): author_email="ipython-dev@scipy.org", url="https://ipython.org", license="BSD", - long_description=LONG_DESCRIPTION, + # long_description=LONG_DESCRIPTION, platforms="Linux, Mac OS X, Windows", keywords=["Interactive", "Interpreter", "Shell", "Web"], project_urls={ @@ -105,28 +81,28 @@ def run(self): ) -if any(a.startswith(("bdist", "install")) for a in sys.argv): - sys.path.insert(0, here) - from ipykernel.kernelspec import KERNEL_NAME, make_ipkernel_cmd, write_kernel_spec +# if any(a.startswith(("bdist", "install")) for a in sys.argv): +# sys.path.insert(0, here) +# from ipykernel.kernelspec import KERNEL_NAME, make_ipkernel_cmd, write_kernel_spec - # When building a wheel, the executable specified in the kernelspec is simply 'python'. - if any(a.startswith("bdist") for a in sys.argv): - argv = make_ipkernel_cmd(executable="python") - # When installing from source, the full `sys.executable` can be used. - if any(a.startswith("install") for a in sys.argv): - argv = make_ipkernel_cmd() - dest = os.path.join(here, "data_kernelspec") - if os.path.exists(dest): - shutil.rmtree(dest) - write_kernel_spec(dest, overrides={"argv": argv}) +# # When building a wheel, the executable specified in the kernelspec is simply 'python'. +# if any(a.startswith("bdist") for a in sys.argv): +# argv = make_ipkernel_cmd(executable="python") +# # When installing from source, the full `sys.executable` can be used. +# if any(a.startswith("install") for a in sys.argv): +# argv = make_ipkernel_cmd() +# dest = os.path.join(here, "data_kernelspec") +# if os.path.exists(dest): +# shutil.rmtree(dest) +# write_kernel_spec(dest, overrides={"argv": argv}) - setup_args["data_files"] = [ - ( - pjoin("share", "jupyter", "kernels", KERNEL_NAME), - glob(pjoin("data_kernelspec", "*")), - ) - ] +# setup_args["data_files"] = [ +# ( +# pjoin("share", "jupyter", "kernels", KERNEL_NAME), +# glob(pjoin("data_kernelspec", "*")), +# ) +# ] -if __name__ == "__main__": - setup(**setup_args) +# if __name__ == "__main__": +setup(**setup_args) From edff326dbb9693002221f2832c527fee786eebe8 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Fri, 13 May 2022 06:58:38 -0500 Subject: [PATCH 2/5] Remove setuptools files --- setup.cfg | 54 --------------------------- setup.py | 108 ------------------------------------------------------ 2 files changed, 162 deletions(-) delete mode 100644 setup.cfg delete mode 100644 setup.py diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index f91a2d114..000000000 --- a/setup.cfg +++ /dev/null @@ -1,54 +0,0 @@ - -[bdist_wheel] -universal=0 - -[metadata] -license_file = COPYING.md -version = attr: ipykernel._version.__version__ -name = ipykernel -author = IPython Development Team -author_email = ipython-dev@scipy.org -license = BSD -description = IPython Kernel for Jupyter -keywords = Interactive, Interpreter, Shell, Web -url = https://ipython.org -long_description_content_type = text/markdown -classifiers = - Intended Audience :: Developers - Intended Audience :: System Administrators - Intended Audience :: Science/Research - License :: OSI Approved :: BSD License - Programming Language :: Python - Programming Language :: Python :: 3 - Programming Language :: Python :: 3.7 - Programming Language :: Python :: 3.8 - Programming Language :: Python :: 3.9 - Programming Language :: Python :: 3.10 -platforms = Linux,, Mac, OS, X,, Windows - -[options] -py_modules = ipykernel_launcher -install_requires = - debugpy>=1.0 - ipython>=7.23.1 - traitlets>=5.1.0 - jupyter_client>=6.1.12 - tornado>=6.1 - matplotlib-inline>=0.1 - appnope;platform_system=="Darwin" - psutil - nest_asyncio - packaging -python_requires = >=3.7 -scripts = - -[options.extras_require] -test = - pytest>=6.0 - pytest-cov - flaky - ipyparallel - pre-commit - pytest-timeout - -[options.package_data] diff --git a/setup.py b/setup.py deleted file mode 100644 index 4740bb89b..000000000 --- a/setup.py +++ /dev/null @@ -1,108 +0,0 @@ -#!/usr/bin/env python - -# Copyright (c) IPython Development Team. -# Distributed under the terms of the Modified BSD License. - -import os -import shutil -import sys -from glob import glob -from typing import Dict - -from setuptools import setup - -# the name of the package -name = "ipykernel" - - -from os.path import join as pjoin - -package_data = { - "ipykernel": ["resources/*.*", "py.typed"], -} - - -setup_args: Dict[str, object] = dict( - name=name, - scripts=glob(pjoin("scripts", "*")), - # packages=packages, - py_modules=["ipykernel_launcher"], - package_data=package_data, - description="IPython Kernel for Jupyter", - long_description_content_type="text/markdown", - author="IPython Development Team", - author_email="ipython-dev@scipy.org", - url="https://ipython.org", - license="BSD", - # long_description=LONG_DESCRIPTION, - platforms="Linux, Mac OS X, Windows", - keywords=["Interactive", "Interpreter", "Shell", "Web"], - project_urls={ - "Documentation": "https://ipython.readthedocs.io/", - "Funding": "https://numfocus.org/", - "Source": "https://github.com/ipython/ipykernel", - "Tracker": "https://github.com/ipython/ipykernel/issues", - }, - python_requires=">=3.7", - install_requires=[ - "debugpy>=1.0", - "ipython>=7.23.1", - "traitlets>=5.1.0", - "jupyter_client>=6.1.12", - "tornado>=6.1", - "matplotlib-inline>=0.1", - 'appnope;platform_system=="Darwin"', - "psutil", - "nest_asyncio", - "packaging", - ], - extras_require={ - "test": [ - "pytest>=6.0", - "pytest-cov", - "flaky", - "ipyparallel", - "pre-commit", - "pytest-timeout", - ], - }, - classifiers=[ - "Intended Audience :: Developers", - "Intended Audience :: System Administrators", - "Intended Audience :: Science/Research", - "License :: OSI Approved :: BSD License", - "Programming Language :: Python", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - ], -) - - -# if any(a.startswith(("bdist", "install")) for a in sys.argv): -# sys.path.insert(0, here) -# from ipykernel.kernelspec import KERNEL_NAME, make_ipkernel_cmd, write_kernel_spec - -# # When building a wheel, the executable specified in the kernelspec is simply 'python'. -# if any(a.startswith("bdist") for a in sys.argv): -# argv = make_ipkernel_cmd(executable="python") -# # When installing from source, the full `sys.executable` can be used. -# if any(a.startswith("install") for a in sys.argv): -# argv = make_ipkernel_cmd() -# dest = os.path.join(here, "data_kernelspec") -# if os.path.exists(dest): -# shutil.rmtree(dest) -# write_kernel_spec(dest, overrides={"argv": argv}) - -# setup_args["data_files"] = [ -# ( -# pjoin("share", "jupyter", "kernels", KERNEL_NAME), -# glob(pjoin("data_kernelspec", "*")), -# ) -# ] - - -# if __name__ == "__main__": -setup(**setup_args) From ecb21e304d228ac719091d866851cb3df85f8dde Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Sat, 14 May 2022 19:45:49 -0500 Subject: [PATCH 3/5] add sdist handling --- hatch_build.py | 1 - pyproject.toml | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/hatch_build.py b/hatch_build.py index 31be2ff1e..fca67e502 100644 --- a/hatch_build.py +++ b/hatch_build.py @@ -7,7 +7,6 @@ class CustomHook(BuildHookInterface): def initialize(self, version, build_data): - here = os.path.abspath(os.path.dirname(__file__)) sys.path.insert(0, here) from ipykernel.kernelspec import make_ipkernel_cmd, write_kernel_spec diff --git a/pyproject.toml b/pyproject.toml index ed9630e77..a4ab188b7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -48,6 +48,7 @@ test = [ # Used to call hatch_build.py [tool.hatch.build.targets.wheel.hooks.custom] +[tool.hatch.build.targets.sdist.hooks.custom] [tool.hatch.build.targets.wheel.shared-data] "data_kernelspec" = "share/jupyter/kernels/python3" From 56f7d551c28e4a5255dc18dcbad6d1e4cdda7300 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Sat, 14 May 2022 22:29:32 -0500 Subject: [PATCH 4/5] cleanup --- pyproject.toml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index a4ab188b7..f34a60402 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -47,14 +47,13 @@ test = [ ] # Used to call hatch_build.py -[tool.hatch.build.targets.wheel.hooks.custom] -[tool.hatch.build.targets.sdist.hooks.custom] +[tool.hatch.build.hooks.custom] [tool.hatch.build.targets.wheel.shared-data] "data_kernelspec" = "share/jupyter/kernels/python3" -[tool.hatch.build] -include = ["ipykernel/**", "ipykernel_launcher.py"] +[tool.hatch.build.force-include] +"./ipykernel_launcher.py" = "ipykernel_launcher.py" [tool.hatch.version] path = "ipykernel/_version.py" From 0e57c3e7d9c02ede2d079a80519eb2f64a73c7e2 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Mon, 16 May 2022 05:49:06 -0500 Subject: [PATCH 5/5] cleanup --- pyproject.toml | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index f34a60402..5b76a7c7f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,11 +1,13 @@ [build-system] -requires = ["hatchling", "jupyter_client"] +requires = ["hatchling>=0.25", "jupyter_client>=6"] build-backend = "hatchling.build" [project] name = "ipykernel" +version = "6.13.0" authors = [{name = "IPython Development Team", email = "ipython-dev@scipy.org"}] -license = {text = "BSD"} +license = {file = "COPYING.md"} +readme = "README.md" description = "IPython Kernel for Jupyter" keywords = ["Interactive", "Interpreter", "Shell", "Web"] classifiers = [ @@ -34,7 +36,6 @@ dependencies = [ "nest_asyncio", "packaging", ] -dynamic = ["version"] [project.optional-dependencies] test = [ @@ -52,11 +53,8 @@ test = [ [tool.hatch.build.targets.wheel.shared-data] "data_kernelspec" = "share/jupyter/kernels/python3" -[tool.hatch.build.force-include] -"./ipykernel_launcher.py" = "ipykernel_launcher.py" - -[tool.hatch.version] -path = "ipykernel/_version.py" +[tool.hatch.build] +artifacts = ["ipykernel_launcher.py"] [tool.jupyter-releaser] skip = ["check-links"] @@ -75,6 +73,9 @@ tag_template = "v{new_version}" [[tool.tbump.file]] src = "ipykernel/_version.py" +[[tool.tbump.file]] +src = "pyproject.toml" + [tool.mypy] check_untyped_defs = true disallow_any_generics = true