Skip to content

Commit

Permalink
feat: FS-2031 added justfile and docker compose for developers
Browse files Browse the repository at this point in the history
  • Loading branch information
Rusich90 committed Feb 20, 2025
1 parent a13332d commit 6c21147
Show file tree
Hide file tree
Showing 18 changed files with 279 additions and 294 deletions.
9 changes: 6 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,31 +36,34 @@ repos:
- id: lint
name: Linter
stages: [pre-commit, pre-merge-commit, manual]
entry: "scripts/lint-pre-commit.sh"
entry: just linter
language: python
types: [python]
require_serial: true
verbose: true
pass_filenames: false

- repo: local
hooks:
- id: static-analysis
name: Static analysis
entry: "scripts/static-pre-commit.sh"
entry: just static-analysis
language: python
types: [python]
require_serial: true
verbose: true
pass_filenames: false

- repo: local
hooks:
- id: docs
name: Build docs
entry: "scripts/build-docs-pre-commit.sh"
entry: just docs-build
language: python
files: ^docs
require_serial: true
verbose: true
pass_filenames: false

- repo: https://github.com/Yelp/detect-secrets
rev: v1.5.0
Expand Down
110 changes: 68 additions & 42 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,69 +4,89 @@

After cloning the project, you'll need to set up the development environment. Here are the guidelines on how to do this.

## Virtual Environment with `venv`
## Install Justfile Utility

Create a virtual environment in a directory using Python's `venv` module:
Install justfile on your system:

```bash
python -m venv venv
brew install justfile
```

That will create a `./venv/` directory with Python binaries, allowing you to install packages in an isolated environment.
View all available commands:

## Activate the Environment
```bash
just
```

Activate the new environment with:
## Init development environment

Build Python and create a virtual environment:

```bash
source ./venv/bin/activate
just init
```

Ensure you have the latest pip version in your virtual environment:
By default, this builds Python 3.8. If you need another version, pass it as an argument to the just command:

```bash
python -m pip install --upgrade pip
just init 3.11.5
```

## Installing Dependencies
To check available Python versions, refer to the pyproject.toml file in the project root.

After activating the virtual environment as described above, run:
## Activate the Environment

Activate the new environment with

For Unix-based systems:

```bash
pip install -e ".[dev]"
source ./venv/bin/activate
```

This will install all the dependencies and your local **FastStream** in your virtual environment.
For Windows (PowerShell):

### Using Your local **FastStream**
```bash
.\venv\Scripts\Activate.ps1
```

If you create a Python file that imports and uses **FastStream**, and run it with the Python from your local environment, it will use your local **FastStream** source code.
Install and configure pre-commit:

Whenever you update your local **FastStream** source code, it will automatically use the latest version when you run your Python file again. This is because it is installed with `-e`.
```bash
just pre-commit-install
```

This way, you don't have to "install" your local version to be able to test every change.
## Run all Dependencies

To use your local **FastStream CLI**, type:
Start all dependencies as docker containers:

```bash
python -m faststream ...
just up
```

Once you are done with development and running tests, you can stop the dependencies' docker containers by running:

```bash
just stop
# or
just down
```

## Running Tests

### Pytest
To run tests, use:

```bash
just test
```

To run tests with your current **FastStream** application and Python environment, use:
To run tests with coverage:

```bash
pytest tests
# or
./scripts/test.sh
# with coverage output
./scripts/test-cov.sh
just coverage-test
```

In your project, you'll find some *pytest marks*:
In your project, some tests are grouped under specific pytest marks:

* **slow**
* **rabbit**
Expand All @@ -75,34 +95,40 @@ In your project, you'll find some *pytest marks*:
* **redis**
* **all**

By default, running *pytest* will execute "not slow" tests.

To run all tests use:
By default, will execute "all" tests. You can specify marks to include or exclude tests:

```bash
pytest -m 'all'
just test kafka
# or
just test rabbit
# or
just test 'not confluent'
# or
just test 'not confluent and not nats'
# or
just coverage-test kafka
```

If you don't have a local broker instance running, you can run tests without those dependencies:
## Linter

Run all linters:

```bash
pytest -m 'not rabbit and not kafka and not nats and not redis and not confluent'
just linter
```

To run tests based on RabbitMQ, Kafka, or other dependencies, the following dependencies are needed to be started as docker containers:
## Static analysis

```yaml
{! includes/docker-compose.yaml !}
```

You can start the dependencies easily using provided script by running:
Run static analysis tools:

```bash
./scripts/start_test_env.sh
just static-analysis
```

Once you are done with development and running tests, you can stop the dependencies' docker containers by running:
## Pre-commit

Run pre-commit checks:

```bash
./scripts/stop_test_env.sh
just pre-commit
```
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM python:3.10
ARG PYTHON_VERSION=3.8

FROM python:$PYTHON_VERSION

ENV PYTHONUNBUFFERED=1

Expand All @@ -7,4 +9,3 @@ COPY . /src
WORKDIR /src

RUN pip install --upgrade pip && pip install -e ".[dev]"

3 changes: 2 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ services:
build: .
volumes:
- ./:/src
network_mode: "host"
network_mode: "host"
tty: true
Loading

0 comments on commit 6c21147

Please sign in to comment.