Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R Support [WIP] #349

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
0baba03
take bits from conda-skeleton code and add cran subparser
ForgottenProgramme Mar 7, 2022
2c93c45
get index
ForgottenProgramme Mar 15, 2022
47e94ca
add cranstrategy abstract class
ForgottenProgramme Mar 15, 2022
4b9357d
add create_r_recipe_from_list method
ForgottenProgramme Mar 15, 2022
6ca4fb8
add conditions in parser
ForgottenProgramme Mar 16, 2022
25013de
Fix fetch_data interface
marcelotrevisani Mar 18, 2022
6cafe83
remove pip
ForgottenProgramme Mar 23, 2022
f240b93
populate get_cran_metadata func
ForgottenProgramme Mar 23, 2022
d14ebc3
download tarball
ForgottenProgramme Mar 24, 2022
f86bae4
Write downloaded tarball to disk.
jezdez Mar 24, 2022
f59dd10
return recipe
ForgottenProgramme Mar 24, 2022
5b3630c
format requirements list
ForgottenProgramme Mar 25, 2022
2505545
add comment
ForgottenProgramme Mar 28, 2022
834f76a
Recipe adjustments for constrains in run requirements
marcelotrevisani Mar 28, 2022
21820db
Merge branch 'main' of https://github.com/ForgottenProgramme/grayskul…
ForgottenProgramme May 24, 2022
d988cfc
Merge branch 'main' of https://github.com/ForgottenProgramme/grayskul…
ForgottenProgramme May 25, 2022
4177cd6
Merge branch 'conda-incubator:main' into cran-branch
ForgottenProgramme Jul 5, 2022
01e1f3f
add 'r-base' to host and run req everytime
ForgottenProgramme Jul 5, 2022
a5154cb
Merge branch 'cran-branch' of https://github.com/ForgottenProgramme/g…
ForgottenProgramme Jul 5, 2022
383e4a3
sort the package list
ForgottenProgramme Jul 5, 2022
e8c4a7d
commit errorneous code with comment
ForgottenProgramme Jul 6, 2022
d32ddba
add cran metadata as comment at the top of the recipe
ForgottenProgramme Jul 7, 2022
0f21581
add posix and native at the top of the recipe
ForgottenProgramme Jul 13, 2022
4cf9669
add cli test for cran
ForgottenProgramme Jul 13, 2022
1bcc47d
Update grayskull/__main__.py
ForgottenProgramme Jul 20, 2022
b09629e
Update grayskull/strategy/cran.py
ForgottenProgramme Jul 20, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 132 additions & 14 deletions grayskull/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,83 @@ def main(args=None):
if not args:
args = sys.argv[1:] or ["--help"]

