diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a2dbe30..cb6a1b5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -29,19 +29,21 @@ jobs: python3 --version pre-commit --version - name: Checkout Current Repo - uses: actions/checkout@v1 + uses: actions/checkout@v4 with: submodules: true + show-progress: false - name: Library version run: git describe --dirty --always --tags - name: Pre-commit hooks run: | pre-commit run --all-files - name: Checkout tools repo - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: repository: adafruit/actions-ci-circuitpython-libs path: actions-ci + show-progress: false - name: Install dependencies # (e.g. - apt-get: gettext, etc; pip: circuitpython-build-tools, requirements.txt; etc.) run: | diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ffeb537..e843eff 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -12,7 +12,9 @@ jobs: upload-pypi: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v4 + with: + show-progress: false - name: Check For setup.py id: need-pypi run: | diff --git a/circup/__init__.py b/circup/__init__.py index 21ea508..166dfe1 100644 --- a/circup/__init__.py +++ b/circup/__init__.py @@ -498,6 +498,7 @@ def ensure_latest_bundle(bundle): def extract_metadata(path): + # pylint: disable=too-many-locals,too-many-branches """ Given an file path, return a dictionary containing metadata extracted from dunder attributes found therein. Works with both .py and .mpy files. @@ -528,6 +529,7 @@ def extract_metadata(path): if result: logger.info("Extracted metadata: %s", result) elif path.endswith(".mpy"): + find_by_regexp_match = False result["mpy"] = True with open(path, "rb") as mpy_file: content = mpy_file.read() @@ -541,10 +543,20 @@ def extract_metadata(path): loc = content.find(b"__version__") - 1 compatibility = (None, "7.0.0-alpha.1") elif mpy_version == b"C\x05": - # Two bytes in mpy version 5 + # Two bytes for the length of "__version__" in mpy version 5 loc = content.find(b"__version__") - 2 - compatibility = ("7.0.0-alpha.1", None) - if loc > -1: + compatibility = ("7.0.0-alpha.1", "8.99.99") + elif mpy_version == b"C\x06": + # Two bytes in mpy version 6 + find_by_regexp_match = True + compatibility = ("9.0.0-alpha.1", None) + if find_by_regexp_match: + # Too hard to find the version positionally. + # Find the first thing that looks like an x.y.z version number. + match = re.search(rb"([\d]+\.[\d]+\.[\d]+)\x00", content) + if match: + result["__version__"] = match.group(1).decode("utf-8") + elif loc > -1: # Backtrack until a byte value of the offset is reached. offset = 1 while offset < loc: diff --git a/tests/test_circup.py b/tests/test_circup.py index a73f002..db1924d 100644 --- a/tests/test_circup.py +++ b/tests/test_circup.py @@ -316,7 +316,7 @@ def test_Module_mpy_mismatch(): bundle = circup.Bundle(TEST_BUNDLE_NAME) m1 = circup.Module(path, repo, "1.2.3", "1.2.3", True, bundle, (None, None)) m2 = circup.Module( - path, repo, "1.2.3", "1.2.3", True, bundle, ("7.0.0-alpha.1", None) + path, repo, "1.2.3", "1.2.3", True, bundle, ("7.0.0-alpha.1", "8.99.99") ) m3 = circup.Module( path, repo, "1.2.3", "1.2.3", True, bundle, (None, "7.0.0-alpha.1") @@ -592,7 +592,7 @@ def test_extract_metadata_byte_code_v7(): result = circup.extract_metadata("tests/local_module_cp7.mpy") assert result["__version__"] == "1.2.3" assert result["mpy"] is True - assert result["compatibility"] == ("7.0.0-alpha.1", None) + assert result["compatibility"] == ("7.0.0-alpha.1", "8.99.99") def test_find_modules():