vercel-headers-bundle 0.7.1__tar.gz → 0.7.2__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.
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: vercel-headers-bundle
3
- Version: 0.7.1
3
+ Version: 0.7.2
4
4
  Summary: Request header helpers for Vercel Python applications
5
5
  License-Expression: MIT
6
6
  License-File: LICENSE
@@ -8,6 +8,7 @@ from typing import Any
8
8
 
9
9
  from hatchling.metadata.plugin.interface import MetadataHookInterface
10
10
  from packaging.requirements import Requirement
11
+ from packaging.specifiers import SpecifierSet
11
12
 
12
13
  try:
13
14
  import tomllib
@@ -29,8 +30,10 @@ class WorkspaceDependenciesMetadataHook(MetadataHookInterface):
29
30
  }
30
31
  workspace_root = _find_workspace_root(Path(self.root))
31
32
 
33
+ package = pyproject.get("project", {}).get("name", str(self.root))
34
+
32
35
  metadata["dependencies"] = [
33
- _rewrite_dependency(requirement, workspace_names, workspace_root)
36
+ _rewrite_dependency(requirement, workspace_names, workspace_root, package)
34
37
  for requirement in dependency_table.get("dependencies", [])
35
38
  ]
36
39
 
@@ -55,24 +58,56 @@ def _rewrite_dependency(
55
58
  requirement: str,
56
59
  workspace_names: set[str],
57
60
  workspace_root: Path | None,
61
+ package: str,
58
62
  ) -> str:
59
63
  parsed = Requirement(requirement)
60
64
  normalized = parsed.name.lower().replace("_", "-")
61
65
  if normalized not in workspace_names or workspace_root is None:
62
66
  return requirement
63
- return _with_lower_bound(parsed, _read_workspace_version(workspace_root, normalized))
67
+ version = _read_workspace_version(workspace_root, normalized)
68
+ return _with_lower_bound(parsed, version, requirement, package)
64
69
 
65
70
 
66
- def _with_lower_bound(requirement: Requirement, version: str) -> str:
71
+ def _with_lower_bound(requirement: Requirement, version: str, declared: str, package: str) -> str:
67
72
  extras = f"[{','.join(sorted(requirement.extras))}]" if requirement.extras else ""
68
73
  specifiers = [
69
74
  str(specifier) for specifier in requirement.specifier if specifier.operator != ">="
70
75
  ]
71
76
  specifier_text = ",".join([f">={version}", *specifiers])
77
+ _reject_unsatisfiable(package, requirement.name, declared, specifier_text, version)
72
78
  marker = f" ; {requirement.marker}" if requirement.marker else ""
73
79
  return f"{requirement.name}{extras}{specifier_text}{marker}"
74
80
 
75
81
 
82
+ def _reject_unsatisfiable(
83
+ package: str, dependency: str, declared: str, specifier_text: str, version: str
84
+ ) -> None:
85
+ """Refuse to publish a bound that no version of *dependency* can satisfy.
86
+
87
+ The lower bound is generated from the sibling's current version while the
88
+ rest of the specifier is whatever the package declared, so a hand-written
89
+ upper bound that the sibling has since reached produces something like
90
+ ``>=0.3.0,<0.3.0``. Nothing rejects that later: the wheel builds, uploads,
91
+ and only fails when someone tries to install it. Fail the build instead --
92
+ CI builds every package, so the bump that crosses the bound is caught by
93
+ its own pull request.
94
+
95
+ The test is that the sibling version *being released* satisfies the bound,
96
+ which is narrower than the range being non-empty: `>=0.7.1,!=0.7.1` leaves
97
+ room for a later version, but says the release under way is unusable.
98
+ """
99
+ # `prereleases=True` so a workspace version like `0.4.0b1` is judged
100
+ # against its own bound rather than excluded for being a prerelease.
101
+ if SpecifierSet(specifier_text).contains(version, prereleases=True):
102
+ return
103
+ raise RuntimeError(
104
+ f"{package} declares {declared!r}, but {dependency} is at {version} in "
105
+ f"the workspace, so publishing would pin {dependency}{specifier_text} — "
106
+ f"which excludes {version} itself, the version being released. "
107
+ f"Raise the upper bound in [tool.vercel.release.dependencies] of {package}."
108
+ )
109
+
110
+
76
111
  def _read_workspace_version(workspace_root: Path, package_name: str) -> str:
77
112
  for pattern in ("src/*/pyproject.toml", "integrations/*/pyproject.toml"):
78
113
  for pyproject_path in workspace_root.glob(pattern):
@@ -52,6 +52,11 @@ exclude = [
52
52
  include = "../../scripts/poe/poe.toml"
53
53
  verbosity = -1
54
54
 
55
+ [tool.mypy]
56
+ cache_dir = "../../.mypy_cache/vercel-headers"
57
+ explicit_package_bases = true
58
+ packages = ["vercel.headers"]
59
+
55
60
  [tool.poe.tasks.typecheck]
56
61
  cmd = "$MYPY"
57
62
 
@@ -68,7 +68,8 @@ class _HeadersLike(Protocol):
68
68
 
69
69
 
70
70
  class _RequestLike(Protocol):
71
- headers: _HeadersLike
71
+ @property
72
+ def headers(self) -> _HeadersLike: ...
72
73
 
73
74
 
74
75
  class Geo(TypedDict, total=False):
@@ -0,0 +1 @@
1
+ __version__ = "0.7.2"
@@ -1 +0,0 @@
1
- __version__ = "0.7.1"