Skip to content

Commit

Permalink
Update CONTRIBUTING.md and associated docker-ldap.sh script
Browse files Browse the repository at this point in the history
  • Loading branch information
consideRatio committed Jun 4, 2023
1 parent d824640 commit f8a035c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 55 deletions.
71 changes: 26 additions & 45 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Contributing

Welcome! As a [Jupyter](https://jupyter.org) project, we follow the [Jupyter contributor guide](https://jupyter.readthedocs.io/en/latest/contributor/content-contributor.html).
Welcome! As a [Jupyter](https://jupyter.org) project, you can follow the [Jupyter contributor guide](https://docs.jupyter.org/en/latest/contributing/content-contributor.html).

Make sure to also follow [Project Jupyter's Code of Conduct](https://github.com/jupyter/governance/blob/main/conduct/code_of_conduct.md)
for a friendly and welcoming collaborative environment.
Expand All @@ -9,68 +9,45 @@ This guide was adapted from the [contributing guide in the main `jupyterhub` rep

## Setting up a development environment

JupyterHub requires Python >= 3.5.
JupyterHub requires Python >= 3.7.

As a Python project, a development install of JupyterHub follows standard practices for installation and testing.

Note: if you have Docker installed locally, you can run all of the subsequent commands inside of a container after you run the following initial commands:

```
```shell
# starts an openldap server inside a docker container
./ci/docker-ldap.sh
docker run -v $PWD:/usr/local/src --workdir /usr/local/src --net=host --rm -it python:3.6 bash

# starts a python docker image
docker run --rm -it -v $PWD:/usr/local/src --workdir=/usr/local/src --net=host python:3.11 bash
```

1. Do a development install with pip

```bash
cd ldapauthenticator
python3 -m pip install --editable .
```
```bash
pip install --editable ".[test]"
```

1. Install the development requirements,
which include things like testing tools

```bash
python3 -m pip install -r dev-requirements.txt
```
1. Set up pre-commit hooks for automatic code formatting, etc.

```bash
pre-commit install
```

You can also invoke the pre-commit hook manually at any time with
```bash
pip install pre-commit
```bash
pre-commit run
```
pre-commit install --install-hooks
```

To clean up your development LDAP deployment, run:
```
docker rm -f ldap
```
You can also invoke the pre-commit hook manually at any time with

## Contributing
```bash
pre-commit run
```

JupyterHub has adopted automatic code formatting so you shouldn't
need to worry too much about your code style.
As long as your code is valid,
the pre-commit hook should take care of how it should look.
You can invoke the pre-commit hook by hand at any time with:
To clean up your development LDAP deployment, run:

```bash
pre-commit run
```

which should run any autoformatting on your code
and tell you about any errors it couldn't fix automatically.
You may also install [black integration](https://github.com/ambv/black#editor-integration)
into your text editor to format code automatically.

If you have already committed files before setting up the pre-commit
hook with `pre-commit install`, you can fix everything up using
`pre-commit run --all-files`. You need to make the fixing commit
yourself after that.
docker rm -f test-openldap
```
## Testing
Expand All @@ -80,7 +57,11 @@ or that trigger any bugs that you have fixed to catch regressions.
You can run the tests with:
```bash
pytest -v
# starts an openldap server inside a docker container
./ci/docker-ldap.sh
# run tests
pytest
```

The tests live in `ldapauthenticator/tests`.
Expand Down
25 changes: 15 additions & 10 deletions ci/docker-ldap.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
#!/usr/bin/env bash
# source this file to setup LDAP
# for local testing (as similar as possible to docker)

set -e

NAME="hub-test-ldap"
DOCKER_RUN="docker run -d --name $NAME"
RUN_ARGS="-p 389:10389 -p 636:10636 rroemhild/test-openldap"

docker rm -f "$NAME" 2>/dev/null || true

$DOCKER_RUN $RUN_ARGS
# This file (re-)starts an openldap server to test against within a docker
# container based on the image rroemhild/test-openldap.
#
# ref: https://github.com/rroemhild/docker-test-openldap
# ref: https://hub.docker.com/r/rroemhild/test-openldap/
#
# Stop any existing test-openldap container
docker rm --force test-openldap 2>/dev/null || true
# Start a container, and expose some ports, where 389 and 636 are the local
# system's ports that are redirected to the started container.
#
# - 389:10389 (ldap)
# - 636:10636 (ldaps)
#
docker run --detach --name=test-openldap -p 389:10389 -p 636:10636 rroemhild/test-openldap:2.1

0 comments on commit f8a035c

Please sign in to comment.