Skip to content

Commit 17bf201

Browse files
authored
Use hatch environments to simplify test, coverage, and docs build (#1007)
1 parent 0fd422c commit 17bf201

File tree

6 files changed

+94
-69
lines changed

6 files changed

+94
-69
lines changed

.github/workflows/python-tests.yml

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,15 @@ jobs:
3131
uses: actions/checkout@v2
3232
- name: Base Setup
3333
uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
34-
- name: Install the Python dependencies
35-
run: |
36-
pip install -e ".[test,dev]" codecov
3734
- name: Run the tests
3835
if: ${{ !startsWith(matrix.python-version, 'pypy') && !startsWith(matrix.os, 'windows') }}
39-
run: |
40-
args="-vv --cov jupyter_server --cov-branch --cov-report term-missing:skip-covered"
41-
python -m pytest $args --cov-fail-under 70 || python -m pytest $args --lf
36+
run: hatch run cov:test || hatch run cov:test --lf
4237
- name: Run the tests on pypy and windows
4338
if: ${{ startsWith(matrix.python-version, 'pypy') || startsWith(matrix.os, 'windows') }}
44-
run: |
45-
python -m pytest -vv || python -m pytest -vv --lf
39+
run: hatch run test:test || hatch run test:test --lf
4640
- name: Coverage
4741
run: |
42+
pip install codecov
4843
codecov
4944
5045
pre-commit:
@@ -67,26 +62,28 @@ jobs:
6762
echo "or after-the-fact on already committed files with"
6863
echo " pre-commit run --all-files --hook-stage=manual"
6964
70-
test_docs_and_examples:
71-
name: Test Docs and Examples
65+
test_docs:
66+
name: Test Docs
67+
runs-on: ubuntu-latest
68+
steps:
69+
- uses: actions/checkout@v2
70+
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
71+
- run: hatch run docs:build
72+
73+
test_examples:
74+
name: Test Examples
7275
timeout-minutes: 10
7376
runs-on: ubuntu-latest
7477
steps:
7578
- uses: actions/checkout@v2
76-
- name: Base Setup
77-
uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
79+
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
7880
- name: Install the Python dependencies for the examples
7981
run: |
8082
pip install -e ".[test]"
8183
cd examples/simple && pip install -e .
8284
- name: Run the tests for the examples
8385
run: |
8486
python -m pytest examples/simple
85-
- name: Test the docs
86-
run: |
87-
cd docs
88-
pip install -r doc-requirements.txt
89-
make html SPHINXOPTS="-W"
9087
9188
test_minimum_versions:
9289
name: Test Minimum Versions
@@ -101,8 +98,7 @@ jobs:
10198
- name: Install miniumum versions
10299
uses: jupyterlab/maintainer-tools/.github/actions/install-minimums@v1
103100
- name: Run the unit tests
104-
run: |
105-
pytest -vv -W default || pytest -vv -W default --lf
101+
run: hatch run test:nowarn || hatch run test:nowarn --lf
106102

107103
test_prereleases:
108104
name: Test Prereleases
@@ -126,7 +122,7 @@ jobs:
126122
- name: Run the tests
127123
run: |
128124
pip install jupyter_client@https://github.com/blink1073/jupyter_client/archive/refs/heads/synchronous_managers.zip
129-
pytest -vv || pytest -vv --lf
125+
pytest -vv -W default || pytest -vv -W default --lf
130126
131127
make_sdist:
132128
name: Make SDist
@@ -146,7 +142,8 @@ jobs:
146142
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
147143
- uses: jupyterlab/maintainer-tools/.github/actions/test-sdist@v1
148144
with:
149-
test_command: pytest -vv || pytest -vv --lf
145+
package_spec: .
146+
test_command: hatch run test:test || hatch run test:test --lf
150147

151148
check_links:
152149
name: Check Links

CONTRIBUTING.rst

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ The development version of the server requires `node <https://nodejs.org/en/down
2424
Once you have installed the dependencies mentioned above, use the following
2525
steps::
2626

27-
pip install --upgrade setuptools pip
27+
pip install --upgrade pip
2828
git clone https://github.com/jupyter/jupyter_server
2929
cd jupyter_server
30-
pip install -e ".[dev,test]"
30+
pip install -e ".[test]"
3131

3232
If you are using a system-wide Python installation and you only want to install the server for you,
3333
you can add ``--user`` to the install commands.
@@ -45,11 +45,10 @@ need to worry too much about your code style.
4545
As long as your code is valid,
4646
the pre-commit hook should take care of how it should look.
4747
`pre-commit` and its associated hooks will automatically be installed when
48-
you run ``pip install -e ".[dev,test]"``
48+
you run ``pip install -e ".[test]"``
4949

50-
To install ``pre-commit`` manually, run the following::
50+
To install ``pre-commit`` hook manually, run the following::
5151

52-
pip install pre-commit
5352
pre-commit install
5453

5554

@@ -78,9 +77,9 @@ running other instances of Jupyter Server. You can try the following steps:
7877

7978
1. Uninstall all instances of the jupyter_server package. These include any installations you made using
8079
pip or conda
81-
2. Run ``python3 -m pip install -e .`` in the jupyter_server repository to install the jupyter_server from there
80+
2. Run ``python -m pip install -e .`` in the jupyter_server repository to install the jupyter_server from there
8281
3. Run ``npm run build`` to make sure the Javascript and CSS are updated and compiled
83-
4. Launch with ``python3 -m jupyter_server --port 8989``, and check that the browser is pointing to ``localhost:8989``
82+
4. Launch with ``python -m jupyter_server --port 8989``, and check that the browser is pointing to ``localhost:8989``
8483
(rather than the default 8888). You don't necessarily have to launch with port 8989, as long as you use
8584
a port that is neither the default nor in use, then it should be fine.
8685
5. Verify the installation with the steps in the previous section.
@@ -98,36 +97,43 @@ To run the Python tests, use::
9897
pytest
9998
pytest examples/simple # to test the examples
10099

101-
Building the Docs
102-
=================
100+
You can also run the tests using ``hatch`` without installing test dependencies in your local environment::
101+
102+
pip install hatch
103+
hatch run test:test
103104

104-
To build the documentation you'll need `Sphinx <http://www.sphinx-doc.org/en/master/>`_,
105-
`pandoc <https://pandoc.org/>`_ and a few other packages.
105+
The command takes any argument that you can give to ``pytest``, e.g.::
106106

107-
To install (and activate) a `conda environment`_ named ``jupyter_server_docs``
108-
containing all the necessary packages (except pandoc), use::
107+
hatch run test:test -k name_of_method_to_test
109108

110-
conda env create -f docs/environment.yml
111-
conda activate jupyter_server_docs
109+
You can also drop into a shell in the test environment by running::
112110

113-
.. _conda environment:
114-
https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#creating-an-environment-from-an-environment-yml-file
111+
hatch -e test shell
112+
113+
Building the Docs
114+
=================
115115

116-
If you want to install the necessary packages with ``pip`` instead::
116+
Install the docs requirements using ``pip``::
117117

118-
pip install -r docs/doc-requirements.txt
118+
pip install .[doc]
119119

120120
Once you have installed the required packages, you can build the docs with::
121121

122122
cd docs
123123
make html
124124

125-
After that, the generated HTML files will be available at
126-
``build/html/index.html``. You may view the docs in your browser.
125+
You can also run the tests using ``hatch`` without installing test dependencies
126+
in your local environment.
127+
128+
pip install hatch
129+
hatch run docs:build
127130

128-
You can automatically check if all hyperlinks are still valid::
131+
You can also drop into a shell in the docs environment by running::
129132

130-
make linkcheck
133+
hatch -e docs shell
134+
135+
After that, the generated HTML files will be available at
136+
``build/html/index.html``. You may view the docs in your browser.
131137

132138
Windows users can find ``make.bat`` in the ``docs`` folder.
133139

docs/doc-requirements.txt

Lines changed: 0 additions & 17 deletions
This file was deleted.

docs/environment.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,3 @@ dependencies:
33
- nodejs
44
- python
55
- pip
6-
- pip:
7-
- -r doc-requirements.txt
8-
- ..

pyproject.toml

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,24 +62,58 @@ test = [
6262
"pytest-tornasync",
6363
"pytest>=6.0",
6464
"requests",
65+
"pre-commit"
6566
]
66-
dev = [
67-
"coverage",
68-
"pre-commit",
69-
"pytest-cov",
67+
docs = [
68+
# needed because m2r uses deprecated APIs
69+
# m2r is depended on by sphinxcontrib-openapi
70+
"docutils<0.19",
71+
"ipykernel",
72+
"jinja2",
73+
"jupyter_client",
74+
"jupyter_server",
75+
"mistune<1.0.0",
76+
"myst-parser",
77+
"nbformat",
78+
"prometheus_client",
79+
"pydata_sphinx_theme",
80+
"Send2Trash",
81+
"sphinxcontrib-openapi",
82+
"sphinxcontrib_github_alt",
83+
"sphinxemoji",
84+
"tornado",
7085
]
7186

7287
[project.scripts]
7388
jupyter-server = "jupyter_server.serverapp:main"
7489

90+
[tool.hatch.envs.docs]
91+
features = ["docs"]
92+
[tool.hatch.envs.docs.scripts]
93+
build = "make -C docs html SPHINXOPTS='-W'"
94+
95+
[tool.hatch.envs.test]
96+
features = ["test"]
97+
[tool.hatch.envs.test.scripts]
98+
test = "python -m pytest -vv {args}"
99+
nowarn = "python -m pytest -vv -W default {args}"
100+
101+
[tool.hatch.envs.cov]
102+
features = ["test"]
103+
dependencies = ["coverage", "pytest-cov"]
104+
[tool.hatch.envs.cov.env-vars]
105+
ARGS = "-vv --cov jupyter_server --cov-branch --cov-report term-missing:skip-covered"
106+
[tool.hatch.envs.cov.scripts]
107+
test = "python -m pytest $ARGS --cov-fail-under 70 {args}"
108+
75109
[tool.hatch.version]
76110
path = "jupyter_server/_version.py"
77111

78112
[tool.hatch.build]
79113
artifacts = ["jupyter_server/static/style"]
80114

81115
[tool.hatch.build.hooks.jupyter-builder]
82-
dependencies = ["hatch-jupyter-builder>=0.3.3"]
116+
dependencies = ["hatch-jupyter-builder>=0.7.1"]
83117
build-function = "hatch_jupyter_builder.npm_builder"
84118
ensured-targets = [
85119
"jupyter_server/static/style/bootstrap.min.css",

readthedocs.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,11 @@ sphinx:
33
configuration: docs/source/conf.py
44
conda:
55
environment: docs/environment.yml
6+
python:
7+
version: 3.8
8+
install:
9+
# install itself with pip install .
10+
- method: pip
11+
path: .
12+
extra_requirements:
13+
- docs

0 commit comments

Comments
 (0)