Skip to content

Commit 44a86b8

Browse files
authored
Merge pull request #83 from Jylpah/dev
version 0.3.5
2 parents 3bb1f90 + c8b04e8 commit 44a86b8

File tree

10 files changed

+706
-456
lines changed

10 files changed

+706
-456
lines changed

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "pyutils"
3-
version = "0.3.4"
3+
version = "0.3.6"
44
authors = [{ name = "Jylpah", email = "[email protected]" }]
55
description = "Misc Python utils and classes"
66
readme = "README.md"
@@ -19,10 +19,10 @@ dependencies = [
1919
"aiofiles>=23.1.0",
2020
"aiohttp>=3.8.4",
2121
"aioconsole>=0.6.1",
22-
"aiosqlite>=0.19.0",
22+
# "aiosqlite>=0.19.0",
2323
"aiocsv>=1.2.4",
2424
"alive-progress>=3.1.1",
25-
"isort>=5.12.0",
25+
# "isort>=5.12.0",
2626
"pydantic>=1.10.7, == 1.*",
2727
"pymongo>=4.3.3",
2828
]

src/pyutils/__init__.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,18 @@
3939
epoch_now,
4040
alive_bar_monitor,
4141
is_alphanum,
42-
# read_config,
42+
# read_config,
4343
get_datestr,
4444
get_url,
45-
get_urls,
46-
get_url_JSON_model,
47-
get_url_JSON_models,
45+
# get_urls,
46+
get_url_model,
47+
# get_url_JSON_models,
4848
get_url_JSON,
49-
get_urls_JSON,
50-
get_urls_JSON_models,
49+
# get_urls_JSON,
50+
# get_urls_JSON_models,
5151
get_temp_filename,
5252
chunker,
53+
str2path,
5354
)
5455

5556

src/pyutils/csvexportable.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
from datetime import date, datetime
1414
from aiofiles import open
1515
from enum import Enum
16+
from pathlib import Path
17+
18+
from .utils import str2path
1619

1720
# Setup logging
1821
logger = logging.getLogger()
@@ -50,7 +53,9 @@ def csv_headers(self) -> list[str]:
5053
"""Provide CSV headers as list"""
5154
return list(self.dict(exclude_unset=False, by_alias=False).keys())
5255

53-
def _csv_write_fields(self, left: dict[str, Any]) -> tuple[dict[str, Any], dict[str, Any]]:
56+
def _csv_write_fields(
57+
self, left: dict[str, Any]
58+
) -> tuple[dict[str, Any], dict[str, Any]]:
5459
"""Write CSV fields with custom encoders
5560
5661
Returns columns_done, columns_left
@@ -90,7 +95,9 @@ def csv_row(self) -> dict[str, str | int | float | bool]:
9095
res[key] = None
9196
return self._clear_None(res)
9297

93-
def _clear_None(self, res: dict[str, str | int | float | bool | None]) -> dict[str, str | int | float | bool]:
98+
def _clear_None(
99+
self, res: dict[str, str | int | float | bool | None]
100+
) -> dict[str, str | int | float | bool]:
94101
out: dict[str, str | int | float | bool] = dict()
95102
for key, value in res.items():
96103
if value is None:
@@ -100,7 +107,9 @@ def _clear_None(self, res: dict[str, str | int | float | bool | None]) -> dict[s
100107
return out
101108

102109
@classmethod
103-
def _csv_read_fields(cls, row: dict[str, Any]) -> tuple[dict[str, Any], dict[str, Any]]:
110+
def _csv_read_fields(
111+
cls, row: dict[str, Any]
112+
) -> tuple[dict[str, Any], dict[str, Any]]:
104113
"""read CSV fields with custom encoding.
105114
Returns read, unread fields as dict[str, Any]"""
106115

@@ -140,7 +149,9 @@ def from_csv(cls, row: dict[str, Any]) -> Self | None:
140149
elif field_type is bool:
141150
res[field] = row[field] == "True"
142151
elif issubclass(field_type, Enum):
143-
res[field] = field_type[str(row[field])] ## Enums are stored by key, not value
152+
res[field] = field_type[
153+
str(row[field])
154+
] ## Enums are stored by key, not value
144155
elif field_type is date:
145156
res[field] = date.fromisoformat(row[field])
146157
elif field_type is datetime:
@@ -162,11 +173,11 @@ def from_csv(cls, row: dict[str, Any]) -> Self | None:
162173
return None
163174

164175
@classmethod
165-
async def import_csv(cls, filename: str) -> AsyncGenerator[Self, None]:
176+
async def import_csv(cls, filename: Path | str) -> AsyncGenerator[Self, None]:
166177
"""Import from filename, one model per line"""
167178
try:
179+
debug("importing from CSV file: %s", str(filename))
168180
dialect: Type[Dialect] = excel
169-
debug("importing from CSV file: %s", filename)
170181
async with open(filename, mode="r", newline="") as f:
171182
async for row in AsyncDictReader(f, dialect=dialect):
172183
# debug ("row: %s", row)

0 commit comments

Comments
 (0)