Merge pull request #1259 from pybricks/dlech

v2.0.0-beta.8
This commit is contained in:
David Lechner
2022-10-25 12:00:58 -05:00
committed by GitHub
3 changed files with 34 additions and 14 deletions
+9 -1
View File
@@ -4,6 +4,13 @@
## [Unreleased]
## [2.0.0-beta.8] - 2022-10-25
### Fixed
- Fixed crash when user program contains syntax error ([support#755]).
[support#755]: https://github.com/pybricks/support/issues/755
## [2.0.0-beta.7] - 2022-10-24
### Fixed
@@ -430,7 +437,8 @@ Prerelease changes are documented at [support#48].
<!-- links for version headings -->
[Unreleased]: https://github.com/pybricks/pybricks-code/compare/v2.0.0-beta.7...HEAD
[Unreleased]: https://github.com/pybricks/pybricks-code/compare/v2.0.0-beta.8...HEAD
[2.0.0-beta.8]: https://github.com/pybricks/pybricks-code/compare/v2.0.0-beta.7...v2.0.0-beta.8
[2.0.0-beta.7]: https://github.com/pybricks/pybricks-code/compare/v2.0.0-beta.6...v2.0.0-beta.7
[2.0.0-beta.6]: https://github.com/pybricks/pybricks-code/compare/v2.0.0-beta.5...v2.0.0-beta.6
[2.0.0-beta.5]: https://github.com/pybricks/pybricks-code/compare/v2.0.0-beta.4...v2.0.0-beta.5
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@pybricks/pybricks-code",
"version": "2.0.0-beta.7",
"version": "2.0.0-beta.8",
"license": "MIT",
"author": "The Pybricks Authors",
"repository": {
+24 -12
View File
@@ -74,25 +74,37 @@ export function validateFileName(
/**
* Finds modules imported by a Python script.
*
* Returns an empty list if there are syntax errors.
*
* @param py A Python Script.
* @returns A list of the names of modules imported by this file.
*/
export function findImportedModules(py: string): ReadonlySet<string> {
const modules = new Set<string>();
const tree = parse(py);
// find all import statements in the syntax tree and collect imported modules
walk(tree, {
onEnterNode(node, _ancestors) {
if (node.type === 'import') {
for (const name of node.names) {
modules.add(name.path);
try {
const tree = parse(py);
// find all import statements in the syntax tree and collect imported modules
walk(tree, {
onEnterNode(node, _ancestors) {
if (node.type === 'import') {
for (const name of node.names) {
modules.add(name.path);
}
} else if (node.type === 'from') {
modules.add(node.base);
}
} else if (node.type === 'from') {
modules.add(node.base);
}
},
});
},
});
} catch (err) {
// istanbul ignore if
if (process.env.NODE_ENV === 'development') {
console.debug(err);
}
// files with syntax errors are ignored
}
return modules;
}