Skip to content

Commit 30cad3d

Browse files
committed
Merge branch 'SD-27' of https://github.com/cmu-delphi/signal_documentation into ci-tests
2 parents 6d3864f + ec55a42 commit 30cad3d

File tree

17 files changed

+236
-106
lines changed

17 files changed

+236
-106
lines changed

.flake8

Lines changed: 0 additions & 9 deletions
This file was deleted.

.isort.cfg

Lines changed: 0 additions & 5 deletions
This file was deleted.

Pipfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ django-import-export = "*"
2525
coverage = "*"
2626
django-coverage-plugin = "*"
2727
django-extensions-models = "*"
28+
mypy = "*"
29+
django-stubs = "*"
2830

2931
[dev-packages]
3032
flake8 = "*"

Pipfile.lock

Lines changed: 82 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

setup.cfg

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
[isort]
2+
multi_line_output=3
3+
force_grid_wrap = 3
4+
include_trailing_comma=True
5+
line_length=158
6+
7+
[flake8]
8+
max-line-length = 158
9+
max-complexity = 10
10+
exclude =
11+
.git,
12+
__pycache__,
13+
.env,
14+
venv,
15+
*/migrations
16+
17+
[mypy]
18+
mypy_path = src/
19+
files = src
20+
warn_return_any = True
21+
warn_unused_configs = True
22+
warn_redundant_casts = True
23+
warn_unused_ignores = True
24+
check_untyped_defs = True
25+
show_error_codes = True
26+
strict_optional = True
27+
ignore_missing_imports = True
28+
plugins =
29+
mypy_django_plugin.main
30+
31+
[mypy.plugins.django-stubs]
32+
django_settings_module = signal_documentation.settings

src/base/admin.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Literal
2+
13
from django.contrib import admin
24

35
from base.models import Link
@@ -8,4 +10,4 @@ class LinkAdmin(admin.ModelAdmin):
810
"""
911
Admin interface for managing link objects.
1012
"""
11-
list_display = ('url', 'link_type')
13+
list_display: tuple[Literal['url'], Literal['link_type']] = ('url', 'link_type')

src/datasources/admin.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Literal
2+
13
from django.contrib import admin
24
from import_export.admin import ImportExportModelAdmin
35

@@ -10,15 +12,19 @@ class SourceSubdivisionAdmin(ImportExportModelAdmin):
1012
"""
1113
Admin interface for managing source subdivision objects.
1214
"""
13-
list_display = ('name', 'db_source')
14-
search_fields = ('name', 'db_source')
15-
resource_classes = [SourceSubdivisionResource]
15+
list_display: tuple[Literal['name'], Literal['db_source']] = ('name', 'db_source')
16+
search_fields: tuple[Literal['name'], Literal['db_source']] = ('name', 'db_source')
17+
resource_classes: list[type[SourceSubdivisionResource]] = [SourceSubdivisionResource]
18+
19+
20+
data_source_search_fields_type = tuple[Literal['name'], Literal['source_subdivision__db_source'], Literal['source_subdivision__name'], Literal['description']]
1621

1722

1823
@admin.register(DataSource)
1924
class DataSourceAdmin(ImportExportModelAdmin):
2025
"""
2126
Admin interface for managing data source objects.
2227
"""
23-
list_display = ('name',)
28+
list_display: tuple[Literal['name']] = ('name',)
29+
search_fields: tuple[Literal['name'], Literal['source_subdivision__db_source'], Literal['source_subdivision__name'], Literal['description']]
2430
search_fields = ('name', 'source_subdivision__db_source', 'source_subdivision__name', 'description')

src/datasources/resources.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import re
2+
from typing import Literal
23

4+
from django.db.models import QuerySet
35
from import_export import resources
46
from import_export.fields import Field, widgets
57

@@ -25,8 +27,10 @@ class SourceSubdivisionResource(resources.ModelResource):
2527

2628
class Meta:
2729
model = SourceSubdivision
30+
fields: tuple[Literal['name'], Literal['display_name'], Literal['description'],
31+
Literal['data_source'], Literal['reference_signal'], Literal['links']]
2832
fields = ('name', 'display_name', 'description', 'data_source', 'reference_signal', 'links')
29-
import_id_fields = ['name']
33+
import_id_fields: list[str] = ['name']
3034
skip_unchanged = True
3135

3236
def before_import_row(self, row, **kwargs) -> None:
@@ -37,22 +41,26 @@ def before_import_row(self, row, **kwargs) -> None:
3741
self.process_links(row)
3842
self.process_datasource(row)
3943

40-
def process_links(self, row):
44+
def process_links(self, row) -> None:
4145
row['Links'] = ''
4246
if row['DUA']:
47+
link: Link
48+
created: bool
4349
link, created = Link.objects.get_or_create(url=row['DUA'], link_type=LinkTypeChoices.DUA)
4450
row['Links'] += row['Links'] + f'|{link.url}'
4551
if row['Link']:
4652
pattern = r'\[(.*?)\]\((.*?)\)'
4753
pattern_match = re.search(pattern, row['Link'])
4854
link_type_mapping = {choice.label: choice.value for choice in LinkTypeChoices}
49-
link_type = link_type_mapping[pattern_match.group(1)]
50-
link_url = pattern_match.group(2)
55+
link_type: str = link_type_mapping[pattern_match.group(1)] # type: ignore
56+
link_url: str = pattern_match.group(2) # type: ignore
5157
link, created = Link.objects.get_or_create(url=link_url, link_type=link_type)
5258
row['Links'] += row['Links'] + f'|{link.url}'
5359

54-
def process_datasource(self, row):
60+
def process_datasource(self, row) -> None:
5561
if row['Name']:
62+
data_source: DataSource
63+
created: bool
5664
data_source, created = DataSource.objects.get_or_create(
5765
name=row['Name'],
5866
defaults={
@@ -61,5 +69,5 @@ def process_datasource(self, row):
6169
'source_license': row['License'],
6270
}
6371
)
64-
links = Link.objects.filter(url__in=row['Links'].split('|')).values_list('id', flat=True)
72+
links: QuerySet[Link] = Link.objects.filter(url__in=row['Links'].split('|')).values_list('id', flat=True)
6573
data_source.links.add(*links)

0 commit comments

Comments
 (0)