From bb2fa3ae1dc197c10597806796ebcc9f15f7a677 Mon Sep 17 00:00:00 2001 From: David Lechner Date: Thu, 22 Dec 2022 13:12:10 -0600 Subject: [PATCH] package: switch to @pybricks/python-program-analysis The package we were using was only for Python 3.4 and didn't include async/await which broke imports in any script that used async/await. Fixes: https://github.com/pybricks/support/issues/873 --- CHANGELOG.md | 4 ++++ package.json | 2 +- src/pybricksMicropython/lib.test.ts | 15 +++++++++++++++ src/pybricksMicropython/lib.ts | 4 ++-- yarn.lock | 10 +++++----- 5 files changed, 27 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 21590a5e..caae5678 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,11 @@ ### Changed - Changed app display from "fullscreen" to "standalone" ([support#867]). +### Fixed +- Fixed imports in scripts that use `async` or `await` keywords ([support#873]). + [support#867]: https://github.com/pybricks/support/issues/867 +[support#873]: https://github.com/pybricks/support/issues/873 ## [2.0.1] - 2022-12-21 diff --git a/package.json b/package.json index 0b02fe08..c9d7ca18 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "@pybricks/jedi": "1.6.0", "@pybricks/mpy-cross-v5": "^2.0.0", "@pybricks/mpy-cross-v6": "^2.0.0", - "@qoretechnologies/python-parser": "^0.4.10", + "@pybricks/python-program-analysis": "^1.0.1", "@reduxjs/toolkit": "^1.9.1", "@shopify/react-i18n": "^7.5.1", "@svgr/webpack": "^6.5.1", diff --git a/src/pybricksMicropython/lib.test.ts b/src/pybricksMicropython/lib.test.ts index 422941e6..db7ae55e 100644 --- a/src/pybricksMicropython/lib.test.ts +++ b/src/pybricksMicropython/lib.test.ts @@ -131,3 +131,18 @@ from q import q ]), ); }); + +test('https://github.com/pybricks/support/issues/873 regression', () => { + const script = ` +from my_module import data + +async def hello(): + print("hello") + +print(data) +`; + + const modules = findImportedModules(script); + + expect(modules).toEqual(new Set(['my_module'])); +}); diff --git a/src/pybricksMicropython/lib.ts b/src/pybricksMicropython/lib.ts index ed745f10..156bce37 100644 --- a/src/pybricksMicropython/lib.ts +++ b/src/pybricksMicropython/lib.ts @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT // Copyright (c) 2022 The Pybricks Authors -import { parse, walk } from '@qoretechnologies/python-parser'; +import { parse, walk } from '@pybricks/python-program-analysis'; import type { FileContents, FileStorageDb } from '../fileStorage'; /** The Python file extension ('.py') */ @@ -99,7 +99,7 @@ export function findImportedModules(py: string): ReadonlySet { }); } catch (err) { // istanbul ignore if - if (process.env.NODE_ENV !== 'test') { + if (process.env.NODE_ENV === 'test') { console.error(err); } diff --git a/yarn.lock b/yarn.lock index 017dda6c..c5ad630f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2418,7 +2418,7 @@ __metadata: "@pybricks/jedi": 1.6.0 "@pybricks/mpy-cross-v5": ^2.0.0 "@pybricks/mpy-cross-v6": ^2.0.0 - "@qoretechnologies/python-parser": ^0.4.10 + "@pybricks/python-program-analysis": ^1.0.1 "@reduxjs/toolkit": ^1.9.1 "@shopify/react-i18n": ^7.5.1 "@svgr/webpack": ^6.5.1 @@ -2541,12 +2541,12 @@ __metadata: languageName: unknown linkType: soft -"@qoretechnologies/python-parser@npm:^0.4.10": - version: 0.4.10 - resolution: "@qoretechnologies/python-parser@npm:0.4.10" +"@pybricks/python-program-analysis@npm:^1.0.1": + version: 1.0.1 + resolution: "@pybricks/python-program-analysis@npm:1.0.1" dependencies: lodash: ^4.17.15 - checksum: ab0d91719a8301b64f9c7fb1a7711721d52d78325abbf0c7c75940a48fd4a3d2b07456c95f8507af19faa333bf87116dd62f18e6c8e76486a57673e3224ac3ee + checksum: f34171e8b315b4f81c7f0768ce644c22965e3f9fc2c2514fa6256601e05f2e4c9df0518b2a591ac8455f4d54f48929cd8c741f8751dd6d6e792a2520339ca7bb languageName: node linkType: hard