Skip to content

Commit dc37884

Browse files
committed
Better importing mechanism avoiding name conflicts with existing packages
1 parent ed57b9b commit dc37884

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

computercraft/server.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from os.path import getmtime, join, dirname, abspath
77
from os import listdir, getcwd
88
import importlib
9+
import importlib.util
910
import argparse
1011

1112
from .subapis.root import RootAPIMixin
@@ -75,7 +76,9 @@ async def reload_all_modules(module_map):
7576

7677
# loading new modules
7778
for m in nxt - prev:
78-
module_map[m] = importlib.import_module(m)
79+
spec = importlib.util.spec_from_file_location('ccprograms.{}'.format(m), m_filename(m))
80+
module_map[m] = importlib.util.module_from_spec(spec)
81+
spec.loader.exec_module(module_map[m])
7982
module_map[m]._mtime_mark = getmtime(m_filename(m))
8083
print('Loaded {}'.format(m))
8184

examples/hello.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
async def program(api):
2+
await api.print('Hello world!')

setup.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ def is_register_command(a):
3838
package_data={'computercraft': ['back.lua']},
3939
install_requires=['aiohttp'],
4040
entry_points={
41-
'console_scripts': [
42-
'computercraft=computercraft.server:main',
43-
],
41+
'console_scripts': ['computercraft = computercraft.server:main'],
4442
},
4543
)

0 commit comments

Comments
 (0)