Skip to content

Commit

Permalink
Merge pull request pixano#26 from pixano/chore/lint_backend
Browse files Browse the repository at this point in the history
feat(ci): Add backend linting
  • Loading branch information
cpvannier authored Jan 9, 2024
2 parents 08e73b2 + 16d61bf commit ccf8773
Show file tree
Hide file tree
Showing 59 changed files with 1,706 additions and 1,181 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/.pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[MASTER]
disable=
C0114, # missing-module-docstring
C0301, # line-too-long (already set by black formatter)
R0903, # too-few-public-methods (PixanoType CustomExtensionType and Scalar, Exporter)
generated-members=
cv2.*, # members not found
duckdb.*, # members not found

[MAIN]
max-branches=20

[DESIGN]
max-args = 10
max-locals = 20

[SIMILARITIES]
min-similarity-lines=10
112 changes: 112 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# @Copyright: CEA-LIST/DIASI/SIALV/LVA (2023)
# @Author: CEA-LIST/DIASI/SIALV/LVA <[email protected]>
# @License: CECILL-C
#
# This software is a collaborative computer program whose purpose is to
# generate and explore labeled data for computer vision applications.
# This software is governed by the CeCILL-C license under French law and
# abiding by the rules of distribution of free software. You can use,
# modify and/ or redistribute the software under the terms of the CeCILL-C
# license as circulated by CEA, CNRS and INRIA at the following URL
#
# http://www.cecill.info

name: Format

on:
push:
branches:
- "**"
pull_request:
branches:
- "develop"
- "main"

permissions:
contents: read

jobs:
# This workflow will format frontend code (Svelte, Typescript) and project files (Markdown, YAML) with Prettier

format_front:
name: Frontend
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18

- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: 8

- name: Install dependencies
run: |
cd ui
pnpm i
- name: Format frontend code with Prettier
run: |
cd ui
pnpm format_check
- name: Format top-level Markdown and YAML files with Prettier
uses: creyD/[email protected]
with:
dry: True
prettier_options: --check ./*.{md,yml}
# Prettier 3.0 not yet available in VSCode extension
prettier_version: 2.8.8

- name: Format GitHub actions YAML files with Prettier
uses: creyD/[email protected]
with:
dry: True
prettier_options: --check ./.github/workflows/*.yml
# Prettier 3.0 not yet available in VSCode extension
prettier_version: 2.8.8

- name: Format docs Markdown files with Prettier
uses: creyD/[email protected]
with:
dry: True
prettier_options: --check ./docs/**/*.md
# Prettier 3.0 not yet available in VSCode extension
prettier_version: 2.8.8

- name: Format backend Markdown files with Prettier
uses: creyD/[email protected]
with:
dry: True
prettier_options: --check ./pixano/**/*.md
# Prettier 3.0 not yet available in VSCode extension
prettier_version: 2.8.8

# This job will format backend code (Python) and notebooks (Jupyter) with black
# For more information see: https://black.readthedocs.io/en/stable/integrations/github_actions.html
format_back:
name: Backend
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Format backend code with black
uses: psf/black@stable
with:
options: "--check --verbose --diff --color"
src: "./pixano"

- name: Format notebooks with black
uses: psf/black@stable
with:
options: "--check --verbose --diff --color"
src: "./notebooks"
jupyter: true
92 changes: 20 additions & 72 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# http://www.cecill.info

name: Lint code
name: Lint

on:
push:
Expand All @@ -26,8 +26,8 @@ permissions:
contents: read

jobs:
# This workflow will lint frontend code (Svelte, Typescript) code with eslint and Prettier
ui_lint:
# This workflow will lint frontend code (Svelte, Typescript) with eslint
lint_front:
name: Frontend
runs-on: ubuntu-latest

Expand All @@ -50,87 +50,35 @@ jobs:
cd ui
pnpm i
- name: Lint frontend code with Prettier
run: |
cd ui
pnpm format_check
- name: Lint frontend code with eslint
run: |
cd ui
pnpm lint
# This job will lint backend code (Python) with black
# For more information see: https://black.readthedocs.io/en/stable/integrations/github_actions.html
python_lint:
# This job will lint backend code (Python) with Pylint
# Disable R0801 (duplicate-code) for backend tests as we reuse some code like sample statistics and importers basic tests
lint_back:
name: Backend
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Lint Python code with black
uses: psf/black@stable
with:
options: "--check --verbose --diff --color"
src: "./pixano"

# This job will lint notebooks code (Jupyter) with black
# For more information see: https://black.readthedocs.io/en/stable/integrations/github_actions.html
jupyter_lint:
name: Notebooks
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Lint Jupyter notebooks with black
uses: psf/black@stable
with:
options: "--check --verbose --diff --color"
src: "./notebooks"
jupyter: true

