From c0e1bc744d99d7cf49805bd135401a5589c2d729 Mon Sep 17 00:00:00 2001 From: Johnny Chen Date: Wed, 26 Feb 2020 04:28:52 +0800 Subject: [PATCH 1/3] print better error message if arguments are wrong --- jill/download.py | 14 ++++++++- jill/install.py | 16 ++++++++-- jill/utils/filters.py | 73 ++++++++++++++++++++++++------------------- 3 files changed, 66 insertions(+), 37 deletions(-) diff --git a/jill/download.py b/jill/download.py index a88ad46..806b290 100644 --- a/jill/download.py +++ b/jill/download.py @@ -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 diff --git a/jill/install.py b/jill/install.py index 7cac190..1b011f5 100644 --- a/jill/install.py +++ b/jill/install.py @@ -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" @@ -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 @@ -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 diff --git a/jill/utils/filters.py b/jill/utils/filters.py index ea6f5f6..6497b38 100644 --- a/jill/utils/filters.py +++ b/jill/utils/filters.py @@ -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) @@ -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)) @@ -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): @@ -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, From 8eab856881d14b8d5d3c1ca261f52ed6a6715a7f Mon Sep 17 00:00:00 2001 From: Johnny Chen Date: Wed, 26 Feb 2020 04:46:47 +0800 Subject: [PATCH 2/3] jill v0.6.6 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index b41674e..ebd5079 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ setuptools.setup( name='jill', - version='0.6.5', + version='0.6.6', author="Johnny Chen", author_email="johnnychen94@hotmail.com", description="JILL -- Julia Installer for Linux (MacOS, Windows and FreeBSD) -- Light", From bd09aa198b496c6ee08e2e4dff3d655cfaf1e0aa Mon Sep 17 00:00:00 2001 From: Johnny Chen Date: Wed, 26 Feb 2020 04:54:11 +0800 Subject: [PATCH 3/3] print debug info for arm arch --- .github/workflows/pythonapp.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pythonapp.yml b/.github/workflows/pythonapp.yml index 5eebd1a..e5b4e61 100644 --- a/.github/workflows/pythonapp.yml +++ b/.github/workflows/pythonapp.yml @@ -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