chalice icon indicating copy to clipboard operation
chalice copied to clipboard

Better handling of chalicelib

Open colde opened this issue 7 years ago • 7 comments

I would like to suggest that chalice does an automatic sys.path.append of the chalicelib directory, both when running chalice local, and when actually running lambda.

This would make it easier to use with very little drawbacks.

Also, the documentation should probably mention the use of chalicelib as well.

colde avatar Apr 20 '17 11:04 colde

The Github page doesn't mention chalicelib, but the full documentation does:

http://chalice.readthedocs.io/en/latest/topics/packaging.html

nedlowe avatar Apr 21 '17 01:04 nedlowe

Is the suggestion to add chalice to sys.path so you don't have to have chalicelib in your imports?

So instead of from chalicelib import mymodule you could just say import mymodule?

jamesls avatar May 02 '17 16:05 jamesls

@jamesls Yeah, that is indeed it. Maybe also some clarification between what should go in chalicelib, and what should go in vendor.

colde avatar May 03 '17 10:05 colde

I disagree, the chalicelib folder should be explicitly referenced (although perhaps it shouldn't have to be called chalicelib, but that's a separate question).

chalicelib is for organising one's own code. vendor is for third-party builds of software that needs to be made available in your Chalice project. For pure-Python projects on PyPI that is unnecessary, but for:

  1. Projects not on PyPI
  2. Non-pure Python projects that need to be built

then they need to be uploaded via vendor.

E.g. https://github.com/amaas-fintech/chalice-vendor-packages - is a package that needs to be compiled into a .so file. When running locally, the package is picked up from my local pip install, but on Chalice it is referenced from the vendor folder - so it works from both (the lambda compliant build obviously wouldn't work locally).

nedlowe avatar May 03 '17 14:05 nedlowe

"from chalicelib import mymodule you could just say import mymodule"

I just spent 40 min trying to figure out why "import mymodule" failed. Better to mention chalicelib in github readme.

charlie0077 avatar Sep 01 '17 06:09 charlie0077

When working locally, I've found that my custom python files work just fine regardless of directory structure.

I too spent a lithe bit of time trying to figure out how deployed chalice app can utilize my custom python files (finally found chalicelib in docs).

I created the following pr, does it help? https://github.com/aws/chalice/pull/496

sbraverman avatar Sep 01 '17 17:09 sbraverman

This looks to me like a design flaw. Conceptually, chalicelib is similar to the site-packages directory found in most Python distributions. It is not a top-level package by itself, it is the root of a package hierarchy, a directory containing top-level packages, a directory whose path occurs on sys.path.

This may work for the simplest use case, one lambda function per project, but as soon as you move to more complex projects, ones with more than one lambda, or ones that are deployed in other ways, not just as a lambda function having every package start with chalicelib is plain odd.

hannes-ucsc avatar Jul 13 '18 02:07 hannes-ucsc