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

Eslint and typescript errors #56

Merged
merged 12 commits into from
Mar 6, 2023
2 changes: 1 addition & 1 deletion .eslintcache

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -37,3 +37,6 @@ package-lock.json
!.yarn/releases
!.yarn/sdks
!.yarn/versions

# venv
.venv/
34 changes: 26 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
.DEFAULT_GOAL := help
pkg_src = coral

flake8 = flake8 $(pkg_src) setup.py
isort = isort $(pkg_src) setup.py
black = black --line-length 140 $(pkg_src) setup.py
pyright = echo 'pyright not used' # pyright $(pkg_src) setup.py
ruff = ruff $(pkg_src) setup.py --line-length 140 --select E,W,F,N,I,C,B,UP,PT,SIM,RUF --ignore E501,C901,B008

.PHONY: start ## Start the development server
start:
python $(pkg_src)

.PHONY: all ## Perform the most common development-time rules
all: format lint test
@@ -13,25 +17,25 @@ ci: check-format lint test

.PHONY: format ## Auto-format the source code
format:
$(isort)
$(ruff) --fix
$(black)

.PHONY: check-format ## Check the source code format without changes
check-format:
$(isort) --check-only
$(black) --check

.PHONY: lint ## Run flake8
.PHONY: lint ## Run flake8 and pyright
lint:
$(flake8)
$(ruff) --format=github
$(pyright)

.PHONY: test ## Run tests
test:
pytest $(pkg_src)

.PHONEY: documentation ## Generate docs
documentation:
mkdocs build
documentation:
echo "TODO"

.PHONY: install ## Install the requirements
install:
@@ -41,6 +45,20 @@ install:
develop:
pip install -e .[develop]

.PHONY: env_encrypt ## Encrypts the current ./<app>/.env
env_encrypt:
openssl aes-256-cbc -pbkdf2 -in ./$(pkg_src)/.env -out ./$(pkg_src)/.env.enc

.PHONY: env_decrypt ## Decrypts the ./<app>/.env.enc
env_decrypt:
@if [ -z "${ENV_PASSWORD}" ]; then \
echo "No ENV_PASSWORD set, prompting for password..."; \
openssl aes-256-cbc -pbkdf2 -d -in ./$(pkg_src)/.env.enc -out ./$(pkg_src)/.env; \
else \
echo "ENV_PASSWORD set, using it..."; \
openssl aes-256-cbc -pbkdf2 -d -in ./$(pkg_src)/.env.enc -out ./$(pkg_src)/.env -pass env:ENV_PASSWORD; \
fi

.PHONY: build ## Build a wheel
build:
python setup.py sdist bdist_wheel --dist-dir dist_python
6 changes: 2 additions & 4 deletions coral/__init__.py
Original file line number Diff line number Diff line change
@@ -4,10 +4,8 @@
# Licensed under the new BSD license, available at http://caleydo.org/license
###############################################################################
from os import path
from typing import Type

from pydantic import BaseModel
from tdp_core.plugin.model import AVisynPlugin, RegHelper
from visyn_core.plugin.model import AVisynPlugin, RegHelper

from .settings import CoralSettings

@@ -34,5 +32,5 @@ def register(self, registry: RegHelper):
)

@property
def setting_class(self) -> Type[BaseModel]:
def setting_class(self) -> type[CoralSettings]:
return CoralSettings
2 changes: 1 addition & 1 deletion coral/db.py
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@
_log.info("Setting up the db view.")

# main dictionary containing all views registered for this plugin
views = dict()
views = {}
schema = "cohort"

# create a view + idtype for each available table
4 changes: 2 additions & 2 deletions coral/migration/env.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import tdp_core.dbmigration.env # NOQA
import visyn_core.dbmigration.env

tdp_core.dbmigration.env.run_migrations_online()
visyn_core.dbmigration.env.run_migrations_online()
6 changes: 2 additions & 4 deletions coral/settings.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from typing import Dict

from pydantic import BaseModel
from tdp_core import manager
from visyn_core import manager


class CoralSettings(BaseModel):
@@ -11,7 +9,7 @@ class CoralSettings(BaseModel):
statement_timeout: str = "300000"
supp_statement_timeout: str = "40000"
statement_timeout_query: str = "set statement_timeout to {}"
logging: Dict = {"version": 1, "disable_existing_loggers": False, "loggers": {"coral": {"level": "DEBUG"}}}
logging: dict = {"version": 1, "disable_existing_loggers": False, "loggers": {"coral": {"level": "DEBUG"}}}


def get_settings() -> CoralSettings:
2 changes: 1 addition & 1 deletion coral/sql.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging

from flask import Flask, abort, jsonify, request
from tdp_core.security import login_required
from visyn_core.security import login_required

from .settings import get_settings
from .sql_query_mapper import QueryElements
36 changes: 9 additions & 27 deletions coral/sql_query_mapper.py
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
from sqlalchemy import create_engine, exc, inspect, text
from sqlalchemy.exc import NoInspectionAvailable
from sqlalchemy.orm import sessionmaker
from tdp_core import manager
from visyn_core import manager

from .settings import get_settings
from .sql_tables import Cohort
@@ -95,7 +95,7 @@ def to_dict(self, row):
try:
return {c.key: getattr(row, c.key) for c in inspect(row).mapper.column_attrs}
except NoInspectionAvailable: # this exception is raised when the result is not of a registered sqlalchemy type due to which the inspection fails
result = dict()
result = {}
result[COLUMN_LABEL_SCORE] = row[0]
result[COLUMN_LABEL_ID] = row[1]
return result
@@ -145,10 +145,7 @@ def get_cohorts_by_id_sql(self, args, error_msg):
str_values = str_values + ("{val}, ".format(val=curr_val))
cnt += 1

if cnt > 0:
str_values = str_values[:-2] # remove the last ', ' from the value list
else:
str_values = "-1" # returns no cohorts -> ids are only positiv
str_values = str_values[:-2] if cnt > 0 else "-1" # returns no cohorts -> ids are only positiv

sql_text = "SELECT id, name, is_initial, previous_cohort, entity_database, entity_schema, entity_table FROM cohort.cohort c WHERE c.id IN ({str_values})".format(
str_values=str_values
@@ -173,7 +170,7 @@ def update_cohort_name_sql(self, args, error_msg):

session_data.query(Cohort).filter(Cohort.id == cohort_id).update({Cohort.name: name}, synchronize_session=False)
# synchronize_session
# False - dont synchronize the session. This option is the most efficient and is reliable once the session is expired,
# False - don`t synchronize the session. This option is the most efficient and is reliable once the session is expired,
# which typically occurs after a commit(), or explicitly using expire_all(). Before the expiration,
# updated objects may still remain in the session with stale values on their attributes, which can lead to confusing results.

@@ -341,19 +338,13 @@ def equals_filter_statement(self, prefix, attribute, values, numeric):
if val.startswith("!"):
add_equals_not_value = True
val = val[1:]
if numeric in ["true"]: # determine if the values are strings or numbers
curr_val = "{val}".format(val=val)
else:
curr_val = "'{val}'".format(val=val)
curr_val = "{val}".format(val=val) if numeric in ["true"] else "'{val}'".format(val=val)

str_not_values = str_not_values + ("{val}, ".format(val=curr_val))

else:
add_equals_value = True
if numeric in ["true"]: # determine if the values are strings or numbers
curr_val = "{val}".format(val=val)
else:
curr_val = "'{val}'".format(val=val)
curr_val = "{val}".format(val=val) if numeric in ["true"] else "'{val}'".format(val=val)

str_values = str_values + ("{val}, ".format(val=curr_val))

@@ -455,10 +446,7 @@ def create_cohort_treatment_filtered(self, args, cohort, error_msg):
raise RuntimeError(error_msg)

array_operation = "="
if base_agent in ["true"]: # determine if the values are strings or numbers
array_operation = "@>"
else:
array_operation = "="
array_operation = "@>" if base_agent in ["true"] else "="

entity_id_col = ""
if cohort.entity_table == "tdp_tissue":
@@ -508,10 +496,7 @@ def create_cohort_treatment_filtered(self, args, cohort, error_msg):
# regimen is defined
if regimen is not None:
reg_sql = ("tmp.rn::int = {val}").format(val=regimen)
if agent is not None:
sql_where = sql_where + " AND " + reg_sql
else:
sql_where = reg_sql
sql_where = sql_where + " AND " + reg_sql if agent is not None else reg_sql

# SQL with the combined filter (actual agent values, null values)
sql_refiend = ""
@@ -555,10 +540,7 @@ def create_cohort_treatment_filtered(self, args, cohort, error_msg):
base_table=cohort.entity_table,
)

if agent_exists:
sql_refiend = sql_refiend + " UNION " + sql_null
else:
sql_refiend = sql_refiend + sql_null
sql_refiend = sql_refiend + " UNION " + sql_null if agent_exists else sql_refiend + sql_null

