micropy-cli: TypeError while generating stubs from board via USB
Describe the bug
micropy fails to generate stubs from a PicoW board running Pimoroni Micropython, when no other stubs exist.
Expected Behavior
Micropy generates stubs successfully.
Current Behavior
Micropy produces a TypeError and doesn’t generate the stubs.
Steps to Reproduce
- Make sure you have no stubs installed - e.g.
rm -rf ~/.micropy - Connect a Raspberry Pi Pico W board via USB, holding bootsel
- Copy the Pimoroni Micropython 1.19.16 image for Pico W to the board, from Releases page
- Run micropy via USB, with something like
micropy stubs create /dev/cu.usbmodem11201
Possible Solution
For me, adding str around name in the line "/".join([package.repo_name, name]) in resolve_package function of repo.py fixed the issue.
def resolve_package(self, name: str) -> StubRepositoryPackage:
"""Resolve a package name to a package path.
Args:
name: Package name.
Returns:
Package location.
Throws:
StubNotFound: When package cannot be resolved.
"""
for package in self.search(str(name)):
if package.match_exact(name) or package.match_exact(
"/".join([package.repo_name, str(name)])
):
return package
latest = self.latest_for_package(package)
if latest and latest.name == name:
return latest
raise exc.StubNotFound(name)
Once the stubs have generated once with this change, the unmodified code works fine - seems to be something about having no stubs, or maybe not having an existing version of the same-named stubs?
Logs
The last section of output from micropy stubs create /dev/cu.usbmodem11201 - everything before this looks normal:
MicroPy Pyboard Reading /stubs/micropython-rp2-1_19_1/websocket.py: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| [329/329 @ 320B/s]
MicroPy Pyboard Reading /stubs/micropython-rp2-1_19_1/zlib.py: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| [273/273 @ 269B/s]
MicroPy Copied Stubs: stubs
Traceback (most recent call last):
File "/opt/homebrew/bin/micropy", line 8, in <module>
sys.exit(cli())
File "/opt/homebrew/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
return self.main(*args, **kwargs)
File "/opt/homebrew/lib/python3.10/site-packages/click/core.py", line 1055, in main
rv = self.invoke(ctx)
File "/opt/homebrew/lib/python3.10/site-packages/click/core.py", line 1657, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/opt/homebrew/lib/python3.10/site-packages/click/core.py", line 1657, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/opt/homebrew/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/opt/homebrew/lib/python3.10/site-packages/click/core.py", line 760, in invoke
return __callback(*args, **kwargs)
File "/opt/homebrew/lib/python3.10/site-packages/click/decorators.py", line 84, in new_func
return ctx.invoke(f, obj, *args, **kwargs)
File "/opt/homebrew/lib/python3.10/site-packages/click/core.py", line 760, in invoke
return __callback(*args, **kwargs)
File "/opt/homebrew/lib/python3.10/site-packages/micropy/cli.py", line 306, in create
return mpy.create_stubs(port, verbose=verbose)
File "/opt/homebrew/lib/python3.10/site-packages/micropy/main.py", line 143, in create_stubs
stub = self.stubs.add(stub_path)
File "/opt/homebrew/lib/python3.10/site-packages/micropy/stubs/stubs.py", line 336, in add
return self._load(stub_source, copy_to=dest)
File "/opt/homebrew/lib/python3.10/site-packages/micropy/stubs/stubs.py", line 98, in _load
with stub_source.ready() as src_path:
File "/opt/homebrew/Cellar/python@3.10/3.10.6_1/Frameworks/Python.framework/Versions/3.10/lib/python3.10/contextlib.py", line 135, in __enter__
return next(self.gen)
File "/opt/homebrew/lib/python3.10/site-packages/micropy/stubs/source.py", line 77, in ready
path = reduce(reducer, self.locators, location or self.location)
File "/opt/homebrew/lib/python3.10/site-packages/micropy/stubs/source.py", line 52, in _do_locate
response = locator.prepare(path)
File "/opt/homebrew/lib/python3.10/site-packages/micropy/stubs/source.py", line 138, in prepare
source = self.repo.resolve_package(location)
File "/opt/homebrew/lib/python3.10/site-packages/micropy/stubs/repo.py", line 134, in resolve_package
"/".join([package.repo_name, name])
TypeError: sequence item 1: expected str instance, PosixPath found
Context (Environment)
- OS: macOS Ventura 13.2.1, M1 processor
- Micropy Version: 4.1.0
- Python Version: Python 3.10.6
- VSCode Version: 1.76.0
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 15 (8 by maintainers)
Just realised I’d chopped off a bit too much - there’s also a “Failed to create the report” message earlier in the output:
I grabbed a copy of the files that had been copied to the temp directory at the point the script fails, interestingly the last few are 0 bytes, these are also the files that display “[0.00/0.00 @ ?B/s]” in the micropy output. The file names also stop before the end of the list above - there’s nothing after
onewire, even though there are other packages listed in the stub creation output from micropy (e.g.uzlib,version,websocketetc. Is there any chance it’s running out of RAM/Flash on the board?@BradenM Ah that’s great - I’ll stand by for the prerelease, thanks!