Skip to content

Commit b169f2a

Browse files
authored
Merge pull request #833 from tiran/use_pypi_org_metadata
feat: setting for use pypi.org metadata
2 parents e20b656 + fdb8ea4 commit b169f2a

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

src/fromager/packagesettings.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,15 @@ class ResolverDist(pydantic.BaseModel):
192192
.. versionadded:: 0.52
193193
"""
194194

195+
use_pypi_org_metadata: bool | None = None
196+
"""Can use metadata from pypi.org JSON / Simple API?
197+
198+
None (default) is for auto-setting. Packages with customizations (config,
199+
patches, plugins) don't use pypi.org metadata by default.
200+
201+
.. versionadded:: 0.70
202+
"""
203+
195204
@pydantic.model_validator(mode="after")
196205
def validate_ignore_platform(self) -> typing.Self:
197206
if self.ignore_platform and not self.include_wheels:
@@ -814,6 +823,21 @@ def resolver_ignore_platform(self) -> bool:
814823
"""Ignore the platform when resolving with wheels?"""
815824
return self._ps.resolver_dist.ignore_platform
816825

826+
@property
827+
def use_pypi_org_metadata(self) -> bool:
828+
"""Can use metadata from pypi.org JSON / Simple API?
829+
830+
By default, packages with customizations do not use public
831+
pypi.org metadata.
832+
"""
833+
ps = self._ps
834+
flag = ps.resolver_dist.use_pypi_org_metadata
835+
if flag is not None:
836+
# flag is set
837+
return flag
838+
# return True if package does not have any customizations
839+
return not self.has_customizations
840+
817841
def build_dir(self, sdist_root_dir: pathlib.Path) -> pathlib.Path:
818842
"""Build directory for package (e.g. subdirectory)"""
819843
build_dir = self._ps.build_dir

tests/test_packagesettings.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
"include_wheels": True,
8080
"sdist_server_url": "https://sdist.test/egg",
8181
"ignore_platform": True,
82+
"use_pypi_org_metadata": True,
8283
},
8384
"variants": {
8485
"cpu": {
@@ -138,6 +139,7 @@
138139
"include_sdists": True,
139140
"include_wheels": False,
140141
"ignore_platform": False,
142+
"use_pypi_org_metadata": None,
141143
},
142144
"variants": {},
143145
}
@@ -176,6 +178,7 @@
176178
"include_sdists": True,
177179
"include_wheels": False,
178180
"ignore_platform": False,
181+
"use_pypi_org_metadata": None,
179182
},
180183
"variants": {
181184
"cpu": {
@@ -785,3 +788,16 @@ def test_pbi_annotations(testdata_context: context.WorkContext) -> None:
785788

786789
pbi = testdata_context.settings.package_build_info(TEST_EMPTY_PKG)
787790
assert pbi.annotations == {}
791+
792+
793+
def test_use_pypi_org_metadata(testdata_context: context.WorkContext) -> None:
794+
pbi = testdata_context.settings.package_build_info(TEST_PKG)
795+
assert pbi.use_pypi_org_metadata
796+
797+
pbi = testdata_context.settings.package_build_info(TEST_EMPTY_PKG)
798+
assert not pbi.use_pypi_org_metadata
799+
800+
pbi = testdata_context.settings.package_build_info(
801+
"somepackage_without_customization"
802+
)
803+
assert pbi.use_pypi_org_metadata

tests/testdata/context/overrides/settings/test_pkg.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ resolver_dist:
4040
include_sdists: true
4141
include_wheels: true
4242
ignore_platform: true
43+
use_pypi_org_metadata: true
4344
variants:
4445
cpu:
4546
annotations:

0 commit comments

Comments
 (0)