2 GoCheese -- Python private package repository and caching proxy
3 Copyright (C) 2019-2023 Sergey Matveev <stargrave@stargrave.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, version 3 of the License.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 MDFile = ".metadata.rec"
23 // https://packaging.python.org/specifications/core-metadata/
25 MDFieldMetadataVersion = "Metadata-Version"
27 MDFieldVersion = "Version"
28 MDFieldDescription = "Description"
29 MDFieldPlatform = "Platform"
30 MDFieldSupportedPlatform = "Supported-Platform"
31 MDFieldSummary = "Summary"
32 MDFieldDescriptionContentType = "Description-Content-Type"
33 MDFieldKeywords = "Keywords"
34 MDFieldHomePage = "Home-page"
35 MDFieldAuthor = "Author"
36 MDFieldAuthorEmail = "Author-email"
37 MDFieldMaintainer = "Maintainer"
38 MDFieldMaintainerEmail = "Maintainer-email"
39 MDFieldLicense = "License"
40 MDFieldRequiresDist = "Requires-Dist"
41 MDFieldRequiresPython = "Requires-Python"
42 MDFieldRequiresExternal = "Requires-External"
43 MDFieldProjectURL = "Project-URL"
44 MDFieldProvidesExtra = "Provides-Extra"
45 MDFieldClassifier = "Classifier"
49 MDFieldToRecField = map[string]string{
50 MDFieldMetadataVersion: "MetadataVersion",
52 MDFieldVersion: "Version",
53 MDFieldDescription: "Description",
54 MDFieldPlatform: "Platform",
55 MDFieldSupportedPlatform: "SupportedPlatform",
56 MDFieldSummary: "Summary",
57 MDFieldDescriptionContentType: "DescriptionContentType",
58 MDFieldKeywords: "Keywords",
59 MDFieldHomePage: "HomePage",
60 MDFieldAuthor: "Author",
61 MDFieldAuthorEmail: "AuthorEmail",
62 MDFieldMaintainer: "Maintainer",
63 MDFieldMaintainerEmail: "MaintainerEmail",
64 MDFieldLicense: "License",
65 MDFieldRequiresDist: "RequiresDist",
66 MDFieldRequiresPython: "RequiresPython",
67 MDFieldRequiresExternal: "RequiresExternal",
68 MDFieldProjectURL: "ProjectURL",
69 MDFieldProvidesExtra: "ProvidesExtra",
70 MDFieldClassifier: "Classifier",
72 MDFormToRecField = [][2]string{
73 {"name", MDFieldToRecField[MDFieldName]},
74 {"version", MDFieldToRecField[MDFieldVersion]},
75 {"platform", MDFieldToRecField[MDFieldPlatform]},
76 {"supported_platform", MDFieldToRecField[MDFieldSupportedPlatform]},
77 {"summary", MDFieldToRecField[MDFieldSummary]},
78 {"description", MDFieldToRecField[MDFieldDescription]},
79 {"description_content_type", MDFieldToRecField[MDFieldDescriptionContentType]},
80 {"keywords", MDFieldToRecField[MDFieldKeywords]},
81 {"home_page", MDFieldToRecField[MDFieldHomePage]},
82 {"author", MDFieldToRecField[MDFieldAuthor]},
83 {"author_email", MDFieldToRecField[MDFieldAuthorEmail]},
84 {"maintainer", MDFieldToRecField[MDFieldMaintainer]},
85 {"maintainer_email", MDFieldToRecField[MDFieldMaintainerEmail]},
86 {"license", MDFieldToRecField[MDFieldLicense]},
87 {"classifiers", MDFieldToRecField[MDFieldClassifier]},
88 {"requires_dist", MDFieldToRecField[MDFieldRequiresDist]},
89 {"requires_python", MDFieldToRecField[MDFieldRequiresPython]},
90 {"requires_external", MDFieldToRecField[MDFieldRequiresExternal]},
91 {"project_url", MDFieldToRecField[MDFieldProjectURL]},
92 {"provides_extra", MDFieldToRecField[MDFieldProvidesExtra]},
96 // It should follow https://www.python.org/dev/peps/pep-0566/
98 Name string `json:"name"`
99 Version string `json:"version"`
100 Platform []string `json:"platform,omitempty"`
101 SupportedPlatform []string `json:"supported_platform,omitempty"`
102 Summary string `json:"summary,omitempty"`
103 Description string `json:"description,omitempty"`
104 DescriptionContentType string `json:"description_content_type,omitempty"`
105 Keywords string `json:"keywords,omitempty"`
106 HomePage string `json:"home_page,omitempty"`
107 Author string `json:"author,omitempty"`
108 AuthorEmail string `json:"author_email,omitempty"`
109 Maintainer string `json:"maintainer,omitempty"`
110 MaintainerEmail string `json:"maintainer_email,omitempty"`
111 License string `json:"license,omitempty"`
112 Classifier []string `json:"classifier,omitempty"`
113 RequiresDist []string `json:"requires_dist,omitempty"`
114 RequiresPython string `json:"requires_python,omitempty"`
115 RequiresExternal []string `json:"requires_external,omitempty"`
116 ProjectURL []string `json:"project_url,omitempty"`
117 ProvidesExtra []string `json:"provides_extra,omitempty"`
120 // But current PyPI does not follow PEP-0566, so just ignore some fields
121 type PkgInfoStripped struct {
122 Name string `json:"name"`
123 Version string `json:"version"`
124 Summary string `json:"summary,omitempty"`
125 Description string `json:"description,omitempty"`
126 DescriptionContentType string `json:"description_content_type,omitempty"`
127 Keywords string `json:"keywords,omitempty"`
128 HomePage string `json:"home_page,omitempty"`
129 Author string `json:"author,omitempty"`
130 AuthorEmail string `json:"author_email,omitempty"`
131 Maintainer string `json:"maintainer,omitempty"`
132 MaintainerEmail string `json:"maintainer_email,omitempty"`
133 License string `json:"license,omitempty"`
134 Classifier []string `json:"classifiers,omitempty"`
135 RequiresPython string `json:"requires_python,omitempty"`
136 RequiresDist []string `json:"requires_dist,omitempty"`
139 // Unknown format: no detailed specification available
140 // https://github.com/cooperlees/peps/blob/warehouse_json_api/pep-9999.rst
141 type PkgReleaseInfo struct {
142 Filename string `json:"filename"`
143 Version string `json:"version"`
144 UploadTimeISO8601 string `json:"upload_time_iso_8601"`
145 Size int64 `json:"size"`
146 HasSig bool `json:"has_sig"`
148 Digests map[string]string `json:"digests"`
151 type PkgMeta struct {
152 Info PkgInfo `json:"info"`
153 LastSerial int64 `json:"last_serial"`
154 Releases map[string][]*PkgReleaseInfo `json:"releases"`
155 URLs []*PkgReleaseInfo `json:"urls"`
158 type PkgMetaStripped struct {
159 Info PkgInfoStripped `json:"info"`
160 Releases map[string][]*PkgReleaseInfo `json:"releases"`