Skip to content

Functions without requirements fail to package #194

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

Closed
xedef opened this issue May 26, 2018 · 3 comments
Closed

Functions without requirements fail to package #194

xedef opened this issue May 26, 2018 · 3 comments
Labels

Comments

@xedef
Copy link

xedef commented May 26, 2018

I have a service with several Python functions in it. Only a couple of them need extra Python packages, so I added a requirements.txt file only for those and set the module for each function.

The problem seems to be that the plugin always expects a requirements file to install for all Python functions so for those that don't have one, it fails with this error:

  Error --------------------------------------------------

  ENOENT: no such file or directory, open 'requirements.txt'

     For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.

  Stack Trace --------------------------------------------

Error: ENOENT: no such file or directory, open 'requirements.txt'
    at Object.fs.openSync (fs.js:653:18)
    at Object.fs.readFileSync (fs.js:554:33)
    at generateRequirementsFile (/Users/fede/sls-lambda-project/node_modules/serverless-python-requirements/lib/pip.js:175:6)
    at installRequirements (/Users/fede/sls-lambda-project/node_modules/serverless-python-requirements/lib/pip.js:41:5)
    at values.filter.map.f (/Users/fede/sls-lambda-project/node_modules/serverless-python-requirements/lib/pip.js:235:11)
    at Array.map (<anonymous>)
    at ServerlessPythonRequirements.installAllRequirements (/Users/fede/sls-lambda-project/node_modules/serverless-python-requirements/lib/pip.js:222:8)
From previous event:
    at PluginManager.invoke (/Users/fede/.nvm/versions/node/v8.5.0/lib/node_modules/serverless/lib/classes/PluginManager.js:372:22)
    at PluginManager.run (/Users/fede/.nvm/versions/node/v8.5.0/lib/node_modules/serverless/lib/classes/PluginManager.js:403:17)
    at variables.populateService.then (/Users/fede/.nvm/versions/node/v8.5.0/lib/node_modules/serverless/lib/Serverless.js:102:33)
    at runCallback (timers.js:781:20)
    at tryOnImmediate (timers.js:743:5)
    at processImmediate [as _immediateCallback] (timers.js:714:5)
From previous event:
    at Serverless.run (/Users/fede/.nvm/versions/node/v8.5.0/lib/node_modules/serverless/lib/Serverless.js:89:74)
    at serverless.init.then (/Users/fede/.nvm/versions/node/v8.5.0/lib/node_modules/serverless/bin/serverless:42:50)
    at <anonymous>

Is there a way to omit certain functions? Or am I missing something?

Thanks!

@dschep
Copy link
Contributor

dschep commented May 29, 2018

mind sharing your serverless.yml? If I understand the issue it is a bug, the default packaging (not per function) skips with out errors(or at least used to) if no requirements files were found. Per function packaging should do the same. I'll see if I can create some test cases to covers these.

@xedef
Copy link
Author

xedef commented May 29, 2018

Hi. I think the key part from your answer is "not per function".

I've just tested this yml:

service: requirements-test

provider:
  name: aws
  runtime: python3.6

package:
  individually: true
  exclude:
    - "**/*"

functions:
  func1:
    handler: func1/index.handler
    module: func1
    include:
      - function1/index.py
  func2:
    handler: func2/index.handler
    include:
      - function2/index.py

plugins:
  - serverless-python-requirements

custom:
  pythonRequirements:
    invalidateCaches: true
    dockerizePip: false

If you create those two functions and don't add a requirements.txt at root level and just only one for func1, when you run sls package, the plugin runs correctly for func1 but for func2 gives that error.

λ ~/tmp/requirements-test/ sls package
Serverless: Installing requirements of func1/requirements.txt in .serverless/func1...

  Error --------------------------------------------------

  ENOENT: no such file or directory, open 'requirements.txt'

     For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.

  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Issues:        forum.serverless.com

  Your Environment Information -----------------------------
     OS:                     darwin
     Node Version:           8.5.0
     Serverless Version:     1.27.3

For the moment, I cant get rid of the error just by adding an empty requirements.txt at root level.

@dschep
Copy link
Contributor

dschep commented May 29, 2018

Thanks for the details. That's a 🐛

For now I recommend the workaround you mention of an empty requirements.txt, but I'll fix this in the next release.

@dschep dschep added the bug label May 29, 2018
bweigel pushed a commit to bweigel/serverless-python-requirements that referenced this issue Nov 15, 2018
- skip requirement generation, if no requirements file is present
bweigel pushed a commit to bweigel/serverless-python-requirements that referenced this issue Nov 17, 2018
- skip requirement generation, if no requirements file is present
bweigel pushed a commit to bweigel/serverless-python-requirements that referenced this issue Nov 18, 2018
bweigel pushed a commit to bweigel/serverless-python-requirements that referenced this issue Nov 18, 2018
@bweigel bweigel mentioned this issue Nov 18, 2018
dschep pushed a commit that referenced this issue Nov 21, 2018
Closes #194 

<strike>...no clue why git(hub) thinks there are 5 commits & 9 changed files (all those changes are already in the master; on which I rebased before branching)</strike>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants