mu-editor / mu

A small, simple editor for beginner Python programmers. Written in Python and Qt5.
http://codewith.mu
GNU General Public License v3.0
1.39k stars 433 forks source link

CircuitPython's `code.py` ends up in Mu installation folder and crashes Mu #2453

Open carlosperate opened 1 year ago

carlosperate commented 1 year ago

Because Python's standard library pdb module does import code:

❯ echo "this file in the Mu installation folder should not be imported" > code.py

❯ python run.py
Traceback (most recent call last):
  File "/Users/microbit-carlos/workspace/carlos/mu/run.py", line 2, in <module>
    from mu.app import run
  File "/Users/microbit-carlos/workspace/carlos/mu/mu/app.py", line 47, in <module>
    from .logic import Editor, LOG_FILE, LOG_DIR, ENCODING
  File "/Users/microbit-carlos/workspace/carlos/mu/mu/logic.py", line 36, in <module>
    from pyflakes.api import check
  File "/Users/microbit-carlos/workspace/carlos/mu/.venv-qt6/lib/python3.10/site-packages/pyflakes/api.py", line 10, in <module>
    from pyflakes import checker, __version__
  File "/Users/microbit-carlos/workspace/carlos/mu/.venv-qt6/lib/python3.10/site-packages/pyflakes/checker.py", line 11, in <module>
    import doctest
  File "/Users/microbit-carlos/.pyenv/versions/3.10.8/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/doctest.py", line 100, in <module>
    import pdb
  File "/Users/microbit-carlos/.pyenv/versions/3.10.8/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/pdb.py", line 77, in <module>
    import code
  File "/Users/microbit-carlos/workspace/carlos/mu/code.py", line 1
    this file in the Mu installation folder should not be imported
         ^^^^
SyntaxError: invalid syntax

The bug here is that somehow the CircuitPython mode must be saving the code.py file in the Mu's cwd instead of the CIRCUITPY drive.

Crash reports:

These other crash reports are from having the cope.py file in other directories, that are likely added to the path as well, like the "Desktop", "Downloads" or other folders:

carlosperate commented 1 year ago

It's very interesting that this has only happened with Mu v1.2.0, not a single crash report from earlier versions. So maybe something we accidentally introduced in the last release?

https://github.com/mu-editor/mu/compare/v1.1.1...v1.2.0