Repository: pex-tool/pex

Issue:
Remove `--sources-directory` / `--resources-directory` distinction.
We do nothing different when gathering these for inclusion in a PEX file. They all just get copied into the PEX file chroot.


Discussion:
Noticed investigating `os.walk`s in #1099.

Resolving patch:
diff --git a/pex/bin/pex.py b/pex/bin/pex.py
--- a/pex/bin/pex.py
+++ b/pex/bin/pex.py
@@ -634,8 +634,10 @@ def configure_clp():
         default=[],
         type=str,
         action="append",
-        help="Add sources directory to be packaged into the generated .pex file."
-        "  This option can be used multiple times.",
+        help=(
+            "Add a directory containing sources and/or resources to be packaged into the generated "
+            ".pex file. This option can be used multiple times."
+        ),
     )
 
     parser.add_option(
@@ -646,8 +648,11 @@ def configure_clp():
         default=[],
         type=str,
         action="append",
-        help="Add resources directory to be packaged into the generated .pex file."
-        "  This option can be used multiple times.",
+        help=(
+            "Add resources directory to be packaged into the generated .pex file."
+            " This option can be used multiple times. DEPRECATED: Use -D/--sources-directory "
+            "instead."
+        ),
     )
 
     parser.add_option(
@@ -822,19 +827,19 @@ def to_python_interpreter(full_path_or_basename):
 
     pex_builder = PEXBuilder(path=safe_mkdtemp(), interpreter=interpreter, preamble=preamble)
 
-    def walk_and_do(fn, src_dir):
-        src_dir = os.path.normpath(src_dir)
-        for root, dirs, files in os.walk(src_dir):
+    if options.resources_directory:
+        pex_warnings.warn(
+            "The `-R/--resources-directory` option is deprecated. Resources should be added via "
+            "`-D/--sources-directory` instead."
+        )
+
+    for directory in OrderedSet(options.sources_directory + options.resources_directory):
+        src_dir = os.path.normpath(directory)
+        for root, _, files in os.walk(src_dir):
             for f in files:
                 src_file_path = os.path.join(root, f)
                 dst_path = os.path.relpath(src_file_path, src_dir)
-                fn(src_file_path, dst_path)
-
-    for directory in options.sources_directory:
-        walk_and_do(pex_builder.add_source, directory)
-
-    for directory in options.resources_directory:
-        walk_and_do(pex_builder.add_resource, directory)
+                pex_builder.add_source(src_file_path, dst_path)
 
     pex_info = pex_builder.info
     pex_info.zip_safe = options.zip_safe
diff --git a/pex/pex_builder.py b/pex/pex_builder.py
--- a/pex/pex_builder.py
+++ b/pex/pex_builder.py
@@ -6,6 +6,7 @@
 import logging
 import os
 
+from pex import pex_warnings
 from pex.common import Chroot, chmod_plus_x, open_zip, safe_mkdir, safe_mkdtemp, temporary_dir
 from pex.compatibility import to_bytes
 from pex.compiler import Compiler
@@ -215,6 +216,10 @@ def add_resource(self, filename, env_filename):
         :param env_filename: The destination filename in the PEX.  This path
           must be a relative path.
         """
+        pex_warnings.warn(
+            "The `add_resource` method is deprecated. Resources should be added via the "
+            "`add_source` method instead."
+        )
         self._ensure_unfrozen("Adding a resource")
         self._copy_or_link(filename, env_filename, "resource")
 


Test patch: