Skip to content

Commit

Permalink
Merge pull request #76 from zytedata/modernize
Browse files Browse the repository at this point in the history
Add Python 3.12 and 3.13, drop Python 3.8, update tool versions
  • Loading branch information
wRAR authored Oct 16, 2024
2 parents b25fb2b + b95d703 commit 1dcb8e0
Show file tree
Hide file tree
Showing 16 changed files with 51 additions and 54 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: '3.x'
python-version: '3.13'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11']
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand All @@ -42,13 +42,13 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['3.11']
python-version: ['3.12'] # Keep in sync with .readthedocs.yml
tox-job: ["mypy", "docs"]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand Down
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
repos:
- repo: https://github.com/PyCQA/isort
rev: 5.13.1
rev: 5.13.2
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 24.3.0
rev: 24.10.0
hooks:
- id: black
- repo: https://github.com/pycqa/flake8
rev: 7.0.0
rev: 7.1.1
hooks:
- id: flake8
- repo: https://github.com/adamchainz/blacken-docs
rev: 1.16.0
rev: 1.19.0
hooks:
- id: blacken-docs
additional_dependencies:
- black==24.3.0
- black==24.10.0
2 changes: 1 addition & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ build:
tools:
# For available versions, see:
# https://docs.readthedocs.io/en/stable/config-file/v2.html#build-tools-python
python: "3.11" # Keep in sync with .github/workflows/test.yml
python: "3.12" # Keep in sync with .github/workflows/test.yml
python:
install:
- requirements: docs/requirements.txt
Expand Down
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Changes
------------------

* Improved how the :ref:`default retry policy <default-retry-policy>` handles
:ref:`temporary download errors <zyte-api-temporary-download-errors>`.
:ref:`temporary download errors <zapi-temporary-download-errors>`.
Before, 3 HTTP 429 responses followed by a single HTTP 520 response would
have prevented a retry. Now, unrelated responses and errors do not count
towards the HTTP 520 retry limit.
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Installation
pip install zyte-api
.. note:: Python 3.8+ is required.
.. note:: Python 3.9+ is required.

.. install-end
Expand Down
9 changes: 1 addition & 8 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
import sys
from pathlib import Path

import sphinx_rtd_theme

sys.path.insert(0, os.path.abspath("../"))


Expand Down Expand Up @@ -58,7 +56,7 @@
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = ".rst"
source_suffix = {".rst": "restructuredtext"}

# The master toctree document.
master_doc = "index"
Expand Down Expand Up @@ -86,11 +84,6 @@
#
html_theme = "sphinx_rtd_theme"

# Add any paths that contain custom themes here, relative to this directory.
# Add path to the RTD explicitly to robustify builds (otherwise might
# fail in a clean Debian build env)
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
Expand Down
14 changes: 7 additions & 7 deletions docs/use/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -134,40 +134,40 @@ The number of concurrent connections if enforced across all method calls,
including different sessions of the same client.

For guidelines on how to choose the optimal value for you, and other
optimization tips, see :ref:`zyte-api-optimize`.
optimization tips, see :ref:`zapi-optimize`.


Errors and retries
==================

Methods of :class:`ZyteAPI` and :class:`AsyncZyteAPI` automatically handle
retries for :ref:`rate-limiting <zyte-api-rate-limit>` and :ref:`unsuccessful
<zyte-api-unsuccessful-responses>` responses, as well as network errors.
retries for :ref:`rate-limiting <zapi-rate-limit>` and :ref:`unsuccessful
<zapi-unsuccessful-responses>` responses, as well as network errors.

.. _retry-policy:
.. _default-retry-policy:

The default retry policy, :data:`~zyte_api.zyte_api_retrying`, does the
following:

- Retries :ref:`rate-limiting responses <zyte-api-rate-limit>` forever.
- Retries :ref:`rate-limiting responses <zapi-rate-limit>` forever.

- Retries :ref:`temporary download errors
<zyte-api-temporary-download-errors>` up to 3 times.
<zapi-temporary-download-errors>` up to 3 times.

- Retries network errors until they have happened for 15 minutes straight.

All retries are done with an exponential backoff algorithm.

.. _aggressive-retry-policy:

If some :ref:`unsuccessful responses <zyte-api-unsuccessful-responses>` exceed
If some :ref:`unsuccessful responses <zapi-unsuccessful-responses>` exceed
maximum retries with the default retry policy, try using
:data:`~zyte_api.aggressive_retrying` instead, which modifies the default retry
policy as follows:

- Temporary download error are retried 7 times. :ref:`Permanent download
errors <zyte-api-permanent-download-errors>` also count towards this retry
errors <zapi-permanent-download-errors>` also count towards this retry
limit.

- Retries permanent download errors up to 3 times.
Expand Down
10 changes: 5 additions & 5 deletions docs/use/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ The input file can be either of the following:
:http:`request:browserHtml` set to ``True``.

- A `JSON Lines <https://jsonlines.org/>`_ file with a object of :ref:`Zyte
API request parameters <zyte-api-reference>` per line. For example:
API request parameters <zapi-reference>` per line. For example:

.. code-block:: json
Expand Down Expand Up @@ -84,19 +84,19 @@ order and hence distribute the load somewhat evenly:
zyte-api urls.txt --shuffle …
For guidelines on how to choose the optimal ``--n-conn`` value for you, and
other optimization tips, see :ref:`zyte-api-optimize`.
other optimization tips, see :ref:`zapi-optimize`.


Errors and retries
==================

``zyte-api`` automatically handles retries for :ref:`rate-limiting
<zyte-api-rate-limit>` and :ref:`unsuccessful
<zyte-api-unsuccessful-responses>` responses, as well as network errors,
<zapi-rate-limit>` and :ref:`unsuccessful
<zapi-unsuccessful-responses>` responses, as well as network errors,
following the :ref:`default retry policy <default-retry-policy>`.

Use ``--dont-retry-errors`` to disable the retrying of error responses, and
retrying only :ref:`rate-limiting responses <zyte-api-rate-limit>`:
retrying only :ref:`rate-limiting responses <zapi-rate-limit>`:

.. code-block:: shell
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ profile = "black"
multi_line_output = 3

[tool.black]
target-version = ["py38", "py39", "py310", "py311", "py312"]
target-version = ["py39", "py310", "py311", "py312", "py313"]
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python
import os

from setuptools import find_packages, setup
Expand Down Expand Up @@ -41,9 +40,10 @@ def get_version():
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
],
)
7 changes: 4 additions & 3 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,10 @@ async def test_run(queries, expected_response, store_errors, exception):
async_client_mock.return_value.iter = request_parallel_mock

# Patch the AsyncZyteAPI class in __main__ with the mock
with patch("zyte_api.__main__.AsyncZyteAPI", async_client_mock), patch(
"zyte_api.__main__.create_session"
) as create_session_mock:
with (
patch("zyte_api.__main__.AsyncZyteAPI", async_client_mock),
patch("zyte_api.__main__.create_session") as create_session_mock,
):
# Mock create_session to return an AsyncMock
create_session_mock.return_value = AsyncMock()

Expand Down
15 changes: 9 additions & 6 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py38,py39,py310,py311,mypy,docs,twine
envlist = py39,py310,py311,py312,py313,mypy,docs,twine

[testenv]
deps =
Expand All @@ -19,9 +19,12 @@ commands =

[testenv:mypy]
deps =
mypy==0.982
mypy==1.12.0
pytest==8.3.3
Twisted==24.7.0
types-tqdm==4.66.0.20240417

commands = mypy --ignore-missing-imports --no-warn-no-return \
commands = mypy --ignore-missing-imports \
zyte_api \
tests

Expand All @@ -39,8 +42,8 @@ commands = pre-commit run --all-files --show-diff-on-failure

[testenv:twine]
deps =
twine==4.0.2
build==1.0.3
twine==5.1.1
build==1.2.2
commands =
python setup.py sdist
python -m build --sdist
twine check dist/*
4 changes: 2 additions & 2 deletions zyte_api/_async.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import asyncio
import time
from asyncio import Future
Expand All @@ -17,8 +19,6 @@

if TYPE_CHECKING:
_ResponseFuture = Future[Dict[str, Any]]
else:
_ResponseFuture = Future # Python 3.8 support


def _post_func(session):
Expand Down
4 changes: 2 additions & 2 deletions zyte_api/_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

class RequestError(ClientResponseError):
"""Exception raised upon receiving a :ref:`rate-limiting
<zyte-api-rate-limit>` or :ref:`unsuccessful
<zyte-api-unsuccessful-responses>` response from Zyte API."""
<zapi-rate-limit>` or :ref:`unsuccessful
<zapi-unsuccessful-responses>` response from Zyte API."""

def __init__(self, *args, **kwargs):
#: Query sent to Zyte API.
Expand Down
2 changes: 1 addition & 1 deletion zyte_api/_retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class RetryFactory:
the corresponding :class:`tenacity.AsyncRetrying` object.
For example, to double the number of attempts for :ref:`temporary
download errors <zyte-api-temporary-download-errors>` and the time network
download errors <zapi-temporary-download-errors>` and the time network
errors are retried:
.. code-block:: python
Expand Down

0 comments on commit 1dcb8e0

Please sign in to comment.