diff --git a/setup.cfg b/.flake8 similarity index 79% rename from setup.cfg rename to .flake8 index 2ee9451f5..6792947f9 100644 --- a/setup.cfg +++ b/.flake8 @@ -1,11 +1,3 @@ - -[bdist_wheel] -universal=0 - -[metadata] -license_file = COPYING.md -version = attr: ipykernel._version.__version__ - [flake8] ignore = E501, W503, E402 builtins = c, get_config diff --git a/hatch_build.py b/hatch_build.py new file mode 100644 index 000000000..fca67e502 --- /dev/null +++ b/hatch_build.py @@ -0,0 +1,25 @@ +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..5b76a7c7f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,16 +1,60 @@ [build-system] -build-backend = "setuptools.build_meta" -requires=[ - "setuptools", - "wheel", - "debugpy", - "ipython>=5", - "jupyter_core>=4.2", - "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 = {file = "COPYING.md"} +readme = "README.md" +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", +] + +[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.hooks.custom] + +[tool.hatch.build.targets.wheel.shared-data] +"data_kernelspec" = "share/jupyter/kernels/python3" + +[tool.hatch.build] +artifacts = ["ipykernel_launcher.py"] [tool.jupyter-releaser] skip = ["check-links"] @@ -29,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 diff --git a/setup.py b/setup.py deleted file mode 100644 index 9bb5e05ce..000000000 --- a/setup.py +++ /dev/null @@ -1,132 +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 -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, ".")) - -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, - 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)