https://github.com/sultaniman/pycran
CRAN R package metadata parser
https://github.com/sultaniman/pycran
cran-r metadata-parser parser python r
Last synced: about 1 year ago
JSON representation
CRAN R package metadata parser
- Host: GitHub
- URL: https://github.com/sultaniman/pycran
- Owner: sultaniman
- License: apache-2.0
- Created: 2020-03-16T11:53:17.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-11-30T17:42:29.000Z (over 5 years ago)
- Last Synced: 2025-02-02T00:17:24.228Z (about 1 year ago)
- Topics: cran-r, metadata-parser, parser, python, r
- Language: Python
- Size: 1.82 MB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
[](https://pypi.org/project/pycran/)




PyCran
## Overview 👀
Yet another metadata parser for `R` source packages and `R` metadata information
```ini
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 💾
```sh
$ pip install pycran
```
## Usage 🚀
### Decode
```python
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
```python
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
```python
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
```python
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!
✨ 🍰 ✨