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

Cannot load Python files with a capitalised extension #396

Closed
carlosperate opened this issue Mar 17, 2018 · 8 comments
Closed

Cannot load Python files with a capitalised extension #396

carlosperate opened this issue Mar 17, 2018 · 8 comments
Assignees
Labels

Comments

@carlosperate
Copy link
Member

Tested on Windows 10, Python 3.5.2 32-bits, latest Mu master (6121350).

To reproduce:

  • Create in the mu_code folder a file named a.PY with some text content
  • Click the Load button
  • Select and open the a.PY file
  • The filed is not opened, no error message given, just a new empty tab opened:

image

Log:

Starting Mu 1.0.0.beta.15
2018-03-17 21:38:00,613 - root:95(run) INFO: uname_result(system='Windows', node='DESKTOP-KD60UUU', release='10', version='10.0.16299', machine='AMD64', processor='Intel64 Family 6 Model 60 Stepping 3, GenuineIntel')
2018-03-17 21:38:00,613 - root:96(run) INFO: Python path: ['C:\\workspace\\mu-temp\\mu', 'C:\\Users\\carlo\\Envs\\py3mu\\Scripts\\python35.zip', 'C:\\Users\\carlo\\Envs\\py3mu\\DLLs', 'C:\\Users\\carlo\\Envs\\py3mu\\lib', 'C:\\Users\\carlo\\Envs\\py3mu\\Scripts', 'C:\\Python35\\Lib', 'C:\\Python35\\DLLs', 'C:\\Users\\carlo\\Envs\\py3mu', 'C:\\Users\\carlo\\Envs\\py3mu\\lib\\site-packages', 'C:\\Users\\carlo\\Envs\\py3mu\\lib\\site-packages\\win32', 'C:\\Users\\carlo\\Envs\\py3mu\\lib\\site-packages\\win32\\lib', 'C:\\Users\\carlo\\Envs\\py3mu\\lib\\site-packages\\Pythonwin', 'C:\\Users\\carlo\\Envs\\py3mu\\lib\\site-packages\\IPython\\extensions']
2018-03-17 21:38:00,613 - mu.logic:499(__init__) INFO: Setting up editor.
2018-03-17 21:38:00,613 - mu.logic:510(__init__) INFO: Settings path: C:\Users\carlo\AppData\Local\python\mu\settings.json
2018-03-17 21:38:00,613 - mu.logic:511(__init__) INFO: Session path: C:\Users\carlo\AppData\Local\python\mu\session.json
2018-03-17 21:38:00,613 - mu.logic:512(__init__) INFO: Log directory: C:\Users\carlo\AppData\Local\python\mu\Logs
2018-03-17 21:38:00,613 - mu.logic:513(__init__) INFO: Data directory: C:\Users\carlo\AppData\Local\python\mu
2018-03-17 21:38:00,666 - mu.logic:521(setup) INFO: Available modes: debugger, python, microbit, pygamezero, adafruit
2018-03-17 21:38:00,713 - mu.logic:856(change_mode) INFO: Workspace directory: C:\Users\carlo\mu_code
2018-03-17 21:38:00,713 - mu.logic:560(restore_session) INFO: Restoring session from: C:\Users\carlo\AppData\Local\python\mu\session.json
2018-03-17 21:38:00,713 - mu.logic:561(restore_session) DEBUG: {'mode': 'python', 'paths': [], 'theme': 'day'}
2018-03-17 21:38:00,713 - mu.logic:580(restore_session) INFO: Loaded files.
2018-03-17 21:38:00,745 - mu.logic:589(restore_session) INFO: Starting with blank file.
2018-03-17 21:38:00,751 - mu.logic:856(change_mode) INFO: Workspace directory: C:\Users\carlo\mu_code
2018-03-17 21:38:08,624 - mu.interface.main:233(get_load_path) DEBUG: Getting load path: C:/Users/carlo/mu_code/a.PY
2018-03-17 21:38:08,624 - mu.logic:615(_load) INFO: Loading script from: C:/Users/carlo/mu_code/a.PY
2018-03-17 21:38:08,624 - mu.logic:643(_load) DEBUG: 
2018-03-17 21:38:10,644 - mu.logic:811(show_logs) INFO: Showing logs from C:\Users\carlo\AppData\Local\python\mu\Logs\mu.log

@tjguk tjguk self-assigned this Mar 17, 2018
@tjguk
Copy link
Collaborator

tjguk commented Mar 17, 2018

I'll pick this up for now, since I'm working in the load/save space for issue #370. At least, please can others leave this area alone for the moment?

@carlosperate
Copy link
Member Author

Great, thanks Tim!

@ZanderBrown
Copy link
Contributor

From my work on #74 (a side project to #385) i've found that Mu tries to load anything other than .py as a hex file.

mu/mu/logic.py

Lines 627 to 639 in 6121350

if path.endswith('.py'):
# Open the file, read the textual content and set the name as
# the path to the file.
with open(path, newline='') as f:
text = f.read()
name = path
else:
# Open the hex, extract the Python script therein and set the
# name to None, thus forcing the user to work out what to name
# the recovered script.
with open(path, newline='') as f:
text = uflash.extract_script(f.read())
name = None

When a hex file is opened the python source is extracted and pasted into a new untitled tab but clearly .PY isn't hex so it's failing with an empty document

Side note: a non micropython hex will crash Mu

So some verification that the file is actually a hex maybe a good idea, and case-insensitive matching of .py

@carlosperate
Copy link
Member Author

Side note: a non micropython hex will crash Mu

If that the case we should probably open a new issue to track that one.

@ZanderBrown
Copy link
Contributor

Technically it would be a uFlash problem, in fact you already reported it ntoll/uflash#29

@carlosperate
Copy link
Member Author

If uFlash is throwing an exception (intentionally or unintentionally) and Mu is crashing instead of catching it, we should still categorise that as a bug in Mu.

@ntoll
Copy link
Member

ntoll commented Mar 20, 2018

@ZanderBrown this should be a very simple fix (try/except/report problem, if encountered). I'm happy to fix this myself, but don't want to tread on @tjguk's toes as he does the encoding / load / save refactoring.

Good catch and +1 on @carlosperate's assessment (Mu should handle the problem, probably as per my description above).

@ntoll
Copy link
Member

ntoll commented Mar 21, 2018

The issues mentioned in this ticket have been fixed and the changes have landed in master.

@ntoll ntoll closed this as completed Mar 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants