From e3f3cdbd70abf024e2312b380853ecdb2e99a307 Mon Sep 17 00:00:00 2001 From: Abhishek Dasgupta Date: Sat, 18 Nov 2023 20:29:22 +0000 Subject: [PATCH] Add CI and pre-commit config --- .github/workflows/tests.yml | 37 +++++++++++++++++++++++++++++++++++++ .pre-commit-config.yaml | 15 +++++++++++++++ pyproject.toml | 5 ++++- test_infer_schema.py | 2 +- 4 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/tests.yml create mode 100644 .pre-commit-config.yaml diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..021eb5c --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,37 @@ +name: tests + +on: + push: + branches: [ main ] + paths: + - '**.py' + - '.github/workflows/tests.yml' + pull_request: + branches: [ main ] + paths: + - '**.py' + - '.github/workflows/tests.yml' + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.8"] + + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: python3 -m pip install '.[test]' + - name: Lint with ruff + run: | + python -m pip install ruff + python -m ruff check . + - name: Test with unittest + run: | + python -m unittest diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..ea2a867 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,15 @@ +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.3.0 + hooks: + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace +- repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.1.6 + hooks: + # Run the linter. + - id: ruff + args: [ --fix ] + # Run the formruatter. + - id: ruff-format diff --git a/pyproject.toml b/pyproject.toml index 3e0e151..88a6efb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,10 +16,13 @@ readme = "README.md" classifiers = ["License :: OSI Approved :: MIT License"] [project.optional-dependencies] -test = ["fastjsonschema==2.19.0"] +test = ["fastjsonschema==2.19.0", "coverage[toml]"] [project.urls] Home = "https://github.com/abhidg/infer-schema" [project.scripts] infer-schema = "infer_schema:main" + +[tool.coverage.run] +omit = ["tests/*", "test_*"] diff --git a/test_infer_schema.py b/test_infer_schema.py index 918439a..8055657 100644 --- a/test_infer_schema.py +++ b/test_infer_schema.py @@ -85,7 +85,7 @@ def validate_csv(file: str, jsonschema_file: str, explicit_nulls: bool = False) for row in reader: try: validate( - crow := casted_row( + casted_row( row, integer_columns, numeric_columns,