Skip to content
Open
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
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 25.12.0
rev: 26.1.0
hooks:
- id: black
- repo: https://github.com/pycqa/isort
rev: 7.0.0
rev: 8.0.0
hooks:
- id: isort
args: ["--profile", "black", "--filter-files"]
Expand All @@ -21,7 +21,7 @@ repos:
- id: flake8
args: ["--max-line-length=88", "--ignore=E20,W503"] # black compatible
- repo: https://github.com/pre-commit/mirrors-eslint
rev: v10.0.0-beta.0
rev: v10.0.1
hooks:
- id: eslint
additional_dependencies:
Expand Down
40 changes: 15 additions & 25 deletions api/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,7 @@ def __change_rows(

sa_table = table_obj.get_oedb_table_proxy()._main_table.get_sa_table()

pks = [c for c in sa_table.columns if c.primary_key] # type:ignore
pks = [c for c in sa_table.columns if c.primary_key] # type: ignore

inserts = []
cursor = load_cursor_from_context(context)
Expand Down Expand Up @@ -1333,11 +1333,11 @@ def add_type(d, type):
engine = _get_engine()

artificial_connection = False
connection: DBAPIConnection = engine.raw_connection() # type:ignore TODO
connection: DBAPIConnection = engine.raw_connection() # type: ignore TODO

if cursor is None:
artificial_connection = True
cursor = cast(AbstractCursor, connection.cursor()) # type:ignore TODO
cursor = cast(AbstractCursor, connection.cursor()) # type: ignore TODO

try:
columns = list(describe_columns(table_obj).keys())
Expand Down Expand Up @@ -1545,7 +1545,7 @@ def set_table_metadata(table: str, metadata):
# ---------------------------------------

django_table_obj = Table.objects.get(name=table)
django_table_obj.oemetadata = metadata_obj # type:ignore
django_table_obj.oemetadata = metadata_obj # type: ignore
django_table_obj.save()

# ---------------------------------------
Expand All @@ -1570,8 +1570,7 @@ def get_single_table_size(table_obj: Table) -> dict | None:
Return size details for one table or None if not found.
"""

sql = text(
"""
sql = text("""
SELECT
:schema AS table_schema,
:table AS table_name,
Expand All @@ -1581,8 +1580,7 @@ def get_single_table_size(table_obj: Table) -> dict | None:
pg_size_pretty(pg_relation_size(format('%I.%I', :schema, :table))) AS table_pretty,
pg_size_pretty(pg_indexes_size(format('%I.%I', :schema, :table))) AS index_pretty,
pg_size_pretty(pg_total_relation_size(format('%I.%I', :schema, :table))) AS total_pretty
""" # noqa: E501
)
""") # noqa: E501

sess = _create_oedb_session()
try:
Expand All @@ -1605,8 +1603,7 @@ def list_table_sizes() -> list[dict]:
List table sizes
"""
oedb_schema = SCHEMA_DATA
sql = text(
f"""
sql = text(f"""
SELECT
table_schema,
table_name,
Expand All @@ -1618,8 +1615,7 @@ def list_table_sizes() -> list[dict]:
WHERE table_schema='{oedb_schema}'
AND table_type = 'BASE TABLE'
ORDER BY pg_total_relation_size(format('%I.%I', table_schema, table_name)) DESC
""" # noqa: E501
)
""") # noqa: E501

sess = _create_oedb_session()
try:
Expand All @@ -1637,14 +1633,12 @@ def list_table_sizes() -> list[dict]:


def table_has_row_with_id(table: Table, id: int | str, id_col: str = "id") -> bool:
query = text(
f"""
query = text(f"""
SELECT count(*)
FROM "{table.oedb_schema}"."{table.name}"
WHERE {id_col} = :id
;
"""
)
""")

engine = _get_engine()
with engine.connect() as conn:
Expand All @@ -1656,13 +1650,11 @@ def table_has_row_with_id(table: Table, id: int | str, id_col: str = "id") -> bo


def table_get_row_count(table: Table) -> int:
query = text(
f"""
query = text(f"""
SELECT count(*)
FROM "{table.oedb_schema}"."{table.name}"
;
"""
)
""")

engine = _get_engine()
with engine.connect() as conn:
Expand All @@ -1689,14 +1681,12 @@ def table_get_approx_row_count(table: Table, precise_below: int = 0) -> int:
# table name. but its validated by constraints
# on django table.name field

query = text(
f"""
query = text(f"""
SELECT reltuples::bigint AS approx_row_count
FROM pg_class
WHERE oid = '"{table.oedb_schema}"."{table.name}"'::regclass
;
"""
)
""")

with engine.connect() as conn:
resp = _execute(conn, query)
Expand Down Expand Up @@ -2118,7 +2108,7 @@ def _execute(
*args,
**kwargs,
) -> ResultProxy:
response = con.execute(sql, *args, **kwargs) # type:ignore
response = con.execute(sql, *args, **kwargs) # type: ignore
# Note: cast is only for type checking,
# should disappear once we migrate to sqlalchemy >= 1.4
response = cast(ResultProxy, response)
Expand Down
8 changes: 4 additions & 4 deletions api/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def get_column_definition_query(d: dict) -> Column:

if d.get("character_maximum_length"):
max_len = int(d["character_maximum_length"])
dt = dt(max_len) # type:ignore
dt = dt(max_len) # type: ignore

_assert_valid_identifier_name(name)
c = Column(name, dt, *args, **kwargs)
Expand Down Expand Up @@ -483,11 +483,11 @@ def _parse_from_item(d):
on_clause = None
if "on" in d:
on_clause = parse_condition(d["on"])
sa_table = left.join( # type:ignore
sa_table = left.join( # type: ignore
right,
onclause=on_clause,
isouter=is_outer, # type:ignore
full=full, # type:ignore
isouter=is_outer, # type: ignore
full=full, # type: ignore
)
else:
raise APIError("Unknown from-item: " + dtype)
Expand Down
2 changes: 1 addition & 1 deletion api/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def __init__(self, connection_id=None, owner: AbstractUser | None = None):
)

engine = _get_engine()
self.connection: DBAPIConnection = engine.connect().connection # type:ignore
self.connection: DBAPIConnection = engine.connect().connection # type: ignore
if connection_id is None:
connection_id = _add_entry(self, _SESSION_CONTEXTS)
elif connection_id not in _SESSION_CONTEXTS:
Expand Down
2 changes: 1 addition & 1 deletion base/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def get_urlpattern_params(pattern: URLPattern) -> list[str]:
if isinstance(pattern2, RegexPattern):
regex = re.compile(
# TODO: better way than using protected attribute?
pattern2._regex # type:ignore
pattern2._regex # type: ignore
)
return list(regex.groupindex.keys())
elif isinstance(pattern2, RoutePattern):
Expand Down
2 changes: 1 addition & 1 deletion dataedit/management/commands/create_example_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def handle(self, *args, **opts):
Table.create_with_oedb_table(
name=table_name,
is_sandbox=True, # tests ALWAYS in sandbox
user=user, # type:ignore
user=user, # type: ignore
column_definitions=column_defs,
constraints_definitions=constraint_defs,
)
Expand Down
14 changes: 4 additions & 10 deletions dataedit/management/commands/migrate_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,11 @@ def handle(self, *args, **options):
color,
usage_tracked_since,
) in con.execute(
text(
"""
text("""
select
id, name_normalized, usage_count, name, color, usage_tracked_since
from public.tags
"""
)
""")
).fetchall():
tag_names[id] = name_normalized
# convert to timezone aware
Expand All @@ -51,15 +49,11 @@ def handle(self, *args, **options):
usage_tracked_since=usage_tracked_since,
)

