asyncer 0.0.7.dev1__tar.gz → 0.0.9__tar.gz

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.
Files changed (67) hide show
  1. {asyncer-0.0.7.dev1 → asyncer-0.0.9}/PKG-INFO +14 -11
  2. {asyncer-0.0.7.dev1 → asyncer-0.0.9}/README.md +8 -8
  3. {asyncer-0.0.7.dev1 → asyncer-0.0.9}/asyncer/__init__.py +1 -1
  4. asyncer-0.0.9/asyncer/_compat.py +37 -0
  5. {asyncer-0.0.7.dev1 → asyncer-0.0.9}/asyncer/_main.py +23 -3
  6. {asyncer-0.0.7.dev1 → asyncer-0.0.9}/pyproject.toml +13 -3
  7. asyncer-0.0.9/requirements-docs-insiders.txt +3 -0
  8. {asyncer-0.0.7.dev1 → asyncer-0.0.9}/requirements-docs.txt +9 -8
  9. asyncer-0.0.9/requirements-github-actions.txt +5 -0
  10. asyncer-0.0.9/requirements-tests.txt +6 -0
  11. {asyncer-0.0.7.dev1 → asyncer-0.0.9}/requirements.txt +1 -1
  12. asyncer-0.0.9/scripts/deploy_docs_status.py +127 -0
  13. asyncer-0.0.9/scripts/docs.py +135 -0
  14. asyncer-0.0.9/scripts/mkdocs_hooks.py +38 -0
  15. {asyncer-0.0.7.dev1 → asyncer-0.0.9}/scripts/test.sh +1 -1
  16. asyncer-0.0.9/tests/test_param_cancellable.py +37 -0
  17. asyncer-0.0.7.dev1/requirements-tests.txt +0 -6
  18. asyncer-0.0.7.dev1/scripts/docs-live.sh +0 -7
  19. asyncer-0.0.7.dev1/scripts/test-files.sh +0 -7
  20. {asyncer-0.0.7.dev1 → asyncer-0.0.9}/LICENSE +0 -0
  21. {asyncer-0.0.7.dev1 → asyncer-0.0.9}/asyncer/py.typed +0 -0
  22. {asyncer-0.0.7.dev1 → asyncer-0.0.9}/docs_src/__init__.py +0 -0
  23. {asyncer-0.0.7.dev1 → asyncer-0.0.9}/docs_src/tutorial/__init__.py +0 -0
  24. {asyncer-0.0.7.dev1 → asyncer-0.0.9}/docs_src/tutorial/asyncify/__init__.py +0 -0
  25. {asyncer-0.0.7.dev1 → asyncer-0.0.9}/docs_src/tutorial/asyncify/tutorial001.py +0 -0
  26. {asyncer-0.0.7.dev1 → asyncer-0.0.9}/docs_src/tutorial/asyncify/tutorial002.py +0 -0
  27. {asyncer-0.0.7.dev1 → asyncer-0.0.9}/docs_src/tutorial/first_steps/__init__.py +0 -0
  28. {asyncer-0.0.7.dev1 → asyncer-0.0.9}/docs_src/tutorial/first_steps/tutorial001.py +0 -0
  29. {asyncer-0.0.7.dev1 → asyncer-0.0.9}/docs_src/tutorial/runnify/__init__.py +0 -0
  30. {asyncer-0.0.7.dev1 → asyncer-0.0.9}/docs_src/tutorial/runnify/tutorial001.py +0 -0
  31. {asyncer-0.0.7.dev1 → asyncer-0.0.9}/docs_src/tutorial/soonify/__init__.py +0 -0
  32. {asyncer-0.0.7.dev1 → asyncer-0.0.9}/docs_src/tutorial/soonify/tutorial001.py +0 -0
  33. {asyncer-0.0.7.dev1 → asyncer-0.0.9}/docs_src/tutorial/soonify/tutorial002.py +0 -0
  34. {asyncer-0.0.7.dev1 → asyncer-0.0.9}/docs_src/tutorial/soonify_return/__init__.py +0 -0
  35. {asyncer-0.0.7.dev1 → asyncer-0.0.9}/docs_src/tutorial/soonify_return/tutorial001.py +0 -0
  36. {asyncer-0.0.7.dev1 → asyncer-0.0.9}/docs_src/tutorial/soonify_return/tutorial002.py +0 -0
  37. {asyncer-0.0.7.dev1 → asyncer-0.0.9}/docs_src/tutorial/soonify_return/tutorial003.py +0 -0
  38. {asyncer-0.0.7.dev1 → asyncer-0.0.9}/docs_src/tutorial/syncify/__init__.py +0 -0
  39. {asyncer-0.0.7.dev1 → asyncer-0.0.9}/docs_src/tutorial/syncify/tutorial001.py +0 -0
  40. {asyncer-0.0.7.dev1 → asyncer-0.0.9}/docs_src/tutorial/syncify_no_raise/__init__.py +0 -0
  41. {asyncer-0.0.7.dev1 → asyncer-0.0.9}/docs_src/tutorial/syncify_no_raise/tutorial001.py +0 -0
  42. {asyncer-0.0.7.dev1 → asyncer-0.0.9}/pdm_build.py +0 -0
  43. {asyncer-0.0.7.dev1 → asyncer-0.0.9}/scripts/format.sh +0 -0
  44. {asyncer-0.0.7.dev1 → asyncer-0.0.9}/scripts/lint.sh +0 -0
  45. {asyncer-0.0.7.dev1 → asyncer-0.0.9}/tests/__init__.py +0 -0
  46. {asyncer-0.0.7.dev1 → asyncer-0.0.9}/tests/conftest.py +0 -0
  47. {asyncer-0.0.7.dev1 → asyncer-0.0.9}/tests/test_others.py +0 -0
  48. {asyncer-0.0.7.dev1 → asyncer-0.0.9}/tests/test_syncify_no_raise.py +0 -0
  49. {asyncer-0.0.7.dev1 → asyncer-0.0.9}/tests/test_tutorial/__init__.py +0 -0
  50. {asyncer-0.0.7.dev1 → asyncer-0.0.9}/tests/test_tutorial/test_asyncify/__init__.py +0 -0
  51. {asyncer-0.0.7.dev1 → asyncer-0.0.9}/tests/test_tutorial/test_asyncify/test_tutorial001.py +0 -0
  52. {asyncer-0.0.7.dev1 → asyncer-0.0.9}/tests/test_tutorial/test_asyncify/test_tutorial002.py +0 -0
  53. {asyncer-0.0.7.dev1 → asyncer-0.0.9}/tests/test_tutorial/test_first_steps/__init__.py +0 -0
  54. {asyncer-0.0.7.dev1 → asyncer-0.0.9}/tests/test_tutorial/test_first_steps/test_tutorial001.py +0 -0
  55. {asyncer-0.0.7.dev1 → asyncer-0.0.9}/tests/test_tutorial/test_runnify/__init__.py +0 -0
  56. {asyncer-0.0.7.dev1 → asyncer-0.0.9}/tests/test_tutorial/test_runnify/test_tutorial001.py +0 -0
  57. {asyncer-0.0.7.dev1 → asyncer-0.0.9}/tests/test_tutorial/test_soonify/__init__.py +0 -0
  58. {asyncer-0.0.7.dev1 → asyncer-0.0.9}/tests/test_tutorial/test_soonify/test_tutorial001.py +0 -0
  59. {asyncer-0.0.7.dev1 → asyncer-0.0.9}/tests/test_tutorial/test_soonify/test_tutorial002.py +0 -0
  60. {asyncer-0.0.7.dev1 → asyncer-0.0.9}/tests/test_tutorial/test_soonify_return/__init__.py +0 -0
  61. {asyncer-0.0.7.dev1 → asyncer-0.0.9}/tests/test_tutorial/test_soonify_return/test_tutorial001.py +0 -0
  62. {asyncer-0.0.7.dev1 → asyncer-0.0.9}/tests/test_tutorial/test_soonify_return/test_tutorial002.py +0 -0
  63. {asyncer-0.0.7.dev1 → asyncer-0.0.9}/tests/test_tutorial/test_soonify_return/test_tutorial003.py +0 -0
  64. {asyncer-0.0.7.dev1 → asyncer-0.0.9}/tests/test_tutorial/test_syncify/__init__.py +0 -0
  65. {asyncer-0.0.7.dev1 → asyncer-0.0.9}/tests/test_tutorial/test_syncify/test_tutorial001.py +0 -0
  66. {asyncer-0.0.7.dev1 → asyncer-0.0.9}/tests/test_tutorial/test_syncify_no_raise/__init__.py +0 -0
  67. {asyncer-0.0.7.dev1 → asyncer-0.0.9}/tests/test_tutorial/test_syncify_no_raise/test_tutorial001.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: asyncer
