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

Add CI, autofixes, and checks configurations #35

Merged
merged 7 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
46 changes: 46 additions & 0 deletions .github/workflows/canopeum_backend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: canopeum_backend

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: pip install -r requirements-dev.txt
working-directory: canopeum_backend
- run: mypy . --python-version=3.12
working-directory: canopeum_backend

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: pip install -r requirements-dev.txt
working-directory: canopeum_backend
- uses: jakebailey/pyright-action@v2
with:
python-version: "3.12"
working-directory: canopeum_backend
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
}
25 changes: 25 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 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: 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",
],
}
118 changes: 118 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
{
"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",
},
"[yaml]": {
"editor.defaultFormatter": "redhat.vscode-yaml"
},
"[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.importFormat": "relative",
"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 [email protected]: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
Loading