pallet-patcher 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,31 @@
1
+ Metadata-Version: 2.2
2
+ Name: pallet-patcher
3
+ Version: 0.0.1
4
+ Summary: Tools for working with curated collections of Cargo packages
5
+ Author-email: Scott K Logan <logans@cottsay.net>
6
+ License: Apache License, Version 2.0
7
+ Classifier: Development Status :: 4 - Beta
8
+ Classifier: Environment :: Console
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: License :: OSI Approved :: Apache Software License
11
+ Classifier: Operating System :: MacOS
12
+ Classifier: Operating System :: Microsoft :: Windows
13
+ Classifier: Operating System :: POSIX
14
+ Classifier: Programming Language :: Python
15
+ Classifier: Programming Language :: Rust
16
+ Classifier: Topic :: Software Development :: Build Tools
17
+ Requires-Python: >=3.6
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ Requires-Dist: tomli>=1.0.0; python_version < "3.11"
21
+ Provides-Extra: test
22
+ Requires-Dist: flake8; extra == "test"
23
+ Requires-Dist: mypy; extra == "test"
24
+ Requires-Dist: pytest; extra == "test"
25
+
26
+ # pallet-patcher
27
+
28
+ _Tools for working with curated collections of Cargo packages_
29
+
30
+ > [!WARNING]
31
+ > This is a prototype package without stable behavior or API.
@@ -0,0 +1,6 @@
1
+ # pallet-patcher
2
+
3
+ _Tools for working with curated collections of Cargo packages_
4
+
5
+ > [!WARNING]
6
+ > This is a prototype package without stable behavior or API.
@@ -0,0 +1,4 @@
1
+ # Copyright 2025 Open Source Robotics Foundation, Inc.
2
+ # Licensed under the Apache License, Version 2.0
3
+
4
+ __version__ = '0.0.1'
@@ -0,0 +1,10 @@
1
+ # Copyright 2025 Open Source Robotics Foundation, Inc.
2
+ # Licensed under the Apache License, Version 2.0
3
+
4
+ import sys
5
+
6
+ from pallet_patcher.command import main
7
+
8
+
9
+ if __name__ == '__main__':
10
+ sys.exit(main())
@@ -0,0 +1,56 @@
1
+ # Copyright 2025 Open Source Robotics Foundation, Inc.
2
+ # Licensed under the Apache License, Version 2.0
3
+
4
+ from argparse import ArgumentParser
5
+ from pathlib import Path
6
+
7
+ from pallet_patcher.manifest import get_dependencies
8
+ from pallet_patcher.manifest import load_manifest
9
+ from pallet_patcher.search import compose
10
+ from pallet_patcher.search import get_cargo_arguments
11
+ from pallet_patcher.search import get_cargo_config
12
+
13
+
14
+ def load_and_compose(manifest_path, search_paths):
15
+ """
16
+ Load a Cargo manifest and compose a package collection for building it.
17
+
18
+ :param manifest_path: Path to the Cargo.toml file on disk
19
+ :type manifest_path: Path
20
+ :param search_paths: List of local registry sources to search for packages
21
+ :type search_paths: list
22
+
23
+ :returns: Collection of packages which may satisfy the requirements to
24
+ build the package.
25
+ :rtype: dict
26
+ """
27
+ manifest = load_manifest(manifest_path)
28
+ location = manifest_path.parent.resolve()
29
+ plain, build, dev = get_dependencies(manifest, location)
30
+ dependencies = [*plain.items(), *build.items(), *dev.items()]
31
+
32
+ return compose(dependencies, search_paths)
33
+
34
+
35
+ def main(argv=None):
36
+ """
37
+ Command line interface for composing Cargo package collections.
38
+
39
+ :param argv: Command line arguments to parse
40
+ :type argv: dict, optional
41
+ """
42
+ parser = ArgumentParser()
43
+ parser.add_argument('manifest_path', type=Path)
44
+ parser.add_argument('search_path', type=Path, nargs='+')
45
+ parser.add_argument(
46
+ '--output-format', choices=('args', 'toml'), default='args')
47
+ args = parser.parse_args(argv)
48
+
49
+ search_paths = [path.resolve() for path in args.search_path]
50
+ composition = load_and_compose(args.manifest_path, search_paths)
51
+
52
+ if args.output_format == 'toml':
53
+ print(get_cargo_config(composition))
54
+ else:
55
+ for argument in get_cargo_arguments(composition):
56
+ print(argument)
@@ -0,0 +1,87 @@
1
+ # Copyright 2025 Open Source Robotics Foundation, Inc.
2
+ # Licensed under the Apache License, Version 2.0
3
+
4
+ import os.path
5
+
6
+ try:
7
+ # Python 3.11+
8
+ from tomllib import loads as toml_loads
9
+ except ImportError:
10
+ try:
11
+ from tomli import loads as toml_loads
12
+ except ImportError:
13
+ from toml import loads as toml_loads
14
+
15
+
16
+ def load_manifest(manifest_path):
17
+ """
18
+ Load data from a Cargo.toml file.
19
+
20
+ :param manifest_path: Path to the Cargo.toml file on disk
21
+ :type manifest_path: Path
22
+
23
+ :returns: Manifest data
24
+ :rtype: dict
25
+ """
26
+ with manifest_path.open('rb') as f:
27
+ return toml_loads(f.read().decode())
28
+
29
+
30
+ def _extract_dependencies(manifest_section, package_name):
31
+ plain_dependencies = {}
32
+ for k, v in manifest_section.get('dependencies', {}).items():
33
+ if k == package_name:
34
+ continue
35
+ plain_dependencies[k] = v
36
+
37
+ build_dependencies = {}
38
+ for k, v in manifest_section.get('build-dependencies', {}).items():
39
+ if k == package_name:
40
+ continue
41
+ build_dependencies[k] = v
42
+
43
+ dev_dependencies = {}
44
+ for k, v in manifest_section.get('dev-dependencies', {}).items():
45
+ if k == package_name:
46
+ continue
47
+ dev_dependencies[k] = v
48
+
49
+ return plain_dependencies, build_dependencies, dev_dependencies
50
+
51
+
52
+ def _resolve_dependencies(dependencies, location):
53
+ for specifications in dependencies.values():
54
+ if not isinstance(specifications, dict):
55
+ continue
56
+ specifications_path = specifications.get('path')
57
+ if specifications_path is None:
58
+ continue
59
+ if not specifications_path.startswith('file://'):
60
+ specifications['path'] = os.path.normpath(
61
+ str((location / specifications_path).absolute()))
62
+
63
+
64
+ def get_dependencies(manifest_data, location):
65
+ """
66
+ Get the dependencies from a Cargo.toml manifest.
67
+
68
+ :param manifest_data: The deserialized data from the Cargo.toml
69
+ :type manifest_data: dict
70
+ :param location: The path to the directory where the Cargo.toml file
71
+ resides on disk to resolve relative dependency paths from
72
+ :type location: Path
73
+
74
+ :returns: Tuple of dependencies: plain, build, dev
75
+ :rtype: tuple
76
+ """
77
+ package_name = manifest_data.get('name')
78
+ all_dependencies = _extract_dependencies(manifest_data, package_name)
79
+ for category, spec in manifest_data.get('target', {}).items():
80
+ dependencies = _extract_dependencies(spec, package_name)
81
+ for existing, new in zip(all_dependencies, dependencies):
82
+ existing.update(new)
83
+
84
+ for dependencies in all_dependencies:
85
+ _resolve_dependencies(dependencies, location)
86
+
87
+ return all_dependencies
@@ -0,0 +1,159 @@
1
+ # Copyright 2025 Open Source Robotics Foundation, Inc.
2
+ # Licensed under the Apache License, Version 2.0
3
+
4
+ import os
5
+ from pathlib import Path
6
+
7
+ from pallet_patcher.manifest import get_dependencies
8
+ from pallet_patcher.manifest import load_manifest
9
+
10
+
11
+ def _get_reference(specification):
12
+ if not isinstance(specification, dict):
13
+ return None
14
+ path = specification.get('path')
15
+ if path is not None:
16
+ return Path(path).as_uri()
17
+ git = specification.get('git')
18
+ if git is not None:
19
+ return git
20
+ return specification.get('registry')
21
+
22
+
23
+ def compose(dependencies, search_paths):
24
+ """
25
+ Compose a collection of crates which may satisfy given dependencies.
26
+
27
+ :param dependencies: List of dependency tuples
28
+ (import name, specifications)
29
+ :type dependencies: tuple
30
+ :param search_paths: List of local registry sources to search for packages
31
+ :type search_paths: list
32
+
33
+ :returns: Collection of packages which may satisfy the required
34
+ dependencies.
35
+ :rtype: dict
36
+ """
37
+ search_paths = list(search_paths)
38
+ composition = {}
39
+ candidates = {}
40
+
41
+ queue = list(dependencies)
42
+ while queue:
43
+ name, specifications = queue.pop(0)
44
+ if isinstance(specifications, dict):
45
+ name = specifications.get('package', name)
46
+
47
+ if name in composition:
48
+ reference = _get_reference(specifications)
49
+ composition[name][0].add(reference)
50
+ continue
51
+
52
+ candidate = candidates.get(name)
53
+ while candidate is None and search_paths:
54
+ search_path = search_paths.pop(0)
55
+ layer = {}
56
+ for manifest_path in search_path.glob('*/Cargo.toml'):
57
+ manifest = load_manifest(manifest_path)
58
+ pkgname = manifest.get('package', {}).get('name')
59
+ if pkgname in candidates:
60
+ continue
61
+ layer.setdefault(pkgname, []).append(
62
+ (manifest_path.parent, manifest))
63
+ candidate = layer.get(name)
64
+ candidates.update(layer)
65
+
66
+ if candidate is None:
67
+ continue
68
+
69
+ reference = _get_reference(specifications)
70
+ locations = set()
71
+ for location, manifest in candidate:
72
+ locations.add(location)
73
+ plain_deps, build_deps, _ = get_dependencies(manifest, location)
74
+ queue.extend(plain_deps.items())
75
+ queue.extend(build_deps.items())
76
+
77
+ composition[name] = ({reference}, locations)
78
+
79
+ return composition
80
+
81
+
82
+ def get_cargo_arguments(composition, default_registry=None):
83
+ """
84
+ Get arguments to pass to 'cargo' which patch package references.
85
+
86
+ :param composition: The curated package composition
87
+ :type composition: dict
88
+ :param default_registry: The default package registry if none was specified
89
+ :type default_registry: str, optional
90
+
91
+ :returns: List of command line arguments
92
+ :rtype: list
93
+ """
94
+ if default_registry is None:
95
+ default_registry = os.environ.get('CARGO_REGISTRY_DEFAULT')
96
+ if not default_registry:
97
+ default_registry = 'crates-io'
98
+ arguments = set()
99
+ for name, (references, candidates) in composition.items():
100
+ for reference in references:
101
+ if reference is None:
102
+ reference = default_registry
103
+ elif any(
104
+ candidate.as_uri() == reference
105
+ for candidate in candidates
106
+ ):
107
+ # Cargo does not allow a patch to point to the same location as
108
+ # the original dependency specification. If we encounter this,
109
+ # just skip the reference entirely since it already points to
110
+ # at least one of our candidates.
111
+ continue
112
+ for idx, candidate in enumerate(candidates):
113
+ # Specifically use ~, which is valid in TOML but not in a
114
+ # Cargo package name to reduce the likelihood of a collision
115
+ section = f"patch.'{reference}'.'{name}~{idx}'"
116
+ arguments.add(f"--config={section}.package='{name}'")
117
+ arguments.add(f"--config={section}.path='{candidate}'")
118
+ return sorted(arguments)
119
+
120
+
121
+ def get_cargo_config(composition, default_registry=None):
122
+ """
123
+ Get Cargo configuration to patch package references.
124
+
125
+ :param composition: The curated package composition
126
+ :type composition: dict
127
+ :param default_registry: The default package registry if none was specified
128
+ :type default_registry: str, optional
129
+
130
+ :returns: Raw TOML configuration
131
+ :rtype: str
132
+ """
133
+ if default_registry is None:
134
+ default_registry = os.environ.get('CARGO_REGISTRY_DEFAULT')
135
+ if not default_registry:
136
+ default_registry = 'crates-io'
137
+ sections = set()
138
+ for name, (references, candidates) in composition.items():
139
+ for reference in references:
140
+ if reference is None:
141
+ reference = default_registry
142
+ elif any(
143
+ candidate.as_uri() == reference
144
+ for candidate in candidates
145
+ ):
146
+ # Cargo does not allow a patch to point to the same location as
147
+ # the original dependency specification. If we encounter this,
148
+ # just skip the reference entirely since it already points to
149
+ # at least one of our candidates.
150
+ continue
151
+ for idx, candidate in enumerate(candidates):
152
+ # Specifically use ~, which is valid in TOML but not in a
153
+ # Cargo package name to reduce the likelihood of a collision
154
+ sections.add('\n'.join((
155
+ f"[patch.'{reference}'.'{name}~{idx}']",
156
+ f"package = '{name}'",
157
+ f"path = '{candidate}'",
158
+ )))
159
+ return '\n\n'.join(sorted(sections))
@@ -0,0 +1,31 @@
1
+ Metadata-Version: 2.2
2
+ Name: pallet-patcher
3
+ Version: 0.0.1
4
+ Summary: Tools for working with curated collections of Cargo packages
5
+ Author-email: Scott K Logan <logans@cottsay.net>
6
+ License: Apache License, Version 2.0
7
+ Classifier: Development Status :: 4 - Beta
8
+ Classifier: Environment :: Console
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: License :: OSI Approved :: Apache Software License
11
+ Classifier: Operating System :: MacOS
12
+ Classifier: Operating System :: Microsoft :: Windows
13
+ Classifier: Operating System :: POSIX
14
+ Classifier: Programming Language :: Python
15
+ Classifier: Programming Language :: Rust
16
+ Classifier: Topic :: Software Development :: Build Tools
17
+ Requires-Python: >=3.6
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ Requires-Dist: tomli>=1.0.0; python_version < "3.11"
21
+ Provides-Extra: test
22
+ Requires-Dist: flake8; extra == "test"
23
+ Requires-Dist: mypy; extra == "test"
24
+ Requires-Dist: pytest; extra == "test"
25
+
26
+ # pallet-patcher
27
+
28
+ _Tools for working with curated collections of Cargo packages_
29
+
30
+ > [!WARNING]
31
+ > This is a prototype package without stable behavior or API.
@@ -0,0 +1,20 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ setup.cfg
5
+ setup.py
6
+ pallet_patcher/__init__.py
7
+ pallet_patcher/__main__.py
8
+ pallet_patcher/command.py
9
+ pallet_patcher/manifest.py
10
+ pallet_patcher/search.py
11
+ pallet_patcher.egg-info/PKG-INFO
12
+ pallet_patcher.egg-info/SOURCES.txt
13
+ pallet_patcher.egg-info/dependency_links.txt
14
+ pallet_patcher.egg-info/entry_points.txt
15
+ pallet_patcher.egg-info/requires.txt
16
+ pallet_patcher.egg-info/top_level.txt
17
+ pallet_patcher.egg-info/zip-safe
18
+ test/test_compose.py
19
+ test/test_copyright_license.py
20
+ test/test_flake8.py
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ pallet-patcher = pallet_patcher.command:main
@@ -0,0 +1,8 @@
1
+
2
+ [:python_version < "3.11"]
3
+ tomli>=1.0.0
4
+
5
+ [test]
6
+ flake8
7
+ mypy
8
+ pytest
@@ -0,0 +1 @@
1
+ pallet_patcher
@@ -0,0 +1,3 @@
1
+ [build-system]
2
+ requires = ["setuptools>=40.8.0"]
3
+ build-backend = "setuptools.build_meta:__legacy__"
@@ -0,0 +1,67 @@
1
+ [metadata]
2
+ name = pallet-patcher
3
+ version = attr: pallet_patcher.__version__
4
+ author_email = Scott K Logan <logans@cottsay.net>
5
+ classifiers =
6
+ Development Status :: 4 - Beta
7
+ Environment :: Console
8
+ Intended Audience :: Developers
9
+ License :: OSI Approved :: Apache Software License
10
+ Operating System :: MacOS
11
+ Operating System :: Microsoft :: Windows
12
+ Operating System :: POSIX
13
+ Programming Language :: Python
14
+ Programming Language :: Rust
15
+ Topic :: Software Development :: Build Tools
16
+ license = Apache License, Version 2.0
17
+ description = Tools for working with curated collections of Cargo packages
18
+ long_description = file: README.md
19
+ long_description_content_type = text/markdown
20
+
21
+ [options]
22
+ python_requires = >=3.6
23
+ install_requires =
24
+ tomli>=1.0.0; python_version < "3.11"
25
+ packages = find:
26
+ zip_safe = true
27
+
28
+ [options.extras_require]
29
+ test =
30
+ flake8
31
+ mypy
32
+ pytest
33
+
34
+ [options.packages.find]
35
+ exclude =
36
+ test
37
+ test.*
38
+
39
+ [tool:pytest]
40
+ junit_suite_name = pallet-patcher
41
+ markers =
42
+ flake8
43
+ linter
44
+
45
+ [options.entry_points]
46
+ console_scripts =
47
+ pallet-patcher = pallet_patcher.command:main
48
+
49
+ [flake8]
50
+ extend_ignore =
51
+ D100
52
+ D104
53
+ import-order-style = google
54
+ per-file-ignores =
55
+ test/**: D101,D102,D103,D104,D105,D107
56
+ show_source = true
57
+
58
+ [mypy]
59
+ ignore_missing_imports = True
60
+
61
+ [coverage:run]
62
+ source = pallet_patcher
63
+
64
+ [egg_info]
65
+ tag_build =
66
+ tag_date = 0
67
+
@@ -0,0 +1,6 @@
1
+ # Copyright 2025 Open Source Robotics Foundation, Inc.
2
+ # Licensed under the Apache License, Version 2.0
3
+
4
+ from setuptools import setup
5
+
6
+ setup()
@@ -0,0 +1,81 @@
1
+ # Copyright 2025 Open Source Robotics Foundation, Inc.
2
+ # Licensed under the Apache License, Version 2.0
3
+
4
+ from pathlib import Path
5
+ import shutil
6
+ import subprocess
7
+
8
+ from pallet_patcher.command import load_and_compose
9
+ from pallet_patcher.search import compose
10
+ from pallet_patcher.search import get_cargo_arguments
11
+ from pallet_patcher.search import get_cargo_config
12
+ import pytest
13
+
14
+ _PACKAGES_PATH = Path(__file__).parent / 'packages'
15
+
16
+ _CARGO = shutil.which('cargo')
17
+
18
+
19
+ def test_dry():
20
+ dependencies = [
21
+ ('pkg-e', '*'),
22
+ ]
23
+ search_paths = (
24
+ _PACKAGES_PATH / 'upper_layer',
25
+ _PACKAGES_PATH / 'lower_layer',
26
+ )
27
+
28
+ composition = compose(dependencies, search_paths)
29
+ assert len(composition) == 5, f'{composition}'
30
+
31
+ arguments = get_cargo_arguments(composition)
32
+ assert len(arguments) == 10, f'{arguments}'
33
+
34
+ config = get_cargo_config(composition)
35
+ assert config
36
+
37
+
38
+ @pytest.mark.skipif(not _CARGO, reason='The cargo executable is not available')
39
+ def test_cargo_arguments(tmpdir):
40
+ layer_src = _PACKAGES_PATH / 'upper_layer'
41
+ layer_dst = Path(tmpdir) / 'upper_layer'
42
+ shutil.copytree(str(layer_src), layer_dst)
43
+
44
+ search_paths = (
45
+ layer_dst,
46
+ _PACKAGES_PATH / 'lower_layer',
47
+ )
48
+
49
+ pkg_e = layer_dst / 'pkg-e-0.0.0'
50
+ composition = load_and_compose(pkg_e / 'Cargo.toml', search_paths)
51
+ arguments = get_cargo_arguments(composition)
52
+
53
+ subprocess.run(
54
+ [_CARGO, 'metadata', '--format-version=1', '--offline', *arguments],
55
+ cwd=str(pkg_e),
56
+ check=True)
57
+
58
+
59
+ @pytest.mark.skipif(not _CARGO, reason='The cargo executable is not available')
60
+ def test_cargo_config(tmpdir):
61
+ layer_src = _PACKAGES_PATH / 'upper_layer'
62
+ layer_dst = Path(tmpdir) / 'upper_layer'
63
+ shutil.copytree(str(layer_src), layer_dst)
64
+
65
+ search_paths = (
66
+ layer_dst,
67
+ _PACKAGES_PATH / 'lower_layer',
68
+ )
69
+
70
+ pkg_e = layer_dst / 'pkg-e-0.0.0'
71
+ composition = load_and_compose(pkg_e / 'Cargo.toml', search_paths)
72
+ config = get_cargo_config(composition)
73
+
74
+ config_file = pkg_e / '.cargo' / 'config.toml'
75
+ config_file.parent.mkdir()
76
+ config_file.write_text(config)
77
+
78
+ subprocess.run(
79
+ [_CARGO, 'metadata', '--format-version=1', '--offline'],
80
+ cwd=str(pkg_e),
81
+ check=True)
@@ -0,0 +1,43 @@
1
+ # Copyright 2016-2018 Dirk Thomas
2
+ # Licensed under the Apache License, Version 2.0
3
+
4
+ from pathlib import Path
5
+ import sys
6
+ from typing import List
7
+
8
+ import pytest
9
+
10
+
11
+ @pytest.mark.linter
12
+ def test_copyright_license() -> None:
13
+ missing = check_files([Path(__file__).parents[1]])
14
+ assert not len(missing), \
15
+ 'In some files no copyright / license line was found'
16
+
17
+
18
+ def check_files(paths) -> List[Path]:
19
+ missing = []
20
+ for path in paths:
21
+ if path.is_dir():
22
+ for p in sorted(path.iterdir()):
23
+ if p.name.startswith('.'):
24
+ continue
25
+ if p.name.endswith('.py') or p.is_dir():
26
+ missing += check_files([p])
27
+ if path.is_file():
28
+ content = path.read_text()
29
+ if not content:
30
+ continue
31
+ lines = content.splitlines()
32
+ has_copyright = any(
33
+ line.startswith('# Copyright')for line in lines)
34
+ has_license = \
35
+ '# Licensed under the Apache License, Version 2.0' in lines
36
+ if not has_copyright or not has_license:
37
+ print(
38
+ 'Could not find copyright / license in:', path,
39
+ file=sys.stderr)
40
+ missing.append(path)
41
+ else:
42
+ print('Found copyright / license in:', path)
43
+ return missing
@@ -0,0 +1,23 @@
1
+ # Copyright 2018 Open Source Robotics Foundation, Inc.
2
+ # Licensed under the Apache License, Version 2.0
3
+
4
+ import os
5
+ import subprocess
6
+ import sys
7
+
8
+ import pytest
9
+
10
+
11
+ @pytest.mark.flake8
12
+ @pytest.mark.linter
13
+ def test_flake8() -> None:
14
+ # flake8 doesn't have a stable public API as of ver 6.1.0.
15
+ # See: https://flake8.pycqa.org/en/latest/user/python-api.html
16
+ # Calling through subprocess is the most stable way to run it.
17
+
18
+ result = subprocess.run(
19
+ [sys.executable, '-m', 'flake8'],
20
+ cwd=os.path.dirname(os.path.dirname(__file__)),
21
+ check=False,
22
+ )
23
+ assert 0 == result.returncode, 'flake8 found violations'