Skip to main content

Parse CRAN package metadata

Project description

PyPI - Python Version Build Status Maintainability codecov PyPI - License

PyCran

Overview 👀

Yet another metadata parser for R source packages and R metadata information

Package: ABACUS
Version: 1.0.0
Depends: R (>= 3.1.0)
Imports: ggplot2 (>= 3.1.0), shiny (>= 1.3.1),
Suggests: rmarkdown (>= 1.13), knitr (>= 1.22)
License: GPL-3
MD5sum: 50c54c4da09307cb95a70aaaa54b9fbd
NeedsCompilation: no

For more see: https://cran.r-project.org/src/contrib/PACKAGES

PyCran lets us parse raw metadata and get it as dictionary, you can:

  1. Encode metadata dictionary to raw format,
  2. Decode raw metadata and receive it as dictionary,
  3. Load from tar archive with R library sources.

Installation 💾

$ pip install pycran

Usage 🚀

Decode

import pycran

raw_metadata = """
Package: ABACUS
Version: 1.0.0
Depends: R (>= 3.1.0)
Imports: ggplot2 (>= 3.1.0), shiny (>= 1.3.1),
Suggests: rmarkdown (>= 1.13), knitr (>= 1.22)
License: GPL-3
MD5sum: 50c54c4da09307cb95a70aaaa54b9fbd
NeedsCompilation: no
"""

assert pycran.decode(raw_metadata) == {
    "Package": "ABACUS",
    "Version": "1.0.0",
    "Depends": "R (>= 3.1.0)",
    "Imports": "ggplot2 (>= 3.1.0), shiny (>= 1.3.1),",
    "Suggests": "rmarkdown (>= 1.13), knitr (>= 1.22)",
    "License": "GPL-3",
    "MD5sum": "50c54c4da09307cb95a70aaaa54b9fbd",
    "NeedsCompilation": "no",
}

Encode

import pycran

metadata = {
    "Package": "ABACUS",
    "Version": "1.0.0",
    "Depends": "R (>= 3.1.0)",
    "Imports": "ggplot2 (>= 3.1.0), shiny (>= 1.3.1),",
    "Suggests": "rmarkdown (>= 1.13), knitr (>= 1.22)",
    "License": "GPL-3",
    "MD5sum": "50c54c4da09307cb95a70aaaa54b9fbd",
    "NeedsCompilation": "no",
}

expected = """
Package: ABACUS
Version: 1.0.0
Depends: R (>= 3.1.0)
Imports: ggplot2 (>= 3.1.0), shiny (>= 1.3.1),
Suggests: rmarkdown (>= 1.13), knitr (>= 1.22)
License: GPL-3
MD5sum: 50c54c4da09307cb95a70aaaa54b9fbd
NeedsCompilation: no
"""

assert pycran.encode(metadata) == expected

Load from R source archive

import pycran

# you can pass path to archive
pycran.from_file("PATH/TO/PACKAGE/ABACUS_1.0.0.tar.gz")

# or you can pass tarfile object
import tarfile

pycran.from_file(tarfile.open("PATH/TO/PACKAGE/ABACUS_1.0.0.tar.gz"))

Parse raw metadata

In cases when you need to parse metadata for multiple packages you can pass the data to pycran.parse function

import pycran

# somehow you download the contents of https://cran.r-project.org/src/contrib/PACKAGES
package_list = requests.get(https://cran.r-project.org/src/contrib/PACKAGES).text()

# And parse it as a result you will get a generator which you can iterate
pycran.parse(package_list)

Enjoy!          

✨ 🍰 ✨            

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pycran-0.2.0.tar.gz (986.0 kB view details)

Uploaded Source

Built Distribution

pycran-0.2.0-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file pycran-0.2.0.tar.gz.

File metadata

  • Download URL: pycran-0.2.0.tar.gz
  • Upload date:
  • Size: 986.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.23.0

File hashes

Hashes for pycran-0.2.0.tar.gz
Algorithm Hash digest
SHA256 07ff69ec8469f90735f075fe26ed267fe9bc1aec8bd519815804ff493ea64283
MD5 17121617ff80f8fd030660d51919e2d6
BLAKE2b-256 6748c4838168c8d2d73f4c9300a6e35c730d6983e5ba83edc6b1f816792c0216

See more details on using hashes here.

File details

Details for the file pycran-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: pycran-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.23.0

File hashes

Hashes for pycran-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c5c119ccab969f659a468aa65b3b1bbdfcad3c835ab30eb0955f5e14f0a9ded1
MD5 14ba570c61b76a24b96d994667cc179b
BLAKE2b-256 2c60a4360a82472dadb529930d936c23fad31f02c51c9c9f59fd98c23cdf561b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page