Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to hatch build backend #1777

Merged
merged 5 commits into from
May 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ docs/source/config_options.rst
.vscode

# Downloaded theme files
jupyter-data/share/jupyter/nbconvert/templates/lab/static/index.css
jupyter-data/share/jupyter/nbconvert/templates/lab/static/theme-dark.css
jupyter-data/share/jupyter/nbconvert/templates/lab/static/theme-light.css
share/templates/lab/static/index.css
share/templates/lab/static/theme-dark.css
share/templates/lab/static/theme-light.css
38 changes: 8 additions & 30 deletions buildapi.py → hatch_build.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,9 @@
"""A build backend that handles installing the template files.

See https://peps.python.org/pep-0517/#in-tree-build-backends
"""
"""Custom build script for hatch backend"""
import os
import sys
from urllib.request import urlopen

from flit_core.buildapi import build_editable # noqa
from flit_core.buildapi import build_sdist # noqa
from flit_core.buildapi import build_wheel # noqa
from flit_core.buildapi import (
get_requires_for_build_editable as get_requires_for_build_editable_orig,
)
from flit_core.buildapi import (
get_requires_for_build_sdist as get_requires_for_build_sdist_orig,
)
from flit_core.buildapi import (
get_requires_for_build_wheel as get_requires_for_build_wheel_orig,
)
from hatchling.builders.hooks.plugin.interface import BuildHookInterface

notebook_css_version = "5.4.0"
notebook_css_url = "https://cdn.jupyter.org/notebook/%s/style/style.min.css" % notebook_css_version
Expand Down Expand Up @@ -50,7 +36,7 @@

osp = os.path
here = osp.abspath(osp.dirname(__file__))
templates_dir = osp.join(here, "jupyter-data", "share", "jupyter", "nbconvert", "templates")
templates_dir = osp.join(here, "share", "templates")


def _get_css_file(template_name, url, filename):
Expand Down Expand Up @@ -88,16 +74,8 @@ def _get_css_files():
_get_css_file(template_name, url, filename)


def get_requires_for_build_wheel(config_settings=None):
_get_css_files()
return get_requires_for_build_wheel_orig(config_settings=config_settings)


def get_requires_for_build_sdist(config_settings=None):
_get_css_files()
return get_requires_for_build_sdist_orig(config_settings=config_settings)


def get_requires_for_build_editable(config_settings=None):
_get_css_files()
return get_requires_for_build_editable_orig(config_settings=config_settings)
class CustomHook(BuildHookInterface):
def initialize(self, version, build_data):
if self.target_name not in ["wheel", "sdist"]:
return
_get_css_files()
3 changes: 2 additions & 1 deletion nbconvert/_version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
__version__ = "7.0.0rc0"
version_info = (7, 0, 0)
pre_info = "rc0"
dev_info = ""
Expand Down Expand Up @@ -64,4 +65,4 @@ def is_canonical(version):
raise ValueError(pep440_err)


__version__ = create_valid_version(version_info, pre_input=pre_info, dev_input=dev_info)
assert __version__ == create_valid_version(version_info, pre_input=pre_info, dev_input=dev_info)
19 changes: 12 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[build-system]
requires = ["flit_core >=3.2,<4"]
build-backend = "buildapi"
backend-path = ["."]
requires = ["hatchling >=0.25"]
build-backend = "hatchling.build"

[project]
name = "nbconvert"
Expand Down Expand Up @@ -91,11 +90,17 @@ all = [
jupyter-nbconvert = "nbconvert.nbconvertapp:main"
jupyter-dejavu = "nbconvert.nbconvertapp:dejavu_main"

[tool.flit.sdist]
include = ["buildapi.py", "jupyter-data"]
[tool.hatch.version]
path = "nbconvert/_version.py"

[tool.flit.external-data]
directory = "jupyter-data"
# Used to call hatch_build.py
[tool.hatch.build.hooks.custom]

[tool.hatch.build.targets.sdist]
artifacts = ["share/templates/lab/static/*.*"]

[tool.hatch.build.targets.wheel.shared-data]
"share/templates" = "share/jupyter/nbconvert/templates"

[tool.pytest.ini_options]
markers = "network: marks tests which require network connection"
Expand Down