-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit (generated by Sicarator)
- Loading branch information
Emilio DE SOUSA
committed
May 27, 2024
0 parents
commit 3248e49
Showing
15 changed files
with
904 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: "Install Dependencies" | ||
description: "Action to build the project dependencies from the main versions" | ||
inputs: | ||
python_version: | ||
required: true | ||
type: string | ||
default: "3.11.6" | ||
poetry_version: | ||
required: true | ||
type: string | ||
default: "1.7.0" | ||
|
||
runs: | ||
using: composite | ||
steps: | ||
- name: Install Poetry | ||
uses: snok/install-poetry@v1 | ||
with: | ||
version: ${{ inputs.poetry_version }} | ||
virtualenvs-create: true | ||
virtualenvs-in-project: false | ||
installer-parallel: true | ||
- uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ inputs.python_version }} | ||
cache: "poetry" | ||
- name: Install Dependencies | ||
run: poetry install --no-root | ||
shell: bash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
name: Tests | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
pull_request: | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.head_ref || github.ref }} | ||
cancel-in-progress: ${{ github.event_name == 'pull_request' }} | ||
|
||
jobs: | ||
setup: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: ./.github/workflows/actions/install_dependencies | ||
|
||
checks: | ||
needs: setup | ||
runs-on: ubuntu-latest | ||
name: ${{ matrix.quality-command }} | ||
strategy: | ||
matrix: | ||
quality-command: | ||
- format-check | ||
- lint-check | ||
- type-check | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: ./.github/workflows/actions/install_dependencies | ||
- name: run ${{ matrix.quality-command }} | ||
run: make ${{ matrix.quality-command }} | ||
|
||
test: | ||
needs: setup | ||
runs-on: ubuntu-latest | ||
name: test | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: ./.github/workflows/actions/install_dependencies | ||
- name: run test | ||
run: make test | ||
# Run even if make test fails for coverage reports | ||
# TODO: select a better xml results displayer | ||
- name: Archive test results coverage results | ||
uses: actions/upload-artifact@v3 | ||
if: always() | ||
with: | ||
name: test_results | ||
path: tests-results.xml | ||
- name: Archive code coverage results | ||
uses: actions/upload-artifact@v3 | ||
if: always() | ||
with: | ||
name: code-coverage-report | ||
path: htmlcov/ | ||
|
||
all_checks_passed: | ||
# Used to easily force requirements checks in GitHub | ||
needs: | ||
- checks | ||
- test | ||
runs-on: ubuntu-latest | ||
steps: | ||
- run: echo "All checks passed" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
|
||
# unit tests / coverage reports | ||
/tests-results.xml | ||
/.coverage | ||
/coverage.xml | ||
/htmlcov/ | ||
|
||
# pyenv | ||
/.python-version | ||
|
||
# IDE | ||
.idea/ | ||
.vscode/ | ||
|
||
# macOS | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
default_install_hook_types: | ||
# Mandatory to install both pre-commit and pre-push hooks (see https://pre-commit.com/#top_level-default_install_hook_types) | ||
# Add new hook types here to ensure automatic installation when running `pre-commit install` | ||
- pre-commit | ||
- pre-push | ||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v4.3.0 | ||
hooks: | ||
- id: trailing-whitespace | ||
- id: end-of-file-fixer | ||
- id: check-yaml | ||
- id: check-json | ||
- id: check-added-large-files | ||
|
||
- repo: local | ||
hooks: | ||
- id: format-fix | ||
name: Formatting (ruff) | ||
entry: ruff format | ||
language: system | ||
types: [python] | ||
stages: [commit] | ||
- id: lint-check | ||
name: Linting (ruff) | ||
entry: ruff check | ||
language: system | ||
types: [python] | ||
stages: [commit] | ||
- id: type-check | ||
name: Type checking (mypy) | ||
entry: make type-check | ||
pass_filenames: false | ||
language: system | ||
types: [python] | ||
stages: [commit] | ||
- id: test | ||
name: Unit testing (pytest) | ||
entry: make test | ||
pass_filenames: false | ||
language: system | ||
types: [python] | ||
stages: [push] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"generator-sicarator": { | ||
"promptValues": { | ||
"authorName": "Emilio DE SOUSA", | ||
"authorEmail": "[email protected]", | ||
"ci": ".github", | ||
"includeApi": false, | ||
"includeDvc": false, | ||
"includeStreamlit": false, | ||
"includeHelloWorld": true | ||
}, | ||
"projectName": "rag-initiator", | ||
"projectSlug": "rag-initiator", | ||
"projectDescription": "repo used to learn how to do a rag" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
######################################################################################################################## | ||
# Project installation | ||
######################################################################################################################## | ||
|
||
install: | ||
pyenv virtualenv --force 3.11.6 rag-initiator | ||
pyenv local rag-initiator | ||
# Running poetry install inside a Make command requires a VIRTUAL_ENV variable | ||
VIRTUAL_ENV=$$(pyenv prefix) poetry install --no-root --sync | ||
|
||
######################################################################################################################## | ||
# Quality checks | ||
######################################################################################################################## | ||
|
||
test: | ||
poetry run pytest tests --cov src --cov-report term --cov-report=html --cov-report xml --junit-xml=tests-results.xml | ||
|
||
format-check: | ||
poetry run ruff format --check src tests | ||
|
||
format-fix: | ||
poetry run ruff format src tests | ||
|
||
lint-check: | ||
poetry run ruff check src tests | ||
|
||
lint-fix: | ||
poetry run ruff check src tests --fix | ||
|
||
type-check: | ||
poetry run mypy src |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
# rag-initiator | ||
|
||
> repo used to learn how to do a rag | ||
## Project requirements | ||
|
||
### Pyenv and `Python 3.11.6` | ||
|
||
- Install [pyenv](https://github.com/pyenv/pyenv) to manage your Python versions and virtual environments: | ||
```bash | ||
curl -sSL https://pyenv.run | bash | ||
``` | ||
- If you are on MacOS and experiencing errors on python install with pyenv, follow this [comment](https://github.com/pyenv/pyenv/issues/1740#issuecomment-738749988) | ||
- Add these lines to your `~/.bashrc` or `~/.zshrc` to be able to activate `pyenv virtualenv`: | ||
```bash | ||
eval "$(pyenv init -)" | ||
eval "$(pyenv virtualenv-init -)" | ||
eval "$(pyenv init --path)" | ||
``` | ||
- Restart your shell | ||
|
||
- Install the right version of `Python` with `pyenv`: | ||
```bash | ||
pyenv install 3.11.6 | ||
``` | ||
|
||
### Poetry | ||
|
||
- Install [Poetry](https://python-poetry.org) to manage your dependencies and tooling configs: | ||
```bash | ||
curl -sSL https://install.python-poetry.org | python - --version 1.7.0 | ||
``` | ||
*If you have not previously installed any Python version, you may need to set your global Python version before installing Poetry:* | ||
```bash | ||
pyenv global 3.11.6 | ||
``` | ||
|
||
## Installation | ||
|
||
### Python virtual environment and dependencies | ||
|
||
1. Create a `pyenv` virtual environment and link it to your project folder: | ||
```bash | ||
pyenv virtualenv 3.11.6 rag-initiator | ||
pyenv local rag-initiator | ||
``` | ||
*Now, every time you are in your project directory your virtualenv will be activated!* | ||
|
||
|
||
2. Install dependencies with `Poetry`: | ||
```bash | ||
poetry install --no-root | ||
``` | ||
|
||
Steps 1. and 2. can also be done in one command: | ||
```bash | ||
make install | ||
``` | ||
|
||
### Install git hooks (running before commit and push commands) | ||
|
||
```bash | ||
poetry run pre-commit install | ||
``` | ||
|
||
## Testing | ||
|
||
To run unit tests, run `pytest` with: | ||
```bash | ||
pytest tests --cov src | ||
``` | ||
or | ||
```bash | ||
make test | ||
``` | ||
|
||
## Formatting and static analysis | ||
|
||
### Code formatting with `ruff` | ||
|
||
To check code formatting, run `ruff format` with: | ||
```bash | ||
ruff format --check . | ||
``` | ||
or | ||
```bash | ||
make format-check | ||
``` | ||
|
||
You can also [integrate it to your IDE](https://docs.astral.sh/ruff/integrations/) to reformat | ||
your code each time you save a file. | ||
|
||
### Static analysis with `ruff` | ||
|
||
To run static analysis, run `ruff` with: | ||
```bash | ||
ruff check src tests | ||
``` | ||
or | ||
```bash | ||
make lint-check | ||
``` | ||
|
||
To run static analysis and to apply auto-fixes, run `ruff` with: | ||
```bash | ||
make lint-fix | ||
``` | ||
### Type checking with `mypy` | ||
|
||
To type check your code, run `mypy` with: | ||
```bash | ||
mypy src --explicit-package-bases --namespace-packages | ||
``` | ||
or | ||
```bash | ||
make type-check | ||
``` |
Oops, something went wrong.