Skip to content
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

wirerope and methodtools cause nuitka binary to fail. #3145

Open
eskiyerli opened this issue Oct 12, 2024 · 5 comments
Open

wirerope and methodtools cause nuitka binary to fail. #3145

eskiyerli opened this issue Oct 12, 2024 · 5 comments
Assignees
Labels
bug excellent_report help wanted Please help with this, we think you can

Comments

@eskiyerli
Copy link

python -m nuitka --version output:  1 ✘
2.4
Commercial: None
Python: 3.12.6 (main, Sep 8 2024, 13:18:56) [GCC 14.2.1 20240805]
Flavor: Unknown
Executable: /usr/bin/python
OS: Linux
Arch: x86_64
Distribution: Manjaro (based on arch) None
Version C compiler: /usr/bin/gcc (gcc 14.2.1).

~/Downloads/RevEDA/reveda.dist /reveda.bin  ✔
Traceback (most recent call last):
File "/home/eskiyerli/Downloads/RevEDA/reveda.dist/reveda.py", line 38, in
File "", line 1360, in _find_and_load
File "", line 1331, in _find_and_load_unlocked
File "", line 935, in _load_unlocked
File "/home/eskiyerli/Downloads/RevEDA/reveda.dist/revedaEditor/gui/revedaMain.py", line 43, in
File "", line 1360, in _find_and_load
File "", line 1331, in _find_and_load_unlocked
File "", line 935, in _load_unlocked
File "/home/eskiyerli/Downloads/RevEDA/reveda.dist/revedaEditor/backend/importViews.py", line 35, in
File "", line 1360, in _find_and_load
File "", line 1331, in _find_and_load_unlocked
File "", line 935, in _load_unlocked
File "/home/eskiyerli/Downloads/RevEDA/reveda.dist/revedaEditor/gui/libraryBrowser.py", line 46, in
File "", line 1360, in _find_and_load
File "", line 1331, in _find_and_load_unlocked
File "", line 935, in _load_unlocked
File "/home/eskiyerli/Downloads/RevEDA/reveda.dist/revedaEditor/gui/symbolEditor.py", line 42, in
File "", line 1360, in _find_and_load
File "", line 1331, in _find_and_load_unlocked
File "", line 935, in _load_unlocked
File "/home/eskiyerli/Downloads/RevEDA/reveda.dist/revedaEditor/gui/symbolScene.py", line 60, in
File "", line 1360, in _find_and_load
File "", line 1331, in _find_and_load_unlocked
File "", line 935, in _load_unlocked
File "/home/eskiyerli/Downloads/RevEDA/reveda.dist/revedaEditor/fileio/loadJSON.py", line 392, in
File "/home/eskiyerli/Downloads/RevEDA/reveda.dist/revedaEditor/fileio/loadJSON.py", line 402, in PCellCache
File "/home/eskiyerli/Downloads/RevEDA/reveda.dist/wirerope/rope.py", line 158, in call
File "/home/eskiyerli/Downloads/RevEDA/reveda.dist/wirerope/callable.py", line 109, in init
File "/home/eskiyerli/Downloads/RevEDA/reveda.dist/wirerope/callable.py", line 49, in detect_function_attr_name
TypeError: function() missing required argument 'globals' (pos 2)

Offending code is:

@classmethod
@lru_cache(maxsize=100)
def getPCellDef(cls, file_path: str) -> dict:
    try:
        with open(file_path, "r") as temp:
            return json.load(temp)
    except (json.JSONDecodeError, FileNotFoundError):
        return {}

I have seen a similar issue report from 2020 but that was closed because the python and nuitka versions were very old. In this case, they are fairly recent. In this case, the versions are the latest:
Python 3.12
methodtools 0.4.5
wirerope 0.4.5
Nuitka 2.4

@kayhayen
Copy link
Member

Latest for Nuitka is 2.4.8 actually and esp. for 3.12 that might mean a lot. This also lacks a self contained example that I could compile, or so it seems.

@kayhayen kayhayen self-assigned this Oct 13, 2024
@kayhayen kayhayen added the needs_example User input needed label Oct 13, 2024
@eskiyerli
Copy link
Author

Same with Nuitka 2.4.8 and python 3.12 in a virtual environment. As it is a part of large software, I need to think of a self-standing example. The whole repository is in revedaRelease.

@kayhayen
Copy link
Member

I cannot execute unknown and therefore untrusted code easily, so I don't compile whole projects outside of paid for contracts, but the stack trace should allow you to easily come up with something.

@eskiyerli
Copy link
Author

eskiyerli commented Oct 14, 2024

In that case, here is a small code that uses methodtools with lru_cache. I ran it with Nuitka 2.4.8 and Python 3.12. It still has the same problem:

from methodtools import lru_cache

class DataProcessor:
    @classmethod
    @lru_cache(maxsize=100)
    def process_data(cls, data):
        # Simulate a time-consuming operation
        result = sum(int(x) for x in data if x.isdigit())
        print(f"Processing data: {data}")
        return result

    @classmethod
    def display_cache_info(cls):
        print(f"Cache info: {cls.process_data.cache_info()}")

if __name__ == "__main__":
    # First call - will process the data
    result1 = DataProcessor.process_data("123abc456")
    print(f"Result 1: {result1}")

    # Second call with the same input - will use cached result
    result2 = DataProcessor.process_data("123abc456")
    print(f"Result 2: {result2}")

    # Call with different input - will process new data
    result3 = DataProcessor.process_data("789xyz")
    print(f"Result 3: {result3}")

    # Display cache information
    DataProcessor.display_cache_info()

@kayhayen
Copy link
Member

Seems wirerope does a bunch of is checks on the function type, that won't work the compiled functions that way. Replacing some of those seems easy to do. This one is more tricky:

    @cached_property
    def is_descriptor(self):
        if self.is_boundmethod:
            return False
        is_descriptor = type(self.wrapped_object).__get__ \
            is not types.FunctionType.__get__  # noqa
        if six.PY2:
            is_descriptor = is_descriptor and \
                not (self.is_unboundmethod or self.is_boundmethod)
        return is_descriptor

I tried editing it a bunch, but it seems very odd in its expectations of what can be done to a function.

@kayhayen kayhayen added bug help wanted Please help with this, we think you can excellent_report and removed needs_example User input needed labels Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug excellent_report help wanted Please help with this, we think you can
Projects
None yet
Development

No branches or pull requests

2 participants