Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 2 additions & 3 deletions .config/mise/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
# and consider this toml file as the only source of truth
# Cf: https://mise.jdx.dev/configuration.html#idiomatic-version-files
legacy_version_file = false
python.compile = true

[tools]
python = "3.12"
poetry = "1.8"
python = "3.13"
poetry = "2.2"

[env]
_.file = '.env'
Expand Down
11 changes: 0 additions & 11 deletions .devcontainer/devcontainer.json

This file was deleted.

1 change: 0 additions & 1 deletion .dockerignore

This file was deleted.

117 changes: 32 additions & 85 deletions .github/workflows/pullrequest-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,91 +10,38 @@ on:
- 'README.md'
- 'catalog-info.yaml'

jobs:
build:
uses: ZeroGachis/.github/.github/workflows/build-image.yml@v4
permissions:
contents: read
security-events: write
actions: read
id-token: write
packages: write
pull-requests: write
checks: write
with:
image_name: magicparse
dockerfile_context: .
vault_url: ${{ vars.PULLREQUEST_VAULT_URL }}
vault_github_actions_role: ${{ vars.VAULT_GITHUB_ACTIONS_ROLE }}
regitry_url: ghcr.io
secrets: inherit

static-metrics:
needs:
[
build,
]
uses: ZeroGachis/.github/.github/workflows/run-docker.yml@v4
permissions:
contents: read
id-token: write
packages: read
actions: write
checks: write
with:
image_url: ${{ needs.build.outputs.image-url }}
workdir: /app
vault_enabled: false
tailscale_enabled: false
run_command: |
poetry install --no-interaction --no-ansi --no-root --only dev
ruff check --diff ./
ruff format --check --diff ./
pyright
secrets: inherit
permissions:
actions: read
checks: write
contents: read
id-token: write
packages: write
pull-requests: write
security-events: write

unit-tests:
needs:
[
build,
]
uses: ZeroGachis/.github/.github/workflows/run-docker-with-db.yml@v4
permissions:
contents: read
id-token: write
packages: read
actions: write
checks: write
with:
image_url: ${{ needs.build.outputs.image-url }}
workdir: /app
run_command: |
poetry install --no-interaction --no-ansi --no-root --only dev
poetry run pytest --verbose --junit-xml reports/unit_tests_results.xml
vault_enabled: false
tailscale_enabled: false
enable_test_report: true
test_report_name: "UT Report"
test_report_path: reports/unit_tests_results.xml
test_report_format: java-junit
secrets: inherit

destroy:
if: always()
needs:
[
build,
unit-tests,
static-metrics,
]
uses: ZeroGachis/.github/.github/workflows/delete-docker-image.yml@v4
permissions:
contents: read
id-token: write
packages: write
with:
image_name: magicparse
image_version: ${{ needs.build.outputs.image-version }}
vault_url: ${{ vars.PULLREQUEST_VAULT_URL }}
vault_github_actions_role: ${{ vars.VAULT_GITHUB_ACTIONS_ROLE }}
secrets: inherit
jobs:
static-analysis-and-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: jdx/mise-action@v3
with:
install: true
install_args: python poetry
cache: true
- name: Install Python dependencies
uses: ZeroGachis/.github/.github/actions/poetry-install@v5
with:
aws_account_id: ${{ vars.PULL_REQUEST_AWS_ACCOUNT_ID }}
install_options: --with ci
depends_on_private_packages: false
- name: Run Linter
run: poetry run ruff check --output-format=github
- name: Run Formatter
run: poetry run ruff format --check
- name: Run Typechecker
run: poetry run basedpyright
- name: Run unit tests
run: poetry run pytest -p pytest_github_actions_annotate_failures
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ jobs:
packages: read
id-token: write
with:
python_version: "3.11"
python_version: "3.13"
environment_name: main
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ repos:
entry: poetry run ruff format
language: system
types: [file, python]
- id: pyright
name: Pyright
entry: poetry run pyright
- id: typechecker
name: typechecker
entry: poetry run basedpyright
language: system
types: [file, python]
12 changes: 0 additions & 12 deletions Dockerfile

This file was deleted.

11 changes: 0 additions & 11 deletions docker-compose.yml

This file was deleted.

4 changes: 2 additions & 2 deletions magicparse/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from collections.abc import Sequence
from collections.abc import Iterable, Sequence
from io import BytesIO

from .schema import (
Expand All @@ -16,7 +16,7 @@
)
from .transform import Transform
from .type_converters import TypeConverter, builtins as builtins_type_converters
from typing import Any, Iterable
from typing import Any
from .validators import Validator, builtins as builtins_validators


Expand Down
13 changes: 7 additions & 6 deletions magicparse/schema.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import codecs
from abc import ABC, abstractmethod
from collections.abc import Iterable, Iterator
import csv
from dataclasses import dataclass

from magicparse.transform import SkipRow
from .fields import Field, ComputedField
from io import BytesIO
from typing import Any, Dict, Iterator, List, Union, Iterable
from typing import Any


@dataclass(frozen=True, slots=True)
Expand All @@ -28,11 +29,11 @@ class RowFailed:


class Schema(ABC):
fields: List[Field]
fields: list[Field]
encoding: str
has_headers: bool

def __init__(self, options: Dict[str, Any]) -> None:
def __init__(self, options: dict[str, Any]) -> None:
self.fields = [Field.build(item) for item in options["fields"]]
self.computed_fields = [ComputedField.build(item) for item in options.get("computed-fields", [])]

Expand Down Expand Up @@ -64,10 +65,10 @@ def register(cls, schema: type["Schema"]) -> None:

cls.registry[schema.key()] = schema

def parse(self, data: Union[bytes, BytesIO]) -> list[RowParsed | RowSkipped | RowFailed]:
def parse(self, data: bytes | BytesIO) -> list[RowParsed | RowSkipped | RowFailed]:
return list(self.stream_parse(data))

def stream_parse(self, data: Union[bytes, BytesIO]) -> Iterable[RowParsed | RowSkipped | RowFailed]:
def stream_parse(self, data: bytes | BytesIO) -> Iterable[RowParsed | RowSkipped | RowFailed]:
if isinstance(data, bytes):
stream = BytesIO(data)
else:
Expand Down Expand Up @@ -128,7 +129,7 @@ def process_fields(


class CsvSchema(Schema):
def __init__(self, options: Dict[str, Any]) -> None:
def __init__(self, options: dict[str, Any]) -> None:
super().__init__(options)
self.delimiter = options.get("delimiter", ",")
self.quotechar = options.get("quotechar", None)
Expand Down
Loading