From 0306fae90cc97ebaff645664f499472c9ec920ca Mon Sep 17 00:00:00 2001 From: Neradoc Date: Wed, 1 Feb 2023 00:37:38 +0100 Subject: [PATCH 01/20] auto install improvements --- .pre-commit-config.yaml | 5 +++-- circup/__init__.py | 22 ++++++++++++++++++---- tests/bad_python.py | 6 ++++++ tests/test_circup.py | 9 +++++++++ 4 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 tests/bad_python.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3e14e75..fa3d605 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -15,11 +15,12 @@ repos: - id: pylint name: lint (code) types: [python] - exclude: "^(docs/|examples/|setup.py$)" + exclude: "^(docs/|examples/|setup.py$|tests/bad_python.py$)" - repo: https://github.com/python/black rev: 22.3.0 hooks: - - id: black + - id: black + exclude: "^tests/bad_python.py$" - repo: https://github.com/fsfe/reuse-tool rev: v0.14.0 hooks: diff --git a/circup/__init__.py b/circup/__init__.py index 2854983..fb0d903 100644 --- a/circup/__init__.py +++ b/circup/__init__.py @@ -1056,7 +1056,15 @@ def libraries_from_imports(code_py, mod_names): :param str code_py: Full path of the code.py file :return: sequence of library names """ - imports = [info.name.split(".", 1)[0] for info in findimports.find_imports(code_py)] + # pylint: disable=broad-except + try: + found_imports = findimports.find_imports(code_py) + except Exception as ex: # broad exception because anything could go wrong + logger.exception(ex) + click.secho('Unable to read the auto file: "{}"'.format(str(ex)), fg="red") + sys.exit(2) + # pylint: enable=broad-except + imports = [info.name.split(".", 1)[0] for info in found_imports] return [r for r in imports if r in mod_names] @@ -1293,7 +1301,7 @@ def list_cli(ctx): # pragma: no cover @click.option("pyext", "--py", is_flag=True) @click.option("-r", "--requirement", type=click.Path(exists=True, dir_okay=False)) @click.option("--auto/--no-auto", "-a/-A") -@click.option("--auto-file", default="code.py") +@click.option("--auto-file", default=None) @click.pass_context def install(ctx, modules, pyext, requirement, auto, auto_file): # pragma: no cover """ @@ -1317,8 +1325,14 @@ def install(ctx, modules, pyext, requirement, auto, auto_file): # pragma: no co with open(requirement, "r", encoding="utf-8") as rfile: requirements_txt = rfile.read() requested_installs = libraries_from_requirements(requirements_txt) - elif auto: - auto_file = os.path.join(ctx.obj["DEVICE_PATH"], auto_file) + elif auto or auto_file: + if auto_file is None: + auto_file = "code.py" + if not os.path.isabs(auto_file) and not auto_file[:2] == "./": + auto_file = os.path.join(ctx.obj["DEVICE_PATH"], auto_file or "code.py") + if not os.path.isfile(auto_file): + click.secho(f"Auto file not found: {auto_file}", fg="red") + sys.exit(1) requested_installs = libraries_from_imports(auto_file, mod_names) else: requested_installs = modules diff --git a/tests/bad_python.py b/tests/bad_python.py new file mode 100644 index 0000000..a5a56e0 --- /dev/null +++ b/tests/bad_python.py @@ -0,0 +1,6 @@ +# SPDX-FileCopyrightText: 2021 Jeff Epler for Adafruit Industries +# +# SPDX-License-Identifier: MIT +# pylint: disable=all + +if True: diff --git a/tests/test_circup.py b/tests/test_circup.py index 1faa69b..0f2ba51 100644 --- a/tests/test_circup.py +++ b/tests/test_circup.py @@ -1030,3 +1030,12 @@ def test_libraries_from_imports(): "adafruit_esp32spi", "adafruit_hid", ] + + +def test_libraries_from_imports_bad(): + """Ensure that we catch an import error""" + TEST_BUNDLE_MODULES = {"one.py": {}, "two.py": {}, "three.py": {}} + runner = CliRunner() + with mock.patch("circup.get_bundle_versions", return_value=TEST_BUNDLE_MODULES): + result = runner.invoke(circup.install, ["--auto-file", "./tests/bad_python.py"]) + assert result.exit_code == 2 From c46d2fdc758650dbfc5947ee797da039d5423174 Mon Sep 17 00:00:00 2001 From: Neradoc Date: Mon, 6 Feb 2023 23:36:49 +0100 Subject: [PATCH 02/20] using os.sep to find the ./ prefix --- circup/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/circup/__init__.py b/circup/__init__.py index fb0d903..3a7f1d2 100644 --- a/circup/__init__.py +++ b/circup/__init__.py @@ -1328,7 +1328,9 @@ def install(ctx, modules, pyext, requirement, auto, auto_file): # pragma: no co elif auto or auto_file: if auto_file is None: auto_file = "code.py" - if not os.path.isabs(auto_file) and not auto_file[:2] == "./": + # pass a local file with "./" or "../" + is_relative = auto_file[:2] in ("." + os.sep, "..") + if not os.path.isabs(auto_file) and not is_relative: auto_file = os.path.join(ctx.obj["DEVICE_PATH"], auto_file or "code.py") if not os.path.isfile(auto_file): click.secho(f"Auto file not found: {auto_file}", fg="red") From f7c812261b4bd2cdb6004d9775a8eedd90309473 Mon Sep 17 00:00:00 2001 From: Neradoc Date: Mon, 6 Feb 2023 23:39:43 +0100 Subject: [PATCH 03/20] move install help to the options, remove no-auto --- circup/__init__.py | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/circup/__init__.py b/circup/__init__.py index 3a7f1d2..373bc2e 100644 --- a/circup/__init__.py +++ b/circup/__init__.py @@ -1298,23 +1298,32 @@ def list_cli(ctx): # pragma: no cover @click.argument( "modules", required=False, nargs=-1, shell_complete=completion_for_install ) -@click.option("pyext", "--py", is_flag=True) -@click.option("-r", "--requirement", type=click.Path(exists=True, dir_okay=False)) -@click.option("--auto/--no-auto", "-a/-A") -@click.option("--auto-file", default=None) +@click.option( + "--py", + is_flag=True, + help="Install the .py version of the module(s) instead of the mpy version.", +) +@click.option( + "pyext", + "-r", + "--requirement", + type=click.Path(exists=True, dir_okay=False), + help="specify a text file to install all modules listed in the text file." + " Typically requirements.txt.", +) +@click.option("--auto", "-a", help="Install the modules imported in code.py.") +@click.option( + "--auto-file", + default=None, + help="Specify the name of a file on the board to read for auto install." + " Also accepts an absolute path or a local ./ path.", +) @click.pass_context def install(ctx, modules, pyext, requirement, auto, auto_file): # pragma: no cover """ Install a named module(s) onto the device. Multiple modules can be installed at once by providing more than one module name, each separated by a space. - - Option --py installs .py version of module(s). - - Option -r allows specifying a text file to install all modules listed in - the text file. - - Option -a installs based on the modules imported by code.py """ # TODO: Ensure there's enough space on the device available_modules = get_bundle_versions(get_bundles_list()) From e7853dfc3a6ed36f5b38e2091a713176f8472721 Mon Sep 17 00:00:00 2001 From: Neradoc Date: Tue, 21 Mar 2023 01:31:53 +0100 Subject: [PATCH 04/20] fix rebase --- circup/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circup/__init__.py b/circup/__init__.py index 373bc2e..4a4d049 100644 --- a/circup/__init__.py +++ b/circup/__init__.py @@ -1299,12 +1299,12 @@ def list_cli(ctx): # pragma: no cover "modules", required=False, nargs=-1, shell_complete=completion_for_install ) @click.option( + "pyext", "--py", is_flag=True, help="Install the .py version of the module(s) instead of the mpy version.", ) @click.option( - "pyext", "-r", "--requirement", type=click.Path(exists=True, dir_okay=False), From 3e7aa71a4472a17ffb32940433bc1e080ab3f6da Mon Sep 17 00:00:00 2001 From: Neradoc Date: Tue, 31 Jan 2023 23:47:06 +0100 Subject: [PATCH 05/20] find all files in packages --- circup/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/circup/__init__.py b/circup/__init__.py index 2854983..4468cd1 100644 --- a/circup/__init__.py +++ b/circup/__init__.py @@ -961,8 +961,8 @@ def get_modules(path): result[os.path.basename(sfm).replace(".py", "").replace(".mpy", "")] = metadata for package_path in package_dir_mods: name = os.path.basename(os.path.dirname(package_path)) - py_files = glob.glob(os.path.join(package_path, "*.py")) - mpy_files = glob.glob(os.path.join(package_path, "*.mpy")) + py_files = glob.glob(os.path.join(package_path, "**/*.py"), recursive=True) + mpy_files = glob.glob(os.path.join(package_path, "**/*.mpy"), recursive=True) all_files = py_files + mpy_files # default value result[name] = {"path": package_path, "mpy": bool(mpy_files)} From 62f7a657cf4d115130c692c5d0421bc09122d1fe Mon Sep 17 00:00:00 2001 From: Neradoc Date: Sat, 1 Apr 2023 17:11:23 +0200 Subject: [PATCH 06/20] Update circup/__init__.py Co-authored-by: Dan Halbert --- circup/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circup/__init__.py b/circup/__init__.py index 4a4d049..bbd0259 100644 --- a/circup/__init__.py +++ b/circup/__init__.py @@ -1338,7 +1338,7 @@ def install(ctx, modules, pyext, requirement, auto, auto_file): # pragma: no co if auto_file is None: auto_file = "code.py" # pass a local file with "./" or "../" - is_relative = auto_file[:2] in ("." + os.sep, "..") + is_relative = auto_file.startswith("." + os.sep) or auto_file.startswith(".." + os.sep) if not os.path.isabs(auto_file) and not is_relative: auto_file = os.path.join(ctx.obj["DEVICE_PATH"], auto_file or "code.py") if not os.path.isfile(auto_file): From 82ffa73b57ad82b706a420d816bb34789eab4abd Mon Sep 17 00:00:00 2001 From: Neradoc Date: Sun, 2 Apr 2023 01:47:16 +0200 Subject: [PATCH 07/20] Other way to find local path --- circup/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circup/__init__.py b/circup/__init__.py index bbd0259..72913d4 100644 --- a/circup/__init__.py +++ b/circup/__init__.py @@ -1338,7 +1338,7 @@ def install(ctx, modules, pyext, requirement, auto, auto_file): # pragma: no co if auto_file is None: auto_file = "code.py" # pass a local file with "./" or "../" - is_relative = auto_file.startswith("." + os.sep) or auto_file.startswith(".." + os.sep) + is_relative = auto_file.split(os.sep)[0] in [os.path.curdir, os.path.pardir] if not os.path.isabs(auto_file) and not is_relative: auto_file = os.path.join(ctx.obj["DEVICE_PATH"], auto_file or "code.py") if not os.path.isfile(auto_file): From aa8ab4e5cd3bb1bf5faf39d2e0ec3d9f3dc5e74d Mon Sep 17 00:00:00 2001 From: Neradoc Date: Thu, 13 Apr 2023 02:19:22 +0200 Subject: [PATCH 08/20] fix --auto requiring an argument --- circup/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/circup/__init__.py b/circup/__init__.py index 97f8f16..2e4dba4 100644 --- a/circup/__init__.py +++ b/circup/__init__.py @@ -1311,7 +1311,9 @@ def list_cli(ctx): # pragma: no cover help="specify a text file to install all modules listed in the text file." " Typically requirements.txt.", ) -@click.option("--auto", "-a", help="Install the modules imported in code.py.") +@click.option( + "--auto", "-a", is_flag=True, help="Install the modules imported in code.py." +) @click.option( "--auto-file", default=None, From 276fdc26b869313c8fca21413db46ea5a23407ce Mon Sep 17 00:00:00 2001 From: Phil Underwood Date: Wed, 26 Apr 2023 17:19:59 +0100 Subject: [PATCH 09/20] correctly install asyncio form requirementes --- circup/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/circup/__init__.py b/circup/__init__.py index 2e4dba4..63355c0 100644 --- a/circup/__init__.py +++ b/circup/__init__.py @@ -432,6 +432,7 @@ def clean_library_name(assumed_library_name): "adafruit_sd": "adafruit_sdcard", "adafruit_simpleio": "simpleio", "pimoroni_ltr559": "pimoroni_circuitpython_ltr559", + "adafruit_asyncio": "asyncio", } if "circuitpython" in assumed_library_name: # convert repo or pypi name to common library name From ce3fd3428894e76bec6910cbfd7a54e2543b636f Mon Sep 17 00:00:00 2001 From: Phil Underwood Date: Wed, 26 Apr 2023 21:57:39 +0100 Subject: [PATCH 10/20] Make changes alphabetised --- circup/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circup/__init__.py b/circup/__init__.py index 63355c0..ae8b1e6 100644 --- a/circup/__init__.py +++ b/circup/__init__.py @@ -426,13 +426,13 @@ def clean_library_name(assumed_library_name): not_standard_names = { # Assumed Name : Actual Name "adafruit_adafruitio": "adafruit_io", + "adafruit_asyncio": "asyncio", "adafruit_busdevice": "adafruit_bus_device", "adafruit_display_button": "adafruit_button", "adafruit_neopixel": "neopixel", "adafruit_sd": "adafruit_sdcard", "adafruit_simpleio": "simpleio", "pimoroni_ltr559": "pimoroni_circuitpython_ltr559", - "adafruit_asyncio": "asyncio", } if "circuitpython" in assumed_library_name: # convert repo or pypi name to common library name From c29fc11ab775bb9b7bb503b1c1a0538fe477020e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 23 May 2023 02:04:52 +0000 Subject: [PATCH 11/20] Bump requests from 2.26.0 to 2.31.0 Bumps [requests](https://github.com/psf/requests) from 2.26.0 to 2.31.0. - [Release notes](https://github.com/psf/requests/releases) - [Changelog](https://github.com/psf/requests/blob/main/HISTORY.md) - [Commits](https://github.com/psf/requests/compare/v2.26.0...v2.31.0) --- updated-dependencies: - dependency-name: requests dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 27985d2..1886e60 100644 --- a/requirements.txt +++ b/requirements.txt @@ -35,7 +35,7 @@ pytest-faulthandler==2.0.1 pytest-random-order==1.0.4 pytz==2019.2 readme-renderer==24.0 -requests==2.26.0 +requests==2.31.0 requests-toolbelt==0.9.1 semver==2.13.0 six==1.12.0 From d411bae64d270da827f0b240fe35d8410150729c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 20 Jul 2023 13:11:46 +0000 Subject: [PATCH 12/20] Bump pygments from 2.7.4 to 2.15.0 Bumps [pygments](https://github.com/pygments/pygments) from 2.7.4 to 2.15.0. - [Release notes](https://github.com/pygments/pygments/releases) - [Changelog](https://github.com/pygments/pygments/blob/master/CHANGES) - [Commits](https://github.com/pygments/pygments/compare/2.7.4...2.15.0) --- updated-dependencies: - dependency-name: pygments dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 1886e60..2117b76 100644 --- a/requirements.txt +++ b/requirements.txt @@ -26,7 +26,7 @@ packaging==19.1 pkginfo==1.5.0.1 pluggy==0.13.1 py==1.10.0 -Pygments==2.7.4 +Pygments==2.15.0 pylint==2.9.6 pyparsing==2.4.2 pytest==5.1.2 From 523b64a2c7359c0d90c4beaeb23694701abd48d9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 25 Jul 2023 20:48:26 +0000 Subject: [PATCH 13/20] Bump certifi from 2022.12.7 to 2023.7.22 Bumps [certifi](https://github.com/certifi/python-certifi) from 2022.12.7 to 2023.7.22. - [Commits](https://github.com/certifi/python-certifi/compare/2022.12.07...2023.07.22) --- updated-dependencies: - dependency-name: certifi dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 1886e60..df0a36c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,7 +6,7 @@ attrs==19.1.0 Babel==2.9.1 black==19.3b0 bleach==3.3.0 -certifi==2022.12.7 +certifi==2023.7.22 chardet==3.0.4 charset-normalizer==2.0.4 click==8.0.1 From 27160fe75d9544d509c72dedf526827813d332fd Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 3 Oct 2023 04:39:00 +0000 Subject: [PATCH 14/20] Bump urllib3 from 1.26.5 to 1.26.17 Bumps [urllib3](https://github.com/urllib3/urllib3) from 1.26.5 to 1.26.17. - [Release notes](https://github.com/urllib3/urllib3/releases) - [Changelog](https://github.com/urllib3/urllib3/blob/main/CHANGES.rst) - [Commits](https://github.com/urllib3/urllib3/compare/1.26.5...1.26.17) --- updated-dependencies: - dependency-name: urllib3 dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 963f4c5..5a446c5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -51,7 +51,7 @@ toml==0.10.0 tqdm==4.35.0 twine==1.13.0 update-checker==0.18.0 -urllib3==1.26.5 +urllib3==1.26.17 wcwidth==0.1.7 webencodings==0.5.1 wrapt==1.12.1 From fbf5aa4d50c3e433523a8504bd199feec35c0122 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Wed, 4 Oct 2023 12:14:42 -0400 Subject: [PATCH 15/20] 7.x bundles are no longer built --- circup/__init__.py | 2 +- tests/test_circup.py | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/circup/__init__.py b/circup/__init__.py index ae8b1e6..13d2470 100644 --- a/circup/__init__.py +++ b/circup/__init__.py @@ -58,7 +58,7 @@ NOT_MCU_LIBRARIES = [ #: The version of CircuitPython found on the connected device. CPY_VERSION = "" #: Module formats list (and the other form used in github files) -PLATFORMS = {"py": "py", "7mpy": "7.x-mpy", "8mpy": "7.x-mpy"} +PLATFORMS = {"py": "py", "8mpy": "8.x-mpy"} #: Commands that do not require an attached board BOARDLESS_COMMANDS = ["show", "bundle-add", "bundle-remove", "bundle-show"] #: Version identifier for a bad MPY file format diff --git a/tests/test_circup.py b/tests/test_circup.py index 0f2ba51..1f9805f 100644 --- a/tests/test_circup.py +++ b/tests/test_circup.py @@ -96,10 +96,10 @@ def test_Bundle_lib_dir(): "adafruit/adafruit-circuitpython-bundle-py/" "adafruit-circuitpython-bundle-py-TESTTAG/lib" ) - assert bundle.lib_dir("7mpy") == ( + assert bundle.lib_dir("8mpy") == ( "DATA_DIR/" - "adafruit/adafruit-circuitpython-bundle-7mpy/" - "adafruit-circuitpython-bundle-7.x-mpy-TESTTAG/lib" + "adafruit/adafruit-circuitpython-bundle-8mpy/" + "adafruit-circuitpython-bundle-8.x-mpy-TESTTAG/lib" ) @@ -312,7 +312,7 @@ def test_Module_mpy_mismatch(): """ path = os.path.join("foo", "bar", "baz", "module.mpy") repo = "https://github.com/adafruit/SomeLibrary.git" - with mock.patch("circup.CPY_VERSION", "7.0.0"): + with mock.patch("circup.CPY_VERSION", "8.0.0"): bundle = circup.Bundle(TEST_BUNDLE_NAME) m1 = circup.Module(path, repo, "1.2.3", "1.2.3", True, bundle, (None, None)) m2 = circup.Module( @@ -328,7 +328,7 @@ def test_Module_mpy_mismatch(): assert m2.outofdate is True assert m3.mpy_mismatch is False assert m3.outofdate is False - with mock.patch("circup.CPY_VERSION", "7.0.0"): + with mock.patch("circup.CPY_VERSION", "8.0.0"): assert m1.mpy_mismatch is False assert m1.outofdate is False assert m2.mpy_mismatch is False @@ -366,7 +366,7 @@ def test_Module_row(): path = os.path.join("foo", "bar", "baz", "module.py") repo = "https://github.com/adafruit/SomeLibrary.git" with mock.patch("circup.os.path.isfile", return_value=True), mock.patch( - "circup.CPY_VERSION", "7.0.0" + "circup.CPY_VERSION", "8.0.0" ): m = circup.Module(path, repo, "1.2.3", None, False, bundle, (None, None)) assert m.row == ("module", "1.2.3", "unknown", "Major Version") From 4e9a70a22a4476fd5d4744860aae890ee0d27c79 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 18 Oct 2023 01:24:38 +0000 Subject: [PATCH 16/20] Bump urllib3 from 1.26.17 to 1.26.18 Bumps [urllib3](https://github.com/urllib3/urllib3) from 1.26.17 to 1.26.18. - [Release notes](https://github.com/urllib3/urllib3/releases) - [Changelog](https://github.com/urllib3/urllib3/blob/main/CHANGES.rst) - [Commits](https://github.com/urllib3/urllib3/compare/1.26.17...1.26.18) --- updated-dependencies: - dependency-name: urllib3 dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 5a446c5..66bd56d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -51,7 +51,7 @@ toml==0.10.0 tqdm==4.35.0 twine==1.13.0 update-checker==0.18.0 -urllib3==1.26.17 +urllib3==1.26.18 wcwidth==0.1.7 webencodings==0.5.1 wrapt==1.12.1 From 575da0797d7a168c563d88f70d57c6e1d6096e1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Smitka?= Date: Sun, 22 Oct 2023 18:38:16 +0200 Subject: [PATCH 17/20] Add board-id and cpy-version params --- circup/__init__.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/circup/__init__.py b/circup/__init__.py index 13d2470..c8af344 100644 --- a/circup/__init__.py +++ b/circup/__init__.py @@ -1157,12 +1157,22 @@ def tags_data_save_tag(key, tag): type=click.Path(exists=True, file_okay=False), help="Path to CircuitPython directory. Overrides automatic path detection.", ) +@click.option( + "--board-id", + default=None, + help="Manual Board ID of the CircuitPython device. If provided in combination with --cpy-version, it overrides the detected board ID.", +) +@click.option( + "--cpy-version", + default=None, + help="Manual CircuitPython version. If provided in combination with --board-id, it overrides the detected CPy version.", +) @click.version_option( prog_name="CircUp", message="%(prog)s, A CircuitPython module updater. Version %(version)s", ) @click.pass_context -def main(ctx, verbose, path): # pragma: no cover +def main(ctx, verbose, path, board_id, cpy_version): # pragma: no cover """ A tool to manage and update libraries on a CircuitPython device. """ @@ -1200,7 +1210,10 @@ def main(ctx, verbose, path): # pragma: no cover click.secho("Could not find a connected CircuitPython device.", fg="red") sys.exit(1) else: - CPY_VERSION, board_id = get_circuitpython_version(device_path) + if board_id is not None and cpy_version is not None: + CPY_VERSION = cpy_version + else: + CPY_VERSION, board_id = get_circuitpython_version(device_path) click.echo( "Found device at {}, running CircuitPython {}.".format( device_path, CPY_VERSION From aa829a58040e0872387eeaaa6643d7190829f6a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Smitka?= Date: Sun, 22 Oct 2023 19:29:27 +0200 Subject: [PATCH 18/20] Fix line lengths --- circup/__init__.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/circup/__init__.py b/circup/__init__.py index c8af344..ced4923 100644 --- a/circup/__init__.py +++ b/circup/__init__.py @@ -1160,12 +1160,14 @@ def tags_data_save_tag(key, tag): @click.option( "--board-id", default=None, - help="Manual Board ID of the CircuitPython device. If provided in combination with --cpy-version, it overrides the detected board ID.", + help="Manual Board ID of the CircuitPython device. If provided in combination " \ + "with --cpy-version, it overrides the detected board ID.", ) @click.option( "--cpy-version", default=None, - help="Manual CircuitPython version. If provided in combination with --board-id, it overrides the detected CPy version.", + help="Manual CircuitPython version. If provided in combination " \ + "with --board-id, it overrides the detected CPy version.", ) @click.version_option( prog_name="CircUp", From 49737096ff34db91beec949d4cd60b7fccb69fb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Smitka?= Date: Sun, 22 Oct 2023 21:52:20 +0200 Subject: [PATCH 19/20] Attempt to remove one if-else I got: circup/__init__.py:1177:0: R0912: Too many branches (13/12) (too-many-branches) --- circup/__init__.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/circup/__init__.py b/circup/__init__.py index ced4923..be8bb9f 100644 --- a/circup/__init__.py +++ b/circup/__init__.py @@ -1212,10 +1212,11 @@ def main(ctx, verbose, path, board_id, cpy_version): # pragma: no cover click.secho("Could not find a connected CircuitPython device.", fg="red") sys.exit(1) else: - if board_id is not None and cpy_version is not None: - CPY_VERSION = cpy_version - else: - CPY_VERSION, board_id = get_circuitpython_version(device_path) + CPY_VERSION, board_id = ( + get_circuitpython_version(device_path) + if board_id is None or cpy_version is None + else (cpy_version, board_id) + ) click.echo( "Found device at {}, running CircuitPython {}.".format( device_path, CPY_VERSION From 0875a4d834533b3cc8142a94bff851ddb97cd910 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Smitka?= Date: Sun, 22 Oct 2023 22:08:28 +0200 Subject: [PATCH 20/20] Attempt to fix splitted long lines --- circup/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/circup/__init__.py b/circup/__init__.py index be8bb9f..c15946f 100644 --- a/circup/__init__.py +++ b/circup/__init__.py @@ -1160,14 +1160,14 @@ def tags_data_save_tag(key, tag): @click.option( "--board-id", default=None, - help="Manual Board ID of the CircuitPython device. If provided in combination " \ - "with --cpy-version, it overrides the detected board ID.", + help="Manual Board ID of the CircuitPython device. If provided in combination " + "with --cpy-version, it overrides the detected board ID.", ) @click.option( "--cpy-version", default=None, - help="Manual CircuitPython version. If provided in combination " \ - "with --board-id, it overrides the detected CPy version.", + help="Manual CircuitPython version. If provided in combination " + "with --board-id, it overrides the detected CPy version.", ) @click.version_option( prog_name="CircUp",