-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* bug fixes for badge generation * adding support for parsing an R requirements file (in DESCRIPTION) * we do not need to test saving * test error Signed-off-by: vsoch <vsoch@users.noreply.github.com> Co-authored-by: vsoch <vsoch@users.noreply.github.com>
- Loading branch information
Showing
13 changed files
with
416 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
__author__ = "Vanessa Sochat" | ||
__copyright__ = "Copyright 2022, Vanessa Sochat" | ||
__license__ = "MPL 2.0" | ||
|
||
# Parse a requirements.txt file to generate a "package" | ||
import citelang.main.endpoints as endpoints | ||
|
||
import re | ||
|
||
from .base import PackagesFromFile | ||
|
||
|
||
class RPackageManager(PackagesFromFile): | ||
""" | ||
Packages from an R DESCRIPTION file, meaning an R package | ||
""" | ||
|
||
name = "R-Package" | ||
underlying_manager = "cran" | ||
default_language = "R" | ||
project_count = None | ||
homepage = "https://cran.r-project.org/" | ||
color = "#006dad" | ||
default_versions = None | ||
|
||
def parse(self, content): | ||
""" | ||
Parse the self.content (the DESCRIPTION file) | ||
""" | ||
repo = self.get_repo() | ||
|
||
libs = [] | ||
parsing = False | ||
for line in content.split("\n"): | ||
# If we are parsing, but hit the end of the list | ||
if parsing and not line.startswith(" "): | ||
break | ||
elif parsing: | ||
libs.append(line.replace(",", "").strip()) | ||
elif "Imports:" in line: | ||
parsing = True | ||
|
||
deps = [] | ||
for line in libs: | ||
version = None | ||
package_name = None | ||
if re.search("(==|<=|>=)", line): | ||
line = line.replace(")", "").replace("(", "") | ||
package_name, _, version = re.split("(==|<=|>=)", line) | ||
package_name = package_name.strip() | ||
version = version.strip() | ||
else: | ||
package_name = line | ||
|
||
# We cannot parse a dep without a name | ||
if not package_name: | ||
continue | ||
|
||
# First add requirements (names and pypi manager) to deps | ||
|
||
# Try to get from cache - either versioned or not | ||
pkg = None | ||
if package_name and version: | ||
cache_name = f"package/cran/{package_name}/{version}" | ||
result = self.cache.get(cache_name) | ||
if result: | ||
pkg = endpoints.get_endpoint("package", data=result) | ||
|
||
elif package_name and not version: | ||
cache_name = f"package/cran/{package_name}" | ||
result = self.cache.get(cache_name) | ||
if result: | ||
pkg = endpoints.get_endpoint("package", data=result) | ||
|
||
if pkg is None: | ||
pkg = endpoints.get_endpoint( | ||
"package", | ||
package_name=package_name, | ||
manager=self.underlying_manager, | ||
) | ||
|
||
# Ensure we have version, fallback to latest | ||
if not version: | ||
version = pkg.data["latest_release_number"] | ||
|
||
# Require saving to cache here - many expensive calls | ||
cache_name = f"package/cran/{package_name}/{version}" | ||
self.cache.set(cache_name, pkg) | ||
|
||
# use latest release version. This will be wrong for an old | ||
# dependency, but it's not worth it to make a ton of extra API calls | ||
dep = { | ||
"name": package_name, | ||
"project_name": package_name, | ||
"number": version, | ||
"published_at": pkg.data["latest_stable_release_published_at"], | ||
"researched_at": None, | ||
"spdx_expression": "NOASSERTION", | ||
"original_license": pkg.data["licenses"], | ||
"repository_sources": ["Cran"], | ||
} | ||
deps.append(dep) | ||
|
||
repo["dependencies"] = deps | ||
self.data["package"] = repo | ||
self.data["dependencies"] = deps | ||
return repo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
Package: eia | ||
Title: API Wrapper for 'US Energy Information Administration' Open Data | ||
Version: 0.3.7 | ||
Authors@R: person("Matthew", "Leonawicz", email = "mfleonawicz@gmail.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0001-9452-2771")) | ||
Description: Provides API access to data from the 'US Energy Information Administration' ('EIA') <https://www.eia.gov/>. | ||
Use of the API requires a free API key obtainable at <https://www.eia.gov/opendata/register.php>. | ||
The package includes functions for searching 'EIA' data categories and importing time series and geoset time series datasets. | ||
Datasets returned by these functions are provided in a tidy format or alternatively in more raw form. | ||
It also offers helper functions for working with 'EIA' date strings and time formats and for inspecting different summaries of series metadata. | ||
The package also provides control over API key storage and caching of API request results. | ||
License: MIT + file LICENSE | ||
Encoding: UTF-8 | ||
LazyData: true | ||
URL: https://docs.ropensci.org/eia/ (website) https://github.com/ropensci/eia | ||
BugReports: https://github.com/ropensci/eia/issues | ||
Imports: | ||
tibble, | ||
cli (>= 3.2.0) | ||
Suggests: | ||
testthat, | ||
knitr, | ||
rmarkdown, | ||
covr, | ||
tidyr, | ||
ggplot2 | ||
VignetteBuilder: knitr | ||
Language: en-US | ||
RoxygenNote: 7.1.1 |
Oops, something went wrong.