Skip to content

Commit

Permalink
Merge pull request #29 from johnnychen94/jc/err_msg
Browse files Browse the repository at this point in the history
print better error message if arguments are wrong
  • Loading branch information
johnnychen94 authored Feb 26, 2020
2 parents f23637a + bd09aa1 commit ca522cb
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 39 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/pythonapp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,10 @@ jobs:
run: |
apt-get update -qq
apt-get install -y -qq -o=Dpkg::Use-Pty=0 python3-pip python3-wheel python3-setuptools gnupg wget --no-install-recommends
export DEBUG=True
pip3 install --upgrade pip --quiet
pip3 install -r requirements.txt --quiet
python -m jill upstream
python3 -m jill upstream
python3 -m jill install --confirm --upstream Official
julia -e 'using InteractiveUtils; versioninfo()'
python3 -m jill install 1.0 --confirm --upstream Official
Expand Down
14 changes: 13 additions & 1 deletion jill/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,19 @@ def download_package(version=None, sys=None, arch=None, *,

# allow downloading unregistered releases, e.g., 1.4.0-rc1
do_release_check = not is_full_version(version)
version = latest_version(version, system, architecture)
wrong_args = False
try:
version = latest_version(version, system, architecture)
except ValueError as e:
# hide the nested error stack :P
wrong_args = True
if wrong_args:
msg = f"something wrong for the platform argument you passed:\n"
msg += f" - version: {version}\n"
msg += f" - system: {system}\n"
msg += f" - archtecture: {architecture}\n"
msg += f"example: jill download 1 linux x86_64"
raise(ValueError(msg))

if architecture in ["ARMv7", "ARMv8"]:
# TODO: fix update functionality for it in version_utils
Expand Down
16 changes: 13 additions & 3 deletions jill/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def get_exec_version(path):
# outputs: "julia version 1.4.0-rc1"
version = subprocess.check_output(ver_cmd).decode("utf-8")
version = version.lower().split("version")[-1].strip()
except: # nopep8
except: # nopep8
# in case it fails in any situation: invalid target or command(.cmd)
# issue: https://github.com/abelsiqueira/jill/issues/25
version = "0.0.1"
Expand Down Expand Up @@ -128,7 +128,7 @@ def make_symlinks(src_bin, symlink_dir, version):
# - don't make symlink to patch level
if os.path.exists(linkpath) or os.path.islink(linkpath):
if (os.path.islink(linkpath) and
os.readlink(linkpath) == src_bin):
os.readlink(linkpath) == src_bin):
# happens when installing a new patch version
continue

