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

Module import error #45

Closed
KarlXerri opened this issue Jul 13, 2016 · 4 comments
Closed

Module import error #45

KarlXerri opened this issue Jul 13, 2016 · 4 comments

Comments

@KarlXerri
Copy link

KarlXerri commented Jul 13, 2016

In order to separate out of one large app.py file, I want to split related code into helper modules, objects, etc and would expect a structure something like the below (just a rough fag-packet example):

  • app.js
    • shared
      • _ _ init _ _.py
      • objects.py
      • utils
        • _ _ init _ _.py
        • jsonutils.py

( _ init.py _ _ formatted to avoid markdown parsing)_

When importing a local module using the local python command from within a virtualenv, I can load the modules as you would expect to do, however when I run 'chalice deploy' or 'chalice deploy --no-autogen-policy', I receive an error:

ImportError: No module named blah>

I've tried various structures:

  1. objects.py file in the project folder
  2. objects.py file in a shared/ folder
  3. shared/ folder with an init.py file within
  4. shared/ folder with shared.py within

In code I've tried various combinations of import:

  1. import objects
  2. from . import objects
  3. import shared
  4. from shared import shared

None of these will work with deploy, which I'm guessing is due to some introspection logic as it works just as expected using local python command within the python2.7 virtualenv.

I've been on dialog with another developer who also confirms this as being a difficulty he encountered. For the immediate it looks like we'll need to write a kitchen sink app.py, but I'm hoping this is not intended behaviour.

@JamieCressey
Copy link

Hey @KarlXerri, have you seen #21? Only an app.py is currently supported.

@KarlXerri
Copy link
Author

Thanks Jamie. Hadn't noticed that (the subject was a bit ambiguous). Keeping this bug rep open in case anyone else searches for it. Devs: Feel free to close if you don't deem it worth keeping alive.

@dkotik
Copy link

dkotik commented Jul 20, 2016

what kind of api only runs from 1 file? the fix should be as easy as setting python path - don't see a reason not to do it.

@jamesls
Copy link
Member

jamesls commented Jul 29, 2016

As @JamieCressey mentioned, this is being tracked in #21, and there's a pull request from @joel-petersen over at #56, with some good discussion.

To summarize, this is something I plan on supporting, we're just in the process of ironing out the details. It would be great to get some feedback over what would work best for you. I'd suggest reading the proposals over in #56 and chime in over what you would prefer.

@jamesls jamesls closed this as completed Jul 29, 2016
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

4 participants