Skip to content

Commit

Permalink
feat: Support Python 3.12 (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon authored Dec 18, 2023
1 parent a485f7c commit e86d03a
Show file tree
Hide file tree
Showing 12 changed files with 424 additions and 327 deletions.
1 change: 0 additions & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[flake8]
docstring-convention = google
ignore = ANN101,W503,E203
max-line-length = 120
max-complexity = 10
per-file-ignores =
tests/*:ANN,D1
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ updates:
schedule:
interval: daily
time: "12:00"
timezone: "UTC"
timezone: "Etc/UTC"
reviewers: [meltano/engineering]
labels: [deps]
versioning-strategy: increase-if-necessary
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/testci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ jobs:
pytest:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
env:
PIP_CONSTRAINT: .github/workflows/constraints.txt

Expand Down
31 changes: 12 additions & 19 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/psf/black
rev: 23.12.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.8
hooks:
- id: black
- id: ruff
args: [--fix, --exit-non-zero-on-fix, --show-fixes]
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.7.1
Expand All @@ -29,22 +31,13 @@ repos:
additional_dependencies:
- types-requests

- repo: https://github.com/pycqa/isort
rev: 5.13.2
- repo: https://github.com/tox-dev/pyproject-fmt
rev: "1.5.3"
hooks:
- id: isort
- id: pyproject-fmt

- repo: https://github.com/pycqa/flake8
rev: 6.1.0
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.27.3
hooks:
- id: flake8
additional_dependencies:
- darglint==1.8.1
- flake8-annotations==2.9.0
- flake8-docstrings==1.6.0

- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
hooks:
- id: pyupgrade
args: [--py37-plus]
- id: check-dependabot
- id: check-github-workflows
20 changes: 9 additions & 11 deletions meltano.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,20 @@ plugins:
extractors:
- name: tap-smoke-test
namespace: tap_smoke_test
# TODO: To test using Meltano, replace with absolute path
# to the tap-smoke-test.sh script:
executable: ./tap-smoke-test.sh
pip_url: -e .
capabilities:
- state
- catalog
- discover
config:
start_date: '2010-01-01T00:00:00Z'
settings:
# TODO: To configure using Meltano, declare settings and their types here:
- name: username
- name: password
kind: password
- name: start_date
value: '2010-01-01T00:00:00Z'
- name: streams
kind: array
- name: schema_inference_record_count
kind: integer
- name: client_exception
kind: boolean
- name: schema_gen_exception
kind: boolean
loaders:
- name: target-jsonl
variant: andyh1203
Expand Down
602 changes: 349 additions & 253 deletions poetry.lock

Large diffs are not rendered by default.

41 changes: 39 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ maintainers = ["Meltano team and contributors <[email protected]>"]
license = "Apache-2.0"

[tool.poetry.dependencies]
python = ">=3.8.1,<3.12"
python = ">=3.8.1"
requests = "~=2.31"
singer-sdk = "~=0.34.0"
genson = "~=1.2"
Expand All @@ -17,9 +17,46 @@ pytest = "~=7.4"
singer-sdk = { version = "~=0.34.0", extras = ["testing"] }

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
requires = [
"poetry-core>=1",
]

[tool.poetry.scripts]
# CLI declaration
tap-smoke-test = 'tap_smoke_test.tap:TapSmokeTest.cli'

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

[tool.ruff.lint]
ignore = [
"ANN101"
]
select = [
"ANN",
"D",
"I",
"UP",
]

[tool.ruff.lint.flake8-annotations]
allow-star-arg-any = true
mypy-init-return = true
suppress-dummy-args = true

[tool.ruff.lint.flake8-import-conventions]
banned-from = ["typing"]

[tool.ruff.lint.flake8-import-conventions.extend-aliases]
typing = "t"

[tool.ruff.lint.isort]
required-imports = ["from __future__ import annotations"]

[tool.ruff.lint.per-file-ignores]
"tests/*" = ["ANN", "D1"]

[tool.ruff.pydocstyle]
convention = "google"
14 changes: 0 additions & 14 deletions tap-smoke-test.sh

This file was deleted.

5 changes: 1 addition & 4 deletions tap_smoke_test/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,4 @@ def read(self) -> Generator[str, None, None]:
if r.ok:
yield from r.iter_lines()
else:
raise Exception(
f"Fetch of remote payload failed. status: [{r.status_code}], "
f"reason: [{r.reason}]"
)
raise Exception(f"Fetch of remote payload failed. status: [{r.status_code}], " f"reason: [{r.reason}]")
4 changes: 1 addition & 3 deletions tap_smoke_test/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ def schema(self) -> dict:
builder = SchemaBuilder()
for count, entry in enumerate(self.reader.read()):
if count > self.config["schema_inference_record_count"]:
logging.info(
"%s stream max schema_inference_record_count hit" % self.name
)
logging.info("%s stream max schema_inference_record_count hit" % self.name)
break
record = json.loads(entry)
builder.add_object(record)
Expand Down
18 changes: 6 additions & 12 deletions tap_smoke_test/tap.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""SmokeTest tap class."""
from __future__ import annotations

from typing import List

Expand All @@ -18,8 +19,7 @@ class TapSmokeTest(Tap):
th.IntegerType,
default=5,
required=False,
description="How many records of the source data "
"should be used for schema inference/construction.",
description="How many records of the source data " "should be used for schema inference/construction.",
),
th.Property(
"streams",
Expand All @@ -34,18 +34,14 @@ class TapSmokeTest(Tap):
"input_filename",
th.StringType,
required=True,
description="Path to a jsonl file containing"
"records to use for mock data.",
description="Path to a jsonl file containing" "records to use for mock data.",
),
th.Property(
"client_exception",
th.BooleanType,
required=False,
default=False,
description=(
"Whether we should simulate failing by having the client "
"raise an exception."
),
description=("Whether we should simulate failing by having the client " "raise an exception."),
),
th.Property(
"schema_gen_exception",
Expand All @@ -60,17 +56,15 @@ class TapSmokeTest(Tap):
th.IntegerType,
required=False,
default=1,
description=(
"The number of times we should playback the input file."
),
description=("The number of times we should playback the input file."),
),
)
),
required=True,
),
).to_dict()

def discover_streams(self) -> List[Stream]:
def discover_streams(self) -> list[Stream]:
"""Return a list of discovered streams.
Returns:
Expand Down
10 changes: 4 additions & 6 deletions tests/test_core.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Tests standard tap features using the built-in SDK tests library."""
from __future__ import annotations

import re
from os import path
from unittest import mock
Expand Down Expand Up @@ -37,9 +39,7 @@ def test_schema_gen_exception():
]
}

with pytest.raises(
Exception, match="Smoke test schema call failing with exception"
):
with pytest.raises(Exception, match="Smoke test schema call failing with exception"):
TapSmokeTest(config=config, parse_env_config=False)


Expand Down Expand Up @@ -113,8 +113,6 @@ def test_remote_file_non_2xx(self, mock_get):
mock_resp = self._mock_response(content="Not found", status=404)
mock_get.return_value = mock_resp

pattern = re.escape(
"Fetch of remote payload failed. status: [404], reason: [Not found]"
)
pattern = re.escape("Fetch of remote payload failed. status: [404], reason: [Not found]")
with pytest.raises(Exception, match=pattern):
_ = TapSmokeTest(config=config, parse_env_config=False)

0 comments on commit e86d03a

Please sign in to comment.