// GoCheese -- Python private package repository and caching proxy // Copyright (C) 2019-2024 Sergey Matveev // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, version 3 of the License. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . package main const ( MDFile = ".metadata.rec" // https://packaging.python.org/specifications/core-metadata/ MDVersion = "2.1" MDFieldMetadataVersion = "Metadata-Version" MDFieldName = "Name" MDFieldVersion = "Version" MDFieldDescription = "Description" MDFieldPlatform = "Platform" MDFieldSupportedPlatform = "Supported-Platform" MDFieldSummary = "Summary" MDFieldDescriptionContentType = "Description-Content-Type" MDFieldKeywords = "Keywords" MDFieldHomePage = "Home-page" MDFieldAuthor = "Author" MDFieldAuthorEmail = "Author-email" MDFieldMaintainer = "Maintainer" MDFieldMaintainerEmail = "Maintainer-email" MDFieldLicense = "License" MDFieldRequiresDist = "Requires-Dist" MDFieldRequiresPython = "Requires-Python" MDFieldRequiresExternal = "Requires-External" MDFieldProjectURL = "Project-URL" MDFieldProvidesExtra = "Provides-Extra" MDFieldClassifier = "Classifier" ) var ( MDFieldToRecField = map[string]string{ MDFieldMetadataVersion: "MetadataVersion", MDFieldName: "Name", MDFieldVersion: "Version", MDFieldDescription: "Description", MDFieldPlatform: "Platform", MDFieldSupportedPlatform: "SupportedPlatform", MDFieldSummary: "Summary", MDFieldDescriptionContentType: "DescriptionContentType", MDFieldKeywords: "Keywords", MDFieldHomePage: "HomePage", MDFieldAuthor: "Author", MDFieldAuthorEmail: "AuthorEmail", MDFieldMaintainer: "Maintainer", MDFieldMaintainerEmail: "MaintainerEmail", MDFieldLicense: "License", MDFieldRequiresDist: "RequiresDist", MDFieldRequiresPython: "RequiresPython", MDFieldRequiresExternal: "RequiresExternal", MDFieldProjectURL: "ProjectURL", MDFieldProvidesExtra: "ProvidesExtra", MDFieldClassifier: "Classifier", } MDFormToRecField = [][2]string{ {"name", MDFieldToRecField[MDFieldName]}, {"version", MDFieldToRecField[MDFieldVersion]}, {"platform", MDFieldToRecField[MDFieldPlatform]}, {"supported_platform", MDFieldToRecField[MDFieldSupportedPlatform]}, {"summary", MDFieldToRecField[MDFieldSummary]}, {"description", MDFieldToRecField[MDFieldDescription]}, {"description_content_type", MDFieldToRecField[MDFieldDescriptionContentType]}, {"keywords", MDFieldToRecField[MDFieldKeywords]}, {"home_page", MDFieldToRecField[MDFieldHomePage]}, {"author", MDFieldToRecField[MDFieldAuthor]}, {"author_email", MDFieldToRecField[MDFieldAuthorEmail]}, {"maintainer", MDFieldToRecField[MDFieldMaintainer]}, {"maintainer_email", MDFieldToRecField[MDFieldMaintainerEmail]}, {"license", MDFieldToRecField[MDFieldLicense]}, {"classifiers", MDFieldToRecField[MDFieldClassifier]}, {"requires_dist", MDFieldToRecField[MDFieldRequiresDist]}, {"requires_python", MDFieldToRecField[MDFieldRequiresPython]}, {"requires_external", MDFieldToRecField[MDFieldRequiresExternal]}, {"project_url", MDFieldToRecField[MDFieldProjectURL]}, {"provides_extra", MDFieldToRecField[MDFieldProvidesExtra]}, } ) // It should follow https://www.python.org/dev/peps/pep-0566/ type PkgInfo struct { Name string `json:"name"` Version string `json:"version"` Platform []string `json:"platform,omitempty"` SupportedPlatform []string `json:"supported_platform,omitempty"` Summary string `json:"summary,omitempty"` Description string `json:"description,omitempty"` DescriptionContentType string `json:"description_content_type,omitempty"` Keywords string `json:"keywords,omitempty"` HomePage string `json:"home_page,omitempty"` Author string `json:"author,omitempty"` AuthorEmail string `json:"author_email,omitempty"` Maintainer string `json:"maintainer,omitempty"` MaintainerEmail string `json:"maintainer_email,omitempty"` License string `json:"license,omitempty"` Classifier []string `json:"classifier,omitempty"` RequiresDist []string `json:"requires_dist,omitempty"` RequiresPython string `json:"requires_python,omitempty"` RequiresExternal []string `json:"requires_external,omitempty"` ProjectURL []string `json:"project_url,omitempty"` ProvidesExtra []string `json:"provides_extra,omitempty"` } // But current PyPI does not follow PEP-0566, so just ignore some fields type PkgInfoStripped struct { Name string `json:"name"` Version string `json:"version"` Summary string `json:"summary,omitempty"` Description string `json:"description,omitempty"` DescriptionContentType string `json:"description_content_type,omitempty"` Keywords string `json:"keywords,omitempty"` HomePage string `json:"home_page,omitempty"` Author string `json:"author,omitempty"` AuthorEmail string `json:"author_email,omitempty"` Maintainer string `json:"maintainer,omitempty"` MaintainerEmail string `json:"maintainer_email,omitempty"` License string `json:"license,omitempty"` Classifier []string `json:"classifiers,omitempty"` RequiresPython string `json:"requires_python,omitempty"` RequiresDist []string `json:"requires_dist,omitempty"` } // Unknown format: no detailed specification available // https://github.com/cooperlees/peps/blob/warehouse_json_api/pep-9999.rst type PkgReleaseInfo struct { Filename string `json:"filename"` Version string `json:"version"` UploadTimeISO8601 string `json:"upload_time_iso_8601"` Size int64 `json:"size"` HasSig bool `json:"has_sig"` Digests map[string]string `json:"digests"` } type PkgMeta struct { Info PkgInfo `json:"info"` LastSerial int64 `json:"last_serial"` Releases map[string][]*PkgReleaseInfo `json:"releases"` URLs []*PkgReleaseInfo `json:"urls"` } type PkgMetaStripped struct { Info PkgInfoStripped `json:"info"` Releases map[string][]*PkgReleaseInfo `json:"releases"` }