Skip to content

Fixes weird bug, where root & submodule requirements weren't packaged correctly #303

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

Merged
merged 1 commit into from
Jan 4, 2019

Conversation

bweigel
Copy link
Contributor

@bweigel bweigel commented Jan 4, 2019

What it does?

This PR fixes a weird bug, that wouldn't let you use a top-level requirements.txt alongside sub-module requirement.txt-files.

Problem

The previous (I guess) unwanted behavior was, that when you had a root level function (i.e. module: .) with a requirements.txt and a second (sub-module) function (i.e. module: my_submodule) the first function didn't receive any requirements at all, whereas all requirements (from root and submodule) ended up in the artifact for function two:

see sample code: https://github.com/bweigel/serverless_playground/tree/293_weird_bug/sls_package

serverless.yml:

service: packaging_test

plugins:
  - serverless-python-requirements

provider:
  name: aws
  runtime: python3.6
  region: eu-central-1

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

functions:
  function-one:
    handler: main.handler
    package:
      include:
        - 'main.py'

  function-two:
    handler: main.handler
    module: fn
    package:
      include:
        - 'fn/**'
$ sls package

The top-level requirements are not packaged for function-one:

$ zipinfo .serverless/function-one.zip
Archive:  .serverless/function-one.zip
Zip file size: 251 bytes, number of entries: 1
-rw-rw-r--  3.0 unx      260 b- defN 80-Jan-01 00:00 main.py
1 file, 260 bytes uncompressed, 139 bytes compressed:  46.5%

