Skip to content

Commit b81afc9

Browse files
committed
Support py 3.13
1 parent 19cdfee commit b81afc9

File tree

4 files changed

+24
-13
lines changed

4 files changed

+24
-13
lines changed

.github/workflows/lint_and_test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
strategy:
1414
matrix:
1515
os: ["ubuntu-latest", "windows-latest"]
16-
version: ['3.11', '3.12']
16+
version: ['3.11', '3.12', '3.13']
1717
fail-fast: false
1818
steps:
1919
- uses: actions/checkout@v5

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ classifiers = [
2424
"Intended Audience :: Developers",
2525
"Programming Language :: Python :: 3.11",
2626
"Programming Language :: Python :: 3.12",
27+
"Programming Language :: Python :: 3.13",
2728
]
2829

2930
dependencies = [

src/genie_python/genie.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,16 +1562,24 @@ def __load_module(name: str, directory: str) -> types.ModuleType:
15621562
raise ValueError(f"Cannot find spec for module {name} in {directory}")
15631563
module = importlib.util.module_from_spec(spec)
15641564

1565-
if module.__file__ is None:
1566-
raise ValueError(f"Module {name} has no __file__ attribute")
1565+
err_msg = (
1566+
f"Cannot load script '{name}' as its name clashes with a standard python module "
1567+
f"or with a module accessible elsewhere on the python path.\n"
1568+
f"The conflicting module was '{module}'.\n"
1569+
f"If this is a user script, rename the user script to avoid the clash."
1570+
)
1571+
1572+
try:
1573+
module_location = str(module.__file__)
1574+
except AttributeError:
1575+
raise ValueError(err_msg) from None
1576+
1577+
if module_location is None:
1578+
raise ValueError(err_msg)
1579+
1580+
if os.path.normpath(os.path.dirname(module_location)) != os.path.normpath(directory):
1581+
raise ValueError(err_msg)
15671582

1568-
if os.path.normpath(os.path.dirname(module.__file__)) != os.path.normpath(directory):
1569-
raise ValueError(
1570-
f"Cannot load script '{name}' as its name clashes with a standard python module "
1571-
f"or with a module accessible elsewhere on the python path.\n"
1572-
f"The conflicting module was at '{module.__file__}'.\n"
1573-
f"If this is a user script, rename the user script to avoid the clash."
1574-
)
15751583
sys.modules[name] = module
15761584
loader = spec.loader
15771585
if loader is None:

tests/test_genie.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@
3434
)
3535

3636
invalid_module_msg = (
37-
f"Cannot load script test as its name clashes with a standard python module "
37+
f"Cannot load script 'test' as its name clashes with a standard python module "
3838
f"or with a module accessible elsewhere on the python path.\nThe conflicting "
39-
f"module was at '{test.__file__}'.\nIf this is a user script, rename the "
39+
f"module was '{test}'.\nIf this is a user script, rename the "
4040
f"user script to avoid the clash."
4141
)
4242

@@ -60,9 +60,11 @@ def test_GIVEN_script_uses_module_name_WHEN_load_script_THEN_error(self):
6060
script = os.path.join(os.path.abspath(os.path.dirname(__file__)), "test_scripts", "test.py")
6161

6262
# Act
63-
with self.assertRaises(ValueError, msg=invalid_module_msg):
63+
with self.assertRaises(ValueError) as ex:
6464
genie.load_script(script)
6565

66+
self.assertEqual(str(ex.exception), invalid_module_msg)
67+
6668
def test_GIVEN_valid_script_WHEN_load_script_THEN_can_call_script(self):
6769
# Arrange
6870
script = os.path.join(

0 commit comments

Comments
 (0)