for table_name, tag_id in con.execute(
text(
"""
for table_name, tag_id in con.execute(text("""
select
table_name, tag
from public.table_tags
"""
)
).fetchall():
""")).fetchall():
table = TableOEP.objects.filter(name=table_name).first()
if not table:
print(f"Warning: table does not exist: {table_name}")
Expand Down
12 changes: 5 additions & 7 deletions dataedit/management/commands/migrate_tags2.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,12 @@ def handle(self, *args, **options):
usage_tracked_since,
category,
) in con.execute(
text(
"""
text("""
select
id, name_normalized, usage_count, name, color, usage_tracked_since,
category
from public.tags
"""
)
""")
).fetchall():
tag_names[tag_id] = tag_name_normalized
tag = TagOEP.objects.filter(name_normalized=tag_name_normalized).first()
Expand All @@ -61,18 +59,18 @@ def handle(self, *args, **options):
)
else:
if category:
tag.category = category # type:ignore
tag.category = category # type: ignore
tag.save()

# update factsheets
for factsheet_class in [BasicFactsheet, Energymodel, Energyframework]:
for factsheet in factsheet_class.objects.all():
tag_int_ids = factsheet.tags_TODO_deprecated # type:ignore
tag_int_ids = factsheet.tags_TODO_deprecated # type: ignore
for tag_int_id in tag_int_ids:
if tag_int_id not in tag_names:
print(f"Missing tag: {tag_int_id}")
continue
tag_name_normalized = tag_names[tag_int_id]
tag = TagOEP.objects.get(name_normalized=tag_name_normalized)
factsheet.tags.add(tag) # type:ignore
factsheet.tags.add(tag) # type: ignore
factsheet.save()
6 changes: 3 additions & 3 deletions dataedit/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ def iter_oem_key_order(metadata: dict):

