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 flit build backend #1767

Merged
merged 13 commits into from
May 9, 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
14 changes: 1 addition & 13 deletions setup.cfg → .flake8
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
[bdist_wheel]
universal=0

[metadata]
license_file = LICENSE

[check-manifest]
ignore =
nbconvert/resources/style.min.css
.circleci/*

[flake8]
ignore = E501, W503, E402
builtins = c, get_config
exclude =
.cache,
.github,
docs,
setup.py
docs
enable-extensions = G
extend-ignore =
G001, G002, G004, G200, G201, G202,
Expand Down
11 changes: 0 additions & 11 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,6 @@ jobs:
echo "or after-the-fact on already committed files with"
echo " pre-commit run --all-files --hook-stage=manual"

check_manifest:
timeout-minutes: 20
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
- name: Check Manifest
run: |
pip install check-manifest
check-manifest --ignore "share/**"

test_minimum_versions:
name: Test Minimum Versions
timeout-minutes: 20
Expand Down
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
share/jupyter/nbconvert/templates/lab/static/index.css
share/jupyter/nbconvert/templates/lab/static/theme-dark.css
share/jupyter/nbconvert/templates/lab/static/theme-light.css
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
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,13 @@ repos:
types: [yaml]
args: ["--schemafile", "https://json.schemastore.org/github-workflow"]
stages: [manual]

- repo: local
hooks:
- id: check-pyproject
name: check pyproject file
language: python
entry: python -m check_requirements
files: ^pyproject.toml$
stages: [manual]
additional_dependencies: ["tomli"]
33 changes: 0 additions & 33 deletions MANIFEST.in

This file was deleted.

103 changes: 103 additions & 0 deletions buildapi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
"""A build backend that handles installing the template files.

See https://peps.python.org/pep-0517/#in-tree-build-backends
"""
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,
)

notebook_css_version = "5.4.0"
notebook_css_url = "https://cdn.jupyter.org/notebook/%s/style/style.min.css" % notebook_css_version

jupyterlab_css_version = "3.1.11"
jupyterlab_css_url = (
"https://unpkg.com/@jupyterlab/nbconvert-css@%s/style/index.css" % jupyterlab_css_version
)

jupyterlab_theme_light_version = "3.1.11"
jupyterlab_theme_light_url = (
"https://unpkg.com/@jupyterlab/theme-light-extension@%s/style/variables.css"
% jupyterlab_theme_light_version
)

jupyterlab_theme_dark_version = "3.1.11"
jupyterlab_theme_dark_url = (
"https://unpkg.com/@jupyterlab/theme-dark-extension@%s/style/variables.css"
% jupyterlab_theme_dark_version
)

template_css_urls = {
"lab": [
(jupyterlab_css_url, "index.css"),
(jupyterlab_theme_light_url, "theme-light.css"),
(jupyterlab_theme_dark_url, "theme-dark.css"),
],
"classic": [(notebook_css_url, "style.css")],
}

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


def _get_css_file(template_name, url, filename):
"""Get a css file and download it to the templates dir"""
directory = osp.join(templates_dir, template_name, "static")
dest = osp.join(directory, filename)
if not osp.exists(directory):
os.makedirs(directory)
print("Downloading CSS: %s" % url)
try:
css = urlopen(url).read()
except Exception as e:
msg = f"Failed to download css from {url}: {e}"
print(msg, file=sys.stderr)
if osp.exists(dest):
print("Already have CSS: %s, moving on." % dest)
else:
raise OSError("Need CSS to proceed.")
return

with open(dest, "wb") as f:
f.write(css)
print("Downloaded Notebook CSS to %s" % dest)


def _get_css_files():
"""Get all of the css files if necessary"""
in_checkout = osp.exists(osp.abspath(osp.join(here, "..", ".git")))
if in_checkout:
print("Not running from git, nothing to do")
return

for template_name, resources in template_css_urls.items():
for url, filename in resources:
_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)
31 changes: 31 additions & 0 deletions check_requirements.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Verify that the "all" reqs are in sync.
import sys

from tomli import load

with open("pyproject.toml", "rb") as fid:
data = load(fid)

all_reqs = data["project"]["optional-dependencies"]["all"]
remaining_all = all_reqs.copy()
errors = []

for (key, reqs) in data["project"]["optional-dependencies"].items():
if key == "all":
continue
for req in reqs:
if req not in all_reqs:
errors.append(req)
elif req in remaining_all:
remaining_all.remove(req)

if errors:
print('Missing deps in "all" reqs:')
print([e for e in errors])

if remaining_all:
print('Reqs in "all" but nowhere else:')
print([r for r in remaining_all])

if errors or remaining_all:
sys.exit(1)
6 changes: 1 addition & 5 deletions docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,11 @@ clean:
rm -rf $(BUILDDIR)/*
rm source/config_options.rst

html: source/config_options.rst
html:
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."

source/config_options.rst:
python3 autogen_config.py
@echo "Created docs for config options"

dirhtml:
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
@echo
Expand Down
1 change: 1 addition & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
# Automatically generate config_options.rst
with open(os.path.join(os.path.dirname(__file__), "..", "autogen_config.py")) as f:
exec(compile(f.read(), "autogen_config.py", "exec"), {})
print("Created docs for config options")

# -- General configuration ------------------------------------------------

Expand Down
4 changes: 2 additions & 2 deletions docs/source/development_release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ Create the release

.. code:: bash

python setup.py sdist
python setup.py bdist_wheel
pip install build
python -m build .

#. You can now test the ``wheel`` and the ``sdist`` locally before uploading
to PyPI. Make sure to use `twine <https://github.com/pypa/twine>`_ to
Expand Down
9 changes: 7 additions & 2 deletions nbconvert/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
"""Utilities for converting notebooks to and from different formats."""

from . import filters, postprocessors, preprocessors, writers
from ._version import __version__, version_info # noqa
from .exporters import *

try:
from . import filters, postprocessors, preprocessors, writers
from .exporters import *
except ModuleNotFoundError:
# We hit this condition when the package is not yet fully installed.
pass
4 changes: 1 addition & 3 deletions nbconvert/exporters/templateexporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@
JINJA_EXTENSIONS = ["jinja2.ext.loopcontrols"]

ROOT = os.path.dirname(__file__)
DEV_MODE = os.path.exists(os.path.join(ROOT, "../../setup.py")) and os.path.exists(
os.path.join(ROOT, "../../share")
)
DEV_MODE = os.path.exists(os.path.join(ROOT, "../../.git"))


default_filters = {
Expand Down
Loading