Skip to content

Commit ac91ba5

Browse files
committed
Bug 1782785 - Patch poetry inside the virtualenv to fix the PyPi repository hash issue r=firefox-build-system-reviewers,glandium
There is a bug in Poetry 1.2.0a2 caused by a breaking change on PyPi's end: pypi/warehouse#11775 This bug was fixed in Poetry 1.2.0b3, but 1.2.0b1 dropped support for Python 3.6, which is a requirement for us. As a temporary workaround, we can patch the fix into our virtualenv's copy of Poetry. This patch should be removed once we switch to using a newer version of Poetry. Differential Revision: https://phabricator.services.mozilla.com/D161544
1 parent 15fbb1a commit ac91ba5

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

python/mozbuild/mozbuild/vendor/vendor_python.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ def vendor(self, keep_extra_files=False):
4848
self.populate_logger()
4949
self.log_manager.enable_unstructured()
5050

51+
self.apply_patches()
52+
5153
vendor_dir = Path(self.topsrcdir) / "third_party" / "python"
5254
requirements_in = vendor_dir / "requirements.in"
5355
poetry_lockfile = vendor_dir / "poetry.lock"
@@ -163,6 +165,48 @@ def _extract(self, src, dest, keep_extra_files=False):
163165
mozfile.move(extracted_package_dir, package_dir)
164166
_denormalize_symlinks(package_dir)
165167

168+
def apply_patches(self):
169+
self._patch_poetry_pypi_repository()
170+
171+
def _patch_poetry_pypi_repository(self):
172+
# There is a bug in Poetry 1.2.0a2 caused by a breaking change
173+
# on PyPi's end: https://github.com/pypi/warehouse/pull/11775
174+
# This bug was fixed in Poetry 1.2.0b3, but 1.2.0b1 dropped
175+
# support for Python 3.6, which is a requirement for us.
176+
# As a temporary workaround, we can patch the fix into our
177+
# virtualenv's copy of Poetry. This patch should be removed
178+
# once we switch to using a newer version of Poetry.
179+
venv = self.virtualenv_manager._virtualenv
180+
181+
# Get the last element since on Windows the
182+
# first element is the virtualenv root
183+
site_packages = Path(venv.site_packages_dirs()[-1])
184+
expected_poetry_dist_info = site_packages / "poetry-1.2.0a2.dist-info"
185+
186+
# If the specific release of poetry isn't in the site-packages directory
187+
# we should not attempt to patch.
188+
if not expected_poetry_dist_info.exists():
189+
print(
190+
f'The version of Poetry that needs patching ("{expected_poetry_dist_info.name}") '
191+
f'could not be found in the "{self.virtualenv_manager._site_name}" virtualenv. '
192+
f"Can this patch be removed?"
193+
)
194+
return
195+
196+
file_to_patch = site_packages / "poetry" / "repositories" / "pypi_repository.py"
197+
198+
with file_to_patch.open(mode="r") as file:
199+
contents = file.read()
200+
201+
contents = contents.replace(
202+
'version_info = json_data["releases"][version]',
203+
'version_info = json_data["urls"]',
204+
)
205+
206+
print(f'Patching "{file_to_patch}"')
207+
with file_to_patch.open(mode="w") as file:
208+
file.write(contents)
209+
166210

167211
def _sort_requirements_in(requirements_in: Path):
168212
requirements = {}

0 commit comments

Comments
 (0)