Skip to content

Commit d7d9ec6

Browse files
committed
Merge branch 'main' into develop
2 parents f761f83 + a1ee2e8 commit d7d9ec6

File tree

8 files changed

+60
-30
lines changed

8 files changed

+60
-30
lines changed

CHANGES.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,28 @@
11
# Change log for CommonPy
22

3+
## Version 1.12.4
4+
5+
Changes in this release:
6+
* Revise the retry algorithm in `timed_request()` again.
7+
* Make `timed_request()` print the response text in case of failures
8+
* Remove `extra_requires` from `setup.py` because it caused installation problems due to the syntax of the requirements file and I don't have patience for figuring out what `setuptools` needs this time.
9+
10+
11+
## Version 1.12.3
12+
13+
This release updates the version of the `dateparser` package in `requirements.txt`, to avoid a deprecation warning when using CommonPy's `parsed_datetime(...)` function.
14+
15+
16+
## Version 1.12.2
17+
18+
This release updates the versions of dependencies in `requirements.txt`.
19+
20+
21+
## Version 1.12.1
22+
23+
This version prevents certain exceptions from being buried and ignored, and improves the network failure retry algorithm.
24+
25+
326
## Version 1.12.0
427

528
Additions in this release:

CITATION.cff

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ cff-version: "1.1.0"
1010
message: "If you use this software, please cite it using these metadata."
1111
repository-code: "https://github.com/caltechlibrary/commonpy"
1212
title: "CommonPy: assortment of Python helper functions and utility classes"
13-
date-released: 2023-03-24
14-
version: "1.12.0"
13+
date-released: 2023-04-21
14+
version: "1.12.4"
1515
doi: 10.22002/20217
1616
keywords:
1717
- Python

