-
Notifications
You must be signed in to change notification settings - Fork 399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
circular import error #704
Comments
Unfortunately we cannot reproduce this in our side. Can you please give us detailed steps to get the error you are getting? We build memray every day in our computers and in GitHub actions in many different platforms and this never appears so clearly there is something peculiar with your setup that's causing this. Without being able to do it on our side we won't be able to understand what's going on. |
Yeah this is more an informational post than a real bug. But the circular import can be seen easily in the code:
I think it only works because the imports are “type hints”, but for some reason the python on my device doesn't recognize them as such. |
Closing this issue for now. Feel free to reopen if necessary. |
I'm gonna reopen this, actually. I'm not really sure why this is happening only for you, but it's probably a good idea to break this circular import anyway... @jmlemetayer Can you confirm that the issue doesn't occur if you make this patch, instead? diff --git a/src/memray/_metadata.py b/src/memray/_metadata.py
index 5d5913b4..f61af98f 100644
--- a/src/memray/_metadata.py
+++ b/src/memray/_metadata.py
@@ -1,7 +1,9 @@
+import typing
from dataclasses import dataclass
from datetime import datetime
-from ._memray import FileFormat
+if typing.TYPE_CHECKING:
+ from ._memray import FileFormat
@dataclass |
Unfortunately this is not working: $ memray -h
Traceback (most recent call last):
File "/usr/bin/memray", line 5, in <module>
from memray.__main__ import main
File "/usr/lib/python3.10/site-packages/memray/__init__.py", line 2, in <module>
from ._memray import AllocationRecord
File "src/memray/_memray.pyx", line 75, in init memray._memray
File "/usr/lib/python3.10/site-packages/memray/_metadata.py", line 10, in <module>
class Metadata:
File "/usr/lib/python3.10/site-packages/memray/_metadata.py", line 22, in Metadata
file_format: FileFormat
NameError: name 'FileFormat' is not defined As I said, I am using Yocto to build the firmware for my device. The recipe can be seen here: I think this is due to a configuration problem. It seems that in my case, |
Er, oops, right. Can you instead try: diff --git a/src/memray/_metadata.py b/src/memray/_metadata.py
index 5d5913b4..96d6416b 100644
--- a/src/memray/_metadata.py
+++ b/src/memray/_metadata.py
@@ -1,7 +1,11 @@
+from __future__ import annotations
+
+import typing
from dataclasses import dataclass
from datetime import datetime
-from ._memray import FileFormat
+if typing.TYPE_CHECKING:
+ from ._memray import FileFormat
@dataclass Same as before, but with the addition of |
That should not make a difference, no... |
Yes, the last fix is working 👍 |
Is there an existing issue for this?
Current Behavior
I am cross-compiling
memray
for an arm target using Yocto. The build went fine, but when I startmemray
I got an error:The full stack is here:
Expected Behavior
No
ImportError
.Steps To Reproduce
Python 3.10.15
memray -h
to raise the errorMemray Version
Tried
1.14.0
and1.15.0
Python Version
3.10
Operating System
Linux
Anything else?
I updated the file
_metadata.py
:This fix the issue on my device.
I don't know why but it is working on my PC without the fix (
Python 3.12.7
).The text was updated successfully, but these errors were encountered: