Skip to content

Commit

Permalink
Version 3.17.2
Browse files Browse the repository at this point in the history
  • Loading branch information
mborsetti committed Dec 11, 2023
1 parent e9f9672 commit b355000
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 9 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.rst
Expand Up @@ -32,6 +32,16 @@ can check out the `wish list <https://github.com/mborsetti/webchanges/blob/main/
Security, in case of vulnerabilities. [triggers a minor patch]
Internals, for changes that don't affect users. [triggers a minor patch]
Version 3.17.2
===================
2023-12-11

Fixed
-----
* Exception in error handling when ``requests`` is not installed (reported by
`yubiuser <https://github.com/yubiuser>`__ in `#66 <https://github.com/mborsetti/webchanges/issues/66>`__).


Version 3.17.1
===================
2023-12-10
Expand Down
4 changes: 2 additions & 2 deletions RELEASE.rst
@@ -1,4 +1,4 @@
Fixed
-----
* Removed dependency on ``requests`` library inadvertently left behind (reported by
`yubiuser <https://github.com/yubiuser>`__ in `#65 <https://github.com/mborsetti/webchanges/issues/65>`__).
* Exception in error handling when ``requests`` is not installed (reported by
`yubiuser <https://github.com/yubiuser>`__ in `#66 <https://github.com/mborsetti/webchanges/issues/66>`__).
2 changes: 1 addition & 1 deletion webchanges/__init__.py
Expand Up @@ -21,7 +21,7 @@
# * MINOR version when you add functionality in a backwards compatible manner, and
# * MICRO or PATCH version when you make backwards compatible bug fixes. We no longer use '0'
# If unsure on increments, use pkg_resources.parse_version to parse
__version__ = '3.17.1'
__version__ = '3.17.2'
__description__ = (
'Check web (or command output) for changes since last run and notify.\n'
'\n'
Expand Down
8 changes: 4 additions & 4 deletions webchanges/jobs.py
Expand Up @@ -970,12 +970,12 @@ def format_error(self, exception: Exception, tb: str) -> str:
:param tb: The traceback.format_exc() string.
:returns: A string to display and/or use in reports.
"""
if httpx and isinstance(
if not isinstance(httpx, str) and isinstance(
exception, (httpx.HTTPError, httpx.InvalidURL, httpx.CookieConflict, httpx.StreamError)
):
# Instead of a full traceback, just show the error
return str(exception)
elif requests and isinstance(exception, requests.exceptions.RequestException):
elif not isinstance(requests, str) and isinstance(exception, requests.exceptions.RequestException):
# Instead of a full traceback, just show the error
return str(exception)
return tb
Expand All @@ -986,7 +986,7 @@ def ignore_error(self, exception: Exception) -> bool:
:param exception: The exception.
:returns: True if the error should be ignored, False otherwise.
"""
if httpx and isinstance(exception, httpx.HTTPError):
if not isinstance(httpx, str) and isinstance(exception, httpx.HTTPError):
if self.ignore_timeout_errors and isinstance(exception, httpx.TimeoutException):
return True
if (
Expand All @@ -1007,7 +1007,7 @@ def ignore_error(self, exception: Exception) -> bool:
elif isinstance(self.ignore_http_error_codes, list):
ignored_codes = [str(s).strip().lower() for s in self.ignore_http_error_codes]
return str(status_code) in ignored_codes or f'{(status_code // 100)}xx' in ignored_codes
elif requests and isinstance(exception, requests.exceptions.RequestException):
elif not isinstance(requests, str) and isinstance(exception, requests.exceptions.RequestException):
if self.ignore_connection_errors and isinstance(exception, requests.exceptions.ConnectionError):
return True
if self.ignore_timeout_errors and isinstance(exception, requests.exceptions.Timeout):
Expand Down
16 changes: 14 additions & 2 deletions webchanges/util.py
Expand Up @@ -22,7 +22,15 @@
from types import ModuleType
from typing import Callable, Match, Optional, Union

import httpx
try:
import httpx
except ImportError as e:
httpx = e.msg # type: ignore[assignment]

try:
import h2
except ImportError:
h2 = None # type: ignore[assignment]

from webchanges import __project_name__, __version__

Expand Down Expand Up @@ -279,8 +287,12 @@ def get_new_version_number(timeout: Optional[Union[float, tuple[float, float]]]
:returns: The new version number if a newer version of project is found on PyPi, empty string otherwise, False if
error retrieving the new version number is encountered.
"""
if httpx is None:
logger.info('Cannot query PyPi for latest release: HTTPX not installed')
return ''

try:
r = httpx.get(f'https://pypi.org/pypi/{__project_name__}/json', timeout=timeout)
r = httpx.Client(http2=h2 is not None).get(f'https://pypi.org/pypi/{__project_name__}/json', timeout=timeout)
except httpx.RequestError as e:
logger.info(f'Exception when querying PyPi for latest release: {e}')
return False
Expand Down

0 comments on commit b355000

Please sign in to comment.