diff --git a/scripts/sync_test_dependencies.py b/scripts/sync_test_dependencies.py index e9f59c632..0f8a8a99d 100644 --- a/scripts/sync_test_dependencies.py +++ b/scripts/sync_test_dependencies.py @@ -56,6 +56,8 @@ "gc", "glob", "hashlib", + "html", + "http", "importlib", "inspect", "io", @@ -72,6 +74,8 @@ "random", "re", "runpy", + "email", + "secrets", "shlex", "shutil", "signal", @@ -105,6 +109,8 @@ "traceback", "pprint", } +if hasattr(sys, "stdlib_module_names"): + STDLIB_MODULES.update(sys.stdlib_module_names) # Known test framework modules TEST_FRAMEWORK_MODULES = { @@ -221,6 +227,7 @@ def get_project_modules() -> set[str]: # Module name to package name mappings for known exceptions MODULE_TO_PACKAGE = { + "jwt": "PyJWT", "yaml": "PyYAML", "PIL": "Pillow", "sklearn": "scikit-learn", diff --git a/templates/consumer-repo/scripts/sync_test_dependencies.py b/templates/consumer-repo/scripts/sync_test_dependencies.py index 1ecbb8fa9..a762c42da 100644 --- a/templates/consumer-repo/scripts/sync_test_dependencies.py +++ b/templates/consumer-repo/scripts/sync_test_dependencies.py @@ -56,6 +56,8 @@ "gc", "glob", "hashlib", + "html", + "http", "importlib", "inspect", "io", @@ -72,6 +74,8 @@ "random", "re", "runpy", + "email", + "secrets", "shlex", "shutil", "signal", @@ -104,6 +108,8 @@ "traceback", "pprint", } +if hasattr(sys, "stdlib_module_names"): + STDLIB_MODULES.update(sys.stdlib_module_names) # Known test framework modules TEST_FRAMEWORK_MODULES = { @@ -220,6 +226,7 @@ def get_project_modules() -> set[str]: # Module name to package name mappings for known exceptions MODULE_TO_PACKAGE = { + "jwt": "PyJWT", "yaml": "PyYAML", "PIL": "Pillow", "sklearn": "scikit-learn", diff --git a/tests/scripts/test_sync_test_dependencies_mapping.py b/tests/scripts/test_sync_test_dependencies_mapping.py index c722748c6..267d52505 100644 --- a/tests/scripts/test_sync_test_dependencies_mapping.py +++ b/tests/scripts/test_sync_test_dependencies_mapping.py @@ -20,6 +20,7 @@ def test_pptx_maps_to_python_pptx_in_repo_script(): ) assert module.MODULE_TO_PACKAGE["pptx"] == "python-pptx" + assert module.MODULE_TO_PACKAGE["jwt"] == "PyJWT" def test_pptx_maps_to_python_pptx_in_consumer_template(): @@ -29,3 +30,22 @@ def test_pptx_maps_to_python_pptx_in_consumer_template(): ) assert module.MODULE_TO_PACKAGE["pptx"] == "python-pptx" + assert module.MODULE_TO_PACKAGE["jwt"] == "PyJWT" + + +def test_stdlib_imports_from_sync_pr_logs_are_ignored_in_repo_script(): + module = _load_module( + "sync_test_dependencies_repo_stdlib", + Path("scripts/sync_test_dependencies.py"), + ) + + assert {"email", "html", "http", "secrets"}.issubset(module.STDLIB_MODULES) + + +def test_stdlib_imports_from_sync_pr_logs_are_ignored_in_consumer_template(): + module = _load_module( + "sync_test_dependencies_consumer_template_stdlib", + Path("templates/consumer-repo/scripts/sync_test_dependencies.py"), + ) + + assert {"email", "html", "http", "secrets"}.issubset(module.STDLIB_MODULES)