Skip to content

Commit d49d95e

Browse files
committed
feat: address review items
1 parent 0607843 commit d49d95e

File tree

10 files changed

+25
-33
lines changed

10 files changed

+25
-33
lines changed

tagstudio/src/core/library/alchemy/library.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
TS_FOLDER_NAME,
4242
)
4343
from ...enums import LibraryPrefs
44+
from ...settings import LibSettings
4445
from .db import make_tables
4546
from .enums import FieldTypeEnum, FilterState, TagColor
4647
from .fields import (
@@ -50,7 +51,6 @@
5051
TextField,
5152
_FieldID,
5253
)
53-
from ...settings import LibSettings
5454
from .joins import TagField, TagSubtag
5555
from .models import Entry, Folder, Preferences, Tag, TagAlias, ValueType
5656
from .visitors import SQLBoolExpressionBuilder
@@ -202,7 +202,7 @@ def migrate_json_to_sqlite(self, json_lib: JsonLibrary):
202202
)
203203

204204
# Preferences
205-
self.settings.extension_list = [ x.strip(".") for x in json_lib.ext_list]
205+
self.settings.extension_list = [x.strip(".") for x in json_lib.ext_list]
206206
self.settings.is_exclude_list = json_lib.is_exclude_list
207207

208208
end_time = time.time()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from .tssettings import TSSettings
21
from .libsettings import LibSettings
2+
from .tssettings import TSSettings
33

44
__all__ = ["TSSettings", "LibSettings"]
Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,38 @@
11
from pathlib import Path
2-
from pydantic import BaseModel, Field
3-
import toml
2+
43
import structlog
4+
import toml
5+
from pydantic import BaseModel, Field
56

67
logger = structlog.get_logger(__name__)
78

9+
810
class LibSettings(BaseModel):
911
is_exclude_list: bool = Field(default=True)
10-
extension_list: list[str] = Field(default = [".json", ".xmp", ".aae"])
12+
extension_list: list[str] = Field(default=[".json", ".xmp", ".aae"])
1113
page_size: int = Field(default=500)
1214
db_version: int = Field(default=2)
1315
filename: str = Field(default="")
1416

1517
@staticmethod
1618
def open(path_value: Path | str) -> "LibSettings":
17-
path: Path
18-
if not isinstance(path_value, Path):
19-
path = Path(path_value)
20-
else:
21-
path = path_value
19+
path: Path = Path(path_value) if not isinstance(path_value, Path) else path_value
2220

2321
if path.exists():
24-
with open(path, "r") as settings_file:
22+
with open(path) as settings_file:
2523
filecontents = settings_file.read()
2624
if len(filecontents.strip()) != 0:
2725
settings_data = toml.loads(filecontents)
2826
settings_data["filename"] = str(path)
2927
return LibSettings(**settings_data)
30-
31-
#either settings file did not exist or was empty - either way, use default settings
28+
29+
# either settings file did not exist or was empty - either way, use default settings
3230
settings = LibSettings(**dict(filename=str(path)))
3331
return settings
34-
32+
3533
def save(self):
3634
if not (parent_path := Path(self.filename).parent).exists():
3735
parent_path.mkdir()
3836

3937
with open(self.filename, "w") as settings_file:
40-
toml.dump(dict(self), settings_file)
38+
toml.dump(dict(self), settings_file)

tagstudio/src/core/settings/tssettings.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from pathlib import Path
2-
from typing import Any
32

43
import toml
54
from pydantic import BaseModel, Field
@@ -24,7 +23,7 @@ class TSSettings(BaseModel):
2423
def read_settings(path: Path | str) -> "TSSettings":
2524
path_value = Path(path)
2625
if path_value.exists():
27-
with open(path, "r") as file:
26+
with open(path) as file:
2827
filecontents = file.read()
2928
if len(filecontents.strip()) != 0:
3029
settings_data = toml.loads(filecontents)
@@ -34,11 +33,7 @@ def read_settings(path: Path | str) -> "TSSettings":
3433
return TSSettings(**dict(filename=str(path)))
3534

3635
def save(self, path: Path | str | None = None) -> None:
37-
path_value: Path
38-
if isinstance(path, str):
39-
path_value = Path(path)
40-
else:
41-
path_value = Path(self.filename)
36+
path_value: Path = Path(path) if isinstance(path, str) else Path(self.filename)
4237

4338
if not path_value.parent.exists():
4439
path_value.parent.mkdir(parents=True, exist_ok=True)

tagstudio/src/core/tscacheddata.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,21 @@ def open(path_value: Path | str | None = None) -> "TSCachedData":
2929
elif isinstance(path_value, Path):
3030
path = path_value
3131
else:
32-
logger.info("no cache location was specified, using ", default_cache_location=default_cache_location)
32+
logger.info(
33+
"no cache location was specified, using ",
34+
default_cache_location=default_cache_location,
35+
)
3336
path = default_cache_location
34-
37+
3538
if path.exists():
36-
with open(path, "r") as cache_file:
39+
with open(path) as cache_file:
3740
filecontents = cache_file.read()
3841
if len(filecontents.strip()) != 0:
3942
cache_data = toml.loads(filecontents)
4043
cache_data["path"] = str(path)
4144
logger.info("opening cache file at ", cache_location=path)
4245
return TSCachedData(**cache_data)
43-
46+
4447
return TSCachedData(**dict(path=str(default_cache_location)))
4548

4649
def save(self):

tagstudio/src/qt/modals/file_extension.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
QVBoxLayout,
1717
QWidget,
1818
)
19-
from src.core.enums import LibraryPrefs
2019
from src.core.library import Library
2120
from src.qt.translations import Translations
2221
from src.qt.widgets.panel import PanelWidget
@@ -114,4 +113,4 @@ def save(self):
114113
extensions.append(ext.text().strip().lstrip(".").lower())
115114

116115
# save preference
117-
self.lib.settings.extension_list = extensions
116+
self.lib.settings.extension_list = extensions

tagstudio/src/qt/ts_qt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
VERSION_BRANCH,
6868
)
6969
from src.core.driver import DriverMixin
70-
from src.core.enums import LibraryPrefs, MacroID
70+
from src.core.enums import MacroID
7171
from src.core.library.alchemy import Library
7272
from src.core.library.alchemy.enums import (
7373
FieldTypeEnum,

tagstudio/src/qt/widgets/migration_modal.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from sqlalchemy import and_, select
2121
from sqlalchemy.orm import Session
2222
from src.core.constants import TS_FOLDER_NAME
23-
from src.core.enums import LibraryPrefs
2423
from src.core.library.alchemy.enums import FieldTypeEnum, TagColor
2524
from src.core.library.alchemy.fields import TagBoxField, _FieldID
2625
from src.core.library.alchemy.joins import TagField, TagSubtag

tagstudio/tests/macros/test_refresh_dir.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from tempfile import TemporaryDirectory
33

44
import pytest
5-
from src.core.enums import LibraryPrefs
65
from src.core.utils.refresh_dir import RefreshDirTracker
76

87
CWD = pathlib.Path(__file__).parent

tagstudio/tests/test_json_migration.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import pathlib
66
from time import time
77

8-
from src.core.enums import LibraryPrefs
98
from src.qt.widgets.migration_modal import JsonMigrationModal
109

1110
CWD = pathlib.Path(__file__)

0 commit comments

Comments
 (0)