# This workflow will lint the rest of the code (Mardown, YAML, JSON) with Prettier
# For more information see: https://github.com/marketplace/actions/prettier-action
other_lint:
name: Other
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Lint top-level Markdown and YAML files with Prettier
uses: creyD/[email protected]
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
dry: True
prettier_options: --check ./*.{md,yml}
# Prettier 3.0 not yet available in VSCode extension
prettier_version: 2.8.8
python-version: "3.10"

- name: Lint GitHub actions with Prettier
uses: creyD/[email protected]
with:
dry: True
prettier_options: --check ./.github/workflows/*.yml
# Prettier 3.0 not yet available in VSCode extension
prettier_version: 2.8.8

- name: Lint docs with Prettier
uses: creyD/[email protected]
with:
dry: True
prettier_options: --check ./docs/**/*.md
# Prettier 3.0 not yet available in VSCode extension
prettier_version: 2.8.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install .
python -m pip install pylint
python -m pip install pixano-inference@git+https://github.com/pixano/pixano-inference
- name: Lint Python READMEs with Prettier
uses: creyD/[email protected]
with:
dry: True
prettier_options: --check ./pixano/**/*.md
# Prettier 3.0 not yet available in VSCode extension
prettier_version: 2.8.8
- name: Lint backend code with Pylint
run: |
pylint pixano/ --rcfile .github/workflows/.pylintrc
pylint notebooks/ --rcfile .github/workflows/.pylintrc
pylint tests/ --rcfile .github/workflows/.pylintrc --disable=R0801
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# This workflow will publish the new version of Pixano to PyPI when a release is created
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Publish code
name: Publish

on:
release:
Expand Down Expand Up @@ -50,7 +50,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install hatch
python -m pip install hatch
- name: Build apps
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# http://www.cecill.info

name: Test code
name: Test

on:
push:
Expand Down
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ All notable changes to Pixano will be documented in this file.

### Added

- Add **S3** compatible storage access
- Add support for **datasets stored on Amazon S3 cloud storage** (pixano#21)
- Select **interactive segmentation models** with **dropdown menu** based on models found in directory (pixano#12)
- Select **semantic search models** with **dropdown menu** based on embeddings found in dataset (pixano#12)
- Add loading animation in frontend UI when loading or saving takes time (pixano#15)
- Add option to load a list of category id and name pairs in Importers and to save it with Exporters (pixano#11)
- Add new methods to PixanoTypes (from_rle() in BBox, file_name, width, and height in Image) (pixano#11)
- Add GitHub actions to format, lint and test code (pixano#2, pixano#3, pixano#4)
- Add new unit tests and refactor existing tests (pixano#11)
- Add GitHub actions to format, lint and test code (pixano#2, pixano#3, pixano#4, pixano#26)
- Add new unit tests and refactor existing tests (pixano#11, pixano#26)

### Changed

Expand All @@ -25,6 +25,7 @@ All notable changes to Pixano will be documented in this file.
- Add new class related to Dataset (DatasetItem)
- Add new classes related to DatasetItem (ItemEmbedding, ItemFeature, ItemObject, ItemView)
- Refactor Exporters, Importers, and InferenceModels using updated API
- Refactor Pixano Explorer and Annotator apps into a single Pixano app using the new ImageWorkspace (pixano#23)
- Reformat Jupyter notebooks with black (pixano#2)
- Reformat and refactor frontend code with Prettier and eslint (pixano#2, pixano#7, pixano#12)
- Replace deprecated frontend package shortid by nanoid (pixano#12)
Expand Down
8 changes: 7 additions & 1 deletion notebooks/datasets/template_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,13 @@ def __init__(
categories = [DatasetCategory(id=i, name=f"Category {i}") for i in range(1, 40)]

# Initialize Importer
super().__init__(name, description, splits, tables, categories)
super().__init__(
name=name,
description=description,
tables=tables,
splits=splits,
categories=categories,
)

def import_rows(self) -> Iterator:
"""Process dataset rows for import
Expand Down
16 changes: 8 additions & 8 deletions notebooks/models/interactive_annotation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -58,7 +58,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -96,7 +96,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -117,14 +117,14 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"library_dir = Path(\"my_datasets/\")\n",
"dataset_dir = library_dir / \"coco_instances\"\n",
"\n",
"views = []\n",
"views = [\"image\"]\n",
"splits = []"
]
},
Expand All @@ -147,11 +147,11 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"model.process_dataset(\n",
"dataset = model.process_dataset(\n",
" dataset_dir=dataset_dir,\n",
" process_type=\"segment_emb\",\n",
" views=views,\n",
Expand Down Expand Up @@ -226,7 +226,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.11"
"version": "3.10.13"
},
"orig_nbformat": 4
},
Expand Down
Loading

0 comments on commit ccf8773

Please sign in to comment.