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

nanodjango convert: OSError #40

Open
fertek opened this issue Oct 7, 2024 · 0 comments
Open

nanodjango convert: OSError #40

fertek opened this issue Oct 7, 2024 · 0 comments
Assignees

Comments

@fertek
Copy link

fertek commented Oct 7, 2024

Thanks for this great project!

I ran into an error when trying to convert a single file into a full Django project.

If I have import urllib.parse code in my app.py file, command nanodjango convert app.py src --name=demo will result in an error:

Traceback (most recent call last):
  File "demo_path/venv/bin/nanodjango", line 8, in <module>
    sys.exit(invoke())
             ^^^^^^^^
  …
  File "demo_path/venv/lib/python3.12/site-packages/nanodjango/app.py", line 471, in convert
    converter.build()
  File "demo_path/venv/lib/python3.12/site-packages/nanodjango/convert/converter.py", line 271, in build
    self.build_app_unused()
  File "demo_path/venv/lib/python3.12/site-packages/nanodjango/convert/converter.py", line 746, in build_app_unused
    obj_src, references = self.collect_definition(obj_name)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "demo_path/venv/lib/python3.12/site-packages/nanodjango/convert/converter.py", line 209, in collect_definition
    obj_src = inspect.getsource(obj)
              ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/inspect.py", line 1278, in getsource
    lines, lnum = getsourcelines(object)
                  ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/inspect.py", line 1260, in getsourcelines
    lines, lnum = findsource(object)
                  ^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/inspect.py", line 1089, in findsource
    raise OSError('could not get source code')
OSError: could not get source code

If I replace import urllib.parse with from urllib import parse, the conversion works.


Ubuntu 24.04.1 LTS
Python 3.12.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In progress
Development

No branches or pull requests

2 participants