Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle mpy version checking for Circuitpython 9 #198

Merged
merged 3 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
18 changes: 15 additions & 3 deletions circup/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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()
Expand All @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_circup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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():
Expand Down
Loading