Merge ~cjwatson/launchpad:canonicalize-python-name into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 633bced55628d7bb767ea4e33c0fadddcdd04726
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:canonicalize-python-name
Merge into: launchpad:master
Diff against target: 138 lines (+86/-1)
4 files modified
lib/lp/archivepublisher/artifactory.py (+6/-1)
lib/lp/archivepublisher/tests/test_artifactory.py (+75/-0)
pyproject.toml (+4/-0)
setup.cfg (+1/-0)
Reviewer Review Type Date Requested Status
Jürgen Gmach Approve
Review via email: mp+429882@code.launchpad.net

Commit message

Canonicalize Python package names for publishing

Description of the change

We'll need to deal with republishing the files that have been published to the wrong place, but we can probably deal with that manually.

To post a comment you must log in.
Revision history for this message
Jürgen Gmach (jugmac00) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/archivepublisher/artifactory.py b/lib/lp/archivepublisher/artifactory.py
2index a2112f5..4bd7f0a 100644
3--- a/lib/lp/archivepublisher/artifactory.py
4+++ b/lib/lp/archivepublisher/artifactory.py
5@@ -18,6 +18,7 @@ from urllib.parse import quote_plus
6 import requests
7 from artifactory import ArtifactoryPath
8 from dohq_artifactory.auth import XJFrogArtApiAuth
9+from packaging import utils as packaging_utils
10 from zope.security.proxy import isinstance as zope_isinstance
11
12 from lp.archivepublisher.diskpool import FileAddActionEnum, poolify
13@@ -58,7 +59,11 @@ def _path_for(
14 package_name = release.getUserDefinedField("package-name")
15 if package_name is None:
16 package_name = source_name
17- path = rootpath / package_name / source_version
18+ path = (
19+ rootpath
20+ / packaging_utils.canonicalize_name(package_name)
21+ / source_version
22+ )
23 elif repository_format == ArchiveRepositoryFormat.CONDA:
24 subdir = release.getUserDefinedField("subdir")
25 if subdir is None:
26diff --git a/lib/lp/archivepublisher/tests/test_artifactory.py b/lib/lp/archivepublisher/tests/test_artifactory.py
27index 86a7d8c..9aea55c 100644
28--- a/lib/lp/archivepublisher/tests/test_artifactory.py
29+++ b/lib/lp/archivepublisher/tests/test_artifactory.py
30@@ -769,6 +769,81 @@ class TestArtifactoryPoolFromLibrarian(TestCaseWithFactory):
31 path.properties,
32 )
33
34+ def test_updateProperties_python_sdist_canonicalizes_name(self):
35+ pool = self.makePool(ArchiveRepositoryFormat.PYTHON)
36+ dses = [
37+ self.factory.makeDistroSeries(
38+ distribution=pool.archive.distribution
39+ )
40+ for _ in range(2)
41+ ]
42+ das = self.factory.makeDistroArchSeries(distroseries=dses[0])
43+ ci_build = self.factory.makeCIBuild(distro_arch_series=das)
44+ spr = self.factory.makeSourcePackageRelease(
45+ archive=pool.archive,
46+ sourcepackagename="python-foo-bar",
47+ version="1.0",
48+ format=SourcePackageType.CI_BUILD,
49+ ci_build=ci_build,
50+ user_defined_fields=[("package-name", "foo_bar")],
51+ )
52+ spph = self.factory.makeSourcePackagePublishingHistory(
53+ archive=pool.archive,
54+ sourcepackagerelease=spr,
55+ distroseries=dses[0],
56+ pocket=PackagePublishingPocket.RELEASE,
57+ component="main",
58+ sourcepackagename="python-foo-bar",
59+ version="1.0",
60+ channel="edge",
61+ format=SourcePackageType.CI_BUILD,
62+ )
63+ spr = spph.sourcepackagerelease
64+ sprf = self.factory.makeSourcePackageReleaseFile(
65+ sourcepackagerelease=spr,
66+ library_file=self.factory.makeLibraryFileAlias(
67+ filename="foo_bar-1.0.tar.gz"
68+ ),
69+ filetype=SourcePackageFileType.SDIST,
70+ )
71+ spphs = [spph]
72+ spphs.append(
73+ spph.copyTo(dses[1], PackagePublishingPocket.RELEASE, pool.archive)
74+ )
75+ transaction.commit()
76+ pool.addFile(None, spr.name, spr.version, sprf)
77+ path = pool.rootpath / "foo-bar" / "1.0" / "foo_bar-1.0.tar.gz"
78+ self.assertTrue(path.exists())
79+ self.assertFalse(path.is_symlink())
80+ self.assertEqual(
81+ {
82+ "launchpad.release-id": ["source:%d" % spr.id],
83+ "launchpad.source-name": ["python-foo-bar"],
84+ "launchpad.source-version": ["1.0"],
85+ "soss.source_url": [
86+ ci_build.git_repository.getCodebrowseUrl()
87+ ],
88+ "soss.commit_id": [ci_build.commit_sha1],
89+ },
90+ path.properties,
91+ )
92+ pool.updateProperties(spr.name, spr.version, [sprf], spphs)
93+ self.assertEqual(
94+ {
95+ "launchpad.release-id": ["source:%d" % spr.id],
96+ "launchpad.source-name": ["python-foo-bar"],
97+ "launchpad.source-version": ["1.0"],
98+ "launchpad.channel": list(
99+ sorted("%s:edge" % ds.name for ds in dses)
100+ ),
101+ "soss.source_url": [
102+ ci_build.git_repository.getCodebrowseUrl()
103+ ],
104+ "soss.commit_id": [ci_build.commit_sha1],
105+ },
106+ path.properties,
107+ )
108+
109 def test_updateProperties_python_wheel(self):
110 pool = self.makePool(ArchiveRepositoryFormat.PYTHON)
111 dses = [
112diff --git a/pyproject.toml b/pyproject.toml
113index 351470d..e553c39 100644
114--- a/pyproject.toml
115+++ b/pyproject.toml
116@@ -62,6 +62,10 @@ module = "lazr.*"
117 ignore_missing_imports = true
118
119 [[tool.mypy.overrides]]
120+module = "packaging"
121+ignore_missing_imports = true
122+
123+[[tool.mypy.overrides]]
124 module = "pymacaroons"
125 ignore_missing_imports = true
126
127diff --git a/setup.cfg b/setup.cfg
128index 367bb34..e69cbc5 100644
129--- a/setup.cfg
130+++ b/setup.cfg
131@@ -71,6 +71,7 @@ install_requires =
132 oops_timeline
133 oops_twisted
134 oops_wsgi
135+ packaging
136 paramiko
137 pkginfo
138 psutil

Subscribers

People subscribed via source and target branches

to status/vote changes: