Skip to content

Commit

Permalink
ci: add flake8 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vicentebolea committed Dec 11, 2023
1 parent 09b4b1d commit 7512341
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 38 deletions.
7 changes: 7 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
[flake8]

exclude=
assets,
.git,
nrtk_explorer.egg-info,
.venv,
vue-components

ignore =
# Black and flake8 conflict here
E203
Expand Down
9 changes: 6 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install black
pip install -e '.[dev]'
- name: Analysing the code with black
run: |
black --check .
- name: Analysing the code with flake8
run: |
flake8
unit_tests:
needs:
- linters
Expand All @@ -38,8 +42,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest
pip install -e .
pip install -e '.[dev]'
- name: Invoke PyTest
run: |
pytest .
9 changes: 0 additions & 9 deletions nrtk_explorer/app/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@
from trame.widgets import html
from nrtk_explorer.library import images_manager

from nrtk_explorer.app.ui.image_list import image_list_component
from nrtk_explorer.app.embeddings import EmbeddingsApp
from nrtk_explorer.app.transforms import TransformsApp
from nrtk_explorer.app.applet import Translator

from PIL import Image as ImageModule
from PIL.Image import Image
import os

import json
Expand Down Expand Up @@ -157,12 +154,6 @@ def on_current_dataset_change(self, current_dataset, **kwargs):

self.reset_data()

i = 0

image_ids = []

current_dir = os.path.dirname(current_dataset)

with open(current_dataset) as f:
dataset = json.load(f)

Expand Down
4 changes: 1 addition & 3 deletions nrtk_explorer/app/embeddings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

from trame.widgets import quasar, html
from trame.ui.quasar import QLayout
from trame.decorators import TrameApp, change
from trame.app import get_server

import os
Expand Down Expand Up @@ -46,7 +45,7 @@ def __init__(
self.state.tab = "PCA"
self._on_select_fn = None
self.reducer = dimension_reducers.DimReducerManager()
self.is_standalone_app = state_translator == None
self.is_standalone_app = state_translator is None
if self.is_standalone_app:
self.local_state["images_manager"] = images_manager.ImagesManager()

Expand All @@ -66,7 +65,6 @@ def on_current_model_change(self, **kwargs):
)

def on_current_dataset_change(self, **kwargs):
current_dataset = self.state.current_dataset
self.state.num_elements_disabled = True
with open(self.state.current_dataset) as f:
dataset = json.load(f)
Expand Down
8 changes: 1 addition & 7 deletions nrtk_explorer/app/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def __init__(
super().__init__(server, state_translator, controller_translator, local_state_translator)
self._ui = None

self.is_standalone_app = state_translator == None
self.is_standalone_app = state_translator is None
if self.is_standalone_app:
self.local_state["images_manager"] = images_manager.ImagesManager()

Expand Down Expand Up @@ -212,12 +212,6 @@ def on_current_dataset_change(self, current_dataset, **kwargs):

self.reset_data()

i = 0

image_ids = []

current_dir = os.path.dirname(current_dataset)

with open(current_dataset) as f:
dataset = json.load(f)

Expand Down
6 changes: 1 addition & 5 deletions nrtk_explorer/app/ui/image_list.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from trame.widgets import client, html
from trame.widgets import html

from nrtk_explorer.widgets.nrtk_explorer import ImageDetection

Expand All @@ -14,7 +14,3 @@ def image_list_component(image_ids_key):
annotations=("get(`${image_id}_result`)",),
categories=("get('annotation_categories')",),
)
# with client.Getter(name=("image_id",), value_name="src"):
# with client.Getter(name=("image_id + '_meta'",), value_name="meta"):
# with client.Getter(name=("image_id + '_result'",), value_name="annotations"):
# ImageDetection(src=("src",), meta=("meta",), annotations=("annotations",))
4 changes: 1 addition & 3 deletions nrtk_explorer/library/dimension_reducers.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from sklearn.decomposition import PCA

import numpy as np
import umap
import hashlib
import time


class DimReducerManager:
Expand All @@ -16,7 +14,7 @@ def reduce(self, features, name, cache=True, **kwargs):
features_id + ":" + name + ":" + ":".join("%s=%r" % x for x in kwargs.items())
)

if cache == False or reduction_id not in self.cached_reductions:
if cache is False or reduction_id not in self.cached_reductions:
reducer = None
if name.upper() == "PCA":
reducer = PCAReducer(**kwargs)
Expand Down
4 changes: 1 addition & 3 deletions nrtk_explorer/library/embeddings_extractor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from PIL.Image import Image
from PIL import Image as ImageModule
from nrtk_explorer.library import images_manager

import warnings
Expand Down Expand Up @@ -50,7 +48,7 @@ def extract(self, paths, n=None, rand=False, cache=True, content=None):
selected_paths = paths

for path in selected_paths:
if cache == False or path not in self.features:
if cache is False or path not in self.features:
img = None
if content:
img = content[path]
Expand Down
2 changes: 0 additions & 2 deletions nrtk_explorer/library/images_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

import base64
import io
import random
import warnings


def image_to_base64_str(img: Image, format: str) -> str:
Expand Down
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,9 @@ dependencies = [

[project.optional-dependencies]
dev = [
"pip>=21.3",
"black",
"flake8",
"pytest",
"setuptools",
'black',
]

[tool.setuptools]
Expand Down

0 comments on commit 7512341

Please sign in to comment.