anyenv 0.3.2__tar.gz → 0.3.3__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 (42) hide show
  1. {anyenv-0.3.2 → anyenv-0.3.3}/PKG-INFO +1 -1
  2. {anyenv-0.3.2 → anyenv-0.3.3}/src/anyenv/__init__.py +1 -1
  3. {anyenv-0.3.2 → anyenv-0.3.3}/src/anyenv/download/aiohttp_backend.py +4 -14
  4. {anyenv-0.3.2 → anyenv-0.3.3}/src/anyenv/download/base.py +3 -1
  5. {anyenv-0.3.2 → anyenv-0.3.3}/src/anyenv/download/functional.py +11 -7
  6. {anyenv-0.3.2 → anyenv-0.3.3}/.copier-answers.yml +0 -0
  7. {anyenv-0.3.2 → anyenv-0.3.3}/.github/FUNDING.yml +0 -0
  8. {anyenv-0.3.2 → anyenv-0.3.3}/.github/copilot-instructions.md +0 -0
  9. {anyenv-0.3.2 → anyenv-0.3.3}/.github/dependabot.yml +0 -0
  10. {anyenv-0.3.2 → anyenv-0.3.3}/.github/workflows/build.yml +0 -0
  11. {anyenv-0.3.2 → anyenv-0.3.3}/.github/workflows/documentation.yml +0 -0
  12. {anyenv-0.3.2 → anyenv-0.3.3}/.gitignore +0 -0
  13. {anyenv-0.3.2 → anyenv-0.3.3}/.pre-commit-config.yaml +0 -0
  14. {anyenv-0.3.2 → anyenv-0.3.3}/LICENSE +0 -0
  15. {anyenv-0.3.2 → anyenv-0.3.3}/README.md +0 -0
  16. {anyenv-0.3.2 → anyenv-0.3.3}/docs/.empty +0 -0
  17. {anyenv-0.3.2 → anyenv-0.3.3}/duties.py +0 -0
  18. {anyenv-0.3.2 → anyenv-0.3.3}/mkdocs.yml +0 -0
  19. {anyenv-0.3.2 → anyenv-0.3.3}/overrides/_dummy.txt +0 -0
  20. {anyenv-0.3.2 → anyenv-0.3.3}/pyproject.toml +0 -0
  21. {anyenv-0.3.2 → anyenv-0.3.3}/src/anyenv/async_run.py +0 -0
  22. {anyenv-0.3.2 → anyenv-0.3.3}/src/anyenv/download/__init__.py +0 -0
  23. {anyenv-0.3.2 → anyenv-0.3.3}/src/anyenv/download/exceptions.py +0 -0
  24. {anyenv-0.3.2 → anyenv-0.3.3}/src/anyenv/download/httpx_backend.py +0 -0
  25. {anyenv-0.3.2 → anyenv-0.3.3}/src/anyenv/download/httpx_serializer.py +0 -0
  26. {anyenv-0.3.2 → anyenv-0.3.3}/src/anyenv/download/pyodide_backend.py +0 -0
  27. {anyenv-0.3.2 → anyenv-0.3.3}/src/anyenv/json_tools/__init__.py +0 -0
  28. {anyenv-0.3.2 → anyenv-0.3.3}/src/anyenv/json_tools/dumping.py +0 -0
  29. {anyenv-0.3.2 → anyenv-0.3.3}/src/anyenv/json_tools/loading.py +0 -0
  30. {anyenv-0.3.2 → anyenv-0.3.3}/src/anyenv/package_install/__init__.py +0 -0
  31. {anyenv-0.3.2 → anyenv-0.3.3}/src/anyenv/package_install/base.py +0 -0
  32. {anyenv-0.3.2 → anyenv-0.3.3}/src/anyenv/package_install/functional.py +0 -0
  33. {anyenv-0.3.2 → anyenv-0.3.3}/src/anyenv/package_install/micropip_install.py +0 -0
  34. {anyenv-0.3.2 → anyenv-0.3.3}/src/anyenv/package_install/pip_install.py +0 -0
  35. {anyenv-0.3.2 → anyenv-0.3.3}/src/anyenv/py.typed +0 -0
  36. {anyenv-0.3.2 → anyenv-0.3.3}/src/anyenv/testing.py +0 -0
  37. {anyenv-0.3.2 → anyenv-0.3.3}/src/anyenv/threadgroup/__init__.py +0 -0
  38. {anyenv-0.3.2 → anyenv-0.3.3}/src/anyenv/threadgroup/threadgroup.py +0 -0
  39. {anyenv-0.3.2 → anyenv-0.3.3}/tests/__init__.py +0 -0
  40. {anyenv-0.3.2 → anyenv-0.3.3}/tests/conftest.py +0 -0
  41. {anyenv-0.3.2 → anyenv-0.3.3}/tests/test_download.py +0 -0
  42. {anyenv-0.3.2 → anyenv-0.3.3}/tests/test_threadgroup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: anyenv
3
- Version: 0.3.2
3
+ Version: 0.3.3
4
4
  Summary: Compatibility layer for some basic operations to allow painless operation in PyOdide and Python pre-releases
5
5
  Project-URL: Documentation, https://phil65.github.io/anyenv/
6
6
  Project-URL: Source, https://github.com/phil65/anyenv
@@ -1,6 +1,6 @@
1
1
  """AnyEnv: A library for environment management and utility functions."""
2
2
 
3
- __version__ = "0.3.2"
3
+ __version__ = "0.3.3"
4
4
 
5
5
  from anyenv.async_run import run_sync, run_sync_in_thread
6
6
  from anyenv.download.functional import (
@@ -103,22 +103,12 @@ class AiohttpBackend(HttpBackend):
103
103
  headers: dict[str, str] | None = None,
104
104
  ) -> CachedSession:
105
105
  if cache:
106
- cache_backend = SQLiteBackend(
107
- cache_name=str(self.cache_dir / "http_cache.db"),
108
- expire_after=self.cache_ttl,
109
- )
110
- return CachedSession(
111
- cache=cache_backend,
112
- headers=headers,
113
- base_url=base_url,
114
- )
106
+ path = str(self.cache_dir / "http_cache.db")
107
+ cache_backend = SQLiteBackend(cache_name=path, expire_after=self.cache_ttl)
108
+ return CachedSession(cache=cache_backend, headers=headers, base_url=base_url)
115
109
 
116
110
  # Even when not caching, we use CachedSession for consistent interface
117
- return CachedSession(
118
- expire_after=0, # Disable caching
119
- headers=headers,
120
- base_url=base_url,
121
- )
111
+ return CachedSession(expire_after=0, headers=headers, base_url=base_url)
122
112
 
123
113
  async def request(
124
114
  self,
@@ -19,6 +19,7 @@ if TYPE_CHECKING:
19
19
  T = TypeVar("T")
20
20
  ProgressCallback = Callable[[int, int], Any] # current, total -> Any
21
21
  Method = Literal["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD"]
22
+ DEFAULT_TTL = 3600
22
23
 
23
24
 
24
25
  class HttpResponse(abc.ABC):
@@ -117,7 +118,7 @@ class HttpBackend(abc.ABC):
117
118
  def __init__(
118
119
  self,
119
120
  cache_dir: str | PathLike[str] | None = None,
120
- cache_ttl: int = 3600,
121
+ cache_ttl: int | None = None,
121
122
  ):
122
123
  """Initialize HTTP backend.
123
124
 
@@ -126,6 +127,7 @@ class HttpBackend(abc.ABC):
126
127
  uses platform-specific user cache directory.
127
128
  cache_ttl: Time-to-live for cached responses in seconds.
128
129
  """
130
+ cache_ttl = cache_ttl or DEFAULT_TTL
129
131
  dir_ = cache_dir or user_cache_dir("anyenv", "anyenv")
130
132
  self.cache_dir = pathlib.Path(dir_)
131
133
  self.cache_ttl = cache_ttl
@@ -19,15 +19,13 @@ BackendType = Literal["httpx", "aiohttp", "pyodide"]
19
19
  def _get_default_backend() -> HttpBackend:
20
20
  """Get the best available HTTP backend."""
21
21
  # Try httpx first
22
- if importlib.util.find_spec("httpx") and importlib.util.find_spec("hishel"):
22
+ if importlib.util.find_spec("httpx"):
23
23
  from anyenv.download.httpx_backend import HttpxBackend
24
24
 
25
25
  return HttpxBackend()
26
26
 
27
27
  # Try aiohttp next
28
- if importlib.util.find_spec("aiohttp") and importlib.util.find_spec(
29
- "aiohttp_client_cache"
30
- ):
28
+ if importlib.util.find_spec("aiohttp"):
31
29
  from anyenv.download.aiohttp_backend import AiohttpBackend
32
30
 
33
31
  return AiohttpBackend()
@@ -46,11 +44,17 @@ def _get_default_backend() -> HttpBackend:
46
44
  raise ImportError(msg)
47
45
 
48
46
 
49
- def get_backend(backend_type: BackendType | None = None) -> HttpBackend:
47
+ def get_backend(
48
+ backend_type: BackendType | None = None,
49
+ cache_path: str | os.PathLike[str] | None = None,
50
+ cache_ttl: int | None = None,
51
+ ) -> HttpBackend:
50
52
  """Get a specific HTTP backend or the best available one.
51
53
 
52
54
  Args:
53
55
  backend_type: Optional backend type to use. If None, uses the best available.
56
+ cache_path: Optional path to use for caching. If None, uses a default path.
57
+ cache_ttl: Optional TTL for cached responses. If None, uses a default TTL.
54
58
 
55
59
  Returns:
56
60
  An instance of the selected HTTP backend.
@@ -65,7 +69,7 @@ def get_backend(backend_type: BackendType | None = None) -> HttpBackend:
65
69
  if importlib.util.find_spec("httpx") and importlib.util.find_spec("hishel"):
66
70
  from anyenv.download.httpx_backend import HttpxBackend
67
71
 
68
- return HttpxBackend()
72
+ return HttpxBackend(cache_dir=cache_path, cache_ttl=cache_ttl)
69
73
  msg = "httpx backend requested but httpx or hishel not installed"
70
74
  raise ImportError(msg)
71
75
 
@@ -75,7 +79,7 @@ def get_backend(backend_type: BackendType | None = None) -> HttpBackend:
75
79
  ):
76
80
  from anyenv.download.aiohttp_backend import AiohttpBackend
77
81
 
78
- return AiohttpBackend()
82
+ return AiohttpBackend(cache_dir=cache_path, cache_ttl=cache_ttl)
79
83
  msg = (
80
84
  "aiohttp backend requested but aiohttp or aiohttp_client_cache not installed"
81
85
  )
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes