Skip to content

Commit

Permalink
chore: Drop support for Python 3.7 (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon authored Dec 15, 2023
1 parent 1335395 commit 627514c
Show file tree
Hide file tree
Showing 13 changed files with 836 additions and 627 deletions.
22 changes: 22 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: 2
updates:
- package-ecosystem: pip
directory: "/.github/workflows"
schedule:
interval: daily
commit-message:
prefix: "ci: "
- package-ecosystem: github-actions
directory: "/"
schedule:
interval: daily
commit-message:
prefix: "ci: "
- package-ecosystem: pip
versioning-strategy: increase
directory: "/"
schedule:
interval: daily
commit-message:
prefix: "chore(deps): "
prefix-development: "chore(deps-dev): "
20 changes: 13 additions & 7 deletions .github/workflows/ci_workflow.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
name: Test Target CSV

on: [push]
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:

jobs:
pytest:
Expand All @@ -10,17 +15,18 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11"]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.4.0
env:
PIP_CONSTRAINT: .github/workflows/constraints.txt
run:
pipx install poetry
- name: Install dependencies
run: |
poetry install
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/constraints.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pip==23.3.1
poetry==1.7.1
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ Built with the [Meltano SDK](https://sdk.meltano.com) for Singer Taps and Target
| timestamp_timezone | False | UTC | The timezone code or name to use when generating `{timestamp}` and `{datestamp}`. Defaults to 'UTC'. For a list of possible values, please see: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones |
| stream_maps | False | None | Allows inline stream transformations and aliasing. For more information see: https://sdk.meltano.com/en/latest/stream_maps.html |
| record_sort_property_name| False | None | A property in the record which will be used as a sort key.<BR/><BR/>If this property is omitted, records will not be sorted. |
| overwrite_behavior | False | replace_file | Determines the overwrite behavior if destination file already exists. Must be one of the following string values: <BR/><BR/>- `append_records` (default) - append records at the insertion point<BR/>- `replace_file` - replace entire file using `default_CSV_template`
|
| overwrite_behavior | False | replace_file | Determines the overwrite behavior if destination file already exists. Must be one of the following string values: <BR/><BR/>- `append_records` (default) - append records at the insertion point<BR/>- `replace_file` - replace entire file using `default_CSV_template` |
| escape_characters | False | None | A string of characters to escape when writing CSV files. |

A full list of supported settings and capabilities is available by running: `target-csv --about`

Expand Down
1,336 changes: 759 additions & 577 deletions poetry.lock

Large diffs are not rendered by default.

19 changes: 10 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ name = "target-csv"
version = "0.0.1"
description = "`target-csv` is a Singer target for CSV, built with the Meltano SDK for Singer Targets."
authors = ["Meltano <[email protected]>"]
license = "Apache 2.0"
license = "Apache-2.0"

[tool.poetry.dependencies]
python = ">=3.7.1,<3.12"
requests = "^2.31.0"
singer-sdk = "^0.21.0"
python = ">=3.8"
singer-sdk = "~=0.34.0"

[tool.poetry.dev-dependencies]
pytest = "^7.2.2"
pytest = "~=7.4"

[tool.poetry.scripts]
target-csv = 'target_csv.target:TargetCSV.cli'
Expand All @@ -21,8 +20,10 @@ requires = ["poetry-core>=1.0.7"]
build-backend = "poetry.core.masonry.api"

[tool.ruff]
target-version = "py37"
line-length = 88
target-version = "py38"

[tool.ruff.lint]
ignore = [
"ANN101", # Missing type annotation for `self` in method
"ANN102", # Missing type annotation for `cls` in class method
Expand All @@ -38,11 +39,11 @@ select = [
"S", # flake8-bandit
]

[tool.ruff.flake8-annotations]
[tool.ruff.lint.flake8-annotations]
allow-star-arg-any = true

[tool.ruff.pydocstyle]
[tool.ruff.lint.pydocstyle]
convention = "google"

[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
"**/tests/*" = ["ANN", "D1", "S101"]
10 changes: 4 additions & 6 deletions target_csv/serialization.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import csv # noqa: D100
from pathlib import Path
from typing import List
from typing import Any, List


def write_csv(filepath: Path, records: List[dict], schema: dict) -> int:
def write_csv(filepath: Path, records: List[dict], schema: dict, **kwargs: Any) -> int:
"""Write a CSV file."""
if "properties" not in schema:
raise ValueError("Stream's schema has no properties defined.")

keys: List[str] = list(schema["properties"].keys())
with open(filepath, "w", encoding="utf-8", newline="") as fp:
writer = csv.DictWriter(fp, fieldnames=keys, dialect="excel")
writer = csv.DictWriter(fp, fieldnames=keys, dialect="excel", **kwargs)
writer.writeheader()
for record_count, record in enumerate(records, start=1):
writer.writerow(record)
Expand All @@ -23,7 +23,5 @@ def read_csv(filepath: Path) -> List[dict]:
result: List[dict] = []
with open(filepath, newline="") as fp:
reader = csv.DictReader(fp, delimiter=",", dialect="excel")
for record in reader:
result.append(record)

result.extend(iter(reader))
return result
7 changes: 6 additions & 1 deletion target_csv/sinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,9 @@ def process_batch(self, context: dict) -> None:

self.logger.info(f"Writing {len(context['records'])} records to file...")

write_csv(output_file, context["records"], self.schema)
write_csv(
output_file,
context["records"],
self.schema,
escapechar=self.config.get("escape_character"),
)
5 changes: 5 additions & 0 deletions target_csv/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,10 @@ class TargetCSV(Target):
),
default="replace_file",
),
th.Property(
"escape_character",
th.StringType,
description="The character to use for escaping special characters.",
),
).to_dict()
default_sink_class = CSVSink
25 changes: 0 additions & 25 deletions target_csv/tests/test_core.py

This file was deleted.

File renamed without changes.
13 changes: 13 additions & 0 deletions tests/test_core.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""Tests standard target features using the built-in SDK tests library."""

from typing import Any, Dict

from singer_sdk.testing import get_target_test_class

from target_csv.target import TargetCSV

SAMPLE_CONFIG: Dict[str, Any] = {
"escape_character": '"',
}

TestTargetCSV = get_target_test_class(TargetCSV, config=SAMPLE_CONFIG)
File renamed without changes.

0 comments on commit 627514c

Please sign in to comment.