-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Adding support for more then just app.py #56
Adding support for more then just app.py #56
Conversation
795f39b
to
a62f7d8
Compare
…sted in internal_requirements.txt which is a \n separated list of files to include in the deploy. supports both subfolders and files in the same directory as the app.py.
a62f7d8
to
cc2d6b8
Compare
Confirmed that this works and was very helpful for a test project I'm building today 👍 I don't yet have an opinion on the structure of the solution, but the feature is definitely a requirement. |
Great! It is a bit patchy, but hopefully something similar can be merged into the main branch! Thank you! |
Yeah I was kind of on the fence about it. Since the tool already requires a requirements.txt to know what libraries to include, I figured the pattern had already been set to require explicitness. The alternatives were to just uploading everything in the local directory or requiring everything to be in a subfolder, though both of those are easy alternatives. The negative with that plan is that it would probably require an exclusion file to prevent some stuff from getting uploaded that is undesirable like credentials and less obvious. |
I actually wouldn't be opposed to just supporting a single local directory in which everything gets included. The logic would roughly be:
The In terms of the app structure, we're already assuming an implicit The plus side would be that everything could still "just work". If we required that What do you all think? |
I love this idea and can't wait to make use of it. |
Just for some context, I implemented this feature before the suggestion of the app directory had been made in another feature request. So when I did implement it, I did it in the most pythonic way I could think of where its generally thought to be better to be explicit instead of implicit (https://www.python.org/dev/peps/pep-0020/), and people's applications wouldn't need to be restructured after merging the pull request. Now that I've read this alternate proposal, I'm not really against it, but it is going to make two different ways to build apps (and 2 different control paths inside chalice). One which just required an app.py and a separate one where everything needs to be in an app directory and they cant co-exist. It would mean as soon as you need to split your code into separate files or include non-pip libraries you need to re-structure your app so it was in a sub library. If the feature is implemented in this more implicit manner, I think it will be clearer and cleaner to just always require an app folder with an app.py in it. And have the chalice new-project structure the application in that way. One of the advantages of this being beta software is that its possible to require restructuring, without having to always stay backwards compatible. What do you think? |
You make good points. I hadn't considered that growing an app from a single file to multiple files would unnecessarily require you to move code around. Even in the simplest case of I do like having the flexibility to structure code however you want, and in multiple directories, but I wonder if there's a way to get something more implicit that's based on what people would expect to be reasonable behavior. As counter-examples I want to avoid, consider the Just throwing out other ideas: a) Any python packages (any top level dir with an Are either of those options any better? Option (b) seems like the best of both worlds. |
this +1:
also aws eb cli pays attention to .git ignore file, could be useful here for flexibility and future-proofing |
@jamesls Maybe a directory named |
I'm personally a fan of option a, which mimics the behavior of |
Initial support for multi app files was added in #146. I know there was a good amount of discussion on this. Thanks everyone for the input on this. FWIW, I tried going down the Please give the current version a try and share any feedback you might have. Hopefully it's a reasonable compromise that accommodates most uses cases. |
Adding support for more then just app.py.
The only way I could currently think to make this work was to have an explicit list of files that need to get updated other then the app.py, used to add them to the zip file. Since we're already relying on people having a requirements.txt for pip installation the new file is called internal_requirements.txt .
It is a \n separated list of files to include in the deploy. Supports both files in sub folders and files in the same directory as the app.py.
I didn't create a test for this use case since I wasn't exactly sure about the formatting for them given that this test relies on multiple files. also the current tests before I changed anything didnt succeed for me.
Pasted below is my example files for testing (not included so as to not pollute the project):
./app.py
from chalice import Chalice
from package import fibo
import fibo_2
app = Chalice(app_name='subfolders')
app.debug = True
@app.route('/')
def index():
fibList = fibo.fib2(10)
fibList2 = fibo_2.fib2(10)
return {'hello': 'world', 'fib' : fibList, 'fib2': fibList2 }
./fibo_2.py
Fibonacci numbers module
def fib2(n): # return Fibonacci series up to n
result = []
a, b = 0, 1
while b < n:
result.append(b)
a, b = b, a+b
return result
./package/fibo.py
Fibonacci numbers module
def fib(n): # write Fibonacci series up to n
a, b = 0, 1
while b < n:
print b,
a, b = b, a+b
def fib2(n): # return Fibonacci series up to n
result = []
a, b = 0, 1
while b < n:
result.append(b)
a, b = b, a+b
return result
./package/init.py
./internal_requirements.txt
package
fibo_2.py
And that's it. Any feedback is appreciated and thanks for the easy tool, it was just missing this one feature to really be useful.