# create the top-level parser
parser = argparse.ArgumentParser(description="Grayskull - Conda recipe generator")
pypi_parser = parser.add_subparsers(help="Options to generate PyPI recipes")
pypi_cmds = pypi_parser.add_parser("pypi", help="Generate recipes based on PyPI")
pypi_cmds.add_argument(
subparsers = parser.add_subparsers(help="sub-command help")
# create parser for cran
cran_parser = subparsers.add_parser("cran", help="Options to generate CRAN recipes")
cran_parser.add_argument(
"cran_packages", nargs="+", help="Specify the CRAN packages name.", default=[]
)
cran_parser.add_argument(
"--stdout",
dest="stdout",
default=True,
help="Disable or enable stdout, if it is False, Grayskull"
" will disable the prints. Default is True",
)
cran_parser.add_argument(
"--list-missing-deps",
default=False,
action="store_true",
dest="list_missing_deps",
help="After the execution Grayskull will print all the missing dependencies.",
)
cran_parser.add_argument(
"--download",
"-d",
dest="download",
action="store_true",
default=False,
help="Download the sdist package and PyPI information in the same folder"
" the recipe is located.",
)
cran_parser.add_argument(
"--maintainers",
"-m",
dest="maintainers",
nargs="+",
help="List of maintainers which will be added to the recipe.",
)
cran_parser.add_argument(
"--output",
"-o",
dest="output",
default=".",
help="Path to where the recipe will be created",
)
cran_parser.add_argument(
"--strict-conda-forge",
default=False,
action="store_true",
dest="is_strict_conda_forge",
help="It will generate the recipes strict for the conda-forge channel.",
)
cran_parser.add_argument(
"--sections",
"-s",
default=None,
required=False,
choices=(
"package",
"source",
"build",
"requirements",
"test",
"about",
"extra",
),
nargs="+",
dest="sections_populate",
help="If sections are specified, grayskull will populate just the sections "
"informed.",
)
# create parser for pypi
pypi_parser = subparsers.add_parser("pypi", help="Options to generate PyPI recipes")
pypi_parser.add_argument(
"pypi_packages", nargs="+", help="Specify the PyPI packages name.", default=[]
)
pypi_cmds.add_argument(
pypi_parser.add_argument(
"--download",
"-d",
dest="download",
Expand All @@ -40,7 +110,7 @@ def main(args=None):
help="Download the sdist package and PyPI information in the same folder"
" the recipe is located.",
)
pypi_cmds.add_argument(
pypi_parser.add_argument(
"--maintainers",
"-m",
dest="maintainers",
Expand All @@ -63,49 +133,49 @@ def main(args=None):
dest="grayskull_power",
help=argparse.SUPPRESS,
)
pypi_cmds.add_argument(
pypi_parser.add_argument(
"--output",
"-o",
dest="output",
default=".",
help="Path to where the recipe will be created",
)
pypi_cmds.add_argument(
pypi_parser.add_argument(
"--stdout",
dest="stdout",
default=True,
help="Disable or enable stdout, if it is False, Grayskull"
" will disable the prints. Default is True",
)
pypi_cmds.add_argument(
pypi_parser.add_argument(
"--list-missing-deps",
default=False,
action="store_true",
dest="list_missing_deps",
help="After the execution Grayskull will print all the missing dependencies.",
)
pypi_cmds.add_argument(
pypi_parser.add_argument(
"--strict-conda-forge",
default=False,
action="store_true",
dest="is_strict_conda_forge",
help="It will generate the recipes strict for the conda-forge channel.",
)
pypi_cmds.add_argument(
pypi_parser.add_argument(
"--pypi-url",
default="https://pypi.org/pypi/",
dest="url_pypi_metadata",
help="Pypi url server",
)
pypi_cmds.add_argument(
pypi_parser.add_argument(
"--recursive",
"-r",
default=False,
action="store_true",
dest="is_recursive",
help="Recursively run grayskull on missing dependencies.",
)
pypi_cmds.add_argument(
pypi_parser.add_argument(
"--sections",
"-s",
default=None,
Expand All @@ -124,7 +194,7 @@ def main(args=None):
help="If sections are specified, grayskull will populate just the sections "
"informed.",
)
pypi_cmds.add_argument(
pypi_parser.add_argument(
"--extras-require-test",
default=None,
dest="extras_require_test",
Expand Down Expand Up @@ -152,7 +222,10 @@ def main(args=None):
print_msg(Style.RESET_ALL)
print_msg(clear_screen())

generate_recipes_from_list(args.pypi_packages, args)
if getattr(args, "pypi_packages", None):
generate_recipes_from_list(args.pypi_packages, args)
elif getattr(args, "cran_packages", None):
generate_r_recipes_from_list(args.cran_packages, args)


def generate_recipes_from_list(list_pkgs, args):
Expand Down Expand Up @@ -210,6 +283,51 @@ def create_python_recipe(pkg_name, sections_populate=None, **kwargs):
)


def generate_r_recipes_from_list(list_pkgs, args):
for pkg_name in list_pkgs:
logging.debug(f"Starting grayskull for pkg: {pkg_name}")
from_local_sdist = origin_is_local_sdist(pkg_name)
cran_label = " (cran)"
print_msg(
f"{Fore.GREEN}\n\n"
f"#### Initializing recipe for "
f"{Fore.BLUE}{pkg_name}{cran_label} {Fore.GREEN}####\n"
)
is_pkg_file = Path(pkg_name).is_file() and (not from_local_sdist)
if is_pkg_file:
args.output = pkg_name
try:
recipe, config = create_r_recipe(
pkg_name,
is_strict_cf=args.is_strict_conda_forge,
download=args.download,
sections_populate=args.sections_populate,
)
except requests.exceptions.HTTPError as err:
print_msg(f"{Fore.RED}Package seems to be missing.\nException: {err}\n\n")
continue

if args.sections_populate is None or "extra" in args.sections_populate:
add_extra_section(recipe, args.maintainers)

generate_recipe(recipe, config, args.output)
print_msg(
f"\n{Fore.GREEN}#### Recipe generated on "
f"{os.path.realpath(args.output)} for {pkg_name} ####\n\n"
)



def create_r_recipe(pkg_name, sections_populate=None, **kwargs):
config = Configuration(name=pkg_name, **kwargs)
return (
GrayskullFactory.create_recipe(
"cran", config, sections_populate=sections_populate
),
config,
)


def add_extra_section(recipe, maintainers: Optional[List] = None):
maintainers = maintainers or [get_git_current_user()]
if "extra" in recipe:
Expand Down
2 changes: 2 additions & 0 deletions grayskull/base/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
from souschef.jinja_expression import get_global_jinja_var
from souschef.recipe import Recipe

from grayskull.strategy.cran import CranStrategy
from grayskull.strategy.pypi import PypiStrategy


class GrayskullFactory(ABC):
REGISTERED_STRATEGY = {
"pypi": PypiStrategy,
"cran": CranStrategy,
}

@staticmethod
Expand Down
Loading