apify 2.4.0b1__py3-none-any.whl → 2.4.0b3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of apify might be problematic. Click here for more details.
apify/_actor.py
CHANGED
|
@@ -3,6 +3,7 @@ from __future__ import annotations
|
|
|
3
3
|
import asyncio
|
|
4
4
|
import os
|
|
5
5
|
import sys
|
|
6
|
+
from contextlib import suppress
|
|
6
7
|
from datetime import timedelta
|
|
7
8
|
from typing import TYPE_CHECKING, Any, Callable, Literal, TypeVar, cast, overload
|
|
8
9
|
|
|
@@ -64,6 +65,7 @@ class _ActorType:
|
|
|
64
65
|
configuration: Configuration | None = None,
|
|
65
66
|
*,
|
|
66
67
|
configure_logging: bool = True,
|
|
68
|
+
exit_process: bool | None = None,
|
|
67
69
|
) -> None:
|
|
68
70
|
"""Create an Actor instance.
|
|
69
71
|
|
|
@@ -74,7 +76,10 @@ class _ActorType:
|
|
|
74
76
|
configuration: The Actor configuration to be used. If not passed, a new Configuration instance will
|
|
75
77
|
be created.
|
|
76
78
|
configure_logging: Should the default logging configuration be configured?
|
|
79
|
+
exit_process: Whether the Actor should call `sys.exit` when the context manager exits. The default is
|
|
80
|
+
True except for the IPython, Pytest and Scrapy environments.
|
|
77
81
|
"""
|
|
82
|
+
self._exit_process = self._get_default_exit_process() if exit_process is None else exit_process
|
|
78
83
|
self._is_exiting = False
|
|
79
84
|
|
|
80
85
|
self._configuration = configuration or Configuration.get_global_configuration()
|
|
@@ -141,9 +146,19 @@ class _ActorType:
|
|
|
141
146
|
|
|
142
147
|
return super().__repr__()
|
|
143
148
|
|
|
144
|
-
def __call__(
|
|
149
|
+
def __call__(
|
|
150
|
+
self,
|
|
151
|
+
configuration: Configuration | None = None,
|
|
152
|
+
*,
|
|
153
|
+
configure_logging: bool = True,
|
|
154
|
+
exit_process: bool | None = None,
|
|
155
|
+
) -> Self:
|
|
145
156
|
"""Make a new Actor instance with a non-default configuration."""
|
|
146
|
-
return self.__class__(
|
|
157
|
+
return self.__class__(
|
|
158
|
+
configuration=configuration,
|
|
159
|
+
configure_logging=configure_logging,
|
|
160
|
+
exit_process=exit_process,
|
|
161
|
+
)
|
|
147
162
|
|
|
148
163
|
@property
|
|
149
164
|
def apify_client(self) -> ApifyClientAsync:
|
|
@@ -281,13 +296,7 @@ class _ActorType:
|
|
|
281
296
|
await asyncio.wait_for(finalize(), cleanup_timeout.total_seconds())
|
|
282
297
|
self._is_initialized = False
|
|
283
298
|
|
|
284
|
-
if
|
|
285
|
-
self.log.debug(f'Not calling sys.exit({exit_code}) because Actor is running in IPython')
|
|
286
|
-
elif os.getenv('PYTEST_CURRENT_TEST', default=False): # noqa: PLW1508
|
|
287
|
-
self.log.debug(f'Not calling sys.exit({exit_code}) because Actor is running in an unit test')
|
|
288
|
-
elif os.getenv('SCRAPY_SETTINGS_MODULE'):
|
|
289
|
-
self.log.debug(f'Not calling sys.exit({exit_code}) because Actor is running with Scrapy')
|
|
290
|
-
else:
|
|
299
|
+
if self._exit_process:
|
|
291
300
|
sys.exit(exit_code)
|
|
292
301
|
|
|
293
302
|
async def fail(
|
|
@@ -1128,6 +1137,26 @@ class _ActorType:
|
|
|
1128
1137
|
|
|
1129
1138
|
return proxy_configuration
|
|
1130
1139
|
|
|
1140
|
+
def _get_default_exit_process(self) -> bool:
|
|
1141
|
+
"""Returns False for IPython, Pytest, and Scrapy environments, True otherwise."""
|
|
1142
|
+
if is_running_in_ipython():
|
|
1143
|
+
self.log.debug('Running in IPython, setting default `exit_process` to False.')
|
|
1144
|
+
return False
|
|
1145
|
+
|
|
1146
|
+
# Check if running in Pytest by detecting the relevant environment variable.
|
|
1147
|
+
if os.getenv('PYTEST_CURRENT_TEST'):
|
|
1148
|
+
self.log.debug('Running in Pytest, setting default `exit_process` to False.')
|
|
1149
|
+
return False
|
|
1150
|
+
|
|
1151
|
+
# Check if running in Scrapy by attempting to import it.
|
|
1152
|
+
with suppress(ImportError):
|
|
1153
|
+
import scrapy # noqa: F401
|
|
1154
|
+
|
|
1155
|
+
self.log.debug('Running in Scrapy, setting default `exit_process` to False.')
|
|
1156
|
+
return False
|
|
1157
|
+
|
|
1158
|
+
return True
|
|
1159
|
+
|
|
1131
1160
|
|
|
1132
1161
|
Actor = cast(_ActorType, Proxy(_ActorType))
|
|
1133
1162
|
"""The entry point of the SDK, through which all the Actor operations should be done."""
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
apify/__init__.py,sha256=HpgKg2FZWJuSPfDygzJ62psylhw4NN4tKFnoYUIhcd4,838
|
|
2
|
-
apify/_actor.py,sha256=
|
|
2
|
+
apify/_actor.py,sha256=PQqFDpAqSbh_aP3EjD8yLGYOmLZMo1qLzqrbVT2KjWE,49697
|
|
3
3
|
apify/_charging.py,sha256=m7hJIQde4M7vS4g_4hsNRP5xHNXjYQ8MyqOEGeNb7VY,12267
|
|
4
4
|
apify/_configuration.py,sha256=yidcWHsu-IJ2mmLmXStKq_HHcdfQxZq7koYjlZfRnQ8,11128
|
|
5
5
|
apify/_consts.py,sha256=_Xq4hOfOA1iZ3n1P967YWdyncKivpbX6RTlp_qanUoE,330
|
|
@@ -36,7 +36,7 @@ apify/scrapy/pipelines/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSu
|
|
|
36
36
|
apify/storages/__init__.py,sha256=FW-z6ubuPnHGM-Wp15T8mR5q6lnpDGrCW-IkgZd5L30,177
|
|
37
37
|
apify/storages/_request_list.py,sha256=7WpcdWvT3QxEBthynBpTVCSNDLXq6UbpQQmfUVyJ1jE,5849
|
|
38
38
|
apify/storages/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
39
|
-
apify-2.4.
|
|
40
|
-
apify-2.4.
|
|
41
|
-
apify-2.4.
|
|
42
|
-
apify-2.4.
|
|
39
|
+
apify-2.4.0b3.dist-info/METADATA,sha256=gir7JYFqfowdPkukMySYVZBX2jU3FY_pYh3_ox6CvRQ,21566
|
|
40
|
+
apify-2.4.0b3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
41
|
+
apify-2.4.0b3.dist-info/licenses/LICENSE,sha256=AsFjHssKjj4LGd2ZCqXn6FBzMqcWdjQre1byPPSypVw,11355
|
|
42
|
+
apify-2.4.0b3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|