3
- Version: 0.0.7.dev1
3
+ Version: 0.0.9
4
4
  Summary: Asyncer, async and await, focused on developer experience.
5
5
  Author-Email: =?utf-8?q?Sebasti=C3=A1n_Ram=C3=ADrez?= <tiangolo@gmail.com>
6
6
  Classifier: Development Status :: 4 - Beta
@@ -18,11 +18,14 @@ Classifier: Programming Language :: Python :: 3.9
18
18
  Classifier: Programming Language :: Python :: 3.10
19
19
  Classifier: Programming Language :: Python :: 3.11
20
20
  Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
21
22
  Classifier: Topic :: Internet
22
23
  Classifier: Typing :: Typed
23
- Project-URL: Homepage, https://github.com/tiangolo/asyncer
24
+ Project-URL: Homepage, https://github.com/fastapi/asyncer
24
25
  Project-URL: Documentation, https://asyncer.tiangolo.com
25
- Project-URL: Repository, https://github.com/tiangolo/asyncer
26
+ Project-URL: Repository, https://github.com/fastapi/asyncer
27
+ Project-URL: Issues, https://github.com/fastapi/asyncer/issues
28
+ Project-URL: Changelog, https://asyncer.tiangolo.com/release-notes/
26
29
  Requires-Python: >=3.8
