Skip to content

Commit

Permalink
Add CI, autofixes, and checks configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel-Therrien-Beslogic committed Mar 22, 2024
1 parent a38c1dc commit ae0c4bd
Show file tree
Hide file tree
Showing 18 changed files with 658 additions and 176 deletions.
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
max_line_length = 120
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.{py,pyi}]
indent_size = 4
42 changes: 42 additions & 0 deletions .github/workflows/canopeum_backend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
on:
push:
pull_request:
branches:
- main

jobs:
mypy:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest", "windows-latest"]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: pip
cache-dependency-path: requirements*.txt
- run: cd canopeum_backend
- run: pip install -r requirements-dev.txt
- run: mypy . --python-version=3.12

pyright:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest", "windows-latest"]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: pip
cache-dependency-path: requirements*.txt
- run: cd canopeum_backend
- run: pip install -r requirements-dev.txt
- uses: jakebailey/pyright-action@v2
with:
python-version: "3.12"
5 changes: 5 additions & 0 deletions .markdownlint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"default": true,
"MD013": false, // Use line-wrap for Markdown
"MD029": false // Allow explicit ordered list number for lists split by block codes
}
28 changes: 28 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# You can run this locally with `pre-commit run [--all]`
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: pretty-format-json
exclude: ".vscode/.*" # Exclude jsonc
args: [--autofix, --no-sort-keys]
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]
- id: end-of-file-fixer
- id: mixed-line-ending
args: [--fix=lf]
- id: check-yaml
- id: check-toml
- id: check-merge-conflict
- id: check-case-conflict
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.4 # must match canopeum_backend/requirements-dev.txt
hooks:
# Run the linter.
- id: ruff
args: [--fix]
# Run the formatter.
- id: ruff-format

ci:
autoupdate_schedule: quarterly
47 changes: 47 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Keep in alphabetical order
{
"recommendations": [
"bierner.github-markdown-preview",
"charliermarsh.ruff",
"davidanson.vscode-markdownlint",
"eamodio.gitlens",
"github.vscode-github-actions",
"ms-python.mypy-type-checker",
"ms-python.python",
"ms-python.vscode-pylance",
// "ms-vscode.powershell",
"pkief.material-icon-theme",
// "redhat.vscode-xml",
"redhat.vscode-yaml",
"tamasfe.even-better-toml",
],
"unwantedRecommendations": [
// Must disable in this workspace //
// https://github.com/microsoft/vscode/issues/40239 //
//
// even-better-toml has format on save
"bungcip.better-toml",
// VSCode has implemented an optimized version
"coenraads.bracket-pair-colorizer",
"coenraads.bracket-pair-colorizer-2",
"shardulm94.trailing-spaces",
// Don't use two mypy extensions simultaneously
"matangover.mypy",
// Obsoleted by Pylance
"ms-pyright.pyright",
//
// Don't recommend to autoinstall //
//
// Use Ruff instead
"ms-python.black-formatter",
"ms-python.flake8",
"ms-python.isort",
"ms-python.pylint",
// We use autopep8
"ms-python.black-formatter",
// Not configurable per workspace, tends to conflict with other linters
"sonarsource.sonarlint-vscode",
// Prefer using VSCode itself as a text editor
"vscodevim.vim",
],
}
114 changes: 114 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
{
"editor.rulers": [
80,
120,
],
"[git-commit]": {
"editor.rulers": [
72,
],
},
"[markdown]": {
"files.trimTrailingWhitespace": false,
},
"files.trimTrailingWhitespace": true,
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,
"files.eol": "\n",
"editor.comments.insertSpace": true,
"editor.insertSpaces": true,
"editor.detectIndentation": false,
"editor.tabSize": 2,
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll": "explicit",
// Let dedicated linter (Ruff) organize imports
"source.organizeImports": "never",
},
"files.associations": {
".flake8": "properties",
"*.qrc": "xml",
"*.ui": "xml",
".markdownlint.json": "jsonc",
},
"search.exclude": {
"**/*.code-search": true,
"*.lock": true,
},
// Set the default formatter to help avoid Prettier
"[json][jsonc]": {
"editor.defaultFormatter": "vscode.json-language-features",
},
"[python]": {
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.tabSize": 4,
"editor.rulers": [
72, // PEP8-17 docstrings
// 79, // PEP8-17 default max
// 88, // Black/Ruff default
// 99, // PEP8-17 acceptable max
120, // Our hard rule
],
},
"mypy-type-checker.importStrategy": "fromEnvironment",
"mypy-type-checker.args": [
// https://github.com/microsoft/vscode-mypy/issues/37#issuecomment-1602702174
"--config-file=${workspaceFolder}/canopeum_backend/pyproject.toml",
],
"python.terminal.activateEnvironment": true,
// python.analysis is Pylance (pyright) configurations
"python.analysis.fixAll": [
"source.convertImportFormat"
// Explicitly omiting "source.unusedImports", can be annoying when commenting code for debugging
],
"python.analysis.diagnosticMode": "workspace",
"ruff.importStrategy": "fromEnvironment",
// Use the Ruff extension instead
"isort.check": false,
"powershell.codeFormatting.pipelineIndentationStyle": "IncreaseIndentationForFirstPipeline",
"powershell.codeFormatting.autoCorrectAliases": true,
"powershell.codeFormatting.trimWhitespaceAroundPipe": true,
"powershell.codeFormatting.useConstantStrings": true,
"powershell.codeFormatting.useCorrectCasing": true,
"powershell.codeFormatting.whitespaceBetweenParameters": true,
"powershell.integratedConsole.showOnStartup": false,
"terminal.integrated.defaultProfile.windows": "PowerShell",
"terminal.integrated.defaultProfile.linux": "pwsh",
"terminal.integrated.defaultProfile.osx": "pwsh",
"xml.codeLens.enabled": true,
"xml.format.spaceBeforeEmptyCloseTag": false,
"xml.format.preserveSpace": [
// Default
"xsl:text",
"xsl:comment",
"xsl:processing-instruction",
"literallayout",
"programlisting",
"screen",
"synopsis",
"pre",
"xd:pre",
// Custom
"string"
],
"[toml]": {
"editor.defaultFormatter": "tamasfe.even-better-toml"
},
"evenBetterToml.formatter.alignComments": false,
"evenBetterToml.formatter.alignEntries": false,
"evenBetterToml.formatter.allowedBlankLines": 1,
"evenBetterToml.formatter.arrayAutoCollapse": true,
"evenBetterToml.formatter.arrayAutoExpand": true,
"evenBetterToml.formatter.arrayTrailingComma": true,
"evenBetterToml.formatter.columnWidth": 80,
"evenBetterToml.formatter.compactArrays": true,
"evenBetterToml.formatter.compactEntries": false,
"evenBetterToml.formatter.compactInlineTables": false,
"evenBetterToml.formatter.indentEntries": false,
"evenBetterToml.formatter.indentTables": false,
"evenBetterToml.formatter.inlineTableExpand": false,
"evenBetterToml.formatter.reorderArrays": true,
"evenBetterToml.formatter.trailingNewline": true,
// We like keeping TOML keys in a certain non-alphabetical order that feels more natural
"evenBetterToml.formatter.reorderKeys": false
}
52 changes: 40 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,46 +11,74 @@ Follow these instructions to get the project up and running on your local machin
### Prerequisites

