Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
6852346
chore(deps): Bump pyopenssl from 22.0.0 to 22.1.0
dependabot[bot] Dec 5, 2022
7a1ea26
Merge pull request #403 from fyntex/dependabot/pip/pyopenssl-22.1.0
ycouce-cdd Jan 5, 2023
d80790e
chore(deps-dev): Bump mypy from 0.982 to 0.991
dependabot[bot] Dec 5, 2022
d2a3e28
chore: Update `Optional` parameters for new version of `mypy`
svillegas-cdd Dec 20, 2022
2ed5388
Merge pull request #406 from fyntex/dependabot/pip/mypy-0.991
ycouce-cdd Jan 5, 2023
ce1d62f
chore(deps): Bump jsonschema from 4.16.0 to 4.17.3
dependabot[bot] Dec 5, 2022
ffd294f
Merge pull request #405 from fyntex/dependabot/pip/jsonschema-4.17.3
svillegas-cdd Jan 23, 2023
519caa4
chore: Add GitHub Dependency Review
jtrobles-cdd Jan 26, 2023
219a51e
Merge pull request #422 from fyntex/task/add-github-dep-review
jtrobles-cdd Jan 26, 2023
f745592
chore: Improve GitHub Dependency Review
jtrobles-cdd Jan 26, 2023
543ba3a
Merge pull request #423 from fyntex/task/improve-github-dep-review
jtrobles-cdd Jan 26, 2023
9f5c08a
chore(deps-dev): Bump black from 22.10.0 to 22.12.0
dependabot[bot] Jan 23, 2023
b3996b6
Merge pull request #411 from fyntex/dependabot/pip/black-22.12.0
jtrobles-cdd Jan 27, 2023
5ad2919
chore: Update Markdownlint configuration
jtrobles-cdd Jan 27, 2023
83e88f8
Merge pull request #425 from fyntex/task/update-markdown-linter-config
jtrobles-cdd Jan 28, 2023
c8278eb
chore(deps): Bump pydantic from 1.10.2 to 1.10.4
dependabot[bot] Jan 1, 2023
3b54a8c
Merge pull request #410 from fyntex/dependabot/pip/pydantic-1.10.4
svillegas-cdd Feb 3, 2023
febd0de
chore: Move Mypy configuration to separate configuration file
jtrobles-cdd Feb 3, 2023
c445366
chore: Move list of files to be scanned by Mypy to Mypy config. file
jtrobles-cdd Feb 3, 2023
a9150d6
chore: Install Python package 'types-pytz'
jtrobles-cdd Feb 3, 2023
b2ed011
chore: Enable type checking for `pytz`
jtrobles-cdd Feb 3, 2023
af968c8
chore: Enable type checking for `signxml`
jtrobles-cdd Feb 3, 2023
f9ba319
chore: Add missing return type annotations to tests
jtrobles-cdd Feb 3, 2023
b7088fd
Merge pull request #433 from fyntex/task/improve-type-checking
jtrobles-cdd Feb 3, 2023
4596d83
chore: Install Python package 'types-pyOpenSSL'
jtrobles-cdd Feb 3, 2023
2f5341a
chore: Enable type checking for `OpenSSL`
jtrobles-cdd Feb 3, 2023
2c165ef
chore: Enable type checking for `cryptography`
jtrobles-cdd Feb 3, 2023
197b653
chore: Install Python package 'types-jsonschema'
jtrobles-cdd Feb 3, 2023
636b0f4
chore: Enable type checking for `jsonschema`
jtrobles-cdd Feb 3, 2023
34fe508
Merge pull request #434 from fyntex/task/improve-type-checking
jtrobles-cdd Feb 3, 2023
233a3d6
chore(deps-dev): Bump coverage from 6.5.0 to 7.1.0
dependabot[bot] Jan 27, 2023
5d7d133
Merge pull request #424 from fyntex/dependabot/pip/coverage-7.1.0
svillegas-cdd Feb 6, 2023
5836771
chore(deps): Bump lxml from 4.9.1 to 4.9.2
dependabot[bot] Jan 27, 2023
6429d7b
Merge pull request #414 from fyntex/dependabot/pip/lxml-4.9.2
svillegas-cdd Feb 6, 2023
9c044c8
chore(deps): Bump pytz from 2022.6 to 2022.7.1
dependabot[bot] Jan 27, 2023
6202f04
Merge pull request #420 from fyntex/dependabot/pip/pytz-2022.7.1
svillegas-cdd Feb 6, 2023
f38747b
chore(deps): Bump pyopenssl from 22.1.0 to 23.0.0
dependabot[bot] Feb 1, 2023
83f91d0
Merge pull request #431 from fyntex/dependabot/pip/pyopenssl-23.0.0
svillegas-cdd Feb 6, 2023
b3f8baf
chore(deps): Bump cryptography from 38.0.4 to 39.0.1
dependabot[bot] Feb 8, 2023
2e571e2
Merge pull request #436 from fyntex/dependabot/pip/cryptography-39.0.1
svillegas-cdd Feb 8, 2023
0412e89
chore(deps): Bump django from 3.2.16 to 3.2.17
dependabot[bot] Feb 6, 2023
871426b
Merge pull request #435 from fyntex/dependabot/pip/django-3.2.17
svillegas-cdd Feb 8, 2023
c03a738
chore(deps): Bump marshmallow from 2.21.0 to 3.19.0
svillegas-cdd Jan 31, 2023
6ff9db7
chore: Update code to work on `marshmallow 3.19.0`
svillegas-cdd Jan 31, 2023
ea5f5e6
Merge pull request #426 from fyntex/task/COMPCLDATA-201-update-marshm…
svillegas-cdd Feb 8, 2023
a476e23
chore: Update history for new version
jtrobles-cdd Feb 10, 2023
ebcbfce
chore: Bump version from 0.19.0 to 0.20.0
jtrobles-cdd Feb 10, 2023
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
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.19.0
current_version = 0.20.0
commit = True
tag = True
message = chore: Bump version from {current_version} to {new_version}
Expand Down
25 changes: 25 additions & 0 deletions .github/workflows/dependency-review.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Dependency Review

on:
pull_request:
types:
- opened
- reopened
- synchronize

permissions:
contents: read

jobs:
dependency-review:
name: Dependency Review
runs-on: ubuntu-22.04

steps:
- name: Check Out VCS Repository
uses: actions/checkout@v3.3.0

- name: Dependency Review
uses: actions/dependency-review-action@v3.0.3
with:
fail-on-severity: critical
4 changes: 4 additions & 0 deletions .markdownlint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ heading-style:

line-length:
line_length: 100
code_block_line_length: 200
tables: false

no-duplicate-heading:
allow_different_nesting: true

no-emphasis-as-heading: false

no-multiple-blanks:
maximum: 2

Expand Down
20 changes: 20 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# History

## 0.20.0 (2023-02-10)

- (PR #403, 2023-01-05) chore(deps): Bump pyopenssl from 22.0.0 to 22.1.0
- (PR #406, 2023-01-05) chore(deps-dev): Bump mypy from 0.982 to 0.991
- (PR #405, 2023-01-23) chore(deps): Bump jsonschema from 4.16.0 to 4.17.3
- (PR #422, 2023-01-26) Add GitHub Dependency Review
- (PR #423, 2023-01-26) Improve GitHub Dependency Review
- (PR #411, 2023-01-26) chore(deps-dev): Bump black from 22.10.0 to 22.12.0
- (PR #425, 2023-01-27) Update Markdownlint configuration
- (PR #410, 2023-02-03) chore(deps): Bump pydantic from 1.10.2 to 1.10.4
- (PR #433, 2023-02-03) Improve type checking
- (PR #434, 2023-02-03) Improve type checking
- (PR #424, 2023-02-06) chore(deps-dev): Bump coverage from 6.5.0 to 7.1.0
- (PR #414, 2023-02-06) chore(deps): Bump lxml from 4.9.1 to 4.9.2
- (PR #420, 2023-02-06) chore(deps): Bump pytz from 2022.6 to 2022.7.1
- (PR #431, 2023-02-06) chore(deps): Bump pyopenssl from 22.1.0 to 23.0.0
- (PR #436, 2023-02-08) chore(deps): Bump cryptography from 38.0.4 to 39.0.1
- (PR #435, 2023-02-08) chore(deps): Bump django from 3.2.16 to 3.2.17
- (PR #426, 2023-02-08) chore(deps): Bump marshmallow from 2.21.0 to 3.19.0

## 0.19.0 (2023-01-05)

- (PR #398, 2022-11-23) fix: Fix Dependabot error pip.….Error: Constraints cannot have extras
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ install-deps-dev: ## Install dependencies for development

lint: ## run tools for code style analysis, static type check, etc
flake8 --config=setup.cfg cl_sii scripts tests
mypy --config-file setup.cfg cl_sii scripts
mypy
isort --check-only .
$(BLACK) --check .

Expand Down
2 changes: 1 addition & 1 deletion cl_sii/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
"""


__version__ = '0.19.0'
__version__ = '0.20.0'
85 changes: 54 additions & 31 deletions cl_sii/extras/mm_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
(for serializers)

"""
from __future__ import annotations


try:
import marshmallow
except ImportError as exc: # pragma: no cover
raise ImportError("Package 'marshmallow' is required to use this module.") from exc

import datetime
from typing import Optional
from typing import Any, Mapping, Optional

import marshmallow.fields

Expand Down Expand Up @@ -46,13 +49,18 @@ class RutField(marshmallow.fields.Field):

default_error_messages = {
'invalid': 'Not a syntactically valid RUT.',
'type': 'Invalid type.',
}

def _serialize(self, value: Optional[object], attr: str, obj: object) -> Optional[str]:
def _serialize(
self, value: Optional[object], attr: str | None, obj: object, **kwargs: Any
) -> Optional[str]:
validated = self._validated(value)
return validated.canonical if validated is not None else None

def _deserialize(self, value: str, attr: str, data: dict) -> Optional[Rut]:
def _deserialize(
self, value: str, attr: str | None, data: Mapping[str, Any] | None, **kwargs: Any
) -> Optional[Rut]:
return self._validated(value)

def _validated(self, value: Optional[object]) -> Optional[Rut]:
Expand All @@ -61,10 +69,10 @@ def _validated(self, value: Optional[object]) -> Optional[Rut]:
else:
try:
validated = Rut(value, validate_dv=False) # type: ignore
except TypeError:
self.fail('type')
except ValueError:
self.fail('invalid')
except TypeError as exc:
raise self.make_error('type') from exc
except ValueError as exc:
raise self.make_error('invalid') from exc
return validated


Expand All @@ -89,13 +97,18 @@ class TipoDteField(marshmallow.fields.Field):

default_error_messages = {
'invalid': 'Not a valid Tipo DTE.',
'type': 'Invalid type.',
}

def _serialize(self, value: Optional[object], attr: str, obj: object) -> Optional[int]:
def _serialize(
self, value: Optional[object], attr: str | None, obj: object, **kwargs: Any
) -> Optional[int]:
validated: Optional[TipoDte] = self._validated(value)
return validated.value if validated is not None else None

def _deserialize(self, value: object, attr: str, data: dict) -> Optional[TipoDte]:
def _deserialize(
self, value: object, attr: str | None, data: Mapping[str, Any] | None, **kwargs: Any
) -> Optional[TipoDte]:
return self._validated(value)

def _validated(self, value: Optional[object]) -> Optional[TipoDte]:
Expand All @@ -104,21 +117,21 @@ def _validated(self, value: Optional[object]) -> Optional[TipoDte]:
else:
if isinstance(value, bool):
# is value is bool, `isinstance(value, int)` is True and `int(value)` works!
self.fail('type')
raise self.make_error('type')
try:
value = int(value) # type: ignore
except ValueError:
except ValueError as exc:
# `int('x')` raises 'ValueError', not 'TypeError'
self.fail('type')
except TypeError:
raise self.make_error('type') from exc
except TypeError as exc:
# `int(date(2018, 10, 10))` raises 'TypeError', unlike `int('x')`
self.fail('type')
raise self.make_error('type') from exc

try:
validated = TipoDte(value) # type: ignore
except ValueError:
except ValueError as exc:
# TipoDte('x') raises 'ValueError', not 'TypeError'
self.fail('invalid')
raise self.make_error('invalid') from exc
return validated


Expand All @@ -142,13 +155,18 @@ class RcvTipoDoctoField(marshmallow.fields.Field):

default_error_messages = {
'invalid': "Not a valid RCV's Tipo de Documento.",
'type': "Invalid type.",
}

def _serialize(self, value: Optional[object], attr: str, obj: object) -> Optional[int]:
def _serialize(
self, value: Optional[object], attr: str | None, obj: object, **kwargs: Any
) -> Optional[int]:
validated: Optional[RcvTipoDocto] = self._validated(value)
return validated.value if validated is not None else None

def _deserialize(self, value: object, attr: str, data: dict) -> Optional[RcvTipoDocto]:
def _deserialize(
self, value: object, attr: str | None, data: Mapping[str, Any] | None, **kwargs: Any
) -> Optional[RcvTipoDocto]:
return self._validated(value)

def _validated(self, value: Optional[object]) -> Optional[RcvTipoDocto]:
Expand All @@ -157,21 +175,21 @@ def _validated(self, value: Optional[object]) -> Optional[RcvTipoDocto]:
else:
if isinstance(value, bool):
# is value is bool, `isinstance(value, int)` is True and `int(value)` works!
self.fail('type')
raise self.make_error('type')
try:
value = int(value) # type: ignore
except ValueError:
except ValueError as exc:
# `int('x')` raises 'ValueError', not 'TypeError'
self.fail('type')
except TypeError:
raise self.make_error('type') from exc
except TypeError as exc:
# `int(date(2018, 10, 10))` raises 'TypeError', unlike `int('x')`
self.fail('type')
raise self.make_error('type') from exc

try:
validated = RcvTipoDocto(value) # type: ignore
except ValueError:
except ValueError as exc:
# RcvTipoDocto('x') raises 'ValueError', not 'TypeError'
self.fail('invalid')
raise self.make_error('invalid') from exc
return validated


Expand All @@ -186,14 +204,19 @@ class RcvPeriodoTributarioField(marshmallow.fields.Field):

default_error_messages = {
'invalid': "Not a valid RCV Periodo Tributario.",
'type': "Invalid type.",
}
_string_format = '%Y-%m' # Example: '2019-12'

def _serialize(self, value: Optional[object], attr: str, obj: object) -> Optional[str]:
def _serialize(
self, value: Optional[object], attr: str | None, obj: object, **kwargs: Any
) -> Optional[str]:
validated: Optional[RcvPeriodoTributario] = self._validated(value)
return validated.as_date().strftime(self._string_format) if validated is not None else None

def _deserialize(self, value: object, attr: str, data: dict) -> Optional[RcvPeriodoTributario]:
def _deserialize(
self, value: object, attr: str | None, data: Mapping[str, Any] | None, **kwargs: Any
) -> Optional[RcvPeriodoTributario]:
return self._validated(value)

def _validated(self, value: Optional[object]) -> Optional[RcvPeriodoTributario]:
Expand All @@ -203,10 +226,10 @@ def _validated(self, value: Optional[object]) -> Optional[RcvPeriodoTributario]:
try:
value = datetime.datetime.strptime(value, self._string_format) # type: ignore
value = value.date()
except ValueError:
self.fail('invalid')
except TypeError:
self.fail('type')
except ValueError as exc:
raise self.make_error('invalid') from exc
except TypeError as exc:
raise self.make_error('type') from exc

validated = RcvPeriodoTributario.from_date(value) # type: ignore

Expand Down
4 changes: 2 additions & 2 deletions cl_sii/libs/csv_utils.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import csv
from typing import IO, Sequence, Type, Union
from typing import IO, Optional, Sequence, Type, Union


def create_csv_dict_reader(
text_stream: IO[str],
csv_dialect: Type[csv.Dialect],
row_dict_extra_fields_key: Union[str, None] = None,
expected_fields_strict: bool = True,
expected_field_names: Sequence[str] = None,
expected_field_names: Optional[Sequence[str]] = None,
) -> csv.DictReader:
"""
Create a CSV dict reader with custom options.
Expand Down
40 changes: 21 additions & 19 deletions cl_sii/libs/mm_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

from datetime import date, datetime
from typing import Any, Union
from typing import Any, Mapping, Optional, Union

import marshmallow
import marshmallow.fields
Expand All @@ -22,10 +24,6 @@ def validate_no_unexpected_input_fields(
Usage::

class MySchema(marshmallow.Schema):

class Meta:
strict = True

folio = marshmallow.fields.Integer()

@marshmallow.validates_schema(pass_original=True)
Expand All @@ -36,7 +34,7 @@ def validate_schema(self, data: dict, original_data: dict) -> None:
# Original inspiration from
# https://marshmallow.readthedocs.io/en/2.x-line/extending.html#validating-original-input-data
fields_name_or_load_from = {
field.name if field.load_from is None else field.load_from
field.name if field.data_key is None else field.data_key
for field_key, field in schema.fields.items()
}
unexpected_input_fields = set(original_data) - fields_name_or_load_from
Expand Down Expand Up @@ -83,7 +81,7 @@ class CustomMarshmallowDateField(marshmallow.fields.Field):
'format': '"{input}" cannot be formatted as a date.',
}

def __init__(self, format: str = None, **kwargs: Any) -> None:
def __init__(self, format: Optional[str] = None, **kwargs: Any) -> None:
"""Constructor.

:param format: Either ``"iso"`` (for ISO-8601) or a date format str.
Expand All @@ -98,41 +96,45 @@ def __init__(self, format: str = None, **kwargs: Any) -> None:
# TODO: for 'marshmallow 3', rename 'dateformat' to 'datetimeformat'.
self.dateformat = format

def _add_to_schema(self, field_name: str, schema: marshmallow.Schema) -> None:
super()._add_to_schema(field_name, schema)
def _bind_to_schema(self, field_name: str, schema: marshmallow.Schema) -> None:
super()._bind_to_schema(field_name, schema)
self.dateformat = self.dateformat or schema.opts.dateformat

def _serialize(self, value: date, attr: str, obj: object) -> Union[str, None]:
def _serialize(
self, value: date, attr: str | None, obj: object, **kwargs: Any
) -> Union[str, None]:
if value is None:
return None
self.dateformat = self.dateformat or self.DEFAULT_FORMAT
format_func = self.DATEFORMAT_SERIALIZATION_FUNCS.get(self.dateformat, None)
if format_func:
try:
date_str = format_func(value)
except (AttributeError, ValueError):
self.fail('format', input=value)
except (AttributeError, ValueError) as exc:
raise self.make_error('format', input=value) from exc
else:
date_str = value.strftime(self.dateformat)

return date_str

def _deserialize(self, value: str, attr: str, data: dict) -> date:
def _deserialize(
self, value: str, attr: str | None, data: Mapping[str, Any] | None, **kwargs: Any
) -> date:
if not value: # Falsy values, e.g. '', None, [] are not valid
self.fail('invalid')
raise self.make_error('invalid')
self.dateformat = self.dateformat or self.DEFAULT_FORMAT
func = self.DATEFORMAT_DESERIALIZATION_FUNCS.get(self.dateformat)
if func:
try:
date_value = func(value) # type: date
except (TypeError, AttributeError, ValueError):
self.fail('invalid')
except (TypeError, AttributeError, ValueError) as exc:
raise self.make_error('invalid') from exc
elif self.dateformat:
try:
date_value = datetime.strptime(value, self.dateformat).date()
except (TypeError, AttributeError, ValueError):
self.fail('invalid')
except (TypeError, AttributeError, ValueError) as exc:
raise self.make_error('invalid') from exc
else:
self.fail('invalid')
raise self.make_error('invalid')

return date_value
Loading