From 42e586bd62a2fd23b78fd2526e5a6862ab24d582 Mon Sep 17 00:00:00 2001 From: antazoey Date: Thu, 14 Mar 2024 15:53:23 -0600 Subject: [PATCH] fix: issue with empty file sources (#117) --- .github/workflows/commitlint.yaml | 4 ++-- .github/workflows/docs.yaml | 6 +++--- .github/workflows/prtitle.yaml | 4 ++-- .github/workflows/publish.yaml | 4 ++-- .github/workflows/test.yaml | 16 ++++++++-------- .pre-commit-config.yaml | 6 +++--- ethpm_types/abi.py | 3 +-- ethpm_types/source.py | 2 +- setup.cfg | 1 + setup.py | 14 +++++++------- tests/test_package_manifest.py | 4 ++++ tests/test_source.py | 11 +++++++++++ 12 files changed, 45 insertions(+), 30 deletions(-) diff --git a/.github/workflows/commitlint.yaml b/.github/workflows/commitlint.yaml index 8aa92e1..1abdef9 100644 --- a/.github/workflows/commitlint.yaml +++ b/.github/workflows/commitlint.yaml @@ -9,12 +9,12 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 - name: Setup Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: "3.10" diff --git a/.github/workflows/docs.yaml b/.github/workflows/docs.yaml index 90912a8..fb52e33 100644 --- a/.github/workflows/docs.yaml +++ b/.github/workflows/docs.yaml @@ -13,10 +13,10 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: "3.10" @@ -29,7 +29,7 @@ jobs: run: python build_docs.py - name: Upload HTML artifact - uses: actions/upload-artifact@v1 + uses: actions/upload-artifact@v4 with: name: DocumentationHTML path: docs/_build/ethpm-types diff --git a/.github/workflows/prtitle.yaml b/.github/workflows/prtitle.yaml index 42b40d1..cdab9c1 100644 --- a/.github/workflows/prtitle.yaml +++ b/.github/workflows/prtitle.yaml @@ -12,10 +12,10 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: "3.10" diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 2c88013..081d138 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -10,10 +10,10 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: "3.10" diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 724df14..eaf704b 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -17,10 +17,10 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: "3.10" @@ -42,10 +42,10 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: "3.10" @@ -66,10 +66,10 @@ jobs: python-version: [3.8, 3.9, "3.10"] # eventually add 3.11 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} @@ -89,10 +89,10 @@ jobs: # fail-fast: true # # steps: -# - uses: actions/checkout@v3 +# - uses: actions/checkout@v4 # # - name: Setup Python -# uses: actions/setup-python@v4 +# uses: actions/setup-python@v5 # with: # python-version: "3.10" # diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 46081d4..55fcde6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,18 +10,18 @@ repos: - id: isort - repo: https://github.com/psf/black - rev: 23.11.0 + rev: 24.2.0 hooks: - id: black name: black - repo: https://github.com/pycqa/flake8 - rev: 6.1.0 + rev: 7.0.0 hooks: - id: flake8 - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.7.1 + rev: v1.9.0 hooks: - id: mypy additional_dependencies: [types-requests, types-setuptools, pydantic] diff --git a/ethpm_types/abi.py b/ethpm_types/abi.py index 0d2c9ba..4b61794 100644 --- a/ethpm_types/abi.py +++ b/ethpm_types/abi.py @@ -93,8 +93,7 @@ def signature(self) -> str: return sig -class BaseABI(BaseModel): - ... +class BaseABI(BaseModel): ... class ConstructorABI(BaseABI): diff --git a/ethpm_types/source.py b/ethpm_types/source.py index ebd668d..06787fc 100644 --- a/ethpm_types/source.py +++ b/ethpm_types/source.py @@ -232,7 +232,7 @@ def validate_model(cls, model): content_result = ( {"content": Content(root={i + 1: x for i, x in enumerate(content.splitlines())})} - if content + if content is not None else model ) return {**content_result, **other_props} diff --git a/setup.cfg b/setup.cfg index 1a237e9..4399e48 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,6 @@ [flake8] max-line-length = 100 +extend-ignore = E203,E701 exclude = venv* .eggs diff --git a/setup.py b/setup.py index a710217..b79bafc 100644 --- a/setup.py +++ b/setup.py @@ -17,11 +17,11 @@ "hypothesis-jsonschema==0.19.0", # Fuzzes based on a json schema ], "lint": [ - "black>=23.11.0,<24", # Auto-formatter and linter - "mypy>=1.7.1,<2", # Static type analyzer + "black>=24.2.0,<25", # Auto-formatter and linter + "mypy>=1.9.0,<2", # Static type analyzer "types-setuptools", # Needed for mypy type shed "types-requests", # Needed for mypy type shed - "flake8>=6.1.0,<7", # Style linter + "flake8>=7.0.0,<8", # Style linter "flake8-breakpoint>=1.1.0,<2", # Detect breakpoints left in code "flake8-print>=5.0.0,<6", # Detect print statements left in code "isort>=5.10.1,<6", # Import sorting linter @@ -31,10 +31,10 @@ "mdformat-pyproject>=0.0.1", # Allows configuring in pyproject.toml ], "doc": [ - "myst-parser>=0.17.0,<0.18", # Tools for parsing markdown files in the docs - "sphinx-click>=3.1.0,<4.0", # For documenting CLI - "Sphinx>=4.4.0,<5.0", # Documentation generator - "sphinx_rtd_theme>=1.0.0,<2", # Readthedocs.org theme + "myst-parser>=1.0.0,<2", # Parse markdown docs + "sphinx-click>=4.4.0,<5", # For documenting CLI + "Sphinx>=6.1.3,<7", # Documentation generator + "sphinx_rtd_theme>=1.2.0,<2", # Readthedocs.org theme "sphinxcontrib-napoleon>=0.7", # Allow Google-style documentation ], "release": [ # `release` GitHub Action job uses this diff --git a/tests/test_package_manifest.py b/tests/test_package_manifest.py index b1920d0..9d2825e 100644 --- a/tests/test_package_manifest.py +++ b/tests/test_package_manifest.py @@ -241,6 +241,10 @@ def test_contract_types(): manifest = PackageManifest(contractTypes=contract_types) assert manifest.contract_types == contract_types + # Show we can also set them. + manifest.contract_types = {} + assert manifest.contract_types == {} + def test_validate_fields(package_manifest): """ diff --git a/tests/test_source.py b/tests/test_source.py index d9d6a7c..2b65734 100644 --- a/tests/test_source.py +++ b/tests/test_source.py @@ -316,3 +316,14 @@ def test_references(): """ source = Source(content="foo\n", references=["bar.txt"]) assert source.references == ["bar.txt"] + + +def test_model_validate_empty_str(): + """ + There was a bug where if a file was empty, + it would try to use the empty str as a + dict to create the source content, due to an improper + truthy check. + """ + source = Source.model_validate("") + assert isinstance(source, Source)