Giter VIP home page Giter VIP logo

Comments (14)

dkotik avatar dkotik commented on May 12, 2024 19

Please, please make this work!

from chalice.

boosh avatar boosh commented on May 12, 2024 8

@jamesls Any progress on allowing routes to be in more than just app.py? It'd be super useful for larger projects.

from chalice.

d3ming avatar d3ming commented on May 12, 2024 3

I'm still having issues getting multiple files to work and I'm using the latest chalice which should have this change. Here's my file structure:

project:
  - chalicelib:
    - __init__.py
    - capture.py
  - app.py
  - __init__.py

In app.py I try to import capture.py by adding this line:

from chalicelib import capture

However, I'm still getting the dreaded Unable to import module 'app' error when I try out the app. I tested this out without using chalice and was able to import/call the module's functions as expected. What am I missing? I'm on chalice 0.5.0

from chalice.

jbarratt avatar jbarratt commented on May 12, 2024 2

I really liked the idea of chalice, but wanted to use it with a more complex package than I was comfortable wedging all into app.py. It was a little hacky to get working, but it's a usable workaround. Using a directory structure like so:

    mychaliceapp/
    mypackage/                       #regular python package tree, with tests, dependencies, multiple mods, etc
        mypackage/__init__.py
        tests/
        setup.py

a python setup.py sdist in my custom package creates a dist/mypackage-0.1.tar.gz. So in the chalice app, ../mypackage/dist/mypackage-0.1.tar.gz can be added to requirements.txt.

To get new code into the lambda deploy is a little tricker since it tries to use the 'replace app.py in the zip file' strategy. So a little refresh_deps.sh script is helpful:

#!/bin/bash

pushd ../mypackage/ && python setup.py sdist && popd
source .chalice/venv/bin/activate
pip uninstall -y mypackage
rm .chalice/deployments/*.zip

So when changes are made in mypackage, I just run ./refresh_deps.sh and it redeploys with them pulled in.

from chalice.

arcsoftech avatar arcsoftech commented on May 12, 2024 2

I'm still having issues getting multiple files to work and I'm using the latest chalice which should have this change. Here's my file structure:
Chalice version 1.1.1
project:

  • models:
    • response_template.py
    • init.py
  • app.py

In app.py I try to import response_template.py by adding this line:

from models import response_template

However, I'm still getting the dreaded Unable to import module 'app' error when I try out the app. I tested this out without using chalice and was able to import/call the module's functions as expected.
Edit:Got it! directory name should be chalicelib

from chalice.

MarkusAholainen avatar MarkusAholainen commented on May 12, 2024 1

I like the idea of Chalice. Keep on the good work.

Chalice should follow as closely Flask as possible to enable running the same project in local (Flask mode) for convienient development and debugging. Please keep this in mind and run your projects as Flask apps and see how easy/difficult that is . Alternatively provide a local mode with standard Python debugging in mind. pdb.set_trace() is a good starting point.

When the single app.py limitation will be fixed?

from chalice.

bmccary avatar bmccary commented on May 12, 2024

I'm looking forward to this feature.

from chalice.

mannysz avatar mannysz commented on May 12, 2024

Awesome feature. Basically you can handle other files by using boto3 with S3 buckets (for the configuration files, for example), but it would be awesome if chalice could handle it (deploy other files in buckets) by itself (despite it would conflict with the intention of being a micro framework).

from chalice.

njsnx avatar njsnx commented on May 12, 2024

What about allowing multiple files to be split up into multiple Lambda functions - There is requirements for multiple functions for one API project that this would fulfill

from chalice.

jamesls avatar jamesls commented on May 12, 2024

Sorry for the delay on this, I've been bouncing some ideas from #56 and trying out a few prototypes of this feature. I've also been chatting with the rest of the python sdk team on this to get more feedback.

While the find_packages('.') approach seems to be the most generic solution, I'm finding that it has a few undesirable characteristics:

  • It's including things I don't want it to. I generally don't want to include every single python file. Including every python file means that I have no way to control what I'm including in the deployment zip file. I'll typically have:
    • python scripts for configuring additional resources (ddb tables, s3 buckets, etc)
    • tests code (usually in tests/ or sometimes just test_app.py if it's simple enough.
  • It's not including all the things I want. I still need a way to include non python files. Anything from .json config files, or misc binary assets.

Now, both of those problems can be solved with an explicit include/exclude list, but I would have to generate those in my common case (where I have tests/, and misc scripts/ files).

The idea that seems to be working out the best is to have a dedicated directory, something like chalicelib/ (not tied to the actual name), that has a simple rule: if the directory exists, anything (recursively) is included in the deployment zipfile.

I have a proof of concept for this, but I'm interested to hear what others think.

/cc @kyleknap @JordonPhillips

from chalice.

jamesls avatar jamesls commented on May 12, 2024

PR: #146

from chalice.

jamesls avatar jamesls commented on May 12, 2024

#146 is merged. I'll get a release out soon. Please try it out and share any feedback you have.

from chalice.

3dw1np avatar 3dw1np commented on May 12, 2024

@d3ming Did you put in chalicelib/init.py the following content :
"from capture import Capture" (assuming Capture is python class)

And why do you have a init.py file in the root directory ?

from chalice.

himanshugpt avatar himanshugpt commented on May 12, 2024

I am facing similar problem. It would be very helpful if it gets fixed soon.

from chalice.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.