Skip to content

Commit

Permalink
docs: add Makefile help
Browse files Browse the repository at this point in the history
  • Loading branch information
derlin committed Mar 18, 2024
1 parent d5364bc commit 609aaba
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 16 deletions.
33 changes: 21 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@
.PHONY: lint test setup_build build
.PHONY: all

lint:
docker run --rm -e LINT_FOLDER_PYTHON=mantelo -v $(CURDIR):/app divio/lint /bin/lint ${ARGS} --run=python
default: help

mypy:
mypy mantelo
help:
@awk 'BEGIN {FS = ": .*##";} /^[$$()% 0-9a-zA-Z_-]+(\\:[$$()% 0-9a-zA-Z_-]+)*:.*?##/ { gsub(/\\:/,":", $$1); printf " \033[36m%-5s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)


##@ Build

build: ## Build the wheels and sdist.
find . -name "*.egg-info" | xargs rm -rf && \
rm -rf dist && \
python -m build

test:
##@ Development

lint: ## Run ruff to format and lint (inside docker).
docker run --rm -e LINT_FOLDER_PYTHON=mantelo -v $(CURDIR):/app divio/lint /bin/lint ${ARGS} --run=python

test: ## Run tests with tox (inside docker).
coverage erase
docker compose up -d --wait keycloak
docker compose run --rm tox ${ARGS}
coverage combine
coverage html
coverage xml

build:
find . -name "*.egg-info" | xargs rm -rf && \
rm -rf dist && \
python -m build

mypy: ## Run mypy locally to check types.
mypy mantelo

export-realms: ## Export realms after changes in Keycloak.
export-realms: ## Export test realms after changes in Keycloak Test Server.
docker compose exec keycloak /opt/keycloak/bin/kc.sh export --dir /tmp/export --users realm_file; \
for realm in master orwell; do \
file=$$realm-realm.json; \
Expand Down
54 changes: 50 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

**✨✨ MANTELO is a super small yet super powerful tool for interacting with the Keycloak Admin API ✨✨**

> Mantelo [manˈtelo], from German "Mantel", from Late Latin "mantum" means "cloak" in Esperanto.
> Mantelo [manˈtelo], from German "*Mantel*", from Late Latin "*mantum*" means "*cloak*" in Esperanto.
It stays always **fresh** and **complete** because it does not implement or wrap any endpoint.
Instead, it offers an object-oriented interface to the Keycloak ReSTful API. Acting as a wrapper
Expand All @@ -25,11 +25,12 @@ the excellent [slumber](https://slumber.readthedocs.io/) library.
- [🚀 Why mantelo?](#-why-mantelo)
- [🏁 Getting started](#-getting-started)
- [🔐 Authenticate to Keycloak](#-authenticate-to-keycloak)
- [Authenticating with username+password](#authenticating-with-usernamepassword)
- [Authenticating with a service account (client ID + secret)](#authenticating-with-a-service-account-client-id--secret)
- [Other ways of authenticating](#other-ways-of-authenticating)
* [Authenticating with username+password](#authenticating-with-usernamepassword)
* [Authenticating with a service account (client ID + secret)](#authenticating-with-a-service-account-client-id--secret)
* [Other ways of authenticating](#other-ways-of-authenticating)
- [📡 Making calls](#-making-calls)
- [💀 Exceptions](#-exceptions)
- [🔧 Development](#-development)

<!-- TOC end -->

Expand Down Expand Up @@ -298,3 +299,48 @@ HttpException(
response='<requests.Response>',
)
```

---

## 🔧 Development

Prerequisites:

- Python
- Docker

To work on this library locally, install the library in edit mode along with the dev dependencies:

```bash
# Use .[dev,test] to also install pytest and related libraries
pip install -e '.[dev]'
```

A **Makefile** is available for all the usual development tasks. Use help to list the available
commands:

```bash
make help
```
```text
Build
build Build the wheels and sdist.
Development
lint Run ruff to format and lint (inside docker).
test Run tests with tox (inside docker).
mypy Run mypy locally to check types.
export-realms Export test realms after changes in Keycloak Test Server.
```

Note that `make test` automatically starts a Keycloak container if it isn't already running. You may
have to stop it manually. The test server is configured using the resources in `tests/realms` and is
available at `http://localhost:9090`. To start the Keycloak server yourself:

```bash
docker compose up --wait
```

You can run the tests directly using `pytest` for faster development, just ensure you installed the
test dependencies (`pip install -e '.[dev,test]'`) and Keycloak is running.

0 comments on commit 609aaba

Please sign in to comment.