Skip to content

Commit

Permalink
Solving Pylint warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderWatzinger committed Dec 10, 2023
1 parent 6d7bff5 commit df81632
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 21 deletions.
1 change: 0 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ disable=C0111, broad-except, cyclic-import, duplicate-code
good-names=f,i,j,k,ex,Run,_,e,js,bc,id,rv,ip,to # default is i,j,k,ex,Run,_
ignore=openatlas.wsgi
min-public-methods=0
--disable=W cidoc_rtfs_parser

[FORMAT]
max-line-length=79
Expand Down
2 changes: 1 addition & 1 deletion openatlas/api/endpoints/iiif.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def get_manifest_version_2(id_: int) -> dict[str, Any]:
def get_metadata(entity: Entity) -> dict[str, Any]:
ext = '.tiff' if g.settings['iiif_conversion'] else entity.get_file_ext()
image_url = f"{g.settings['iiif_url']}{entity.id}{ext}"
req = requests.get(f"{image_url}/info.json")
req = requests.get(f"{image_url}/info.json", timeout=30)
image_api = req.json()
return {'entity': entity, 'img_url': image_url, 'img_api': image_api}

Expand Down
3 changes: 2 additions & 1 deletion openatlas/api/import_scripts/arche.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ def get_existing_ids() -> list[int]:
def fetch_exif(id_: str) -> dict[str, Any]:
req = requests.get(
'https://arche-exif.acdh.oeaw.ac.at/',
params={'id': id_})
params={'id': id_},
timeout=300)
return req.json()


Expand Down
1 change: 0 additions & 1 deletion openatlas/forms/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from flask import g, render_template
from flask_babel import lazy_gettext as _
from markupsafe import Markup
from wtforms import Field, FileField, IntegerField, SelectField, StringField
from wtforms.validators import Email

Expand Down
7 changes: 3 additions & 4 deletions openatlas/forms/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ def hierarchy_name_exists(form: FlaskForm, field: TreeField) -> None:


def validate(form: FlaskForm, extra_validators: validators = None) -> bool:
valid = FlaskForm.validate(form)
if hasattr(form, 'begin_year_from'): # Dates
if not validate_dates(form):
valid = False
valid = FlaskForm.validate(form, extra_validators)
if hasattr(form, 'begin_year_from') and not validate_dates(form):
valid = False
for field_id, field in form.__dict__.items(): # External reference systems
if field_id.startswith('reference_system_id_') \
and field.data \
Expand Down
2 changes: 1 addition & 1 deletion openatlas/models/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def sql_export(format_: str, postfix: Optional[str] = '') -> bool:
env={
'PGPASSWORD': app.config['DATABASE_PASS'],
'SYSTEMROOT': root}).wait()
with open(os.devnull, 'w') as null:
with open(os.devnull, 'w', encoding='utf8') as null:
subprocess.Popen(
['7z', 'a', f'{file}.7z', file],
stdout=null).wait()
Expand Down
15 changes: 7 additions & 8 deletions openatlas/views/imports.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import collections
import pathlib
from pathlib import Path
from typing import Optional, Union

import numpy
Expand All @@ -17,9 +17,9 @@
from openatlas.display.tab import Tab
from openatlas.display.table import Table
from openatlas.display.util import (
button, datetime64_to_timestamp, display_form, format_date,
get_backup_file_data, is_authorized, link, manual, required_group,
button_bar, uc_first, description)
button, button_bar, datetime64_to_timestamp, description, display_form,
format_date, get_backup_file_data, is_authorized, link, manual,
required_group, uc_first)
from openatlas.forms.field import SubmitField
from openatlas.models.entity import Entity
from openatlas.models.imports import Import, is_float
Expand Down Expand Up @@ -178,8 +178,7 @@ class ImportForm(FlaskForm):

def validate(self, extra_validators: validators=None) -> bool:
valid = FlaskForm.validate(self)
if pathlib.Path(str(request.files['file'].filename)) \
.suffix.lower() != '.csv':
if Path(str(request.files['file'].filename)) .suffix.lower() != '.csv':
self.file.errors.append(_('file type not allowed'))
valid = False
return valid
Expand Down Expand Up @@ -216,7 +215,7 @@ def import_data(project_id: int, class_: str) -> str:
headers = list(data_frame.columns.values)
if 'name' not in headers:
messages['error'].append(_('missing name column'))
raise Exception()
raise ValueError()
for item in headers:
if item not in columns['allowed']:
columns['invalid'].append(item)
Expand Down Expand Up @@ -304,7 +303,7 @@ def import_data(project_id: int, class_: str) -> str:
messages['warn'].append(
f"{_('possible duplicates')}: {', '.join(duplicates)}")
if messages['error']:
raise Exception()
raise ValueError()
except Exception as e:
g.logger.log('error', 'import', 'import check failed', e)
flash(_('error at import'), 'error')
Expand Down
2 changes: 0 additions & 2 deletions openatlas/views/search.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Any

from flask import g, render_template, request
from flask_babel import lazy_gettext as _
from flask_wtf import FlaskForm
Expand Down
6 changes: 4 additions & 2 deletions tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ def test_admin(self) -> None:
assert b'Invalid linked entity' in rv.data

file_ = 'Test77.txt'
with open(Path(app.config['UPLOAD_PATH'] / file_), 'w') as _:
file_path = Path(app.config['UPLOAD_PATH'] / file_)
with open(file_path, 'w', encoding='utf8') as _:
pass
with open(Path(Path(g.settings['iiif_path']) / file_), 'w') as _:
iiif_path = Path(Path(g.settings['iiif_path']) / file_)
with open(iiif_path, 'w', encoding='utf8') as _:
pass

rv = self.app.get(
Expand Down

0 comments on commit df81632

Please sign in to comment.