Repository navigation
Conversation
connections: Wait for output.
Update from upstream
Add import inlining option
dlech
left a comment
There was a problem hiding this comment.
Wow! This is very ambitious. We do occasionally get questions about how to share code, so I think this is a useful addition. Really nice to have unit tests too.
I've made a bunch of inline comments and suggestions. Also we just started using black to automatically format the code for us, so if you could poetry run black ., that will take care of formatting.
|
@dlech Thanks for taking time to review this. I'll make the requested changes as soon as I get some time. |
|
@dlech I think I've addressed all your comments now. Please can you check and review. Happy to make more changes if needed. Thanks. |
dlech
left a comment
There was a problem hiding this comment.
Thanks for making the changes. I found a few more things to look at. Also, it looks like you may have used an older version of black to format the code. We use poetry to manage packages and ensure everyone is using the same versions of the development dependencies (see pyproject.toml and poetry.lock)
|
|
||
| # Temporary files | ||
| demo/_*.py | ||
| /tests/inline_test_resources/**/*.flat.py |
There was a problem hiding this comment.
It would be better to create a new .gitignore file in the inline_test_resources directory and just add *.flat.py there. That way if directories ever get moved or renamed, things won't break.
| @@ -0,0 +1,118 @@ | |||
| # Inlining imports with pybricksdev | |||
| Most PoweredUp hubs are too small to have file systems, so splitting your PyBricks code | |||
There was a problem hiding this comment.
| Most PoweredUp hubs are too small to have file systems, so splitting your PyBricks code | |
| Most Powered Up hubs are too small to have file systems, so splitting your Pybricks code |
| that refer to modules in the host file system should be flattened into the | ||
| main script, so that the resulting program is still in one file. The intention is to | ||
| retain compatibility with desktop Python so that PyBricks code could, with simulated | ||
| PyBricks libraries, be run on the desktop. |
There was a problem hiding this comment.
| PyBricks libraries, be run on the desktop. | |
| Pybricks libraries, be run on the desktop. |
| for the 'run' and 'compile' functions in pybricksdev specifies that imports | ||
| that refer to modules in the host file system should be flattened into the | ||
| main script, so that the resulting program is still in one file. The intention is to | ||
| retain compatibility with desktop Python so that PyBricks code could, with simulated |
There was a problem hiding this comment.
| retain compatibility with desktop Python so that PyBricks code could, with simulated | |
| retain compatibility with desktop Python so that Pybricks code could, with simulated |
| ### The --inline-imports option | ||
| Here's an example command line: | ||
|
|
||
| pybricksdev run --inline-imports True ble "Pybricks Hub" demo/shortdemo.py |
There was a problem hiding this comment.
| pybricksdev run --inline-imports True ble "Pybricks Hub" demo/shortdemo.py | |
| pybricksdev run --inline-imports ble demo/shortdemo.py |
There was a problem hiding this comment.
Also, demo/shortdemo.py doesn't import anything and people won't have it anyway if they install pybricksdev from PyPI. So the generic main.py might be a better example file name.
| script_path: Path to the script to be processed. | ||
| import_base: Path to a secondary root directory for inlined imports. Optional. | ||
| The return value is the path to the flattened script |
There was a problem hiding this comment.
| script_path: Path to the script to be processed. | |
| import_base: Path to a secondary root directory for inlined imports. Optional. | |
| The return value is the path to the flattened script | |
| Args: | |
| script_path: Path to the script to be processed. | |
| import_base: Path to a secondary root directory for inlined imports. Optional. | |
| Returns: | |
| The path to the flattened script. |
| parser.add_argument( | ||
| "--import-path", | ||
| dest="importbase", | ||
| help="Additional base dir for inlined imports. Ignored unless --inline-imports is True", |
There was a problem hiding this comment.
All of the other help message already start with lower case.
| help="Additional base dir for inlined imports. Ignored unless --inline-imports is True", | |
| help="additional base dir for inlined imports; ignored when --inline-imports is not present", |
| "-i", | ||
| "--inline-imports", | ||
| dest="inline", | ||
| help="Flatten source into one file before compiling", |
There was a problem hiding this comment.
| help="Flatten source into one file before compiling", | |
| help="flatten source into one file before compiling", |
| "-i", | ||
| "--inline-imports", | ||
| dest="inline", | ||
| help="Flatten source into one file before downloading", |
There was a problem hiding this comment.
| help="Flatten source into one file before downloading", | |
| help="flatten source into one file before downloading", |
| parser.add_argument( | ||
| "--import-path", | ||
| dest="importbase", | ||
| help="Additional base dir for inlined imports. Ignored unless --inline-imports is True", |
There was a problem hiding this comment.
| help="Additional base dir for inlined imports. Ignored unless --inline-imports is True", | |
| help="additional base dir for inlined imports; Ignored when --inline-imports is not present", |
Fix bug where access to class features was not being substituted
372504e to
af3281d
Compare
|
Module imports are now supported by the firmware, so we will close this pull request. Thanks for submitting! |
No description provided.