Skip to content

Commit 5f657e0

Browse files
Merge pull request #20 from phillipdupuis/cicd-tweaks
CICD updates for linting with black, code coverage, and cleaning up naming conventions
2 parents 5ce0534 + 357a38f commit 5f657e0

File tree

6 files changed

+50
-24
lines changed

6 files changed

+50
-24
lines changed

.coveragerc

Whitespace-only changes.

.github/workflows/tests.yml renamed to .github/workflows/cicd.yml

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
name: "Tests"
2-
1+
name: CI/CD
32
on:
43
push:
54
pull_request:
6-
75
jobs:
6+
lint:
7+
name: Lint code with black
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v2
11+
- uses: psf/black@stable
812
test:
9-
name: Test pyglotaran stable
13+
name: Run unit tests
14+
needs: lint
1015
runs-on: ${{ matrix.os }}
1116
strategy:
1217
matrix:
@@ -21,7 +26,6 @@ jobs:
2126
python-version: "3.9"
2227
- os: ubuntu-latest
2328
python-version: "3.10"
24-
2529
steps:
2630
- name: Check out repo
2731
uses: actions/checkout@v3
@@ -38,12 +42,21 @@ jobs:
3842
npm i -g json-schema-to-typescript
3943
- name: Install python dependencies
4044
run: |
41-
python -m pip install -U pip wheel pytest pytest-cov
45+
python -m pip install -U pip wheel pytest pytest-cov coverage
4246
python -m pip install -U .
4347
- name: Run tests
4448
run: |
4549
python -m pytest --cov=pydantic2ts
46-
50+
- name: Generate LCOV File
51+
if: ${{ matrix.os == 'ubuntu-latest' && matrix.python-version == '3.8' }}
52+
run: |
53+
coverage lcov
54+
- name: Coveralls
55+
if: ${{ matrix.os == 'ubuntu-latest' && matrix.python-version == '3.8' }}
56+
uses: coverallsapp/github-action@master
57+
with:
58+
github-token: ${{ secrets.GITHUB_TOKEN }}
59+
path-to-lcov: coverage.lcov
4760
deploy:
4861
name: Deploy to PyPi
4962
runs-on: ubuntu-latest
@@ -61,9 +74,8 @@ jobs:
6174
- name: Build dist
6275
run: |
6376
python setup.py sdist bdist_wheel
64-
6577
- name: Publish package
6678
uses: pypa/gh-action-pypi-publish@v1.5.0
6779
with:
6880
user: __token__
69-
password: ${{ secrets.pypi_password }}
81+
password: ${{ secrets.pypi_password }}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
[![PyPI version](https://badge.fury.io/py/pydantic-to-typescript.svg)](https://badge.fury.io/py/pydantic-to-typescript)
44
[![Tests](https://github.com/phillipdupuis/pydantic-to-typescript/actions/workflows/tests.yml/badge.svg)](https://github.com/phillipdupuis/pydantic-to-typescript/actions/workflows/tests.yml)
5+
[![Coverage Status](https://coveralls.io/repos/github/phillipdupuis/pydantic-to-typescript/badge.svg?branch=master)](https://coveralls.io/github/phillipdupuis/pydantic-to-typescript?branch=master)
56

67
A simple CLI tool for converting pydantic models into typescript interfaces. Useful for any scenario in which python and javascript applications are interacting, since it allows you to have a single source of truth for type definitions.
78

pydantic2ts/cli/script.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ def remove_master_model_from_output(output: str) -> None:
116116
]
117117

118118
new_lines = banner_comment_lines + lines[:start] + lines[(end + 1) :]
119+
119120
with open(output, "w") as f:
120121
f.writelines(new_lines)
121122

@@ -209,9 +210,7 @@ def generate_typescript_defs(
209210

210211
logger.info("Converting JSON schema to typescript definitions...")
211212

212-
os.system(
213-
f'{json2ts_cmd} -i {schema_file_path} -o {output} --bannerComment ""'
214-
)
213+
os.system(f'{json2ts_cmd} -i {schema_file_path} -o {output} --bannerComment ""')
215214
shutil.rmtree(schema_dir)
216215
remove_master_model_from_output(output)
217216

setup.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,11 @@ def readme():
3535
author="Phillip Dupuis",
3636
author_email="phillip_dupuis@alumni.brown.edu",
3737
url="https://github.com/phillipdupuis/pydantic-to-typescript",
38-
packages=find_packages(),
38+
packages=find_packages(exclude=["tests*"]),
3939
install_requires=install_requires,
40+
extras_require={
41+
"dev": ["pytest", "pytest-cov", "coverage"],
42+
},
4043
entry_points={"console_scripts": ["pydantic2ts = pydantic2ts.cli.script:main"]},
4144
classifiers=classifiers,
4245
)

tests/test_script.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import sys
33
import subprocess
4+
import pytest
45
from pydantic2ts import generate_typescript_defs
56

67

@@ -25,13 +26,6 @@ def run_test(
2526
Execute pydantic2ts logic for converting pydantic models into tyepscript definitions.
2627
Compare the output with the expected output, verifying it is identical.
2728
"""
28-
# Literal was only introduced in python 3.8 (Ref.: PEP 586) so tests break
29-
if sys.version_info < (3, 8) and test_name == "submodules":
30-
return
31-
# GenericModel is only supported for python>=3.7
32-
# (Ref.: https://pydantic-docs.helpmanual.io/usage/models/#generic-models)
33-
if sys.version_info < (3, 7) and test_name == "generics":
34-
return
3529
module_path = module_path or get_input_module(test_name)
3630
output_path = tmpdir.join(f"cli_{test_name}.ts").strpath
3731

@@ -52,10 +46,21 @@ def test_single_module(tmpdir):
5246
run_test(tmpdir, "single_module")
5347

5448

49+
@pytest.mark.skipif(
50+
sys.version_info < (3, 8),
51+
reason="Literal requires python 3.8 or higher (Ref.: PEP 586)",
52+
)
5553
def test_submodules(tmpdir):
5654
run_test(tmpdir, "submodules")
5755

5856

57+
@pytest.mark.skipif(
58+
sys.version_info < (3, 7),
59+
reason=(
60+
"GenericModel is only supported for python>=3.7 "
61+
"(Ref.: https://pydantic-docs.helpmanual.io/usage/models/#generic-models)"
62+
),
63+
)
5964
def test_generics(tmpdir):
6065
run_test(tmpdir, "generics")
6166

@@ -68,16 +73,22 @@ def test_excluding_models(tmpdir):
6873

6974
def test_relative_filepath(tmpdir):
7075
test_name = "single_module"
71-
relative_path = os.path.join(".", "tests", "expected_results", test_name, "input.py")
76+
relative_path = os.path.join(
77+
".", "tests", "expected_results", test_name, "input.py"
78+
)
7279
run_test(
73-
tmpdir, "single_module", module_path=relative_path,
80+
tmpdir,
81+
"single_module",
82+
module_path=relative_path,
7483
)
7584

7685

7786
def test_calling_from_python(tmpdir):
7887
run_test(tmpdir, "single_module", call_from_python=True)
79-
run_test(tmpdir, "submodules", call_from_python=True)
80-
run_test(tmpdir, "generics", call_from_python=True)
88+
if sys.version_info >= (3, 8):
89+
run_test(tmpdir, "submodules", call_from_python=True)
90+
if sys.version_info >= (3, 7):
91+
run_test(tmpdir, "generics", call_from_python=True)
8192
run_test(
8293
tmpdir,
8394
"excluding_models",

0 commit comments

Comments
 (0)