codemeta.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"codeRepository": "https://github.com/caltechlibrary/commonpy",
77
"issueTracker": "https://github.com/caltechlibrary/commonpy/issues",
88
"license": "https://github.com/caltechlibrary/commonpy/blob/master/LICENSE",
9-
"version": "1.12.0",
9+
"version": "1.12.4",
1010
"author": [
1111
{
1212
"@type": "Person",

commonpy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
# | by the Makefile. Manual changes to these values will be lost. |
2222
# ╰────────────────────── Notice ── Notice ── Notice ─────────────────────╯
2323

24-
__version__ = '1.12.0'
24+
__version__ = '1.12.4'
2525
__description__ = 'Assortment of Python helper functions and utility classes'
2626
__url__ = 'https://github.com/caltechlibrary/commonpy'
2727
__author__ = 'Michael Hucka'

commonpy/network_utils.py

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@
3737
encountering a network error before they stop and give up.'''
3838

3939
_MAX_CONSECUTIVE_FAILS = 3
40-
'''Maximum number of consecutive failures before pause and try another round.'''
41-
42-
_MAX_RETRIES = 5
4340
'''Maximum number of times we back off and try again. This also affects the
4441
maximum wait time that will be reached after repeated retries.'''
4542

@@ -148,24 +145,26 @@ def addurl(text):
148145
elif client == 'stream':
149146
client = httpx.stream
150147

148+
response = None
151149
failures = 0
152-
retries = 0
153150
error = None
154-
while failures < _MAX_CONSECUTIVE_FAILS and not interrupted():
151+
while failures <= _MAX_CONSECUTIVE_FAILS and not interrupted():
155152
try:
156153
if __debug__: log(addurl(f'doing http {method}'))
157154
func = getattr(client, method)
158155
response = func(url, **kwargs)
159156
# For some statuses, retry once, in case it's a transient problem.
160157
code = response.status_code
161158
if __debug__: log(addurl(f'got response with code {code}'))
162-
if code not in [400, 409, 502, 503, 504] or failures > 0:
159+
if code not in [400, 409, 502, 503, 504] or failures > _MAX_CONSECUTIVE_FAILS:
163160
return response
164-
else:
165-
failures += 1
166161
except KeyboardInterrupt as ex:
167162
if __debug__: log(addurl(f'network {method} interrupted by {antiformat(ex)}'))
168163
raise
164+
except ImportError as ex:
165+
# This can happen if the installation environment has inconsistecies.
166+
log('import error: ' + str(ex))
167+
raise
169168
except (TypeError, httpx.UnsupportedProtocol) as ex:
170169
# Bad arguments to the call, like passing data to a 'get'.
171170
if __debug__: log(addurl(f'exception {antiformat(ex)}'))
@@ -178,7 +177,6 @@ def addurl(text):
178177
if __debug__: log(addurl(f'exception {antiformat(ex)}'))
179178
if failures > 0:
180179
raise
181-
failures += 1
182180
if __debug__: log(addurl('will retry one more time after brief pause'))
183181
except Exception as ex: # noqa PIE786
184182
# Problem might be transient. Don't quit right away.
@@ -189,20 +187,27 @@ def addurl(text):
189187
# about being unable to reconnect and not the original problem.
190188
if not error:
191189
error = ex
192-
if failures >= _MAX_CONSECUTIVE_FAILS:
190+
# If there's response text, it may contain diagnostic info.
191+
if __debug__ and response:
192+
text = response.text[:500] + (' ...' if len(response.text) > 500 else '')
193+
log('response text: ' + text)
194+
if failures == 0:
195+
# Pause briefly b/c it's rarely a good idea to retry immediately.
196+
if __debug__: log(addurl('pausing briefly before retrying'))
197+
wait(0.5)
198+
failures += 1
199+
elif failures < _MAX_CONSECUTIVE_FAILS:
193200
# Pause with exponential back-off, reset failure count & try again.
194-
if retries < _MAX_RETRIES:
195-
retries += 1
196-
failures = 0
197-
pause = 10 * retries * retries
198-
if __debug__: log(addurl('pausing due to consecutive failures'))
199-
wait(pause)
200-
else:
201-
if __debug__: log(addurl('exceeded max failures and max retries'))
201+
pause = 5 * failures * failures
202+
if __debug__: log(addurl('pausing due to consecutive failures'))
203+
wait(pause)
204+
failures += 1
205+
else:
206+
if __debug__: log(addurl('exceeded max failures'))
207+
if error:
202208
raise error
203-
# Pause briefly b/c it's rarely a good idea to retry immediately.
204-
if __debug__: log(addurl('pausing briefly before retrying'))
205-
wait(0.5)
209+
else:
210+
return response
206211
if interrupted():
207212
if __debug__: log(addurl('interrupted'))
208213
raise Interrupted(addurl('Network request has been interrupted'))

requirements.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88

99
PyYAML >= 5.3.1
1010
boltons == 21.0.0
11-
dateparser == 1.0.0
11+
dateparser == 1.1.8
1212
deprecation == 2.1.0
13-
h2 == 3.2.0
14-
httpx == 0.23.0
13+
h2 == 4.0.0
14+
httpx == 0.23.1
1515
humanize >= 3.9.0
1616
python_dateutil == 2.8.2
1717
pywin32 >= 301; sys_platform == 'win32'
@@ -22,6 +22,7 @@ pywin32 >= 301; sys_platform == 'win32'
2222
# to Stack Overflow at https://stackoverflow.com/a/71504213/743730.
2323
regex <= 2022.3.2
2424

25+
setuptools >= 67.5.1
2526
sidetrack >= 2.0.0
2627
tldextract == 3.0.2
2728
validator-collection == 1.5.0

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
[metadata]
1010
name = commonpy
11-
version = 1.12.0
11+
version = 1.12.4
1212
description = Assortment of Python helper functions and utility classes
1313
author = Michael Hucka
1414
author_email = mhucka@caltech.edu

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
from setuptools import setup
1515

16+
1617
def requirements(file):
1718
from os import path
1819
required = []
@@ -33,8 +34,8 @@ def requirements(file):
3334
pass
3435
return required
3536

37+
3638
setup(
3739
setup_requires=['wheel'],
3840
install_requires=requirements('requirements.txt'),
39-
extras_require={'dev': requirements('requirements-dev.txt')},
4041
)

0 commit comments

Comments
 (0)