For frontend

- Node.js
- npm (Node Package Manager)
- Mockoon
For backend
- Python (3.x recommended)
- Python 3.12
- Docker


### Installation

1. Clone the repository:

```bash
```shell
git clone git@github.com:BesLogic/releaf-canopeum.git
cd releaf-canopeum
```

2. Set up Django backend and Database: (Skip this section for Frontend only)
2. Set up a Python 3.12 virtual environment

```bash
docker compose up
```shell
cd canopeum_backend
python3.12 -m venv .venv
```

or on Windows if "python3.12" is not a recognized command:

```powershell
cd canopeum_backend
python -m venv .venv
py -3.12 -m venv .venv
```

Then activate the environemnt (you need to do this everytime if your editor isn't configured to do so):

```shell
source .venv/scripts/activate
python -m pip install -r requirements.txt
```

and on Windows:

```powershell
.venv/scripts/activate
```

In VSCode (Windows):
`CTRL+Shift+P` (Open Command Palette) > `Python: Select Interpreter`
![VSCode_select_venv](/docs/VSCode_select_venv.png)

3. Set up Django backend and Database: (Skip this section for Frontend only)

```shell
docker compose up
cd canopeum_backend
python -m pip install -r requirements-dev.txt
python manage.py migrate
python manage.py runserver
```

3. Set up React frontend:
4. Set up React frontend:

```bash
```shell
cd canopeum_frontend
npm install
npm run dev
```

Run mock data (For Frontend only)

```bash
```shell
# In another CLI
npm install -g @mockoon/cli
cd releaf-canopeum/canopeum_frontend
Expand All @@ -59,7 +87,7 @@ mockoon-cli start --data canopeum-mockoon.json

### Folder Architecture

```bash
```ini
project_name/
├── backend/ # Django backend
Expand Down
2 changes: 1 addition & 1 deletion canopeum_backend/canopeum_backend/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'canopeum_backend.settings')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "canopeum_backend.settings")

application = get_asgi_application()
Loading

0 comments on commit ae0c4bd

Please sign in to comment.