diff --git a/.github/workflows/build-badge.yml b/.github/workflows/build-badge.yml index 403c0db..2c3ec2a 100644 --- a/.github/workflows/build-badge.yml +++ b/.github/workflows/build-badge.yml @@ -2,7 +2,9 @@ name: build on: schedule: - cron: '5 0 * * *' - workflow_dispatch: + push: + branches: + - main jobs: build: diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index 879f093..f890c28 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -27,3 +27,29 @@ jobs: run: | python -m build twine upload dist/* + badge: + needs: deploy + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.11", "3.10", "3.9"] + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + - name: Install ghostscript + run: | + sudo apt-get update + sudo apt-get install ghostscript + - name : Install from PyPI and run tests + run: | + mkdir $HOME/test_external_dir + cd $HOME/test_external_dir + cp $GITHUB_WORKSPACE/tests/ . -r + python -m venv venv + source venv/bin/activate + pip install hotpdf pytest pytest-xdist + python -m pytest tests -n=auto diff --git a/.github/workflows/release-badge.yml b/.github/workflows/release-badge.yml deleted file mode 100644 index eb6ae92..0000000 --- a/.github/workflows/release-badge.yml +++ /dev/null @@ -1,32 +0,0 @@ -name: latest -on: - schedule: - - cron: '5 0 * * *' - workflow_dispatch: - -jobs: - build: - runs-on: ubuntu-latest - strategy: - matrix: - python-version: [3.11, 3.10, 3.9] - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 - with: - python-version: '${{ matrix.python-version }}' - - name: Install ghostscript - run: | - sudo apt-get update - sudo apt-get install ghostscript - - name : Install from PyPI and run tests - run: | - mkdir $HOME/test_external_dir - cd $HOME/test_external_dir - cp $GITHUB_WORKSPACE/tests/ . -r - python -m venv venv - source venv/bin/activate - pip install hotpdf pytest pytest-xdist - python -m pytest tests -n=auto diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3e1a804..685ca35 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -38,6 +38,7 @@ jobs: run: python -m mypy tests: + needs: linter strategy: matrix: python-version: ["3.11", "3.10", "3.9"] diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6a207f8..0e255a9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,33 +1,24 @@ repos: - - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 - hooks: - - id: check-yaml - - id: end-of-file-fixer - - id: trailing-whitespace - - repo: local - hooks: - - id: ruff-format - name: ruff format - entry: ruff format . - language: system - always_run: true - pass_filenames: false - - id: ruff-format-imports - name: ruff format imports - entry: ruff check --select I --fix . - language: system - always_run: true - pass_filenames: false - - id: ruff-lint - name: ruff lint - entry: ruff check . - language: system - always_run: true - pass_filenames: false - - id: mypy - name: mypy - entry: mypy - language: system - always_run: true - pass_filenames: false + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace + - repo: local + hooks: + - id: ruff-format + name: ruff format + entry: ruff format + language: system + pass_filenames: false + - id: ruff-lint + name: ruff lint + entry: ruff check + language: system + pass_filenames: false + - id: mypy + name: mypy + entry: mypy + language: system + pass_filenames: false diff --git a/README.md b/README.md index 8ca1999..89fd38e 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # hotpdf [![Documentation Status](https://readthedocs.org/projects/hotpdf/badge/?version=latest)](https://hotpdf.readthedocs.io/en/latest/?badge=latest) -[![latest](https://github.com/weareprestatech/hotpdf/actions/workflows/release-badge.yml/badge.svg)](https://github.com/weareprestatech/hotpdf/actions/workflows/release-badge.yml) +[![latest](https://github.com/weareprestatech/hotpdf/actions/workflows/python-publish.yml/badge.svg)](https://github.com/weareprestatech/hotpdf/actions/workflows/python-publish.yml) [![build](https://github.com/weareprestatech/hotpdf/actions/workflows/build-badge.yml/badge.svg)](https://github.com/weareprestatech/hotpdf/actions/workflows/build-badge.yml) [![Coverage Status](https://coveralls.io/repos/github/weareprestatech/hotpdf/badge.svg?branch=main)](https://coveralls.io/github/weareprestatech/hotpdf?branch=main) diff --git a/pyproject.toml b/pyproject.toml index 1f157ce..a26927e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,6 +17,8 @@ requires-python = ">=3.9" classifiers = [ "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.9", "Development Status :: 4 - Beta", "Intended Audience :: Developers", "Topic :: Software Development :: Libraries :: Python Modules", @@ -72,6 +74,7 @@ fixable = ["ALL"] exclude = ["docs"] preview = true line-length = 150 +extend-select = ["I"] [tool.mypy] warn_unused_configs = true diff --git a/tests/test_load.py b/tests/test_load.py index 900e3bd..e4ab176 100644 --- a/tests/test_load.py +++ b/tests/test_load.py @@ -195,19 +195,20 @@ def test_get_spans(valid_file_name): occurences_by_page = occurences[page_num] for occurence_by_page in occurences_by_page: element_dimension = get_element_dimension(occurence_by_page) - full_spans_in_bbox = hot_pdf_object.extract_spans( - x0=element_dimension.x0, - y0=element_dimension.y0, - x1=element_dimension.x1, - y1=element_dimension.y1, - ) - __full_spans_in_bbox_unsorted = hot_pdf_object.extract_spans( - x0=element_dimension.x0, - y0=element_dimension.y0, - x1=element_dimension.x1, - y1=element_dimension.y1 + 100, # to simulate multi line extraction - sort=False, - ) + with pytest.warns(UserWarning, match="This function will be deprecated in the next release"): + full_spans_in_bbox = hot_pdf_object.extract_spans( + x0=element_dimension.x0, + y0=element_dimension.y0, + x1=element_dimension.x1, + y1=element_dimension.y1, + ) + __full_spans_in_bbox_unsorted = hot_pdf_object.extract_spans( + x0=element_dimension.x0, + y0=element_dimension.y0, + x1=element_dimension.x1, + y1=element_dimension.y1 + 100, # to simulate multi line extraction + sort=False, + ) assert len(full_spans_in_bbox) == 1 assert len(__full_spans_in_bbox_unsorted) > 1 assert full_spans_in_bbox[0] in __full_spans_in_bbox_unsorted @@ -254,7 +255,7 @@ def test_extract_page_range_exception(multiple_pages_file_name, first_page, last def test_no_spans_in_xml_file_extraction(valid_file_name): hot_pdf_object = HotPdf() - with patch.object(MemoryMap, "_MemoryMap__get_page_spans") as get_page_spans: + with patch.object(MemoryMap, "_MemoryMap__get_page_spans") as get_page_spans, pytest.warns(UserWarning, match="No spans exist on this page"): get_page_spans.return_value = None hot_pdf_object.load(valid_file_name) get_page_spans.assert_called_once() @@ -283,7 +284,7 @@ def test_no_spans_in_xml_file_extraction(valid_file_name): def test_no_spans_in_xml_file_extract_spans(valid_file_name): hot_pdf_object = HotPdf() - with patch.object(MemoryMap, "_MemoryMap__get_page_spans") as get_page_spans: + with patch.object(MemoryMap, "_MemoryMap__get_page_spans") as get_page_spans, pytest.warns(UserWarning, match="No spans exist on this page"): hot_pdf_object.load(valid_file_name) get_page_spans.return_value = None # Test No spans