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

Example throws AttributeError #23

Closed
agricolab opened this issue Jun 20, 2019 · 4 comments
Closed

Example throws AttributeError #23

agricolab opened this issue Jun 20, 2019 · 4 comments

Comments

@agricolab
Copy link

  File "auger/generator/generator.py", line 13, in <genexpr>
    if hasattr(mod, '__file__')

AttributeError: 'NoneType' object has no attribute 'replace

and if if fix that with

def init_module_names():
    modules = [item for item in sys.modules.items()]
    for name, mod in modules:
        try:
            key = getattr(mod, '__file__').replace('.pyc', '.py')
            file_to_module_name[key] = name
        except AttributeError:
            pass

it throws

auger/generator/default.py", line 73, in find_module
    file = getattr(mod, '__file__', '').replace('.pyc', '.py')

AttributeError: 'NoneType' object has no attribute 'replace'

which i can fix with

def find_module(self, code):
    for modname, mod in sys.modules.items():
        try:
            file = getattr(mod, '__file__', '').replace('.pyc', '.py')
            except AttributeError:
                continue
            if file == runtime.get_code_filename(code):
                if modname == "__main__":
                    modname = file.replace(".py", "").replace("/", ".")
                self.add_import(modname)
                return modname, mod

auger then runs the Foo example, and my own use case without any further issues

@NextDesign1
Copy link
Collaborator

Hi there Robert, sorry for the delayed response.

How are you running the Foo example? If I have foo.py in the root of a virtualenv, and run the following script, it runs without issue.

import auger, foo

with auger.magic([foo.Foo]):
    foo.main()

@agricolab
Copy link
Author

agricolab commented Jul 19, 2019

I am using anaconda python 3.7.3. i run a file called test.py with python test.py from bash. The file has the following content:

class Foo:                # Declare a class with a method
    def bar(self, x):
        return 2 * x      # Duplicate x and return it

def main():
    foo = Foo()           # Create an instance of Foo
    print(foo.bar(32))    # Call the bar method and print the result

if __name__ == "__main__":
    import auger
    with auger.magic([Foo]):
        main()

if i start an interactive session, and import them, it would still throw this error. I could try a clean environment, i suppose. I have a couple of editable packages installed in this environment.

@agricolab
Copy link
Author

Okeydokey, created a completely new virtual environment with virtualenv just for auger, with only

auger-python==0.1.35
funcsigs==1.0.2
mock==3.0.5
six==1.12.0

and test.py runs fine. I installed an editable package (with pip install -e ), and it still runs. Might be a conflict with anaconda.

@NextDesign1
Copy link
Collaborator

One thing you should be aware of is that auger is really written for Python 2, not Python 3, so you may run into some compatibility issues. For example, see issue #22

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants