Skip to content

How to add common folder in all functions #265

@infinitedreams9586

Description

@infinitedreams9586

There should be a way to specify common folder to include in all functions.
I have utility folder which is used by all functions.

Activity

dschep

dschep commented on Oct 11, 2018

@dschep
Contributor

Is this specifically when using package: individually?

infinitedreams9586

infinitedreams9586 commented on Oct 11, 2018

@infinitedreams9586
Author

yes, I would like to include a common folder, I tried with vendor, but instead of copying complete folder as it is, it cooies files inside vendor folder. it messes up the import statement in py files.

infinitedreams9586

infinitedreams9586 commented on Oct 11, 2018

@infinitedreams9586
Author

for ex. if I have python file where import is like,

from common.db import tables

and add vendor: common instead of copying common folder as it is, it copies files inside it without common folder, so import statement above fails.

pydanny

pydanny commented on Oct 12, 2018

@pydanny

I've found due to how Python packages and Lambda environments work, you have to create installable packages to support your use case. That's what prompted my pre-alpha configure-django package.

pydanny

pydanny commented on Oct 13, 2018

@pydanny

Another idea is to do this with your vendor library:

vendored-libraries/
--common/
----thing.py
----utils.py

Then you can do things like: from common.thing import do_action.

infinitedreams9586

infinitedreams9586 commented on Oct 13, 2018

@infinitedreams9586
Author

Another idea is to do this with your vendor library:

vendored-libraries/
--common/
----thing.py
----utils.py

Then you can do things like: from common.thing import do_action.

In that case, it will not work on local. As import should be
from vendored-library.common.thing import action
Plugin copies the files instead of complete root folder (vendor folder), that's the issue.

infinitedreams9586

infinitedreams9586 commented on Oct 15, 2018

@infinitedreams9586
Author

I've found due to how Python packages and Lambda environments work, you have to create installable packages to support your use case. That's what prompted my pre-alpha configure-django package.

Could you let me know how to create installable package and use it in yml file ? without publishing the package to public.

dschep

dschep commented on Oct 17, 2018

@dschep
Contributor

So does it not work to have /vendor/common/ and then import common?

dschep

dschep commented on Oct 17, 2018

@dschep
Contributor

Also, bc of how serverless handles them.. symlinks should be a workable solution too:

mkdir lambda1
mkdir lambda2
mkdir common
cd lambda1
ln -s ../common
cd ../lambda2
ln -s ../common
cd .. #done!
infinitedreams9586

infinitedreams9586 commented on Oct 18, 2018

@infinitedreams9586
Author

So does it not work to have /vendor/common/ and then import common?
If I import as import common, it will work on lambda, but it will not work on local env., as
import actually should be import vendor.common

dschep

dschep commented on Oct 18, 2018

@dschep
Contributor

right, you'd have to set PYTHONPATH=vendor to run locally.

infinitedreams9586

infinitedreams9586 commented on Oct 19, 2018

@infinitedreams9586
Author

@dschep Thank you very much. I understood now.
I got everything working as expected, using symlinks method you mentioned above.

Thanks for your help.

dschep

dschep commented on Oct 22, 2018

@dschep
Contributor

👍 Glad you got it working @infinitedreams9586!

I'll leave this open for now as a reminder to write up some better documentation about using the vendor option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @pydanny@miketheman@dschep@infinitedreams9586

        Issue actions

          How to add common folder in all functions · Issue #265 · serverless/serverless-python-requirements