Skip to content

Commit 5ea0449

Browse files
committed
feat: update tests and parser
1 parent fd24c60 commit 5ea0449

File tree

6 files changed

+492
-4
lines changed

6 files changed

+492
-4
lines changed

pkg/lockfile/parse-pylock.go

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,24 @@ import (
77
"github.com/BurntSushi/toml"
88
)
99

10+
type pylockVCS struct {
11+
Type string `toml:"type"`
12+
Commit string `toml:"commit-id"`
13+
}
14+
15+
type pylockDirectory struct {
16+
Path string `toml:"path"`
17+
}
18+
1019
type PylockPackage struct {
11-
Name string `toml:"name"`
12-
Version string `toml:"version"`
20+
Name string `toml:"name"`
21+
Version string `toml:"version"`
22+
VCS pylockVCS `toml:"vcs"`
23+
Directory pylockDirectory `toml:"directory"`
1324
}
1425

1526
type PylockLockfile struct {
27+
Version string `toml:"lock-version"`
1628
Packages []PylockPackage `toml:"packages"`
1729
}
1830

@@ -36,12 +48,23 @@ func ParsePylock(pathToLockfile string) ([]PackageDetails, error) {
3648
packages := make([]PackageDetails, 0, len(parsedLockfile.Packages))
3749

3850
for _, pkg := range parsedLockfile.Packages {
39-
packages = append(packages, PackageDetails{
51+
// this is likely the root package, which is sometimes included in the lockfile
52+
if pkg.Version == "" && pkg.Directory.Path == "." {
53+
continue
54+
}
55+
56+
pkgDetails := PackageDetails{
4057
Name: pkg.Name,
4158
Version: pkg.Version,
4259
Ecosystem: PylockEcosystem,
4360
CompareAs: PylockEcosystem,
44-
})
61+
}
62+
63+
if pkg.VCS.Commit != "" {
64+
pkgDetails.Commit = pkg.VCS.Commit
65+
}
66+
67+
packages = append(packages, pkgDetails)
4568
}
4669

4770
return packages, nil

pkg/lockfile/parse-pylock_test.go

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,189 @@ func TestParsePylock_Example(t *testing.T) {
101101
},
102102
})
103103
}
104+
105+
func TestParsePylock_PackageWithCommits(t *testing.T) {
106+
t.Parallel()
107+
108+
packages, err := lockfile.ParsePylock("testdata/pylock/commits.toml")
109+
110+
if err != nil {
111+
t.Errorf("Got unexpected error: %v", err)
112+
}
113+
114+
expectPackages(t, packages, []lockfile.PackageDetails{
115+
{
116+
Name: "click",
117+
Version: "8.2.1",
118+
Ecosystem: lockfile.PylockEcosystem,
119+
CompareAs: lockfile.PylockEcosystem,
120+
},
121+
{
122+
Name: "mleroc",
123+
Version: "0.1.0",
124+
Ecosystem: lockfile.PylockEcosystem,
125+
CompareAs: lockfile.PylockEcosystem,
126+
Commit: "735093f03c4d8be70bfaaae44074ac92d7419b6d",
127+
},
128+
{
129+
Name: "packaging",
130+
Version: "24.2",
131+
Ecosystem: lockfile.PylockEcosystem,
132+
CompareAs: lockfile.PylockEcosystem,
133+
},
134+
{
135+
Name: "pathspec",
136+
Version: "0.12.1",
137+
Ecosystem: lockfile.PylockEcosystem,
138+
CompareAs: lockfile.PylockEcosystem,
139+
},
140+
{
141+
Name: "python-dateutil",
142+
Version: "2.9.0.post0",
143+
Ecosystem: lockfile.PylockEcosystem,
144+
CompareAs: lockfile.PylockEcosystem,
145+
},
146+
{
147+
Name: "scikit-learn",
148+
Version: "1.6.1",
149+
Ecosystem: lockfile.PylockEcosystem,
150+
CompareAs: lockfile.PylockEcosystem,
151+
},
152+
{
153+
Name: "tqdm",
154+
Version: "4.67.1",
155+
Ecosystem: lockfile.PylockEcosystem,
156+
CompareAs: lockfile.PylockEcosystem,
157+
},
158+
})
159+
}
160+
161+
func TestParsePylock_CreatedByPipWithJustSelf(t *testing.T) {
162+
t.Parallel()
163+
164+
packages, err := lockfile.ParsePylock("testdata/pylock/pip-just-self.toml")
165+
166+
if err != nil {
167+
t.Errorf("Got unexpected error: %v", err)
168+
}
169+
170+
expectPackages(t, packages, []lockfile.PackageDetails{})
171+
}
172+
173+
func TestParsePylock_CreatedByPip(t *testing.T) {
174+
t.Parallel()
175+
176+
// from https://peps.python.org/pep-0751/#example
177+
packages, err := lockfile.ParsePylock("testdata/pylock/pip-full.toml")
178+
179+
if err != nil {
180+
t.Errorf("Got unexpected error: %v", err)
181+
}
182+
183+
expectPackages(t, packages, []lockfile.PackageDetails{
184+
{
185+
Name: "annotated-types",
186+
Version: "0.7.0",
187+
Ecosystem: lockfile.PylockEcosystem,
188+
CompareAs: lockfile.PylockEcosystem,
189+
},
190+
{
191+
Name: "packaging",
192+
Version: "25.0",
193+
Ecosystem: lockfile.PylockEcosystem,
194+
CompareAs: lockfile.PylockEcosystem,
195+
},
196+
{
197+
Name: "pyproject-toml",
198+
Version: "0.1.0",
199+
Ecosystem: lockfile.PylockEcosystem,
200+
CompareAs: lockfile.PylockEcosystem,
201+
},
202+
{
203+
Name: "setuptools",
204+
Version: "80.9.0",
205+
Ecosystem: lockfile.PylockEcosystem,
206+
CompareAs: lockfile.PylockEcosystem,
207+
},
208+
{
209+
Name: "wheel",
210+
Version: "0.45.1",
211+
Ecosystem: lockfile.PylockEcosystem,
212+
CompareAs: lockfile.PylockEcosystem,
213+
},
214+
})
215+
}
216+
217+
func TestParsePylock_CreatedByPdm(t *testing.T) {
218+
t.Parallel()
219+
220+
// from https://peps.python.org/pep-0751/#example
221+
packages, err := lockfile.ParsePylock("testdata/pylock/pdm-full.toml")
222+
223+
if err != nil {
224+
t.Errorf("Got unexpected error: %v", err)
225+
}
226+
227+
expectPackages(t, packages, []lockfile.PackageDetails{
228+
{
229+
Name: "certifi",
230+
Version: "2025.1.31",
231+
Ecosystem: lockfile.PylockEcosystem,
232+
CompareAs: lockfile.PylockEcosystem,
233+
},
234+
{
235+
Name: "chardet",
236+
Version: "3.0.4",
237+
Ecosystem: lockfile.PylockEcosystem,
238+
CompareAs: lockfile.PylockEcosystem,
239+
},
240+
{
241+
Name: "charset-normalizer",
242+
Version: "2.0.12",
243+
Ecosystem: lockfile.PylockEcosystem,
244+
CompareAs: lockfile.PylockEcosystem,
245+
},
246+
{
247+
Name: "colorama",
248+
Version: "0.3.9",
249+
Ecosystem: lockfile.PylockEcosystem,
250+
CompareAs: lockfile.PylockEcosystem,
251+
},
252+
{
253+
Name: "idna",
254+
Version: "2.7",
255+
Ecosystem: lockfile.PylockEcosystem,
256+
CompareAs: lockfile.PylockEcosystem,
257+
},
258+
{
259+
Name: "py",
260+
Version: "1.4.34",
261+
Ecosystem: lockfile.PylockEcosystem,
262+
CompareAs: lockfile.PylockEcosystem,
263+
},
264+
{
265+
Name: "pytest",
266+
Version: "3.2.5",
267+
Ecosystem: lockfile.PylockEcosystem,
268+
CompareAs: lockfile.PylockEcosystem,
269+
},
270+
{
271+
Name: "requests",
272+
Version: "2.27.1",
273+
Ecosystem: lockfile.PylockEcosystem,
274+
CompareAs: lockfile.PylockEcosystem,
275+
},
276+
{
277+
Name: "setuptools",
278+
Version: "39.2.0",
279+
Ecosystem: lockfile.PylockEcosystem,
280+
CompareAs: lockfile.PylockEcosystem,
281+
},
282+
{
283+
Name: "urllib3",
284+
Version: "1.26.20",
285+
Ecosystem: lockfile.PylockEcosystem,
286+
CompareAs: lockfile.PylockEcosystem,
287+
},
288+
})
289+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# This file was autogenerated by uv via the following command:
2+
# uv export -o pylock.toml
3+
lock-version = "1.0"
4+
created-by = "uv"
5+
requires-python = ">=3.11"
6+
7+
[[packages]]
8+
name = "click"
9+
version = "8.2.1"
10+
index = "https://pypi.org/simple"
11+
sdist = { url = "https://files.pythonhosted.org/packages/60/6c/8ca2efa64cf75a977a0d7fac081354553ebe483345c734fb6b6515d96bbc/click-8.2.1.tar.gz", upload-time = 2025-05-20T23:19:49Z, size = 286342, hashes = { sha256 = "27c491cc05d968d271d5a1db13e3b5a184636d9d930f148c50b038f0d0646202" } }
12+
wheels = [{ url = "https://files.pythonhosted.org/packages/85/32/10bb5764d90a8eee674e9dc6f4db6a0ab47c8c4d0d83c27f7c39ac415a4d/click-8.2.1-py3-none-any.whl", upload-time = 2025-05-20T23:19:47Z, size = 102215, hashes = { sha256 = "61a3265b914e850b85317d0b3109c7f8cd35a670f963866005d6ef1d5175a12b" } }]
13+
14+
[[packages]]
15+
name = "mleroc"
16+
version = "0.1.0"
17+
vcs = { type = "git", url = "https://github.com/Veggente/mleroc.git", commit-id = "735093f03c4d8be70bfaaae44074ac92d7419b6d" }
18+
19+
[[packages]]
20+
name = "net-inf-eval"
21+
directory = { path = ".", editable = true }
22+
23+
[[packages]]
24+
name = "packaging"
25+
version = "24.2"
26+
index = "https://pypi.org/simple"
27+
sdist = { url = "https://files.pythonhosted.org/packages/d0/63/68dbb6eb2de9cb10ee4c9c14a0148804425e13c4fb20d61cce69f53106da/packaging-24.2.tar.gz", upload-time = 2024-11-08T09:47:47Z, size = 163950, hashes = { sha256 = "c228a6dc5e932d346bc5739379109d49e8853dd8223571c7c5b55260edc0b97f" } }
28+
wheels = [{ url = "https://files.pythonhosted.org/packages/88/ef/eb23f262cca3c0c4eb7ab1933c3b1f03d021f2c48f54763065b6f0e321be/packaging-24.2-py3-none-any.whl", upload-time = 2024-11-08T09:47:44Z, size = 65451, hashes = { sha256 = "09abb1bccd265c01f4a3aa3f7a7db064b36514d2cba19a2f694fe6150451a759" } }]
29+
30+
[[packages]]
31+
name = "pathspec"
32+
version = "0.12.1"
33+
index = "https://pypi.org/simple"
34+
sdist = { url = "https://files.pythonhosted.org/packages/ca/bc/f35b8446f4531a7cb215605d100cd88b7ac6f44ab3fc94870c120ab3adbf/pathspec-0.12.1.tar.gz", upload-time = 2023-12-10T22:30:45Z, size = 51043, hashes = { sha256 = "a482d51503a1ab33b1c67a6c3813a26953dbdc71c31dacaef9a838c4e29f5712" } }
35+
wheels = [{ url = "https://files.pythonhosted.org/packages/cc/20/ff623b09d963f88bfde16306a54e12ee5ea43e9b597108672ff3a408aad6/pathspec-0.12.1-py3-none-any.whl", upload-time = 2023-12-10T22:30:43Z, size = 31191, hashes = { sha256 = "a0d503e138a4c123b27490a4f7beda6a01c6f288df0e4a8b79c7eb0dc7b4cc08" } }]
36+
37+
[[packages]]
38+
name = "python-dateutil"
39+
version = "2.9.0.post0"
40+
index = "https://pypi.org/simple"
41+
sdist = { url = "https://files.pythonhosted.org/packages/66/c0/0c8b6ad9f17a802ee498c46e004a0eb49bc148f2fd230864601a86dcf6db/python-dateutil-2.9.0.post0.tar.gz", upload-time = 2024-03-01T18:36:20Z, size = 342432, hashes = { sha256 = "37dd54208da7e1cd875388217d5e00ebd4179249f90fb72437e91a35459a0ad3" } }
42+
wheels = [{ url = "https://files.pythonhosted.org/packages/ec/57/56b9bcc3c9c6a792fcbaf139543cee77261f3651ca9da0c93f5c1221264b/python_dateutil-2.9.0.post0-py2.py3-none-any.whl", upload-time = 2024-03-01T18:36:18Z, size = 229892, hashes = { sha256 = "a8b2bc7bffae282281c8140a97d3aa9c14da0b136dfe83f850eea9a5f7470427" } }]
43+
44+
[[packages]]
45+
name = "scikit-learn"
46+
version = "1.6.1"
47+
index = "https://pypi.org/simple"
48+
sdist = { url = "https://files.pythonhosted.org/packages/9e/a5/4ae3b3a0755f7b35a280ac90b28817d1f380318973cff14075ab41ef50d9/scikit_learn-1.6.1.tar.gz", upload-time = 2025-01-10T08:07:55Z, size = 7068312, hashes = { sha256 = "b4fc2525eca2c69a59260f583c56a7557c6ccdf8deafdba6e060f94c1c59738e" } }
49+
wheels = [
50+
{ url = "https://files.pythonhosted.org/packages/6c/2a/e291c29670795406a824567d1dfc91db7b699799a002fdaa452bceea8f6e/scikit_learn-1.6.1-cp311-cp311-macosx_10_9_x86_64.whl", upload-time = 2025-01-10T08:06:16Z, size = 12102620, hashes = { sha256 = "72abc587c75234935e97d09aa4913a82f7b03ee0b74111dcc2881cba3c5a7b33" } },
51+
{ url = "https://files.pythonhosted.org/packages/25/92/ee1d7a00bb6b8c55755d4984fd82608603a3cc59959245068ce32e7fb808/scikit_learn-1.6.1-cp311-cp311-macosx_12_0_arm64.whl", upload-time = 2025-01-10T08:06:21Z, size = 11116234, hashes = { sha256 = "b3b00cdc8f1317b5f33191df1386c0befd16625f49d979fe77a8d44cae82410d" } },
52+
{ url = "https://files.pythonhosted.org/packages/30/cd/ed4399485ef364bb25f388ab438e3724e60dc218c547a407b6e90ccccaef/scikit_learn-1.6.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", upload-time = 2025-01-10T08:06:27Z, size = 12592155, hashes = { sha256 = "dc4765af3386811c3ca21638f63b9cf5ecf66261cc4815c1db3f1e7dc7b79db2" } },
53+
{ url = "https://files.pythonhosted.org/packages/a8/f3/62fc9a5a659bb58a03cdd7e258956a5824bdc9b4bb3c5d932f55880be569/scikit_learn-1.6.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", upload-time = 2025-01-10T08:06:32Z, size = 13497069, hashes = { sha256 = "25fc636bdaf1cc2f4a124a116312d837148b5e10872147bdaf4887926b8c03d8" } },
54+
{ url = "https://files.pythonhosted.org/packages/a1/a6/c5b78606743a1f28eae8f11973de6613a5ee87366796583fb74c67d54939/scikit_learn-1.6.1-cp311-cp311-win_amd64.whl", upload-time = 2025-01-10T08:06:35Z, size = 11139809, hashes = { sha256 = "fa909b1a36e000a03c382aade0bd2063fd5680ff8b8e501660c0f59f021a6415" } },
55+
{ url = "https://files.pythonhosted.org/packages/0a/18/c797c9b8c10380d05616db3bfb48e2a3358c767affd0857d56c2eb501caa/scikit_learn-1.6.1-cp312-cp312-macosx_10_13_x86_64.whl", upload-time = 2025-01-10T08:06:40Z, size = 12104516, hashes = { sha256 = "926f207c804104677af4857b2c609940b743d04c4c35ce0ddc8ff4f053cddc1b" } },
56+
{ url = "https://files.pythonhosted.org/packages/c4/b7/2e35f8e289ab70108f8cbb2e7a2208f0575dc704749721286519dcf35f6f/scikit_learn-1.6.1-cp312-cp312-macosx_12_0_arm64.whl", upload-time = 2025-01-10T08:06:43Z, size = 11167837, hashes = { sha256 = "2c2cae262064e6a9b77eee1c8e768fc46aa0b8338c6a8297b9b6759720ec0ff2" } },
57+
{ url = "https://files.pythonhosted.org/packages/a4/f6/ff7beaeb644bcad72bcfd5a03ff36d32ee4e53a8b29a639f11bcb65d06cd/scikit_learn-1.6.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", upload-time = 2025-01-10T08:06:47Z, size = 12253728, hashes = { sha256 = "1061b7c028a8663fb9a1a1baf9317b64a257fcb036dae5c8752b2abef31d136f" } },
58+
{ url = "https://files.pythonhosted.org/packages/29/7a/8bce8968883e9465de20be15542f4c7e221952441727c4dad24d534c6d99/scikit_learn-1.6.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", upload-time = 2025-01-10T08:06:50Z, size = 13147700, hashes = { sha256 = "2e69fab4ebfc9c9b580a7a80111b43d214ab06250f8a7ef590a4edf72464dd86" } },
59+
{ url = "https://files.pythonhosted.org/packages/62/27/585859e72e117fe861c2079bcba35591a84f801e21bc1ab85bce6ce60305/scikit_learn-1.6.1-cp312-cp312-win_amd64.whl", upload-time = 2025-01-10T08:06:54Z, size = 11110613, hashes = { sha256 = "70b1d7e85b1c96383f872a519b3375f92f14731e279a7b4c6cfd650cf5dffc52" } },
60+
{ url = "https://files.pythonhosted.org/packages/2e/59/8eb1872ca87009bdcdb7f3cdc679ad557b992c12f4b61f9250659e592c63/scikit_learn-1.6.1-cp313-cp313-macosx_10_13_x86_64.whl", upload-time = 2025-01-10T08:06:58Z, size = 12010001, hashes = { sha256 = "2ffa1e9e25b3d93990e74a4be2c2fc61ee5af85811562f1288d5d055880c4322" } },
61+
{ url = "https://files.pythonhosted.org/packages/9d/05/f2fc4effc5b32e525408524c982c468c29d22f828834f0625c5ef3d601be/scikit_learn-1.6.1-cp313-cp313-macosx_12_0_arm64.whl", upload-time = 2025-01-10T08:07:01Z, size = 11096360, hashes = { sha256 = "dc5cf3d68c5a20ad6d571584c0750ec641cc46aeef1c1507be51300e6003a7e1" } },
62+
{ url = "https://files.pythonhosted.org/packages/c8/e4/4195d52cf4f113573fb8ebc44ed5a81bd511a92c0228889125fac2f4c3d1/scikit_learn-1.6.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", upload-time = 2025-01-10T08:07:06Z, size = 12209004, hashes = { sha256 = "c06beb2e839ecc641366000ca84f3cf6fa9faa1777e29cf0c04be6e4d096a348" } },
63+
{ url = "https://files.pythonhosted.org/packages/94/be/47e16cdd1e7fcf97d95b3cb08bde1abb13e627861af427a3651fcb80b517/scikit_learn-1.6.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", upload-time = 2025-01-10T08:07:11Z, size = 13171776, hashes = { sha256 = "e8ca8cb270fee8f1f76fa9bfd5c3507d60c6438bbee5687f81042e2bb98e5a97" } },
64+
{ url = "https://files.pythonhosted.org/packages/34/b0/ca92b90859070a1487827dbc672f998da95ce83edce1270fc23f96f1f61a/scikit_learn-1.6.1-cp313-cp313-win_amd64.whl", upload-time = 2025-01-10T08:07:16Z, size = 11071865, hashes = { sha256 = "7a1c43c8ec9fde528d664d947dc4c0789be4077a3647f232869f41d9bf50e0fb" } },
65+
{ url = "https://files.pythonhosted.org/packages/12/ae/993b0fb24a356e71e9a894e42b8a9eec528d4c70217353a1cd7a48bc25d4/scikit_learn-1.6.1-cp313-cp313t-macosx_10_13_x86_64.whl", upload-time = 2025-01-10T08:07:20Z, size = 11955804, hashes = { sha256 = "a17c1dea1d56dcda2fac315712f3651a1fea86565b64b48fa1bc090249cbf236" } },
66+
{ url = "https://files.pythonhosted.org/packages/d6/54/32fa2ee591af44507eac86406fa6bba968d1eb22831494470d0a2e4a1eb1/scikit_learn-1.6.1-cp313-cp313t-macosx_12_0_arm64.whl", upload-time = 2025-01-10T08:07:23Z, size = 11100530, hashes = { sha256 = "6a7aa5f9908f0f28f4edaa6963c0a6183f1911e63a69aa03782f0d924c830a35" } },
67+
{ url = "https://files.pythonhosted.org/packages/3f/58/55856da1adec655bdce77b502e94a267bf40a8c0b89f8622837f89503b5a/scikit_learn-1.6.1-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", upload-time = 2025-01-10T08:07:26Z, size = 12433852, hashes = { sha256 = "0650e730afb87402baa88afbf31c07b84c98272622aaba002559b614600ca691" } },
68+
{ url = "https://files.pythonhosted.org/packages/ff/4f/c83853af13901a574f8f13b645467285a48940f185b690936bb700a50863/scikit_learn-1.6.1-cp313-cp313t-win_amd64.whl", upload-time = 2025-01-10T08:07:31Z, size = 11337256, hashes = { sha256 = "3f59fe08dc03ea158605170eb52b22a105f238a5d512c4470ddeca71feae8e5f" } },
69+
]
70+
71+
[[packages]]
72+
name = "tqdm"
73+
version = "4.67.1"
74+
index = "https://pypi.org/simple"
75+
sdist = { url = "https://files.pythonhosted.org/packages/a8/4b/29b4ef32e036bb34e4ab51796dd745cdba7ed47ad142a9f4a1eb8e0c744d/tqdm-4.67.1.tar.gz", upload-time = 2024-11-24T20:12:22Z, size = 169737, hashes = { sha256 = "f8aef9c52c08c13a65f30ea34f4e5aac3fd1a34959879d7e59e63027286627f2" } }
76+
wheels = [{ url = "https://files.pythonhosted.org/packages/d0/30/dc54f88dd4a2b5dc8a0279bdd7270e735851848b762aeb1c1184ed1f6b14/tqdm-4.67.1-py3-none-any.whl", upload-time = 2024-11-24T20:12:19Z, size = 78540, hashes = { sha256 = "26445eca388f82e72884e0d580d5464cd801a3ea01e63e5601bdff9ba6a48de2" } }]

0 commit comments

Comments
 (0)