Skip to content

Commit

Permalink
ci: Use third-party pre-commit hooks (meltano#707)
Browse files Browse the repository at this point in the history
* ci: Use third-party pre-commit hooks

* Add readme badge

* Apply initial pre-commit changes

* Remove packages from pyproject.toml

* Drop lint job in GitLab CI
  • Loading branch information
edgarrmondragon authored Jun 17, 2022
1 parent 04fe710 commit 09beefb
Show file tree
Hide file tree
Showing 24 changed files with 101 additions and 142 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ current_version = 0.5.0
commit = True
tag = False
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<release>[a-z]+)(?P<build>\d+))?
serialize =
serialize =
{major}.{minor}.{patch}-{release}{build}
{major}.{minor}.{patch}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- { tox-env: py, python-version: "3.9", os: "ubuntu-latest" }
- { tox-env: py, python-version: "3.10", os: "ubuntu-latest" }
- { tox-env: doctest, python-version: "3.10", os: "ubuntu-latest" }
- { tox-env: lint, python-version: "3.8", os: "ubuntu-latest" }
- { tox-env: mypy, python-version: "3.8", os: "ubuntu-latest" }

steps:
- name: Check out the repository
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,3 @@ venv.bak/
.dmypy.json
dmypy.json
.DS_Store

10 changes: 0 additions & 10 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,6 @@ build_and_test:
poetry run pytest tests/cookiecutters
fi
lint:
stage: test
parallel:
matrix:
- PYTHON_VERSION: ["3.8"]
image: python:${PYTHON_VERSION}
script:
- poetry run tox -e lint


version_bump_trigger:
# This job triggers for any branches named like `release/vX.Y.Z`
# The job will automatically flush the changelog, bump version refs,
Expand Down
1 change: 0 additions & 1 deletion .gitlab/issue_templates/Feature Request.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@

## Best reasons not to build
[//]: # (Will this negatively affect any existing functionality? Do you anticipate any breaking changes versus what may already be working today? Make the counter-argument to your proposal here.)

91 changes: 62 additions & 29 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,34 +1,67 @@
ci:
autofix_prs: false
autoupdate_schedule: weekly
autoupdate_commit_msg: 'chore: pre-commit autoupdate'

repos:
- repo: local
hooks:
- id: black
name: black
entry: poetry run black
language: system
types: [python]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
hooks:
- id: check-json
- id: check-toml
exclude: |
(?x)^(
cookiecutter/.*/pyproject.toml
)$
- id: check-yaml
exclude: |
(?x)^(
cookiecutter/.*/meltano.yml
)$
- id: end-of-file-fixer
exclude: (cookiecutter/.*|docs/.*|samples/.*\.json)
- id: trailing-whitespace
exclude: |
(?x)^(
singer_sdk/helpers/_simpleeval.py|
tests/core/test_simpleeval.py
)$
- id: isort
name: isort
entry: poetry run isort
language: system
types: [python]
- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black
language_version: python3.10
exclude: |
(?x)^(
cookiecutter/.*|
singer_sdk/helpers/_simpleeval.py|
tests/core/test_simpleeval.py
)$
- id: flake8
name: flake8
entry: poetry run flake8
language: system
types: [python]
files: 'singer_sdk/.*'
- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
exclude: (cookiecutter/.*|singer_sdk/helpers/_simpleeval/.*)

- id: mypy
name: mypy
entry: poetry run mypy
language: system
types: [python]
exclude: tests/.*
- repo: https://github.com/pycqa/flake8
rev: 4.0.1
hooks:
- id: flake8
additional_dependencies:
- darglint==1.8.1
- flake8-annotations==2.9.0
- flake8-docstrings==1.6.0
files: 'singer_sdk/.*'

- id: pyupgrade
name: pyupgrade
entry: poetry run pyupgrade --py37-plus
language: system
types: [python]
- repo: https://github.com/asottile/pyupgrade
rev: v2.32.1
hooks:
- id: pyupgrade
args: [--py37-plus]
exclude: |
(?x)^(
singer_sdk/helpers/_simpleeval.py|
tests/core/test_simpleeval.py
)$
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ Optionally, you may use the expanded syntax to specify a scope in the form `<typ
- `taps` # tap SDK only
- `targets` # target SDK only
- `mappers` # mappers only
- `templates` # cookiecutters
- `templates` # cookiecutters

More advanced rules and settings can be found within the file `.github/semantic.yml`.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
[![PyPI Version](https://img.shields.io/pypi/v/singer-sdk?color=blue)](https://pypi.org/project/singer-sdk)
[![Documentation Status](https://readthedocs.org/projects/meltano-sdk/badge/?version=latest)](https://sdk.meltano.com/en/latest/?badge=latest)
[![codecov](https://codecov.io/gh/meltano/sdk/branch/main/graph/badge.svg?token=kS1zkemAgo)](https://codecov.io/gh/meltano/sdk)
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/meltano/sdk/main.svg)](https://results.pre-commit.ci/latest/github/meltano/sdk/main)

The Tap and Target SDKs are the fastest way to build custom data extractors and loaders!
Taps and targets built on the SDK are automatically compliant with the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,5 @@ meltano elt {{ cookiecutter.tap_id }} target-jsonl

### SDK Dev Guide

See the [dev guide](https://sdk.meltano.com/en/latest/dev_guide.html) for more instructions on how to use the SDK to
See the [dev guide](https://sdk.meltano.com/en/latest/dev_guide.html) for more instructions on how to use the SDK to
develop your own taps and targets.
6 changes: 3 additions & 3 deletions cookiecutter/tap-template/{{cookiecutter.tap_id}}/meltano.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
version: 1
send_anonymous_usage_stats: true
project_id: {{cookiecutter.tap_id}}
project_id: "{{cookiecutter.tap_id}}"
plugins:
extractors:
- name: {{cookiecutter.tap_id}}
namespace: {{cookiecutter.library_name}}
- name: "{{cookiecutter.tap_id}}"
namespace: "{{cookiecutter.library_name}}"
pip_url: -e .
capabilities:
- state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class {{ cookiecutter.source_name }}Connector(SQLConnector):
@staticmethod
def to_sql_type(jsonschema_type: dict) -> sqlalchemy.types.TypeEngine:
"""Returns a JSON Schema equivalent for the given SQL type.

Developers may optionally add custom logic before calling the default
implementation inherited from the base class.
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
version: 1
send_anonymous_usage_stats: true
project_id: {{cookiecutter.target_id}}
project_id: "{{cookiecutter.target_id}}"
plugins:
extractors: []
loaders:
- name: {{cookiecutter.target_id}}
namespace: {{cookiecutter.library_name}}
- name: "{{cookiecutter.target_id}}"
namespace: "{{cookiecutter.library_name}}"
pip_url: -e .
capabilities:
- state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def process_record(self, record: dict, context: dict) -> None:

def start_batch(self, context: dict) -> None:
"""Start a batch.
Developers may optionally add additional markers to the `context` dict,
which is unique to this batch.
"""
Expand Down
2 changes: 1 addition & 1 deletion docs/_templates/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
The SDK is built with love by the <a href="https://meltano.com">Meltano</a> core team and contributors, with
contributions from developers across the <a href="https://singer.io">Singer</a> open source community.

<!-- Docs built using <a href="https://www.sphinx-doc.org">Sphinx</a> and <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
<!-- Docs built using <a href="https://www.sphinx-doc.org">Sphinx</a> and <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
from <a href="https://readthedocs.org">Read the Docs</a>. -->
{% endblock %}
4 changes: 2 additions & 2 deletions docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ Most likely you should delete the project and start over.
## What are all of the Property options?

The property types are documented in the [JSON Schema builder docs](./typing).
However, if you're using an IDE such as VSCode, you should be able to set up the environment to give you autocompletion prompts or hints.
However, if you're using an IDE such as VSCode, you should be able to set up the environment to give you autocompletion prompts or hints.
Ensure your interpreter is set to poetry if you've followed the [Dev Guide](./dev_guide.md).
Checkout this [gif](https://visualstudiomagazine.com/articles/2021/04/20/~/media/ECG/visualstudiomagazine/Images/2021/04/poetry.ashx) for how to change your interpreter.

## I'm having trouble getting the base class to __init__.

Ensure you're using the `super()` method to inherit methods from the base class.
Ensure you're using the `super()` method to inherit methods from the base class.

```python
class MyStream(Stream):
Expand Down
2 changes: 1 addition & 1 deletion docs/implementation/metrics.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# [SDK Implementation Details](./index.md) - Tap Metrics

Metrics logging is specified in the
Metrics logging is specified in the
[Singer Spec](https://hub.meltano.com/singer/spec#metrics). The SDK will automatically
emit two types of metrics `record_count` and `http_request_duration`.

Expand Down
8 changes: 4 additions & 4 deletions docs/parent_streams.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ from a parent record each time the child stream is invoked.

Here is an abbreviated example from the Gitlab sample (also in this repo) which uses the
above techniques.
In this example, EpicIssuesStream is a child of EpicsStream.
In this example, EpicIssuesStream is a child of EpicsStream.

```py
class GitlabStream(RESTStream):
# Base stream definition with auth and pagination logic
# Base stream definition with auth and pagination logic
# This logic works for other base classes as well, including Stream, GraphQLStream, etc.


Expand All @@ -49,13 +49,13 @@ class EpicsStream(GitlabStream):


class EpicIssuesStream(GitlabStream):
# Note that this class inherits from the GitlabStream base class, and not from
# Note that this class inherits from the GitlabStream base class, and not from
# the EpicsStream class.

name = "epic_issues"

# EpicIssues streams should be invoked once per parent epic:
parent_stream_type = EpicsStream
parent_stream_type = EpicsStream

# Assume epics don't have `updated_at` incremented when issues are changed:
ignore_parent_replication_keys = True
Expand Down
Loading

0 comments on commit 09beefb

Please sign in to comment.