swh.loader.package.npm.loader module#
- class swh.loader.package.npm.loader.NpmPackageInfo(url: str, filename: str | None, version: str, raw_info: Dict[str, Any], package_name: str, date: str | None, shasum: str, *, directory_extrinsic_metadata: List[RawExtrinsicMetadataCore] = [], checksums: Dict[str, str] = {})[source]#
Bases:
BasePackageInfo
Method generated by attrs for class NpmPackageInfo.
- shasum#
sha1 checksum
- class swh.loader.package.npm.loader.NpmLoader(storage: StorageInterface, url: str, **kwargs: Any)[source]#
Bases:
PackageLoader
[NpmPackageInfo
]Load npm origin’s artifact releases into swh archive.
Constructor
- Args
str: origin url (e.g. https://www.npmjs.com/package/<package-name>)
- get_versions() Sequence[str] [source]#
Return the list of all published package versions.
- Raises:
class – swh.loader.exception.NotFound error when failing to read the published package versions.
- Returns:
Sequence of published versions
- get_default_version() str [source]#
Retrieve the latest release version if any.
- Returns:
Latest version
- get_metadata_authority()[source]#
For package loaders that get extrinsic metadata, returns the authority the metadata are coming from.
- get_package_info(version: str) Iterator[Tuple[str, NpmPackageInfo]] [source]#
- Given a release version of a package, retrieve the associated
package information for such version.
- Parameters:
version – Package version
- Returns:
(branch name, package metadata)
- build_release(p_info: NpmPackageInfo, uncompressed_path: str, directory: bytes) Release | None [source]#
Build the release from the archive metadata (extrinsic artifact metadata) and the intrinsic metadata.
- Parameters:
p_info – Package information
uncompressed_path – Artifact uncompressed path on disk
- swh.loader.package.npm.loader.extract_npm_package_author(package_json: Dict[str, Any]) Person [source]#
Extract package author from a
package.json
file content and return it in swh format.- Parameters:
package_json – Dict holding the content of parsed
package.json
file- Returns:
Person
- swh.loader.package.npm.loader.load_json(json_bytes)[source]#
Try to load JSON from bytes and return a dictionary.
First try to decode from utf-8. If the decoding failed, try to detect the encoding and decode again with replace error handling.
If JSON is malformed, an empty dictionary will be returned.
- swh.loader.package.npm.loader.extract_intrinsic_metadata(dir_path: str) Dict [source]#
- Given an uncompressed path holding the pkginfo file, returns a
pkginfo parsed structure as a dict.
The release artifact contains at their root one folder. For example: $ tar tvf zprint-0.0.6.tar.gz drwxr-xr-x root/root 0 2018-08-22 11:01 zprint-0.0.6/ …
- Parameters:
dir_path (str) – Path to the uncompressed directory representing a release artifact from npm.
- Returns:
the pkginfo parsed structure as a dict if any or None if none was present.