opr_result_context = {}
if reviews.exists():
latest_review: PeerReview = reviews.last() # type:ignore (reviews.exists())
latest_review: PeerReview = reviews.last() # type: ignore (reviews.exists())
opr_manager.update_open_since(opr=latest_review)
current_reviewer = opr_manager.load(latest_review).current_reviewer
opr_context.update(
Expand Down Expand Up @@ -1432,8 +1432,8 @@ def post(self, request: HttpRequest, table: str, review_id=None) -> HttpResponse

# Set new review values and update existing review
active_peer_review.review = merged_review_data
active_peer_review.reviewer = user # type:ignore TODO why type warning?
active_peer_review.contributor = contributor # type:ignore TODO
active_peer_review.reviewer = user # type: ignore TODO why type warning?
active_peer_review.contributor = contributor # type: ignore TODO
active_peer_review.update(review_type=review_post_type)
else:
error_msg = (
Expand Down
2 changes: 1 addition & 1 deletion factsheet/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def build_sector_dropdowns_from_oeo(g: Graph):

# sector individuals: ?sector oeo:is_defined_by ?sd
for sector in g.subjects(PROP_DEFINED_BY, sd):
sec_label = _label(g, sector) # type:ignore
sec_label = _label(g, sector) # type: ignore
definition = g.value(sector, PROP_DEFINITION)

sectors_list.append(
Expand Down
2 changes: 1 addition & 1 deletion login/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ class myuser(AbstractBaseUser, PermissionHolder):
] # related_name, for static type checking

USERNAME_FIELD = "name"
REQUIRED_FIELDS = [name] # type:ignore TODO: why do we need this?
REQUIRED_FIELDS = [name] # type: ignore TODO: why do we need this?

objects = OEPUserManager()

Expand Down
4 changes: 2 additions & 2 deletions login/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@

class TestUtils(TestCase):
def test_user_get_tables_queryset(self):
user_a: User = User.objects.create_user( # type:ignore
user_a: User = User.objects.create_user( # type: ignore
name="A", email="a@test.test", affiliation="test"
)
user_b: User = User.objects.create_user( # type:ignore
user_b: User = User.objects.create_user( # type: ignore
name="B", email="b@test.test", affiliation="test"
)

Expand Down
2 changes: 1 addition & 1 deletion login/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -855,5 +855,5 @@ def metadata_review_badge_indicator_icon_file_view(request, user_id, table_name)
return render(
request,
"login/partials/badge_icon.html",
context=context, # type:ignore (we have Literals in type signature)
context=context, # type: ignore (we have Literals in type signature)
)
4 changes: 2 additions & 2 deletions modelview/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __init__(self, *args, **kwargs):
self.fields[key].required = False
else:
f = [not f.null for f in Energymodel._meta.fields if f.name == key][0]
cls_name = self.fields[key].widget.__class__.__name__ # type:ignore
cls_name = self.fields[key].widget.__class__.__name__ # type: ignore
self.fields[key].required = f and cls_name != "CheckboxInput"

class Meta:
Expand All @@ -42,7 +42,7 @@ def __init__(self, *args, **kwargs):
f = [not f.null for f in Energyframework._meta.fields if f.name == key][
0
]
cls_name = self.fields[key].widget.__class__.__name__ # type:ignore
cls_name = self.fields[key].widget.__class__.__name__ # type: ignore
self.fields[key].required = f and cls_name != "CheckboxInput"
if "help_text" in self.fields[key].__dict__:
self.fields[key].help_text = self.fields[key].help_text.replace(
Expand Down
4 changes: 1 addition & 3 deletions modelview/templatetags/modelview_extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ def checktable(model, label, prefix, suffixes, separator="_"):
{2}
</table>
</td>
</tr>""".format(
label, header, ""
)
</tr>""".format(label, header, "")


@register.simple_tag
Expand Down
2 changes: 1 addition & 1 deletion modelview/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def model_to_csv_view(request, sheettype):
tag_ids = tag_ids.split(",")

header = list(
field.attname # type:ignore because hasattr(field, "attname")
field.attname # type: ignore because hasattr(field, "attname")
for field in c._meta.get_fields()
if hasattr(field, "attname")
)
Expand Down
4 changes: 2 additions & 2 deletions oedb/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from oedb.connection import __get_connection_string, _get_engine # noqa: E402
from oedb.structures import Base # noqa: E402

target_metadata = Base.metadata # type:ignore
target_metadata = Base.metadata # type: ignore

alembic_cfg = Config()
db_url = __get_connection_string()
Expand All @@ -33,7 +33,7 @@

# Interpret the config file for Python logging.
# This line sets up loggers basically.
fileConfig(config.config_file_name) # type:ignore
fileConfig(config.config_file_name) # type: ignore

# add your model's MetaData object here
# for 'autogenerate' support
Expand Down
Loading