# complete SQL statement that filters the data based on the given cohort
new_sql_text = """SELECT cohort.* FROM ({entities}) cohort
34 changes: 34 additions & 0 deletions coral/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import pytest
from fastapi import FastAPI
from fastapi.testclient import TestClient
from visyn_core.security.manager import SecurityManager
from visyn_core.security.model import User
from visyn_core.server.visyn_server import create_visyn_server
from visyn_core.tests.fixtures.postgres_db import postgres_db

assert postgres_db # silence unused import warning


@pytest.fixture(scope="session")
def app(postgres_db) -> FastAPI:
server = create_visyn_server(
workspace_config={
"tdp_core": {"enabled_plugins": ["tdp_core", "coral"]},
"coral": {
"dburl": postgres_db.url,
},
}
)

return server


@pytest.fixture()
def client(monkeypatch, app: FastAPI):
def mock_current_user_in_manager(self):
return User(id="admin")

monkeypatch.setattr(SecurityManager, "current_user", property(mock_current_user_in_manager))

with TestClient(app) as client:
yield client
5 changes: 5 additions & 0 deletions coral/tests/test_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from fastapi.testclient import TestClient


def test_loggedinas(client: TestClient):
assert client.get("/loggedinas").json()["name"] == "admin"
2 changes: 0 additions & 2 deletions coral/tests/test_dummy.py

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
"name": "coral",
"description": "Coral is a web-based cohort analysis tool to interactively create, refine, and analyze patient cohorts.",
"homepage": "https://caleydo.org",
"version": "4.0.1-SNAPSHOT",
"version": "4.1.1-SNAPSHOT",
"author": {
"name": "PatrickAdelberger",
"email": "coral@caleydo.org",
12 changes: 4 additions & 8 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
black~=22.3.0
debugpy~=1.5.1
flake8~=4.0.1
isort~=5.10.1
mkdocs-material~=8.2.8
pep8-naming~=0.12.1
black~=22.12.0
pyright~=1.1.285
pytest-runner~=6.0.0
pytest~=7.1.1
recommonmark~=0.7.1
pytest~=7.2.0
ruff==0.0.218
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -57,7 +57,7 @@ def requirements(file):
package_data={},
# Although 'package_data' is the preferred approach, in some case you may
# need to place data files outside of your packages. See:
# http://docs.python.org/3.4/distutils/setupscript.html#installing-additional-files # noqa
# http://docs.python.org/3.4/distutils/setupscript.html#installing-additional-files
# In this case, 'data_file' will be installed into '<sys.prefix>/my_data'
data_files=[], # [('my_data', ['data/data_file'])],
)
26 changes: 15 additions & 11 deletions src/Cohort.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { IAllFilters, IDType, IDTypeLike, IDTypeManager, IRow, IServerColumn, UniqueIdManager } from 'tdp_core';
/* eslint-disable @typescript-eslint/no-use-before-define */
import { IDType, IDTypeLike, IDTypeManager, IRow, IServerColumn } from 'visyn_core';
import { IAllFilters, UniqueIdManager } from 'tdp_core';
import {
ECloneFilterTypes,
EElementProvType,
@@ -30,6 +32,17 @@ import {
dataDBCohortWithNumFilter,
getCohortData,
getCohortSize,
sizeDBCohortDepletionScoreFilter,
sizeDBCohortGeneWithEqualsFilter,
sizeDBCohortGeneWithNumFilter,
sizeDBCohortPanelAnnotationFilter,
sizeDBCohortWithEqualsFilter,
sizeDBCohortWithNumFilter,
updateCohortName,
} from './base/rest';
import type { Task } from './Tasks';
import { deepCopy, handleDataLoadError, handleDataSaveError, log, mergeTwoAllFilters } from './util';
import {
ICohortDBDataParams,
ICohortDBParams,
ICohortDBSizeParams,
@@ -49,17 +62,8 @@ import {
ICohortRow,
IEqualsList,
INumRange,
sizeDBCohortDepletionScoreFilter,
sizeDBCohortGeneWithEqualsFilter,
sizeDBCohortGeneWithNumFilter,
sizeDBCohortPanelAnnotationFilter,
sizeDBCohortWithEqualsFilter,
sizeDBCohortWithNumFilter,
updateCohortName,
valueListDelimiter,
} from './base/rest';
import { mergeTwoAllFilters, Task } from './Tasks';
import { deepCopy, handleDataLoadError, handleDataSaveError, log } from './util';
} from './base/interfaces';

type ICreateMethod<T> = (
params:
15 changes: 15 additions & 0 deletions src/CohortContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { ICohort } from './app/interfaces';
import type { CohortOverview } from './Overview/CohortOverview';
import type Taskview from './Taskview/Taskview';

export interface ICohortContext {
cohortOverview: CohortOverview;
taskview: Taskview;
referenceCohort: ICohort;
}

export const CohortContext: ICohortContext = {
cohortOverview: null,
taskview: null,
referenceCohort: null,
};
Loading