27
30
  Requires-Dist: anyio<5.0,>=3.4.0
28
31
  Requires-Dist: typing_extensions>=4.8.0; python_version < "3.10"
@@ -35,14 +38,14 @@ Description-Content-Type: text/markdown
35
38
  <em>Asyncer, async and await, focused on developer experience.</em>
36
39
  </p>
37
40
  <p align="center">
38
- <a href="https://github.com/tiangolo/asyncer/actions?query=workflow%3ATest" target="_blank">
39
- <img src="https://github.com/tiangolo/asyncer/workflows/Test/badge.svg" alt="Test">
41
+ <a href="https://github.com/fastapi/asyncer/actions?query=workflow%3ATest+event%3Apush+branch%3Amain" target="_blank">
42
+ <img src="https://github.com/fastapi/asyncer/actions/workflows/test.yml/badge.svg?event=push&branch=main" alt="Test">
40
43
  </a>
41
- <a href="https://github.com/tiangolo/asyncer/actions?query=workflow%3APublish" target="_blank">
42
- <img src="https://github.com/tiangolo/asyncer/workflows/Publish/badge.svg" alt="Publish">
44
+ <a href="https://github.com/fastapi/asyncer/actions?query=workflow%3APublish" target="_blank">
45
+ <img src="https://github.com/fastapi/asyncer/actions/workflows/publish.yml/badge.svg" alt="Publish">
43
46
  </a>
44
- <a href="https://coverage-badge.samuelcolvin.workers.dev/redirect/tiangolo/asyncer" target="_blank">
45
- <img src="https://coverage-badge.samuelcolvin.workers.dev/tiangolo/asyncer.svg" alt="Coverage">
47
+ <a href="https://coverage-badge.samuelcolvin.workers.dev/redirect/fastapi/asyncer" target="_blank">
48
+ <img src="https://coverage-badge.samuelcolvin.workers.dev/fastapi/asyncer.svg" alt="Coverage">
46
49
  <a href="https://pypi.org/project/asyncer" target="_blank">
47
50
  <img src="https://img.shields.io/pypi/v/asyncer?color=%2334D058&label=pypi%20package" alt="Package version">
48
51
  </a>
@@ -52,7 +55,7 @@ Description-Content-Type: text/markdown
52
55
 
53
56
  **Documentation**: <a href="https://asyncer.tiangolo.com" target="_blank">https://asyncer.tiangolo.com</a>
54
57
 
55
- **Source Code**: <a href="https://github.com/tiangolo/asyncer" target="_blank">https://github.com/tiangolo/asyncer</a>
58
+ **Source Code**: <a href="https://github.com/fastapi/asyncer" target="_blank">https://github.com/fastapi/asyncer</a>
56
59
 
57
60
  ---
58
61
 
@@ -152,4 +155,4 @@ Everything in **Asyncer** is designed to get the best **developer experience** p
152
155
 
153
156
  ## License
154
157
 
155
- This project is licensed under the terms of the [MIT license](https://github.com/tiangolo/asyncer/blob/main/LICENSE).
158
+ This project is licensed under the terms of the [MIT license](https://github.com/fastapi/asyncer/blob/main/LICENSE).
@@ -5,14 +5,14 @@
5
5
  <em>Asyncer, async and await, focused on developer experience.</em>
6
6
  </p>
7
7
  <p align="center">
8
- <a href="https://github.com/tiangolo/asyncer/actions?query=workflow%3ATest" target="_blank">
9
- <img src="https://github.com/tiangolo/asyncer/workflows/Test/badge.svg" alt="Test">
8
+ <a href="https://github.com/fastapi/asyncer/actions?query=workflow%3ATest+event%3Apush+branch%3Amain" target="_blank">
9
+ <img src="https://github.com/fastapi/asyncer/actions/workflows/test.yml/badge.svg?event=push&branch=main" alt="Test">
10
10
  </a>
11
- <a href="https://github.com/tiangolo/asyncer/actions?query=workflow%3APublish" target="_blank">
12
- <img src="https://github.com/tiangolo/asyncer/workflows/Publish/badge.svg" alt="Publish">
11
+ <a href="https://github.com/fastapi/asyncer/actions?query=workflow%3APublish" target="_blank">
12
+ <img src="https://github.com/fastapi/asyncer/actions/workflows/publish.yml/badge.svg" alt="Publish">
13
13
  </a>
14
- <a href="https://coverage-badge.samuelcolvin.workers.dev/redirect/tiangolo/asyncer" target="_blank">
15
- <img src="https://coverage-badge.samuelcolvin.workers.dev/tiangolo/asyncer.svg" alt="Coverage">
14
+ <a href="https://coverage-badge.samuelcolvin.workers.dev/redirect/fastapi/asyncer" target="_blank">
15
+ <img src="https://coverage-badge.samuelcolvin.workers.dev/fastapi/asyncer.svg" alt="Coverage">
16
16
  <a href="https://pypi.org/project/asyncer" target="_blank">
17
17
  <img src="https://img.shields.io/pypi/v/asyncer?color=%2334D058&label=pypi%20package" alt="Package version">
18
18
  </a>
@@ -22,7 +22,7 @@
22
22
 
23
23
  **Documentation**: <a href="https://asyncer.tiangolo.com" target="_blank">https://asyncer.tiangolo.com</a>
24
24
 
25
- **Source Code**: <a href="https://github.com/tiangolo/asyncer" target="_blank">https://github.com/tiangolo/asyncer</a>
25
+ **Source Code**: <a href="https://github.com/fastapi/asyncer" target="_blank">https://github.com/fastapi/asyncer</a>
26
26
 
27
27
  ---
28
28
 
@@ -122,4 +122,4 @@ Everything in **Asyncer** is designed to get the best **developer experience** p
122
122
 
123
123
  ## License
124
124
 
125
- This project is licensed under the terms of the [MIT license](https://github.com/tiangolo/asyncer/blob/main/LICENSE).
125
+ This project is licensed under the terms of the [MIT license](https://github.com/fastapi/asyncer/blob/main/LICENSE).
@@ -1,4 +1,4 @@
1
- __version__ = "0.0.7.dev1"
1
+ __version__ = "0.0.9"
2
2
 
3
3
  from ._main import PendingValueException as PendingValueException
4
4
  from ._main import SoonValue as SoonValue
@@ -0,0 +1,37 @@
1
+ # AnyIO 4.1.0 renamed cancellable to abandon_on_cancel
2
+ import importlib
3
+ import importlib.metadata
4
+ from typing import Callable, TypeVar, Union
5
+
6
+ import anyio
7
+ import anyio.to_thread
8
+ from anyio import CapacityLimiter
9
+ from typing_extensions import TypeVarTuple, Unpack
10
+
11
+ ANYIO_VERSION = importlib.metadata.version("anyio")
12
+
13
+ T_Retval = TypeVar("T_Retval")
14
+ PosArgsT = TypeVarTuple("PosArgsT")
15
+
16
+ if ANYIO_VERSION >= "4.1.0":
17
+
18
+ async def run_sync(
19
+ func: Callable[[Unpack[PosArgsT]], T_Retval],
20
+ *args: Unpack[PosArgsT],
21
+ abandon_on_cancel: bool = False,
22
+ limiter: Union[CapacityLimiter, None] = None,
23
+ ) -> T_Retval:
24
+ return await anyio.to_thread.run_sync(
25
+ func, *args, abandon_on_cancel=abandon_on_cancel, limiter=limiter
26
+ )
27
+ else:
28
+
29
+ async def run_sync(
30
+ func: Callable[[Unpack[PosArgsT]], T_Retval],
31
+ *args: Unpack[PosArgsT],
32
+ abandon_on_cancel: bool = False,
33
+ limiter: Union[CapacityLimiter, None] = None,
34
+ ) -> T_Retval:
35
+ return await anyio.to_thread.run_sync(
36
+ func, *args, cancellable=abandon_on_cancel, limiter=limiter
37
+ )
@@ -12,6 +12,9 @@ from typing import (
12
12
  TypeVar,
13
13
  Union,
14
14
  )
15
+ from warnings import warn
16
+
17
+ from asyncer._compat import run_sync
15
18
 
16
19
  if sys.version_info >= (3, 10):
17
20
  from typing import ParamSpec
@@ -19,6 +22,8 @@ else:
19
22
  from typing_extensions import ParamSpec
20
23
 
21
24
  import anyio
25
+ import anyio.from_thread
26
+ import anyio.to_thread
22
27
  import sniffio
23
28
  from anyio._core._eventloop import threadlocals
24
29
  from anyio.abc import TaskGroup as _TaskGroup
@@ -301,6 +306,9 @@ def syncify(
301
306
  @functools.wraps(async_function)
302
307
  def wrapper(*args: T_ParamSpec.args, **kwargs: T_ParamSpec.kwargs) -> T_Retval:
303
308
  current_async_module = (
309
+ getattr(threadlocals, "current_token", None)
310
+ or
311
+ # TODO: remove when deprecating AnyIO 4.10.0
304
312
  getattr(threadlocals, "current_async_backend", None)
305
313
  or
306
314
  # TODO: remove when deprecating AnyIO 3.x
@@ -317,7 +325,8 @@ def syncify(
317
325
  def asyncify(
318
326
  function: Callable[T_ParamSpec, T_Retval],
319
327
  *,
320
- cancellable: bool = False,
328
+ abandon_on_cancel: bool = False,
329
+ cancellable: Union[bool, None] = None,
321
330
  limiter: Optional[anyio.CapacityLimiter] = None,
322
331
  ) -> Callable[T_ParamSpec, Awaitable[T_Retval]]:
323
332
  """
@@ -357,13 +366,24 @@ def asyncify(
357
366
  original one, that when called runs the same original function in a thread worker
358
367
  and returns the result.
359
368
  """
369
+ if cancellable is not None:
370
+ abandon_on_cancel = cancellable
371
+ warn(
372
+ "The `cancellable=` keyword argument to `asyncer.asyncify()` is "
373
+ "deprecated since Asyncer 0.0.8, following AnyIO 4.1.0. "
374
+ "Use `abandon_on_cancel=` instead.",
375
+ DeprecationWarning,
376
+ stacklevel=2,
377
+ )
360
378
 
379
+ @functools.wraps(function)
361
380
  async def wrapper(
362
381
  *args: T_ParamSpec.args, **kwargs: T_ParamSpec.kwargs
363
382
  ) -> T_Retval:
364
383
  partial_f = functools.partial(function, *args, **kwargs)
365
- return await anyio.to_thread.run_sync(
366
- partial_f, cancellable=cancellable, limiter=limiter
384
+
385
+ return await run_sync(
386
+ partial_f, abandon_on_cancel=abandon_on_cancel, limiter=limiter
367
387
  )
368
388
 
369
389
  return wrapper
@@ -29,6 +29,7 @@ classifiers = [
29
29
  "Programming Language :: Python :: 3.10",
30
30
  "Programming Language :: Python :: 3.11",
31
31
  "Programming Language :: Python :: 3.12",
32
+ "Programming Language :: Python :: 3.13",
32
33
  "Topic :: Internet",
33
34
  "Typing :: Typed",
34
35
  ]
@@ -36,12 +37,14 @@ dependencies = [
36
37
  "anyio >=3.4.0,<5.0",
37
38
  "typing_extensions >=4.8.0; python_version < '3.10'",
38
39
  ]
39
- version = "0.0.7.dev1"
40
+ version = "0.0.9"
40
41
 
41
42
  [project.urls]
42
- Homepage = "https://github.com/tiangolo/asyncer"
43
+ Homepage = "https://github.com/fastapi/asyncer"
43
44
  Documentation = "https://asyncer.tiangolo.com"
44
- Repository = "https://github.com/tiangolo/asyncer"
45
+ Repository = "https://github.com/fastapi/asyncer"
46
+ Issues = "https://github.com/fastapi/asyncer/issues"
47
+ Changelog = "https://asyncer.tiangolo.com/release-notes/"
45
48
 
46
49
  [project.optional-dependencies]
47
50
 
@@ -67,18 +70,25 @@ name = "asyncer-slim"
67
70
 
68
71
  [tool.coverage.run]
69
72
  parallel = true
73
+ data_file = "coverage/.coverage"
70
74
  source = [
71
75
  "docs_src",
72
76
  "tests",
73
77
  "asyncer",
74
78
  ]
75
79
  context = "${CONTEXT}"
80
+ dynamic_context = "test_function"
76
81
 
77
82
  [tool.coverage.report]
83
+ show_missing = true
84
+ sort = "-Cover"
78
85
  omit = [
79
86
  "docs_src/tutorial/soonify_return/tutorial002.py",
80
87
  ]
81
88
 
89
+ [tool.coverage.html]
90
+ show_contexts = true
91
+
82
92
  [tool.mypy]
83
93
  strict = true
84
94
 
@@ -0,0 +1,3 @@
1
+ git+https://${TOKEN}@github.com/squidfunk/mkdocs-material-insiders.git@9.5.30-insiders-4.53.11
2
+ git+https://${TOKEN}@github.com/pawamoy-insiders/griffe-typing-deprecated.git
3
+ git+https://${TOKEN}@github.com/pawamoy-insiders/mkdocstrings-python.git
@@ -1,17 +1,18 @@
1
1
  -e .
2
2
 
3
- mkdocs-material==9.4.7
3
+ mkdocs-material==9.6.20
4
4
  mdx-include >=1.4.1,<2.0.0
5
- mkdocs-markdownextradata-plugin >=0.1.7,<0.3.0
6
5
  mkdocs-redirects>=1.2.1,<1.3.0
7
6
  pyyaml >=5.3.1,<7.0.0
8
7
  # For Material for MkDocs, Chinese search
9
- jieba==0.42.1
8
+ # jieba==0.42.1
10
9
  # For image processing by Material for MkDocs
11
- pillow==10.1.0
10
+ pillow==11.3.0
12
11
  # For image processing by Material for MkDocs
13
- cairosvg==2.7.0
14
- mkdocstrings[python]==0.23.0
15
- griffe-typingdoc==0.2.2
12
+ cairosvg==2.8.2
13
+ # mkdocstrings[python]==0.25.1
14
+ # Enable griffe-typingdoc once dropping Python 3.7 and upgrading typing-extensions
15
+ # griffe-typingdoc==0.2.5
16
16
  # For griffe, it formats with black
17
- black==23.3.0
17
+ typer == 0.17.4
18
+ mkdocs-macros-plugin==1.3.9
@@ -0,0 +1,5 @@
1
+ PyGithub>=2.3.0,<3.0.0
2
+ pydantic>=2.5.3,<3.0.0
3
+ pydantic-settings>=2.1.0,<3.0.0
4
+ httpx>=0.27.0,<0.29.0
5
+ smokeshow
@@ -0,0 +1,6 @@
1
+ -e .
2
+
3
+ pytest >=7.0.1,<9.0.0
4
+ coverage[toml] >=6.2,<8.0
5
+ mypy ==1.14.1
6
+ ruff ==0.13.0
@@ -3,4 +3,4 @@
3
3
  -r requirements-tests.txt
4
4
  -r requirements-docs.txt
5
5
 
6
- pre-commit >=2.17.0,<4.0.0
6
+ pre-commit >=2.17.0,<5.0.0
@@ -0,0 +1,127 @@
1
+ import logging
2
+ import re
3
+ from typing import Literal
4
+
5
+ from github import Auth, Github
6
+ from pydantic import BaseModel, SecretStr
7
+ from pydantic_settings import BaseSettings
8
+
9
+ site_domain = "asyncer.tiangolo.com"
10
+
11
+
12
+ class Settings(BaseSettings):
13
+ github_repository: str
14
+ github_token: SecretStr
15
+ deploy_url: str | None = None
16
+ commit_sha: str
17
+ run_id: int
18
+ state: Literal["pending", "success", "error"] = "pending"
19
+
20
+
21
+ class LinkData(BaseModel):
22
+ previous_link: str
23
+ preview_link: str
24
+
25
+
26
+ def main() -> None:
27
+ logging.basicConfig(level=logging.INFO)
28
+ settings = Settings()
29
+
30
+ logging.info(f"Using config: {settings.model_dump_json()}")
31
+ g = Github(auth=Auth.Token(settings.github_token.get_secret_value()))
32
+ repo = g.get_repo(settings.github_repository)
33
+ use_pr = next(
34
+ (pr for pr in repo.get_pulls() if pr.head.sha == settings.commit_sha), None
35
+ )
36
+ if not use_pr:
37
+ logging.error(f"No PR found for hash: {settings.commit_sha}")
38
+ return
39
+ commits = list(use_pr.get_commits())
40
+ current_commit = [c for c in commits if c.sha == settings.commit_sha][0]
41
+ run_url = f"https://github.com/{settings.github_repository}/actions/runs/{settings.run_id}"
42
+ if settings.state == "pending":
43
+ current_commit.create_status(
44
+ state="pending",
45
+ description="Deploying Docs",
46
+ context="deploy-docs",
47
+ target_url=run_url,
48
+ )
49
+ logging.info("No deploy URL available yet")
50
+ return
51
+ if settings.state == "error":
52
+ current_commit.create_status(
53
+ state="error",
54
+ description="Error Deploying Docs",
55
+ context="deploy-docs",
56
+ target_url=run_url,
57
+ )
58
+ logging.info("Error deploying docs")
59
+ return
60
+ assert settings.state == "success"
61
+ if not settings.deploy_url:
62
+ current_commit.create_status(
63
+ state="success",
64
+ description="No Docs Changes",
65
+ context="deploy-docs",
66
+ target_url=run_url,
67
+ )
68
+ logging.info("No docs changes found")
69
+ return
70
+ assert settings.deploy_url
71
+ current_commit.create_status(
72
+ state="success",
73
+ description="Docs Deployed",
74
+ context="deploy-docs",
75
+ target_url=run_url,
76
+ )
77
+
78
+ files = list(use_pr.get_files())
79
+ docs_files = [f for f in files if f.filename.startswith("docs/")]
80
+
81
+ deploy_url = settings.deploy_url.rstrip("/")
82
+ links: list[LinkData] = []
83
+ for f in docs_files:
84
+ match = re.match(r"docs/(.*)", f.filename)
85
+ if not match:
86
+ continue
87
+ path = match.group(1)
88
+ if path.endswith("index.md"):
89
+ use_path = path.replace("index.md", "")
90
+ else:
91
+ use_path = path.replace(".md", "/")
92
+ link = LinkData(
93
+ previous_link=f"https://{site_domain}/{use_path}",
94
+ preview_link=f"{deploy_url}/{use_path}",
95
+ )
96
+ links.append(link)
97
+ links.sort(key=lambda x: x.preview_link)
98
+
99
+ header = "## 📝 Docs preview"
100
+ message = header
101
+ message += f"\n\nLast commit {settings.commit_sha} at: {deploy_url}"
102
+
103
+ if links:
104
+ message += "\n\n### Modified Pages\n\n"
105
+ for link in links:
106
+ message += f"* {link.preview_link}"
107
+ message += f" - ([before]({link.previous_link}))"
108
+ message += "\n"
109
+
110
+ print(message)
111
+ issue = use_pr.as_issue()
112
+ comments = list(issue.get_comments())
113
+ for comment in comments:
114
+ if (
115
+ comment.body.startswith(header)
116
+ and comment.user.login == "github-actions[bot]"
117
+ ):
118
+ comment.edit(message)
119
+ break
120
+ else:
121
+ issue.create_comment(message)
122
+
123
+ logging.info("Finished")
124
+
125
+
126
+ if __name__ == "__main__":
127
+ main()
@@ -0,0 +1,135 @@
1
+ import logging
2
+ import os
3
+ import re
4
+ import subprocess
5
+ from functools import lru_cache
6
+ from http.server import HTTPServer, SimpleHTTPRequestHandler
7
+ from importlib import metadata
8
+ from pathlib import Path
9
+
10
+ import typer
11
+
12
+ logging.basicConfig(level=logging.INFO)
13
+
14
+ mkdocs_name = "mkdocs.yml"
15
+ en_docs_path = Path("")
16
+
17
+ app = typer.Typer()
18
+
19
+
20
+ @lru_cache
21
+ def is_mkdocs_insiders() -> bool:
22
+ version = metadata.version("mkdocs-material")
23
+ return "insiders" in version
24
+
25
+
26
+ @app.callback()
27
+ def callback() -> None:
28
+ if is_mkdocs_insiders():
29
+ os.environ["INSIDERS_FILE"] = "./mkdocs.insiders.yml"
30
+ # For MacOS with insiders and Cairo
31
+ os.environ["DYLD_FALLBACK_LIBRARY_PATH"] = "/opt/homebrew/lib"
32
+
33
+
34
+ def generate_readme_content() -> str:
35
+ en_index = en_docs_path / "docs" / "index.md"
36
+ content = en_index.read_text("utf-8")
37
+ match_pre = re.search(r"</style>\n\n", content)
38
+ if not match_pre:
39
+ raise RuntimeError("Couldn't find pre section (<style>) in index.md")
40
+ frontmatter_end = match_pre.end()
41
+ new_content = content[frontmatter_end:]
42
+ # Remove content between <!-- only-mkdocs --> and <!-- /only-mkdocs -->
43
+ new_content = re.sub(
44
+ r"<!-- only-mkdocs -->.*?<!-- /only-mkdocs -->",
45
+ "",
46
+ new_content,
47
+ flags=re.DOTALL,
48
+ )
49
+ return new_content
50
+
51
+
52
+ @app.command()
53
+ def generate_readme() -> None:
54
+ """
55
+ Generate README.md content from main index.md
56
+ """
57
+ typer.echo("Generating README")
58
+ readme_path = Path("README.md")
59
+ new_content = generate_readme_content()
60
+ readme_path.write_text(new_content, encoding="utf-8")
61
+
62
+
63
+ @app.command()
64
+ def verify_readme() -> None:
65
+ """
66
+ Verify README.md content from main index.md
67
+ """
68
+ typer.echo("Verifying README")
69
+ readme_path = Path("README.md")
70
+ generated_content = generate_readme_content()
71
+ readme_content = readme_path.read_text("utf-8")
72
+ if generated_content != readme_content:
73
+ typer.secho(
74
+ "README.md outdated from the latest index.md", color=typer.colors.RED
75
+ )
76
+ raise typer.Abort()
77
+ typer.echo("Valid README ✅")
78
+
79
+
80
+ @app.command()
81
+ def live(dirty: bool = False) -> None:
82
+ """
83
+ Serve with livereload a docs site for a specific language.
84
+
85
+ This only shows the actual translated files, not the placeholders created with
86
+ build-all.
87
+
88
+ Takes an optional LANG argument with the name of the language to serve, by default
89
+ en.
90
+ """
91
+ # Enable line numbers during local development to make it easier to highlight
92
+ args = ["mkdocs", "serve", "--dev-addr", "127.0.0.1:8008"]
93
+ if dirty:
94
+ args.append("--dirty")
95
+ subprocess.run(args, env={**os.environ, "LINENUMS": "true"}, check=True)
96
+
97
+
98
+ @app.command()
99
+ def build() -> None:
100
+ """
101
+ Build the docs.
102
+ """
103
+ insiders_env_file = os.environ.get("INSIDERS_FILE")
104
+ print(f"Insiders file {insiders_env_file}")
105
+ if is_mkdocs_insiders():
106
+ print("Using insiders")
107
+ print("Building docs")
108
+ subprocess.run(["mkdocs", "build"], check=True)
109
+ typer.secho("Successfully built docs", color=typer.colors.GREEN)
110
+
111
+
112
+ @app.command()
113
+ def serve() -> None:
114
+ """
115
+ A quick server to preview a built site.
116
+
117
+ For development, prefer the command live (or just mkdocs serve).
118
+
119
+ This is here only to preview the documentation site.
120
+
121
+ Make sure you run the build command first.
122
+ """
123
+ typer.echo("Warning: this is a very simple server.")
124
+ typer.echo("For development, use the command live instead.")
125
+ typer.echo("This is here only to preview the documentation site.")
126
+ typer.echo("Make sure you run the build command first.")
127
+ os.chdir("site")
128
+ server_address = ("", 8008)
129
+ server = HTTPServer(server_address, SimpleHTTPRequestHandler)
130
+ typer.echo("Serving at: http://127.0.0.1:8008")
131
+ server.serve_forever()
132
+
133
+
134
+ if __name__ == "__main__":
135
+ app()
@@ -0,0 +1,38 @@
1
+ from typing import Any, List, Union
2
+
3
+ from mkdocs.config.defaults import MkDocsConfig
4
+ from mkdocs.structure.files import Files
5
+ from mkdocs.structure.nav import Link, Navigation, Section
6
+ from mkdocs.structure.pages import Page
7
+
8
+
9
+ def generate_renamed_section_items(
10
+ items: List[Union[Page, Section, Link]], *, config: MkDocsConfig
11
+ ) -> List[Union[Page, Section, Link]]:
12
+ new_items: List[Union[Page, Section, Link]] = []
13
+ for item in items:
14
+ if isinstance(item, Section):
15
+ new_title = item.title
16
+ new_children = generate_renamed_section_items(item.children, config=config)
17
+ first_child = new_children[0]
18
+ if isinstance(first_child, Page):
19
+ if first_child.file.src_path.endswith("index.md"):
20
+ # Read the source so that the title is parsed and available
21
+ first_child.read_source(config=config)
22
+ new_title = first_child.title or new_title
23
+ # Creating a new section makes it render it collapsed by default
24
+ # no idea why, so, let's just modify the existing one
25
+ # new_section = Section(title=new_title, children=new_children)
26
+ item.title = new_title
27
+ item.children = new_children
28
+ new_items.append(item)
29
+ else:
30
+ new_items.append(item)
31
+ return new_items
32
+
33
+
34
+ def on_nav(
35
+ nav: Navigation, *, config: MkDocsConfig, files: Files, **kwargs: Any
36
+ ) -> Navigation:
37
+ new_items = generate_renamed_section_items(nav.items, config=config)
38
+ return Navigation(items=new_items, pages=nav.pages)
@@ -5,5 +5,5 @@ set -x
5
5
 
6
6
  coverage run -m pytest tests
7
7
  coverage combine
8
- coverage report --show-missing
8
+ coverage report
9
9
  coverage html
@@ -0,0 +1,37 @@
1
+ import warnings
2
+
3
+ import anyio
4
+ import pytest
5
+ from asyncer import asyncify
6
+
7
+
8
+ def test_cancellable_warns():
9
+ def do_async_work():
10
+ return "Hello World!"
11
+
12
+ async def main():
13
+ result = await asyncify(do_async_work, cancellable=True)()
14
+ return result
15
+
16
+ with pytest.warns(DeprecationWarning) as record:
17
+ result = anyio.run(main)
18
+ assert isinstance(record[0].message, Warning)
19
+ assert (
20
+ "The `cancellable=` keyword argument to `asyncer.asyncify()` is "
21
+ "deprecated since Asyncer 0.0.8" in record[0].message.args[0]
22
+ )
23
+ assert result == "Hello World!"
24
+
25
+
26
+ def test_abandon_on_cancel_no():
27
+ def do_async_work():
28
+ return "Hello World!"
29
+
30
+ async def main():
31
+ result = await asyncify(do_async_work, abandon_on_cancel=True)()
32
+ return result
33
+
34
+ with warnings.catch_warnings():
35
+ warnings.simplefilter("error")
36
+ result = anyio.run(main)
37
+ assert result == "Hello World!"
@@ -1,6 +0,0 @@
1
- -e .
2
-
3
- pytest >=7.0.1,<8.0.0
4
- coverage[toml] >=6.2,<8.0
5
- mypy ==1.4.1
6
- ruff ==0.2.0
@@ -1,7 +0,0 @@
1
- #!/usr/bin/env bash
2
-
3
- set -e
4
-
5
- export DYLD_FALLBACK_LIBRARY_PATH="/opt/homebrew/lib"
6
-
7
- mkdocs serve --config-file mkdocs.insiders.yml
@@ -1,7 +0,0 @@
1
- #!/usr/bin/env bash
2
-
3
- set -e
4
- set -x
5
-
6
- # Check README.md is up to date
7
- diff --brief docs/index.md README.md
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes