BradenM / micropy-cli

Micropython Project Management Tool with VSCode support, Linting, Intellisense, Dependency Management, and more!
https://micropy-cli.readthedocs.io
MIT License
311 stars 25 forks source link

Create stubs spits out ValueError #583

Closed whinee closed 6 months ago

whinee commented 6 months ago

Im trying to make a stub for the board A9G pudding.

Describe the bug

I don't know, but when I run the following command:

micropy stubs create /dev/ttyUSB0

This spits out:

MicroPy  Connecting to Pyboard @ /dev/ttyUSB0
MicroPy  ✔ Connected!
2024-02-11 13:00:39.418 | DEBUG    | stubber.minify:minify_script:253 - Original length : 26905
2024-02-11 13:00:39.418 | INFO     | stubber.minify:minify_script:254 - Minified length : 11631
2024-02-11 13:00:39.418 | INFO     | stubber.minify:minify_script:255 - Reduced by      : 15274 
2024-02-11 13:00:39.658 | DEBUG    | stubber.minify:cross_compile:328 - mpy-cross compiled to    : mpy_cross_ax_tpivz.mpy
MicroPy  Executing stubber on pyboard...
MicroPy  Pyboard  Writing /createstubs.mpy: 100%|█| [10.4k/10.4k
MicroPy  ✔ Done!
MicroPy  Copying stubs...
╭───────────── Traceback (most recent call last) ──────────────╮
│ /home/lyra/storage/projects/fw-linux/.venv/lib64/python3.11/ │
│ site-packages/micropy/app/stubs.py:187 in stubs_create       │
│                                                              │
│   184 │   log.success("Done!")                               │
│   185 │   log.info("Copying stubs...")                       │
│   186 │   with tempfile.TemporaryDirectory() as tmpdir:      │
│ ❱ 187 │   │   pyb.copy_from(                                 │
│   188 │   │   │   DevicePath("/stubs"),                      │
│   189 │   │   │   tmpdir,                                    │
│   190 │   │   │   verify_integrity=True,                     │
│                                                              │
│ ╭───────────────────────── locals ─────────────────────────╮ │
│ │        _get_desc = <function                             │ │
│ │                    stubs_create.<locals>._get_desc at    │ │
│ │                    0x7f4d3b1f8f40>                       │ │
│ │          backend = <CreateBackend.upydevice:             │ │
│ │                    'upydevice'>                          │ │
│ │          compile = True                                  │ │
│ │     create_stubs = <_io.BytesIO object at                │ │
│ │                    0x7f4d3a125670>                       │ │
│ │              ctx = <click.core.Context object at         │ │
│ │                    0x7f4d3b5b2690>                       │ │
│ │         dev_path = 'createstubs.mpy'                     │ │
│ │          exclude = []                                    │ │
│ │ exclude_defaults = True                                  │ │
│ │              log = <micropy.logger.ServiceLog object at  │ │
│ │                    0x7f4d3b1ddc10>                       │ │
│ │  message_handler = MessageHandlers(                      │ │
│ │                    │   on_message=<function              │ │
│ │                    stubs_create.<locals>.<lambda> at     │ │
│ │                    0x7f4d3b1fa0c0>,                      │ │
│ │                    )                                     │ │
│ │           module = []                                    │ │
│ │  module_defaults = True                                  │ │
│ │               mp = <micropy.main.MicroPy object at       │ │
│ │                    0x7f4d3b1dc990>                       │ │
│ │             port = '/dev/ttyUSB0'                        │ │
│ │              pyb = <micropy.pyd.pydevice.PyDevice object │ │
│ │                    at 0x7f4d3ad0ed50>                    │ │
│ │          pyb_log = <micropy.logger.ServiceLog object at  │ │
│ │                    0x7f4d3ad0fbd0>                       │ │
│ │           tmpdir = '/tmp/tmp037u6p9c'                    │ │
│ │          variant = <CreateStubsVariant.BASE: 'base'>     │ │
│ ╰──────────────────────────────────────────────────────────╯ │
│                                                              │
│ /home/lyra/storage/projects/fw-linux/.venv/lib64/python3.11/ │
│ site-packages/micropy/pyd/pydevice.py:50 in copy_from        │
│                                                              │
│   47 │   │   src_path = Path(str(source_path))               │
│   48 │   │   # 'is_dir/file' only works on existing paths.   │
│   49 │   │   if not src_path.suffix:                         │
│ ❱ 50 │   │   │   return self.pydevice.copy_dir(              │
│   51 │   │   │   │   DevicePath(source_path),                │
│   52 │   │   │   │   target_path,                            │
│   53 │   │   │   │   consumer=self.consumer,                 │
│                                                              │
│ ╭───────────────────────── locals ─────────────────────────╮ │
│ │ exclude_integrity = {'usys.py', 'sys.py'}                │ │
│ │              self = <micropy.pyd.pydevice.PyDevice       │ │
│ │                     object at 0x7f4d3ad0ed50>            │ │
│ │       source_path = '/stubs'                             │ │
│ │          src_path = PosixPath('/stubs')                  │ │
│ │       target_path = '/tmp/tmp037u6p9c'                   │ │
│ │  verify_integrity = True                                 │ │
│ ╰──────────────────────────────────────────────────────────╯ │
│                                                              │
│ /home/lyra/storage/projects/fw-linux/.venv/lib64/python3.11/ │
│ site-packages/micropy/pyd/backend_upydevice.py:157 in        │
│ copy_dir                                                     │
│                                                              │
│   154 │   │   target_path = Path(str(target_path))  # type:  │
│   155 │   │   source_path = self.resolve_path(source_path)   │
│   156 │   │   exclude_integrity = exclude_integrity or set() │
│ ❱ 157 │   │   for file_path in self.iter_files(source_path): │
│   158 │   │   │   rel_path = PurePosixPath(file_path).relati │
│   159 │   │   │   │   list(PurePosixPath(file_path).parents) │
│   160 │   │   │   )                                          │
│                                                              │
│ ╭───────────────────────── locals ─────────────────────────╮ │
│ │ exclude_integrity = {'usys.py', 'sys.py'}                │ │
│ │            kwargs = {                                    │ │
│ │                     │   'consumer':                      │ │
│ │                     <micropy.pyd.consumers.ConsumerDele… │ │
│ │                     object at 0x7f4d3ad0ed90>,           │ │
│ │                     │   'verify_integrity': True         │ │
│ │                     }                                    │ │
│ │              self = <micropy.pyd.backend_upydevice.UPyD… │ │
│ │                     object at 0x7f4d3ad0eb90>            │ │
│ │       source_path = '/stubs'                             │ │
│ │       target_path = PosixPath('/tmp/tmp037u6p9c')        │ │
│ ╰──────────────────────────────────────────────────────────╯ │
│                                                              │
│ /home/lyra/storage/projects/fw-linux/.venv/lib64/python3.11/ │
│ site-packages/micropy/pyd/backend_upydevice.py:140 in        │
│ iter_files                                                   │
│                                                              │
│   137 │   │   if not results:                                │
│   138 │   │   │   return                                     │
│   139 │   │   for file_result in results:                    │
│ ❱ 140 │   │   │   name, type_, _, _ = file_result            │
│   141 │   │   │   abs_path = PurePosixPath(path) / name      │
│   142 │   │   │   if type_ == stat.S_IFDIR:                  │
│   143 │   │   │   │   yield from self.iter_files(abs_path)   │
│                                                              │
│ ╭───────────────────────── locals ─────────────────────────╮ │
│ │ file_result = 'T'                                        │ │
│ │        path = '/stubs'                                   │ │
│ │     results = 'Traceback (most recent call last):\n      │ │
│ │               File "<stdin>", line 1, in                 │ │
│ │               <module>\nOSError'+19                      │ │
│ │        self = <micropy.pyd.backend_upydevice.UPyDeviceB… │ │
│ │               object at 0x7f4d3ad0eb90>                  │ │
│ ╰──────────────────────────────────────────────────────────╯ │
╰──────────────────────────────────────────────────────────────╯
ValueError: not enough values to unpack (expected 4, got 1)

Expected Behavior

For it to work.

Current Behavior

Error.

Steps to Reproduce

Run the following command:

micropy stubs create /dev/ttyUSB0

Logs

[2024-02-11 13:00:37] DEBUG: hookproxy(add_from_file): Method added to proxy: (<function PackagesModule.add_from_file at 0x7f4d3e5f59e0>, '_hook__add_from_file__path_None__dev_False')
[2024-02-11 13:00:37] DEBUG: hookproxy(add_package): Method added to proxy: (<function PackagesModule.add_package at 0x7f4d3e5f5a80>, '_hook__add_package__dev_False')
[2024-02-11 13:00:37] DEBUG: hookproxy(add_package): Method added to proxy: (<function DevPackagesModule.add_package at 0x7f4d3e5f60c0>, '_hook__add_package__dev_True')
[2024-02-11 13:00:37] DEBUG: hookproxy(add_from_file): Method added to proxy: (<function DevPackagesModule.add_from_file at 0x7f4d3e5f6200>, '_hook__add_from_file__path_None__dev_True')
[2024-02-11 13:00:37] DEBUG: hookproxy(stubs): Method added to proxy: (<function StubsModule.stubs at 0x7f4d3d95dc60>, '_hook__stubs__')
[2024-02-11 13:00:37] DEBUG: hookproxy(add_stub): Method added to proxy: (<function StubsModule.add_stub at 0x7f4d3d95f560>, '_hook__add_stub__')
[2024-02-11 13:00:38] DEBUG: micropy: MicroPy Loaded
[2024-02-11 13:00:38] DEBUG: fw-linux: adding module: StubsModule
[2024-02-11 13:00:38] DEBUG: fw-linux: adding module: PackagesModule
[2024-02-11 13:00:38] DEBUG: fw-linux: adding module: DevPackagesModule
[2024-02-11 13:00:38] DEBUG: fw-linux: adding module: TemplatesModule
[2024-02-11 13:00:38] INFO: micropy: Connecting to Pyboard @ /dev/ttyUSB0
[2024-02-11 13:00:38] INFO: micropy: Connected!
[2024-02-11 13:00:39] INFO: micropy: Executing stubber on pyboard...
[2024-02-11 13:00:51] INFO: micropy: Done!
[2024-02-11 13:00:51] INFO: micropy: Copying stubs...

Context (Environment)

whinee commented 6 months ago

line 136 of file /home/lyra/storage/projects/fw-linux/.venv/lib64/python3.11/site-packages/micropy/pyd/backend_upydevice.py:

results = self._pydevice.cmd(f"list(uos.ilistdir('{path}'))", silent=True, rtn_resp=True)

equals to:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 2] ENOENT

No wonder!

Running the following makes the first error go away:

mkdir stubs
ampy --port /dev/ttyUSB0 put stubs

However, a new error arise:

MicroPy  Connecting to Pyboard @ /dev/ttyUSB0
MicroPy  ✔ Connected!
2024-02-11 13:14:29.126 | DEBUG    | stubber.minify:minify_script:253 - Original length : 26905
2024-02-11 13:14:29.126 | INFO     | stubber.minify:minify_script:254 - Minified length : 11631
2024-02-11 13:14:29.126 | INFO     | stubber.minify:minify_script:255 - Reduced by      : 15274 
2024-02-11 13:14:29.354 | DEBUG    | stubber.minify:cross_compile:328 - mpy-cross compiled to    : mpy_cross_3_qc0ugh.mpy
MicroPy  Executing stubber on pyboard...
MicroPy  Pyboard  Writing /createstubs.mpy: 100%|███████████████████████████████████████████████████████████| [10.4k/10.4k @ 1.04kB/s]
MicroPy  Pyboard  Traceback (most recent call last):
MicroPy  Pyboard  File "<stdin>", line 1, in <module>
MicroPy  Pyboard  ValueError: incompatible .mpy file
MicroPy  ✔ Done!
MicroPy  Copying stubs...