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

Setup release process and other improvements #4

Merged
merged 8 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion .github/workflows/backport.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ jobs:
with:
target-branch: 0.12.x
pull-request: ${{ github.event.pull_request.url }}
no-squash: ${{ env.NO_SQUASH_OPTION }}
no-squash: ${{ env.NO_SQUASH_OPTION }}
2 changes: 1 addition & 1 deletion .github/workflows/check-openapi-change.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ on:

jobs:
check-openapi-change:
# TODO: find a way to set name including the branch we are checking
name: check-openapi-change-${{ github.event.client_payload.branch }}
runs-on: ubuntu-latest
env:
FORCE_COLOR: "1"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This workflow will run the full CI for the Horreum python library including the build and the tests execution
# This is going to be triggered on every pull request as well as on main branch.
# This is going to be triggered on every pull request as well as on all stable branches (e.g., main and 0.12.x).
name: Python client ci

on:
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ bin/
**/.kiota.log

# Openapi
openapi/openapi.yaml
openapi/openapi.yaml

# Generate code
src/horreum/raw_client/**
lampajr marked this conversation as resolved.
Show resolved Hide resolved
10 changes: 6 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ KIOTA_VERSION ?= "v1.12.0"
HORREUM_BRANCH ?= "master"
HORREUM_OPENAPI_PATH ?= "https://raw.githubusercontent.com/Hyperfoil/Horreum/${HORREUM_BRANCH}/docs/site/content/en/openapi/openapi.yaml"
GENERATED_CLIENT_PATH = "${PROJECT_PATH}/src/horreum/raw_client"
OPENAPI_PATH = "${PROJECT_PATH}/openapi"

.PHONY: help
help: ## Display this help.
Expand All @@ -41,8 +42,8 @@ clean-bin: ## Clean external tools
@rm -rf ${PROJECT_BIN}

.PHONY: clean
clean: ## Clean external tools and output dirs
@rm -rf ${PROJECT_DIST} ${GENERATED_CLIENT_PATH}/api ${GENERATED_CLIENT_PATH}/models ${GENERATED_CLIENT_PATH}/horreum_raw_client.py ${GENERATED_CLIENT_PATH}/kiota-lock.json
clean: ## Clean output directories
@rm -rf ${PROJECT_DIST} ${GENERATED_CLIENT_PATH} ${OPENAPI_PATH}

.PHONY: kiota
kiota: ${PROJECT_BIN}/kiota ## Install kiota tool under ${PROJECT_PATH}/bin
Expand All @@ -66,6 +67,7 @@ tools: kiota ## Install external tools.
generate: tools ## Generate the Horreum client
@{\
set -e ;\
curl -sSfL -o ${PROJECT_PATH}/openapi/openapi.yaml ${HORREUM_OPENAPI_PATH} ;\
${PROJECT_BIN}/kiota generate -l python -c HorreumRawClient -n raw_client -d ${PROJECT_PATH}/openapi/openapi.yaml -o ${GENERATED_CLIENT_PATH} ;\
mkdir -p ${OPENAPI_PATH} ;\
curl -sSfL -o ${OPENAPI_PATH}/openapi.yaml ${HORREUM_OPENAPI_PATH} ;\
lampajr marked this conversation as resolved.
Show resolved Hide resolved
${PROJECT_BIN}/kiota generate -l python -c HorreumRawClient -n raw_client -d ${OPENAPI_PATH}/openapi.yaml -o ${GENERATED_CLIENT_PATH} ;\
}
26 changes: 22 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ Contributions to `horreum-client-python` Please check our [CONTRIBUTING.md](./CO

### Development

Install all dev dependencies (consider using Python virtual environments):
Install poetry dependency (consider using Python virtual environments):
```bash
pip install -r dev-constraints.txt
pip install --constraint=./dev-constraints.txt poetry
poetry --version
lampajr marked this conversation as resolved.
Show resolved Hide resolved
```

Generate source files
Expand All @@ -58,15 +59,32 @@ poetry build
```

#### Tests
Tests can be executed using [nox](https://nox.thea.codes/en/stable/) sessions.

Right now tests are not automated, therefore you need to start up the Horreum server manually,
To install it in your local environment, please run:
```bash
pip install --constraint=./dev-constraints.txt nox nox-poetry
nox --version
```

To check available sessions, run:
```bash
nox -l
```

And execute them by running:
```bash
nox -s [session]
```
lampajr marked this conversation as resolved.
Show resolved Hide resolved

Right now integrations tests are not fully automated, therefore you need to start up the Horreum server manually,
you can check more details in [Horreum README](https://github.com/Hyperfoil/Horreum/blob/master/README.md#getting-started-with-development-server).

> **_NOTE_**: The database should be empty to get all tests working

Once the Horreum server is up and running on `localhost:8080`, you can trigger integration tests by running:
```bash
pytest test/
nox -s its
```

### If you have any idea or doubt 👇
Expand Down
11 changes: 7 additions & 4 deletions docs/GET_STARTED.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,23 @@ In this document you can find all information to get started using the Horreum p
---
## Prerequisites

* Python environment, e.g., `pyenv` or `miniconda` with all development dependencies installed:
* Python environment, e.g., `pyenv` or `miniconda` with `poetry` dependency installed:
```bash
pip install -r dev-constraints.txt
pip install --constraint=./dev-constraints.txt poetry
poetry --version
```

## Installation

Once all dependencies are installed simply build the `whl` by running:
Once all [prerequisites](#prerequisites) are satisfied, run the following commands.

First of all, generate the Horreum client:

```bash
make generate
```

to generate source files and
Then, simply build the _wheel_ by running:

```bash
poetry build
Expand Down
10 changes: 4 additions & 6 deletions docs/RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ versioning scheme to keep coherence among all Horreum-related projects versions.

### Tag a new version

Checkout to your branch, either a `stable` (e.g., `0.12.x`) or the `main` one.
Checkout to your branch, either a "stable" (e.g., `0.12.x`) or the `main` one.

```bash
git checkout origin/main
Expand All @@ -25,7 +25,7 @@ This will bump your version, from `0.12-dev` to `0.12`.

To double-check the version, run:
```bash
poetry version [15:55:39]
poetry version
# horreum 0.12
```

Expand All @@ -49,14 +49,12 @@ from _stable_ rather than from `main`.

### Create stable branch

> **NOTE**: If the _stable_ branch is already existing simply skip this step at all as this means
> you already did the following steps.
> **NOTE**: If the _stable_ branch already exists, simply skip this step, as this means the following steps have already been done.

To create a _stable_ branch from the `main` one, e.g., `0.12.x`, run the following commands.

```bash
git checkout origin/main
git checkout -b 0.12.x
git checkout origin/main -b 0.12.x
git checkout origin/main
```

Expand Down
24 changes: 23 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,33 @@

@session(python=py_versions)
def tests(s: Session):
""" Run unit tests """
s.install(".")
s.install("pytest")
s.install(
"asyncio",
"pytest",
"pytest-asyncio"
)
# run tests
s.run(
"pytest",
"test/horreum_client_test.py",
*s.posargs
)


@session(python=py_versions)
def its(s: Session):
""" Run integration tests """
s.install(".")
s.install(
"asyncio",
"pytest",
"pytest-asyncio"
)
# run tests
s.run(
"pytest",
"test/horreum_client_it.py",
*s.posargs
)
lampajr marked this conversation as resolved.
Show resolved Hide resolved
Empty file removed openapi/.gitkeep
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is odd. Why is it important for a Git checkout to have an otherwise empty openapi directory? (E.g., why isn't this directory created as needed by the build process?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, as mentioned #4 (comment) I re-create the folder during the generate command.

Empty file.
2 changes: 1 addition & 1 deletion src/horreum/horreum_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from kiota_http.httpx_request_adapter import HttpxRequestAdapter

from .keycloak_access_provider import KeycloakAccessProvider
from .raw_client import HorreumRawClient
from .raw_client.horreum_raw_client import HorreumRawClient


async def setup_auth_provider(base_url: str, username: str, password: str) -> AccessTokenProvider:
Expand Down
5 changes: 0 additions & 5 deletions src/horreum/raw_client/.gitignore

This file was deleted.

5 changes: 0 additions & 5 deletions src/horreum/raw_client/__init__.py

This file was deleted.

12 changes: 2 additions & 10 deletions test/horreum_client_it.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,6 @@ async def authenticated_client() -> HorreumClient:
return client


def test_check_client_version(anonymous_client_without_check: HorreumClient):
version = anonymous_client_without_check.version()
# TODO: we could load the toml and check the versions match
assert version != ""


@pytest.mark.asyncio
async def test_check_server_version(anonymous_client: HorreumClient):
version = await anonymous_client.raw_client.api.config.version.get()
Expand All @@ -73,11 +67,9 @@ async def test_check_auth_token(authenticated_client: HorreumClient):

@pytest.mark.asyncio
async def test_missing_username_with_password():
try:
with pytest.raises(RuntimeError) as ex:
await new_horreum_client(base_url="http://localhost:8080", password=password)
pytest.fail("expect RuntimeError here")
except RuntimeError as e:
assert str(e) == "providing password without username, have you missed something?"
assert str(ex.value) == "providing password without username, have you missed something?"


@pytest.mark.asyncio
Expand Down
15 changes: 2 additions & 13 deletions test/horreum_client_test.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
import httpx
import pytest
from kiota_abstractions.authentication import BaseBearerTokenAuthenticationProvider
from kiota_abstractions.base_request_configuration import RequestConfiguration
from kiota_abstractions.headers_collection import HeadersCollection
from kiota_abstractions.method import Method
from kiota_abstractions.request_information import RequestInformation

from horreum.horreum_client import new_horreum_client, HorreumClient
from horreum.raw_client.api.test.test_request_builder import TestRequestBuilder
from horreum.raw_client.models.protected_type_access import ProtectedType_access
from horreum.raw_client.models.test import Test

username = "user"
password = "secret"


@pytest.fixture()
Expand All @@ -22,7 +10,8 @@ async def anonymous_client() -> HorreumClient:
return client


def test_check_client_version(anonymous_client: HorreumClient):
@pytest.mark.asyncio
async def test_check_client_version(anonymous_client: HorreumClient):
version = HorreumClient.version()
lampajr marked this conversation as resolved.
Show resolved Hide resolved
# TODO: we could load the toml and check the versions match
assert version != ""