Expand Down Expand Up @@ -332,12 +332,22 @@ def install_julia(version=None, *,
if not to_continue:
return False

wrong_args = False
try:
version = latest_version(version, system, arch)
except ValueError as e:
# hide the nested error stack :P
wrong_args = True
if wrong_args:
msg = f"wrong version argument: {version}\n"
msg += f"Example: jill install 1"
raise(ValueError(msg))

overwrite = True if version == "latest" else False
print(f"{color.BOLD}----- Download Julia -----{color.END}")
package_path = download_package(version, system, arch,
upstream=upstream,
overwrite=overwrite)
version = latest_version(version, system, arch)
if not package_path:
return False

Expand Down
73 changes: 40 additions & 33 deletions jill/utils/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,30 +116,33 @@ def is_valid_release(version, system, architecture):

class NameFilter:
def __init__(self,
name: str,
f: Callable = identity,
rules: Optional[Mapping] = None,
validate: Callable = no_validate):
self.f = f
self.name = name
self.rules = rules if rules else {}
self.validate = validate

def __call__(self, *args, **kwargs):
if not self.validate(*args, **kwargs):
# TODO: add error handler
msg = f"validation fails:\n"
msg += f" - args: {args}\n - kwargs: {kwargs}"
msg = f"validation on {self.name} fails:\n"
msg += f" - args: {args}\n - kwargs: {kwargs}\n"
msg += f"Please check if you have passed the right parameters"
raise ValueError(msg)
# directly return rst if there're no special filter rules
rst = self.f(*args, **kwargs)
return self.rules.get(rst, rst)


f_major_version = NameFilter(lambda x: x.lstrip('v').split('.')[0],
f_major_version = NameFilter("version", lambda x: x.lstrip('v').split('.')[0],
validate=is_version)
f_minor_version = NameFilter(lambda x: '.'.join(x.lstrip('v').
split('.')[0:2]),
f_minor_version = NameFilter("version", lambda x: '.'.join(x.lstrip('v').
split('.')[0:2]),
validate=is_version)
f_patch_version = NameFilter(lambda x: x.lstrip('v').split('-')[0],
f_patch_version = NameFilter("version", lambda x: x.lstrip('v').split('-')[0],
validate=is_version)


Expand Down Expand Up @@ -171,32 +174,35 @@ def _version(ver):
return ver.lstrip('v')


f_vmajor_version = NameFilter(_vmajor_version)
f_Vmajor_version = NameFilter(lambda x: f_vmajor_version(x).capitalize())
f_vminor_version = NameFilter(_vminor_version)
f_Vminor_version = NameFilter(lambda x: f_vminor_version(x).capitalize())
f_vpatch_version = NameFilter(_vpatch_version)
f_Vpatch_version = NameFilter(lambda x: f_vpatch_version(x).capitalize())
f_vmajor_version = NameFilter("version", _vmajor_version)
f_Vmajor_version = NameFilter(
"version", lambda x: f_vmajor_version(x).capitalize())
f_vminor_version = NameFilter("version", _vminor_version)
f_Vminor_version = NameFilter(
"version", lambda x: f_vminor_version(x).capitalize())
f_vpatch_version = NameFilter("version", _vpatch_version)
f_Vpatch_version = NameFilter(
"version", lambda x: f_vpatch_version(x).capitalize())

f_version = NameFilter(_version, validate=is_version)
f_version = NameFilter("version", _version, validate=is_version)

f_system = NameFilter(validate=is_system)
f_System = NameFilter(f=lambda x: f_system(x).capitalize())
f_SYSTEM = NameFilter(f=lambda x: f_system(x).upper())
f_system = NameFilter("system", validate=is_system)
f_System = NameFilter("system", f=lambda x: f_system(x).capitalize())
f_SYSTEM = NameFilter("system", f=lambda x: f_system(x).upper())

f_sys = NameFilter(rules=rule_sys, validate=is_system)
f_Sys = NameFilter(f=lambda x: f_sys(x).capitalize())
f_SYS = NameFilter(f=lambda x: f_sys(x).upper())
f_sys = NameFilter("sys", rules=rule_sys, validate=is_system)
f_Sys = NameFilter("sys", f=lambda x: f_sys(x).capitalize())
f_SYS = NameFilter("sys", f=lambda x: f_sys(x).upper())

f_os = NameFilter(rules=rules_os, validate=is_system)
f_Os = NameFilter(f=lambda x: f_os(x).capitalize())
f_OS = NameFilter(f=lambda x: f_os(x).upper())
f_os = NameFilter("os", rules=rules_os, validate=is_system)
f_Os = NameFilter("os", f=lambda x: f_os(x).capitalize())
f_OS = NameFilter("os", f=lambda x: f_os(x).upper())

f_arch = NameFilter(rules=rules_arch, validate=is_architecture)
f_Arch = NameFilter(f=lambda x: f_arch(x).capitalize())
f_ARCH = NameFilter(f=lambda x: f_arch(x).upper())
f_arch = NameFilter("arch", rules=rules_arch, validate=is_architecture)
f_Arch = NameFilter("arch", f=lambda x: f_arch(x).capitalize())
f_ARCH = NameFilter("arch", f=lambda x: f_arch(x).upper())

f_osarch = NameFilter(f=lambda os, arch: f"{os}-{arch}",
f_osarch = NameFilter("osarch", f=lambda os, arch: f"{os}-{arch}",
rules=rules_osarch,
validate=lambda os, arch:
is_os(os) and is_architecture(arch))
Expand All @@ -216,17 +222,18 @@ def _OSarch(os, arch):
return os.upper() + '-' + arch


f_Osarch = NameFilter(_Osarch)
f_OSarch = NameFilter(_OSarch)
f_Osarch = NameFilter("osarch", _Osarch)
f_OSarch = NameFilter("osarch", _OSarch)

f_osbit = NameFilter(f=lambda os, arch: f"{os}{arch}",
f_osbit = NameFilter("osbit", f=lambda os, arch: f"{os}{arch}",
rules=rules_osbit,
validate=lambda os, arch:
is_os(os) and is_architecture(arch))

f_bit = NameFilter(rules=rules_bit, validate=is_architecture)
f_bit = NameFilter("bit", rules=rules_bit, validate=is_architecture)

f_extension = NameFilter(rules=rules_extension, validate=is_system)
f_extension = NameFilter(
"extension", rules=rules_extension, validate=is_system)


def _meta_filename(t, *args, **kwargs):
Expand All @@ -243,8 +250,8 @@ def _latest_filename(**kwargs):
return _meta_filename(default_latest_filename_template, **kwargs)


f_filename = NameFilter(_filename)
f_latest_filename = NameFilter(_latest_filename)
f_filename = NameFilter("filename", _filename)
f_latest_filename = NameFilter("filename", _latest_filename)


def generate_info(plain_version: str,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

setuptools.setup(
name='jill',
version='0.6.5',
version='0.6.6',
author="Johnny Chen",
author_email="[email protected]",
description="JILL -- Julia Installer for Linux (MacOS, Windows and FreeBSD) -- Light",
Expand Down

0 comments on commit ca522cb

Please sign in to comment.