diff --git a/lambda_uploader/package.py b/lambda_uploader/package.py
index 5e22d83..6a0fe87 100644
--- a/lambda_uploader/package.py
+++ b/lambda_uploader/package.py
@@ -228,12 +228,11 @@ class Package(object):
 
         for p in self._extra_files:
             LOG.info('Copying extra %s into package' % p)
+            ignore += ["%s" % p]
             if os.path.isdir(p):
-                utils.copy_tree(p, package)
-                ignore += ["^%s/*" % p]
+                utils.copy_tree(p, package, include_parent=True)
             else:
                 shutil.copy(p, package)
-                ignore += ["%s" % p]
 
         # Append the temp workspace to the ignore list:
         ignore += ["^%s/*" % TEMP_WORKSPACE_NAME]
diff --git a/lambda_uploader/utils.py b/lambda_uploader/utils.py
index 2a3c841..e7664b6 100644
--- a/lambda_uploader/utils.py
+++ b/lambda_uploader/utils.py
@@ -21,8 +21,18 @@ import re
 LOG = logging.getLogger(__name__)
 
 
-def copy_tree(src, dest, ignore=[]):
+def copy_tree(src, dest, ignore=[], include_parent=False):
+    if os.path.isfile(src):
+        raise Exception('Cannot use copy_tree with a file as the src')
+
     LOG.info('Copying source files')
+    if include_parent:
+        # if src is foo, make dest/foo and copy files there
+        nested_dest = os.path.join(dest, os.path.basename(src))
+        os.makedirs(nested_dest)
+    else:
+        nested_dest = dest
+
     # Re-create directory structure
     for root, _, files in os.walk(src):
         for filename in files:
@@ -33,7 +43,7 @@ def copy_tree(src, dest, ignore=[]):
 
             sub_dirs = os.path.dirname(os.path.relpath(path,
                                                        start=src))
-            pkg_path = os.path.join(dest, sub_dirs)
+            pkg_path = os.path.join(nested_dest, sub_dirs)
             if not os.path.isdir(pkg_path):
                 os.makedirs(pkg_path)
 

Easy sharing of code between lambda functions
Is there a way to share python code between lambdas, without having to create an additional package to install via requirements?

e.g., in the Serverless framework, there's the concept of a "lib" folder which can contain modules shared between multiple lambdas.


diff --git a/test/test_package.py b/test/test_package.py
index 5de87eb..104bed9 100644
--- a/test/test_package.py
+++ b/test/test_package.py
@@ -120,7 +120,7 @@ def test_package_with_extras():
     assert path.isfile(expected_extra_file1)
 
     # test a recursive directory
-    expected_extra_file2 = path.join(PACKAGE_TEMP_DIR, 'foo/__init__.py')
+    expected_extra_file2 = path.join(PACKAGE_TEMP_DIR, 'extra/foo/__init__.py')
     assert path.isfile(expected_extra_file2)
 
 

pip install -e .[dev]
parse_log_pytest
requirements.txt
pytest cython distro pytest-cov pytest-xdist pytest-mock pytest-asyncio pytest-bdd pytest-benchmark pytest-randomly responses mock hypothesis freezegun trustme requests-mock requests tomlkit
apt-get update apt-get install -y gcc
3.9
requirements/base.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
attrs==25.3.0
boto3==1.2.2
botocore==1.3.30
certifi==2025.1.31
cffi==1.17.1
charset-normalizer==3.4.1
coverage==7.8.0
cryptography==44.0.2
Cython==3.0.12
distlib==0.3.9
distro==1.9.0
docutils==0.21.2
exceptiongroup==1.2.2
execnet==2.1.1
filelock==3.18.0
freezegun==1.5.1
gherkin-official==29.0.0
hypothesis==6.130.5
idna==3.10
importlib_metadata==8.6.1
iniconfig==2.1.0
jmespath==0.10.0
-e git+https://github.com/rackerlabs/lambda-uploader.git@d4b3a4a582baf41325e0551e987a9d6ab6a0b02d#egg=lambda_uploader
Mako==1.3.9
MarkupSafe==3.0.2
mock==5.2.0
packaging==24.2
parse==1.20.2
parse_type==0.6.4
platformdirs==4.3.7
pluggy==1.5.0
py-cpuinfo==9.0.0
pycparser==2.22
pytest==8.3.5
pytest-asyncio==0.26.0
pytest-bdd==8.1.0
pytest-benchmark==5.1.0
pytest-cov==6.0.0
pytest-mock==3.14.0
pytest-randomly==3.16.0
pytest-xdist==3.6.1
python-dateutil==2.9.0.post0
PyYAML==6.0.2
requests==2.32.3
requests-mock==1.12.1
responses==0.25.7
six==1.17.0
sortedcontainers==2.4.0
tomli==2.2.1
tomlkit==0.13.2
trustme==1.2.1
typing_extensions==4.13.0
urllib3==2.3.0
virtualenv==20.29.3
zipp==3.21.0

name: lambda-uploader
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=3.0.16=h5eee18b_0
  - pip=25.0=py39h06a4308_0
  - python=3.9.21=he870216_1
  - readline=8.2=h5eee18b_0
  - setuptools=75.8.0=py39h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - tzdata=2025a=h04d1e81_0
  - wheel=0.45.1=py39h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - attrs==25.3.0
      - boto3==1.2.2
      - botocore==1.3.30
      - certifi==2025.1.31
      - cffi==1.17.1
      - charset-normalizer==3.4.1
      - coverage==7.8.0
      - cryptography==44.0.2
      - cython==3.0.12
      - distlib==0.3.9
      - distro==1.9.0
      - docutils==0.21.2
      - exceptiongroup==1.2.2
      - execnet==2.1.1
      - filelock==3.18.0
      - freezegun==1.5.1
      - gherkin-official==29.0.0
      - hypothesis==6.130.5
      - idna==3.10
      - importlib-metadata==8.6.1
      - iniconfig==2.1.0
      - jmespath==0.10.0
      - mako==1.3.9
      - markupsafe==3.0.2
      - mock==5.2.0
      - packaging==24.2
      - parse==1.20.2
      - parse-type==0.6.4
      - platformdirs==4.3.7
      - pluggy==1.5.0
      - py-cpuinfo==9.0.0
      - pycparser==2.22
      - pytest==8.3.5
      - pytest-asyncio==0.26.0
      - pytest-bdd==8.1.0
      - pytest-benchmark==5.1.0
      - pytest-cov==6.0.0
      - pytest-mock==3.14.0
      - pytest-randomly==3.16.0
      - pytest-xdist==3.6.1
      - python-dateutil==2.9.0.post0
      - pyyaml==6.0.2
      - requests==2.32.3
      - requests-mock==1.12.1
      - responses==0.25.7
      - six==1.17.0
      - sortedcontainers==2.4.0
      - tomli==2.2.1
      - tomlkit==0.13.2
      - trustme==1.2.1
      - typing-extensions==4.13.0
      - urllib3==2.3.0
      - virtualenv==20.29.3
      - zipp==3.21.0
prefix: /opt/conda/envs/lambda-uploader

test/test_package.py::test_package_with_extras
test/test_package.py::test_install_requirements
test/test_package.py::test_bad_existing_virtualenv test/test_package.py::test_package test/test_package.py::test_default_virtualenv test/test_package.py::test_prepare_workspace test/test_package.py::test_package_zip_location test/test_package.py::test_omit_virtualenv test/test_package.py::test_package_name test/test_package.py::test_existing_virtualenv
lambda_uploader/package.py lambda_uploader/utils.py
lambda_uploader/package.py lambda_uploader/utils.py