mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-24 10:41:35 +01:00
python relative import
This commit is contained in:
15
README.adoc
15
README.adoc
@@ -18506,6 +18506,8 @@ The only `Impl` used appears to be `O3CPUImpl`? This is explicitly instantiated
|
||||
template class O3ThreadContext<O3CPUImpl>;
|
||||
....
|
||||
|
||||
see also: https://stackoverflow.com/questions/64420547/in-gem5-how-do-i-know-the-specific-location-of-the-class/64423633#64423633
|
||||
|
||||
Unlike in `SimpleThread` however, `O3ThreadContext` does not contain the register data itself, e.g. `O3ThreadContext::readIntRegFlat` instead forwards to `cpu`:
|
||||
|
||||
....
|
||||
@@ -20912,6 +20914,19 @@ link:rootfs_overlay/lkmc/python/unittest_find/[] contains examples to test how t
|
||||
* https://stackoverflow.com/questions/1732438/how-do-i-run-all-python-unit-tests-in-a-directory
|
||||
* https://stackoverflow.com/questions/46976256/recursive-unittest-discovery-with-python3-and-without-init-py-files
|
||||
|
||||
====== Python relative imports
|
||||
|
||||
link:rootfs_overlay/lkmc/python/relative_import/[] contains examples to test how how to do relative imports in Python.
|
||||
|
||||
This subject is impossible to understand.
|
||||
|
||||
Related questions:
|
||||
|
||||
* https://stackoverflow.com/questions/16981921/relative-imports-in-python-3
|
||||
* https://stackoverflow.com/questions/14132789/relative-imports-for-the-billionth-time
|
||||
* https://stackoverflow.com/questions/21490860/relative-imports-with-unittest-in-python
|
||||
* https://stackoverflow.com/questions/714063/importing-modules-from-parent-folder
|
||||
|
||||
===== Build and install the interpreter
|
||||
|
||||
Buildroot has a Python package that can be added to the guest image:
|
||||
|
||||
1
rootfs_overlay/lkmc/python/relative_import/README.adoc
Normal file
1
rootfs_overlay/lkmc/python/relative_import/README.adoc
Normal file
@@ -0,0 +1 @@
|
||||
https://cirosantilli.com/linux-kernel-module-cheat#python-relative-imports
|
||||
7
rootfs_overlay/lkmc/python/relative_import/mydir/myfile_user.py
Executable file
7
rootfs_overlay/lkmc/python/relative_import/mydir/myfile_user.py
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import myfile
|
||||
|
||||
assert myfile.a == 1
|
||||
|
||||
b = myfile.a + 1
|
||||
1
rootfs_overlay/lkmc/python/relative_import/myfile.py
Normal file
1
rootfs_overlay/lkmc/python/relative_import/myfile.py
Normal file
@@ -0,0 +1 @@
|
||||
a = 1
|
||||
7
rootfs_overlay/lkmc/python/relative_import/myfile_user.py
Executable file
7
rootfs_overlay/lkmc/python/relative_import/myfile_user.py
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import myfile
|
||||
import mydir.myfile_user
|
||||
|
||||
assert myfile.a == 1
|
||||
assert mydir.myfile_user.b == 2
|
||||
20
rootfs_overlay/lkmc/python/relative_import/test
Executable file
20
rootfs_overlay/lkmc/python/relative_import/test
Executable file
@@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eux
|
||||
|
||||
# myfile_user works from all directories.
|
||||
./myfile_user.py
|
||||
cd ..
|
||||
relative_import/myfile_user.py
|
||||
cd relative_import/mydir
|
||||
../myfile_user.py
|
||||
cd ..
|
||||
|
||||
# TODO any better way to run mydir/myfile_user.py?
|
||||
|
||||
# ./mydir/myfile_user.py
|
||||
#Traceback (most recent call last):
|
||||
# File "./mydir/myfile_user.py", line 3, in <module>
|
||||
# import myfile
|
||||
#ModuleNotFoundError: No module named 'myfile'
|
||||
|
||||
python -m mydir.myfile_user
|
||||
Reference in New Issue
Block a user