pw_build: pw_python_distribution package_data support

pw_python_distribution target setup.cfg files can add package_data
or entry_point sections now. Entries are already processed correctly
to not clobber others merged from existing pw_python_package targets.

Change-Id: Ia1d73aa9407452d08f1bac4cf078404d4afcb119
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/109550
Reviewed-by: Carlos Chinchilla <cachinchilla@google.com>
Pigweed-Auto-Submit: Anthony DiGirolamo <tonymd@google.com>
Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
diff --git a/pw_build/py/create_python_tree_test.py b/pw_build/py/create_python_tree_test.py
index 01fefcb..5935d22 100644
--- a/pw_build/py/create_python_tree_test.py
+++ b/pw_build/py/create_python_tree_test.py
@@ -105,6 +105,10 @@
 
 [options]
 zip_safe = False
+
+[options.package_data]
+megapackage =
+    py.typed
 ''')
         config = load_common_config(common_config=common_config,
                                     append_git_sha=False,
@@ -230,6 +234,8 @@
     httpwatcher
 
 [options.package_data]
+megapackage =
+    py.typed
 mars =
     py.typed
 saturn =
@@ -244,7 +250,7 @@
         expected_cfg_lines = [
             line.rstrip() for line in expected_cfg.splitlines() if line
         ]
-        self.assertEqual(result_cfg_lines, expected_cfg_lines)
+        self.assertEqual(expected_cfg_lines, result_cfg_lines)
 
 
     @parameterized.expand([
diff --git a/pw_build/py/pw_build/create_python_tree.py b/pw_build/py/pw_build/create_python_tree.py
index 7398a8a..43e9f3a 100644
--- a/pw_build/py/pw_build/create_python_tree.py
+++ b/pw_build/py/pw_build/create_python_tree.py
@@ -136,16 +136,6 @@
         raise UnexpectedConfigSection(
             f'[options] packages already defined as: {value}')
 
-    if config.has_section('options.package_data'):
-        raise UnexpectedConfigSection(
-            '[options.package_data] already defined as:\n' +
-            str(dict(config['options.package_data'].items())))
-
-    if config.has_section('options.entry_points'):
-        raise UnexpectedConfigSection(
-            '[options.entry_points] already defined as:\n' +
-            str(dict(config['options.entry_points'].items())))
-
     # Append build metadata if applicable.
     build_metadata = []
     if append_date:
@@ -166,8 +156,10 @@
 ) -> None:
     """Merge setup.cfg files from a set of python packages."""
     config['options']['packages'] = 'find:'
-    config['options.package_data'] = {}
-    config['options.entry_points'] = {}
+    if not config.has_section('options.package_data'):
+        config['options.package_data'] = {}
+    if not config.has_section('options.entry_points'):
+        config['options.entry_points'] = {}
 
     # Save a list of packages being bundled.
     included_packages = [pkg.package_name for pkg in python_packages]