Skip to content

Commit

Permalink
Merge pull request #118 from carpentriesoffline/92-api-cleanup
Browse files Browse the repository at this point in the history
Updating API to be more intuitive
  • Loading branch information
ethanwhite authored Apr 29, 2024
2 parents 9a22d01 + fec51de commit 86ce452
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
34 changes: 17 additions & 17 deletions offlinedatasci/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,29 @@ def get_installer_function(selection, ods_dir):
try_except_functions(ods_dir, download_rstudio)
elif selection == "python":
try_except_functions(ods_dir, download_python)
else:
try:
download_function = f"download_{selection}"
getattr(sys.modules[__name__], download_function)(ods_dir)
except Exception:
print(f'method does not exist for selection: {selection}')
elif selection == "r-packages":
try_except_functions(ods_dir, download_r_packages)
elif selection == "python-packages":
try_except_functions(ods_dir, download_python_packages)
elif selection == "lessons":
try_except_functions(ods_dir, download_lessons)

def main():
parser = argparse.ArgumentParser(prog = 'offlinedatasci')
subparsers = parser.add_subparsers(help = 'sub-command help', dest='command')
INSTALL_OPTIONS = ["all", "lessons", "minicran", "python", "python_libraries", "r", "rstudio"]
INSTALL_OPTIONS = ["all", "lessons", "r-packages", "python", "python-packages", "r", "rstudio"]

install_parser = subparsers.add_parser('install')
install_parser.add_argument('item',
default = 'all',
nargs = '+',
choices=INSTALL_OPTIONS)

packages_parser = subparsers.add_parser('add-packages')
packages_parser.add_argument('language',
packages_parser = subparsers.add_parser('add')
packages_parser.add_argument('package_type',
nargs = 1,
choices =['r', 'python'])
packages_parser.add_argument('libraries',
choices =['r-packages', 'python-packages'])
packages_parser.add_argument('packages',
nargs = '+')

parser.add_argument('path',
Expand All @@ -48,12 +48,12 @@ def main():
for i in args.item:
get_installer_function(i, ods_dir)

elif args.command == 'add-packages':
packages_to_install = package_selection(args.language[0], args.libraries)
if args.language[0] == "python":
download_python_libraries(ods_dir, packages_to_install)
elif args.language[0] == "r":
download_minicran(ods_dir, packages_to_install)
elif args.command == 'add':
packages_to_install = package_selection(args.package_type[0], args.packages)
if args.package_type[0] == "python-packages":
download_python_packages(ods_dir, packages_to_install)
elif args.package_type[0] == "r-packages":
download_r_packages(ods_dir, packages_to_install)


if __name__=='__main__':
Expand Down
16 changes: 8 additions & 8 deletions offlinedatasci/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def download_all(ods_dir):
print(f"Error downloading RStudio: {e}")

try:
download_minicran(ods_dir)
download_r_packages(ods_dir)
except Exception as e:
print(f"Error downloading R packages: {e}")

Expand All @@ -80,7 +80,7 @@ def download_all(ods_dir):
print(f"Error downloading Python: {e}")

try:
download_python_libraries(ods_dir)
download_python_packages(ods_dir)
except Exception as e:
print(f"Error downloading Python packages: {e}")

Expand Down Expand Up @@ -329,7 +329,7 @@ def table_parse_version_info(row,oscolnum,hrefcolnum):
link_inner_html = link.text.strip()
return {"osver": os, "version": link_inner_html, "url": link_url}

def download_minicran(ods_dir,
def download_r_packages(ods_dir,
py_library_reqs = ["tidyverse", "RSQLite"],
r_version = None):
"""Creating partial CRAN mirror of workshop libraries.
Expand Down Expand Up @@ -357,7 +357,7 @@ def download_minicran(ods_dir,
subprocess.run(["Rscript", minicranpath, ods_dir, custom_library_string, r_major_minor_version])


def download_python_libraries(ods_dir,py_library_reqs = [ "matplotlib", "notebook","numpy", "pandas"] ):
def download_python_packages(ods_dir,py_library_reqs = [ "matplotlib", "notebook","numpy", "pandas"] ):
"""Creating partial PyPI mirror of workshop libraries.
Keyword arguments:
Expand Down Expand Up @@ -393,19 +393,19 @@ def download_python_libraries(ods_dir,py_library_reqs = [ "matplotlib", "noteboo
}
pypi_mirror.create_mirror(**mirror_creation_parameters)

def get_default_packages(language):
def get_default_packages(package_type):
packages = {
"r": {
"r-packages": {
"data-carpentry": ["tidyverse", "RSQLite"],
"data-science": ["dplyr", "ggplot2", "shiny", "lubridate", "knitr", "esquisse", "mlr3", "knitr", "DT"]
},
"python": {
"python-packages": {
"data-carpentry": ["pandas", "notebook", "numpy", "matplotlib", "plotnine"],
"software-carpentry": ["matplotlib", "notebook", "numpy", "pandas"] ,
"data-science": ["scipy", "numpy", "pandas", "matplotlib", "keras", "scikit-learn", "beautifulsoup4", "seaborn","torch"]
}
}
return packages[language]
return packages[package_type]


def package_selection(language, custom_package_list):
Expand Down
2 changes: 1 addition & 1 deletion test/test_offlinedatasci.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def test_download_python(tmp_path):
def test_download_python_libraries(tmp_path):
# test on notebook since it has caused issues in the past
# See https://github.com/carpentriesoffline/offlinedatasci/issues/95
download_python_libraries(tmp_path, ['notebook'])
download_python_packages(tmp_path, ['notebook'])
assert glob(f"{tmp_path}/pythonlibraries/*.whl")
assert glob(f"{tmp_path}/pypi/index.html")

Expand Down

0 comments on commit 86ce452

Please sign in to comment.