Skip to content

Commit 76e3bd6

Browse files
committed
Switch to hatch backend
1 parent dd65e4a commit 76e3bd6

File tree

6 files changed

+173
-76
lines changed

6 files changed

+173
-76
lines changed

.flake8

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[flake8]
2+
ignore = E501, W503, E402
3+
builtins = c, get_config
4+
exclude =
5+
.cache,
6+
.github,
7+
docs,
8+
setup.py
9+
enable-extensions = G
10+
extend-ignore =
11+
G001, G002, G004, G200, G201, G202,
12+
# black adds spaces around ':'
13+
E203,
14+
per-file-ignores =
15+
# B011: Do not call assert False since python -O removes these calls
16+
# F841 local variable 'foo' is assigned to but never used
17+
ipykernel/tests/*: B011, F841

hatch_build.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import os
2+
import shutil
3+
import sys
4+
5+
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
6+
7+
8+
class CustomHook(BuildHookInterface):
9+
def initialize(self, version, build_data):
10+
11+
here = os.path.abspath(os.path.dirname(__file__))
12+
sys.path.insert(0, here)
13+
from ipykernel.kernelspec import make_ipkernel_cmd, write_kernel_spec
14+
15+
# When building a standard wheel, the executable specified in the kernelspec is simply 'python'.
16+
if version == "standard":
17+
argv = make_ipkernel_cmd(executable="python")
18+
19+
# When installing an editable wheel, the full `sys.executable` can be used.
20+
else:
21+
argv = make_ipkernel_cmd()
22+
23+
dest = os.path.join(here, "data_kernelspec")
24+
if os.path.exists(dest):
25+
shutil.rmtree(dest)
26+
write_kernel_spec(dest, overrides={"argv": argv})

ipykernel/kernelspec.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313

1414
from jupyter_client.kernelspec import KernelSpecManager
1515

16-
from .debugger import _is_debugpy_available
16+
try:
17+
from .debugger import _is_debugpy_available
18+
except ImportError:
19+
_is_debugpy_available = False
1720

1821
pjoin = os.path.join
1922

pyproject.toml

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,62 @@
11
[build-system]
2-
build-backend = "setuptools.build_meta"
3-
requires=[
4-
"setuptools",
5-
"wheel",
6-
"debugpy",
7-
"ipython>=5",
8-
"jupyter_core>=4.2",
9-
"jupyter_client",
2+
requires = ["hatchling", "jupyter_client"]
3+
build-backend = "hatchling.build"
4+
5+
[project]
6+
name = "ipykernel"
7+
authors = [{name = "IPython Development Team", email = "[email protected]"}]
8+
license = {text = "BSD"}
9+
description = "IPython Kernel for Jupyter"
10+
keywords = ["Interactive", "Interpreter", "Shell", "Web"]
11+
classifiers = [
12+
"Intended Audience :: Developers",
13+
"Intended Audience :: System Administrators",
14+
"Intended Audience :: Science/Research",
15+
"License :: OSI Approved :: BSD License",
16+
"Programming Language :: Python",
17+
"Programming Language :: Python :: 3",
18+
"Programming Language :: Python :: 3.7",
19+
"Programming Language :: Python :: 3.8",
20+
"Programming Language :: Python :: 3.9",
21+
"Programming Language :: Python :: 3.10",
22+
]
23+
urls = {Homepage = "https://ipython.org"}
24+
requires-python = ">=3.7"
25+
dependencies = [
26+
"debugpy>=1.0",
27+
"ipython>=7.23.1",
28+
"traitlets>=5.1.0",
29+
"jupyter_client>=6.1.12",
30+
"tornado>=6.1",
31+
"matplotlib-inline>=0.1",
32+
'appnope;platform_system=="Darwin"',
33+
"psutil",
34+
"nest_asyncio",
35+
"packaging",
36+
]
37+
dynamic = ["version"]
38+
39+
[project.optional-dependencies]
40+
test = [
41+
"pytest>=6.0",
42+
"pytest-cov",
43+
"flaky",
44+
"ipyparallel",
45+
"pre-commit",
46+
"pytest-timeout",
1047
]
1148

12-
[tool.check-manifest]
13-
ignore = []
49+
# Used to call hatch_build.py
50+
[tool.hatch.build.targets.wheel.hooks.custom]
51+
52+
[tool.hatch.build.targets.wheel.shared-data]
53+
"data_kernelspec" = "share/jupyter/kernels/python3"
54+
55+
[tool.hatch.build]
56+
include = ["ipykernel/**", "ipykernel_launcher.py"]
57+
58+
[tool.hatch.version]
59+
path = "ipykernel/_version.py"
1460

1561
[tool.jupyter-releaser]
1662
skip = ["check-links"]

setup.cfg

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,50 @@ universal=0
55
[metadata]
66
license_file = COPYING.md
77
version = attr: ipykernel._version.__version__
8+
name = ipykernel
9+
author = IPython Development Team
10+
author_email = [email protected]
11+
license = BSD
12+
description = IPython Kernel for Jupyter
13+
keywords = Interactive, Interpreter, Shell, Web
14+
url = https://ipython.org
15+
long_description_content_type = text/markdown
16+
classifiers =
17+
Intended Audience :: Developers
18+
Intended Audience :: System Administrators
19+
Intended Audience :: Science/Research
20+
License :: OSI Approved :: BSD License
21+
Programming Language :: Python
22+
Programming Language :: Python :: 3
23+
Programming Language :: Python :: 3.7
24+
Programming Language :: Python :: 3.8
25+
Programming Language :: Python :: 3.9
26+
Programming Language :: Python :: 3.10
27+
platforms = Linux,, Mac, OS, X,, Windows
828

9-
[flake8]
10-
ignore = E501, W503, E402
11-
builtins = c, get_config
12-
exclude =
13-
.cache,
14-
.github,
15-
docs,
16-
setup.py
17-
enable-extensions = G
18-
extend-ignore =
19-
G001, G002, G004, G200, G201, G202,
20-
# black adds spaces around ':'
21-
E203,
22-
per-file-ignores =
23-
# B011: Do not call assert False since python -O removes these calls
24-
# F841 local variable 'foo' is assigned to but never used
25-
ipykernel/tests/*: B011, F841
29+
[options]
30+
py_modules = ipykernel_launcher
31+
install_requires =
32+
debugpy>=1.0
33+
ipython>=7.23.1
34+
traitlets>=5.1.0
35+
jupyter_client>=6.1.12
36+
tornado>=6.1
37+
matplotlib-inline>=0.1
38+
appnope;platform_system=="Darwin"
39+
psutil
40+
nest_asyncio
41+
packaging
42+
python_requires = >=3.7
43+
scripts =
44+
45+
[options.extras_require]
46+
test =
47+
pytest>=6.0
48+
pytest-cov
49+
flaky
50+
ipyparallel
51+
pre-commit
52+
pytest-timeout
53+
54+
[options.package_data]

setup.py

Lines changed: 24 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -10,46 +10,22 @@
1010
from typing import Dict
1111

1212
from setuptools import setup
13-
from setuptools.command.bdist_egg import bdist_egg
1413

1514
# the name of the package
1615
name = "ipykernel"
1716

1817

19-
class bdist_egg_disabled(bdist_egg):
20-
"""Disabled version of bdist_egg
21-
22-
Prevents setup.py install from performing setuptools' default easy_install,
23-
which it should never ever do.
24-
"""
25-
26-
def run(self):
27-
sys.exit("Aborting implicit building of eggs. Use `pip install .` to install from source.")
28-
29-
30-
pjoin = os.path.join
31-
here = os.path.abspath(os.path.dirname(__file__))
32-
pkg_root = pjoin(here, name)
33-
34-
packages = []
35-
for d, _, _ in os.walk(pjoin(here, name)):
36-
if os.path.exists(pjoin(d, "__init__.py")):
37-
packages.append(d[len(here) + 1 :].replace(os.path.sep, "."))
18+
from os.path import join as pjoin
3819

3920
package_data = {
4021
"ipykernel": ["resources/*.*", "py.typed"],
4122
}
4223

43-
with open(pjoin(here, "README.md")) as fid:
44-
LONG_DESCRIPTION = fid.read()
4524

4625
setup_args: Dict[str, object] = dict(
4726
name=name,
48-
cmdclass={
49-
"bdist_egg": bdist_egg if "bdist_egg" in sys.argv else bdist_egg_disabled,
50-
},
5127
scripts=glob(pjoin("scripts", "*")),
52-
packages=packages,
28+
# packages=packages,
5329
py_modules=["ipykernel_launcher"],
5430
package_data=package_data,
5531
description="IPython Kernel for Jupyter",
@@ -58,7 +34,7 @@ def run(self):
5834
author_email="[email protected]",
5935
url="https://ipython.org",
6036
license="BSD",
61-
long_description=LONG_DESCRIPTION,
37+
# long_description=LONG_DESCRIPTION,
6238
platforms="Linux, Mac OS X, Windows",
6339
keywords=["Interactive", "Interpreter", "Shell", "Web"],
6440
project_urls={
@@ -105,28 +81,28 @@ def run(self):
10581
)
10682

10783

108-
if any(a.startswith(("bdist", "install")) for a in sys.argv):
109-
sys.path.insert(0, here)
110-
from ipykernel.kernelspec import KERNEL_NAME, make_ipkernel_cmd, write_kernel_spec
84+
# if any(a.startswith(("bdist", "install")) for a in sys.argv):
85+
# sys.path.insert(0, here)
86+
# from ipykernel.kernelspec import KERNEL_NAME, make_ipkernel_cmd, write_kernel_spec
11187

112-
# When building a wheel, the executable specified in the kernelspec is simply 'python'.
113-
if any(a.startswith("bdist") for a in sys.argv):
114-
argv = make_ipkernel_cmd(executable="python")
115-
# When installing from source, the full `sys.executable` can be used.
116-
if any(a.startswith("install") for a in sys.argv):
117-
argv = make_ipkernel_cmd()
118-
dest = os.path.join(here, "data_kernelspec")
119-
if os.path.exists(dest):
120-
shutil.rmtree(dest)
121-
write_kernel_spec(dest, overrides={"argv": argv})
88+
# # When building a wheel, the executable specified in the kernelspec is simply 'python'.
89+
# if any(a.startswith("bdist") for a in sys.argv):
90+
# argv = make_ipkernel_cmd(executable="python")
91+
# # When installing from source, the full `sys.executable` can be used.
92+
# if any(a.startswith("install") for a in sys.argv):
93+
# argv = make_ipkernel_cmd()
94+
# dest = os.path.join(here, "data_kernelspec")
95+
# if os.path.exists(dest):
96+
# shutil.rmtree(dest)
97+
# write_kernel_spec(dest, overrides={"argv": argv})
12298

123-
setup_args["data_files"] = [
124-
(
125-
pjoin("share", "jupyter", "kernels", KERNEL_NAME),
126-
glob(pjoin("data_kernelspec", "*")),
127-
)
128-
]
99+
# setup_args["data_files"] = [
100+
# (
101+
# pjoin("share", "jupyter", "kernels", KERNEL_NAME),
102+
# glob(pjoin("data_kernelspec", "*")),
103+
# )
104+
# ]
129105

130106

131-
if __name__ == "__main__":
132-
setup(**setup_args)
107+
# if __name__ == "__main__":
108+
setup(**setup_args)

0 commit comments

Comments
 (0)