but are instead included in function-two (where they don't belong):

 $ zipinfo .serverless/fn-packaging_test-dev-function-two.zip
Archive:  .serverless/fn-packaging_test-dev-function-two.zip
Zip file size: 116671 bytes, number of entries: 52
-rw-rw-r--  3.0 unx        0 b- stor 98-Jan-01 00:00 __init__.py
drwxrwxr-x  3.0 unx        0 b- stor 19-Jan-04 14:40 __pycache__/
-rw-rw-r--  3.0 unx      148 b- defN 98-Jan-01 00:00 __pycache__/__init__.cpython-36.pyc
-rw-rw-r--  3.0 unx      290 b- defN 98-Jan-01 00:00 __pycache__/other_module.cpython-36.pyc
-rw-rw-r--  3.0 unx      237 b- defN 98-Jan-01 00:00 __pycache__/yam.cpython-36.pyc
-rw-rw-r--  3.0 unx      260 b- defN 98-Jan-01 00:00 main.py
-rw-rw-r--  3.0 unx       61 b- defN 98-Jan-01 00:00 other_module.py
-rw-rw-r--  3.0 unx        8 b- defN 98-Jan-01 00:00 requirements.txt
-rw-rw-r--  3.0 unx    45208 b- defN 98-Jan-01 00:00 dataclasses.py
drwxrwxr-x  3.0 unx        0 b- stor 19-Jan-04 14:40 urllib3/
-rw-rw-r--  3.0 unx    13839 b- defN 98-Jan-01 00:00 urllib3/connection.py
-rw-rw-r--  3.0 unx     2722 b- defN 98-Jan-01 00:00 urllib3/__init__.py
-rw-rw-r--  3.0 unx    10746 b- defN 98-Jan-01 00:00 urllib3/_collections.py
drwxrwxr-x  3.0 unx        0 b- stor 19-Jan-04 14:40 urllib3/contrib/
-rw-rw-r--  3.0 unx        0 b- stor 98-Jan-01 00:00 urllib3/contrib/__init__.py
drwxrwxr-x  3.0 unx        0 b- stor 19-Jan-04 14:40 urllib3/contrib/_securetransport/
-rw-rw-r--  3.0 unx        0 b- stor 98-Jan-01 00:00 urllib3/contrib/_securetransport/__init__.py
-rw-rw-r--  3.0 unx      717 b- defN 98-Jan-01 00:00 urllib3/contrib/_appengine_environ.py
-rw-rw-r--  3.0 unx    35097 b- defN 98-Jan-01 00:00 urllib3/connectionpool.py
-rw-rw-r--  3.0 unx    10914 b- defN 98-Jan-01 00:00 urllib3/contrib/appengine.py
-rw-rw-r--  3.0 unx    17560 b- defN 98-Jan-01 00:00 urllib3/contrib/_securetransport/bindings.py
-rw-rw-r--  3.0 unx    12162 b- defN 98-Jan-01 00:00 urllib3/contrib/_securetransport/low_level.py
-rw-rw-r--  3.0 unx     4459 b- defN 98-Jan-01 00:00 urllib3/contrib/ntlmpool.py
-rw-rw-r--  3.0 unx    15806 b- defN 98-Jan-01 00:00 urllib3/contrib/pyopenssl.py
-rw-rw-r--  3.0 unx     6391 b- defN 98-Jan-01 00:00 urllib3/contrib/socks.py
-rw-rw-r--  3.0 unx     6604 b- defN 98-Jan-01 00:00 urllib3/exceptions.py
-rw-rw-r--  3.0 unx     5943 b- defN 98-Jan-01 00:00 urllib3/fields.py
-rw-rw-r--  3.0 unx    30309 b- defN 98-Jan-01 00:00 urllib3/contrib/securetransport.py
-rw-rw-r--  3.0 unx     2436 b- defN 98-Jan-01 00:00 urllib3/filepost.py
drwxrwxr-x  3.0 unx        0 b- stor 19-Jan-04 14:40 urllib3/packages/
-rw-rw-r--  3.0 unx      109 b- defN 98-Jan-01 00:00 urllib3/packages/__init__.py
drwxrwxr-x  3.0 unx        0 b- stor 19-Jan-04 14:40 urllib3/packages/backports/
-rw-rw-r--  3.0 unx        0 b- stor 98-Jan-01 00:00 urllib3/packages/backports/__init__.py
-rw-rw-r--  3.0 unx    30098 b- defN 98-Jan-01 00:00 urllib3/packages/six.py
-rw-rw-r--  3.0 unx     1456 b- defN 98-Jan-01 00:00 urllib3/packages/backports/makefile.py
drwxrwxr-x  3.0 unx        0 b- stor 19-Jan-04 14:40 urllib3/packages/ssl_match_hostname/
-rw-rw-r--  3.0 unx      688 b- defN 98-Jan-01 00:00 urllib3/packages/ssl_match_hostname/__init__.py
-rw-rw-r--  3.0 unx     5683 b- defN 98-Jan-01 00:00 urllib3/packages/ssl_match_hostname/_implementation.py
-rw-rw-r--  3.0 unx    16853 b- defN 98-Jan-01 00:00 urllib3/poolmanager.py
drwxrwxr-x  3.0 unx        0 b- stor 19-Jan-04 14:40 urllib3/util/
-rw-rw-r--  3.0 unx     4639 b- defN 98-Jan-01 00:00 urllib3/util/connection.py
-rw-rw-r--  3.0 unx      497 b- defN 98-Jan-01 00:00 urllib3/util/queue.py
-rw-rw-r--  3.0 unx    25609 b- defN 98-Jan-01 00:00 urllib3/response.py
-rw-rw-r--  3.0 unx     3705 b- defN 98-Jan-01 00:00 urllib3/util/request.py
-rw-rw-r--  3.0 unx     2586 b- defN 98-Jan-01 00:00 urllib3/util/response.py
-rw-rw-r--  3.0 unx    15105 b- defN 98-Jan-01 00:00 urllib3/util/retry.py
-rw-rw-r--  3.0 unx    13143 b- defN 98-Jan-01 00:00 urllib3/util/ssl_.py
-rw-rw-r--  3.0 unx     9757 b- defN 98-Jan-01 00:00 urllib3/util/timeout.py
-rw-rw-r--  3.0 unx     6487 b- defN 98-Jan-01 00:00 urllib3/util/url.py
-rw-rw-r--  3.0 unx     5403 b- defN 98-Jan-01 00:00 urllib3/util/wait.py
-rw-rw-r--  3.0 unx     1044 b- defN 98-Jan-01 00:00 urllib3/util/__init__.py
-rw-rw-r--  3.0 unx     5991 b- defN 98-Jan-01 00:00 urllib3/request.py
52 files, 370770 bytes uncompressed, 110057 bytes compressed:  70.3%

Relates to

Copy link
Contributor

@dschep dschep left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @bweigel, this PR looks great. Love the attention to detail!

I'll merge it after tests pass.

@dschep dschep merged commit 190df96 into serverless:master Jan 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants