tracdap-ext-git 0.10.0__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,118 @@
1
+ Metadata-Version: 2.4
2
+ Name: tracdap-ext-git
3
+ Version: 0.10.0
4
+ Summary: An extension for TRAC D.A.P. that loads models from Git repositories
5
+ Author-email: Martin Traverse <martin@fintrac.co.uk>
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://tracdap.finos.org/
8
+ Project-URL: Documentation, https://tracdap.readthedocs.io/
9
+ Project-URL: Source Code, https://github.com/finos/tracdap
10
+ Project-URL: Issue Tracker, https://github.com/finos/tracdap/issues
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: 3.14
18
+ Classifier: Intended Audience :: Developers
19
+ Classifier: Intended Audience :: End Users/Desktop
20
+ Classifier: Intended Audience :: Financial and Insurance Industry
21
+ Classifier: Topic :: Office/Business
22
+ Classifier: Topic :: Office/Business :: Financial
23
+ Classifier: Topic :: Software Development
24
+ Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
25
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
26
+ Requires-Python: >=3.10
27
+ Description-Content-Type: text/markdown
28
+ License-File: LICENSE
29
+ Requires-Dist: tracdap-runtime==0.10.*
30
+ Requires-Dist: dulwich~=1.2.5
31
+ Requires-Dist: urllib3>=2.2.0
32
+ Dynamic: license-file
33
+
34
+ <div align="center">
35
+
36
+ ![TRAC the modern model platform](https://github.com/finos/tracdap/raw/main/doc/_images/tracmmp_horizontal_400.png)
37
+
38
+ <br />
39
+
40
+ <div>
41
+ <a href="https://pypi.org/project/tracdap-ext-git"><img alt="PyPI Version" src="https://img.shields.io/pypi/v/tracdap-ext-git.svg?maxAge=3600" /></a>
42
+ <a href="https://pypi.org/project/tracdap-ext-git"><img alt="Python Versions" src="https://img.shields.io/pypi/pyversions/tracdap-ext-git.svg?maxAge=3600" /></a>
43
+ <a href="https://github.com/finos/tracdap/actions/workflows/packaging.yaml?query=branch%3Amain"><img alt="Packaging status" src="https://github.com/finos/tracdap/actions/workflows/packaging.yaml/badge.svg?branch:main&workflow:CI" /></a>
44
+ <a href="https://github.com/finos/tracdap/actions/workflows/compliance.yaml?query=branch%3Amain"><img alt="Compliance status" src="https://github.com/finos/tracdap/actions/workflows/compliance.yaml/badge.svg?branch:main&workflow:CI" /></a>
45
+ <a href="https://github.com/finos/tracdap/blob/main/LICENSE"><img alt="License - Apache-2.0" src="https://img.shields.io/pypi/l/tracdap-ext-git.svg" /></a>
46
+ <a href="https://community.finos.org/docs/governance/software-projects/stages/incubating/"><img alt="FINOS - Incubating" src="https://cdn.jsdelivr.net/gh/finos/contrib-toolbox@master/images/badge-incubating.svg" /></a>
47
+ </div>
48
+
49
+ <p>
50
+ <a href="https://www.fintrac.co.uk/">Homepage</a>
51
+ ◆ <a href="https://docs.fintrac.co.uk/versions/latest/modelling">Documentation</a>
52
+ ◆ <a href="https://github.com/fintrac-hub/examples">Examples</a>
53
+ ◆ <a href="https://github.com/finos/tracdap">Source Code</a>
54
+ ◆ <a href="https://github.com/finos/tracdap/issues">Issue Tracker</a>
55
+ </p>
56
+ </div>
57
+
58
+
59
+ # Git Extension for the TRAC Model Runtime
60
+
61
+ This extension allows TRAC to load models dynamically from Git repositories.
62
+
63
+ - Includes a pure-Python implementation using the excellent [dulwich](https://pypi.org/project/dulwich/) library
64
+ - Includes a native Git implementation that wraps a Git binaries on the host system
65
+ - Support for private repositories using tokens
66
+ - Handles corporate firewalls, proxies and SSL
67
+
68
+ This extension is a pre-release and will be finalized inTRAC 0.10.
69
+
70
+
71
+ ## Installing
72
+
73
+ The HTTP extension can be installed with [pip](https://pip.pypa.io):
74
+
75
+ ```shell
76
+ $ pip install tracdap-ext-git
77
+ ```
78
+
79
+ The package has the following dependencies:
80
+
81
+ - tracdap-runtime (version 0.10.0-beta2 or later)
82
+ - dulwich (0.24.x series)
83
+ - urllib3 (version 2.2 or later)
84
+
85
+
86
+ ## Using the Git model repository
87
+
88
+ With the Git extension installed, you can add a Git model repository as a resource in sys_config.yaml like this:
89
+
90
+ ```yaml
91
+ resources:
92
+
93
+ my_repository:
94
+ resourceType: MODEL_REPOSITORY
95
+ protocol: git
96
+ properties:
97
+ repoUrl: https://github.com/a-user/my-repository
98
+ ```
99
+
100
+ By default the extension will use the pure-python implementation of Git, to use native Git binaries set
101
+ `nativeGit: true` as a property on the repository. To supply credentials, use either the `username` and
102
+ `password` properties, or the `token` property. In production deployments these properties should be
103
+ supplied using the TRAC secrets mechanism.
104
+
105
+ Using the pure-Python implementation, all of TRAC's network properties are respected.
106
+ In particular, to supply an enterprise root trust certificate you can set
107
+ `network.ssl.caCertificates` to the path of a certificate in PEM format.
108
+ Setting `network.ssl.publicCertificates: true` will include the global, public CAs
109
+ in addition to the enterprise root.
110
+
111
+ All properties starting with the prefix `git.` are treated as Git configuration and
112
+ written into the Git config file for the repository when it is checked out. For example,
113
+ setting `git.http.sslCAInfo` will set the `sslCAInfo` property in the `http` section of the
114
+ Git configuration. This is an alternate way of specifying SSL details that works with the
115
+ native Git implementation, but can also be used to set arbitrary Git configuration values
116
+ with either implementation. Some Git config values may not be respected by Dulwich, so it
117
+ is recommended to use the TRAC config settings with the pure-Python implementation and
118
+ native Git config settings with the native Git implementation.
@@ -0,0 +1,85 @@
1
+ <div align="center">
2
+
3
+ ![TRAC the modern model platform](https://github.com/finos/tracdap/raw/main/doc/_images/tracmmp_horizontal_400.png)
4
+
5
+ <br />
6
+
7
+ <div>
8
+ <a href="https://pypi.org/project/tracdap-ext-git"><img alt="PyPI Version" src="https://img.shields.io/pypi/v/tracdap-ext-git.svg?maxAge=3600" /></a>
9
+ <a href="https://pypi.org/project/tracdap-ext-git"><img alt="Python Versions" src="https://img.shields.io/pypi/pyversions/tracdap-ext-git.svg?maxAge=3600" /></a>
10
+ <a href="https://github.com/finos/tracdap/actions/workflows/packaging.yaml?query=branch%3Amain"><img alt="Packaging status" src="https://github.com/finos/tracdap/actions/workflows/packaging.yaml/badge.svg?branch:main&workflow:CI" /></a>
11
+ <a href="https://github.com/finos/tracdap/actions/workflows/compliance.yaml?query=branch%3Amain"><img alt="Compliance status" src="https://github.com/finos/tracdap/actions/workflows/compliance.yaml/badge.svg?branch:main&workflow:CI" /></a>
12
+ <a href="https://github.com/finos/tracdap/blob/main/LICENSE"><img alt="License - Apache-2.0" src="https://img.shields.io/pypi/l/tracdap-ext-git.svg" /></a>
13
+ <a href="https://community.finos.org/docs/governance/software-projects/stages/incubating/"><img alt="FINOS - Incubating" src="https://cdn.jsdelivr.net/gh/finos/contrib-toolbox@master/images/badge-incubating.svg" /></a>
14
+ </div>
15
+
16
+ <p>
17
+ <a href="https://www.fintrac.co.uk/">Homepage</a>
18
+ ◆ <a href="https://docs.fintrac.co.uk/versions/latest/modelling">Documentation</a>
19
+ ◆ <a href="https://github.com/fintrac-hub/examples">Examples</a>
20
+ ◆ <a href="https://github.com/finos/tracdap">Source Code</a>
21
+ ◆ <a href="https://github.com/finos/tracdap/issues">Issue Tracker</a>
22
+ </p>
23
+ </div>
24
+
25
+
26
+ # Git Extension for the TRAC Model Runtime
27
+
28
+ This extension allows TRAC to load models dynamically from Git repositories.
29
+
30
+ - Includes a pure-Python implementation using the excellent [dulwich](https://pypi.org/project/dulwich/) library
31
+ - Includes a native Git implementation that wraps a Git binaries on the host system
32
+ - Support for private repositories using tokens
33
+ - Handles corporate firewalls, proxies and SSL
34
+
35
+ This extension is a pre-release and will be finalized inTRAC 0.10.
36
+
37
+
38
+ ## Installing
39
+
40
+ The HTTP extension can be installed with [pip](https://pip.pypa.io):
41
+
42
+ ```shell
43
+ $ pip install tracdap-ext-git
44
+ ```
45
+
46
+ The package has the following dependencies:
47
+
48
+ - tracdap-runtime (version 0.10.0-beta2 or later)
49
+ - dulwich (0.24.x series)
50
+ - urllib3 (version 2.2 or later)
51
+
52
+
53
+ ## Using the Git model repository
54
+
55
+ With the Git extension installed, you can add a Git model repository as a resource in sys_config.yaml like this:
56
+
57
+ ```yaml
58
+ resources:
59
+
60
+ my_repository:
61
+ resourceType: MODEL_REPOSITORY
62
+ protocol: git
63
+ properties:
64
+ repoUrl: https://github.com/a-user/my-repository
65
+ ```
66
+
67
+ By default the extension will use the pure-python implementation of Git, to use native Git binaries set
68
+ `nativeGit: true` as a property on the repository. To supply credentials, use either the `username` and
69
+ `password` properties, or the `token` property. In production deployments these properties should be
70
+ supplied using the TRAC secrets mechanism.
71
+
72
+ Using the pure-Python implementation, all of TRAC's network properties are respected.
73
+ In particular, to supply an enterprise root trust certificate you can set
74
+ `network.ssl.caCertificates` to the path of a certificate in PEM format.
75
+ Setting `network.ssl.publicCertificates: true` will include the global, public CAs
76
+ in addition to the enterprise root.
77
+
78
+ All properties starting with the prefix `git.` are treated as Git configuration and
79
+ written into the Git config file for the repository when it is checked out. For example,
80
+ setting `git.http.sslCAInfo` will set the `sslCAInfo` property in the `http` section of the
81
+ Git configuration. This is an alternate way of specifying SSL details that works with the
82
+ native Git implementation, but can also be used to set arbitrary Git configuration values
83
+ with either implementation. Some Git config values may not be respected by Dulwich, so it
84
+ is recommended to use the TRAC config settings with the pure-Python implementation and
85
+ native Git config settings with the native Git implementation.
@@ -0,0 +1,60 @@
1
+
2
+
3
+ [build-system]
4
+
5
+ requires = ["setuptools >= 77.0.3"]
6
+ build-backend = "setuptools.build_meta"
7
+
8
+ [project]
9
+
10
+ dynamic = ["version", "dependencies"]
11
+
12
+ name = "tracdap-ext-git"
13
+ description = "An extension for TRAC D.A.P. that loads models from Git repositories"
14
+ readme = "README.md"
15
+
16
+ license = "Apache-2.0"
17
+ license-files = ["LICENSE"]
18
+
19
+ authors = [
20
+ {name = "Martin Traverse", email = "martin@fintrac.co.uk"}
21
+ ]
22
+
23
+ classifiers = [
24
+ "Operating System :: OS Independent",
25
+ "Programming Language :: Python :: 3",
26
+ "Programming Language :: Python :: 3.10",
27
+ "Programming Language :: Python :: 3.11",
28
+ "Programming Language :: Python :: 3.12",
29
+ "Programming Language :: Python :: 3.13",
30
+ "Programming Language :: Python :: 3.14",
31
+ "Intended Audience :: Developers",
32
+ "Intended Audience :: End Users/Desktop",
33
+ "Intended Audience :: Financial and Insurance Industry",
34
+ "Topic :: Office/Business",
35
+ "Topic :: Office/Business :: Financial",
36
+ "Topic :: Software Development",
37
+ "Topic :: Software Development :: Libraries :: Application Frameworks",
38
+ "Topic :: Software Development :: Libraries :: Python Modules"
39
+ ]
40
+
41
+ requires-python = ">= 3.10"
42
+
43
+
44
+ [project.urls]
45
+
46
+ Homepage = "https://tracdap.finos.org/"
47
+ Documentation = "https://tracdap.readthedocs.io/"
48
+ "Source Code" = "https://github.com/finos/tracdap"
49
+ "Issue Tracker" = "https://github.com/finos/tracdap/issues"
50
+
51
+ [tool.setuptools.packages.find]
52
+
53
+ where = ["src"]
54
+ namespaces = true
55
+
56
+
57
+ [tool.setuptools.dynamic]
58
+
59
+ version = { attr = "tracdap.ext.git.__version__" }
60
+ dependencies = { file = ["requirements.txt"] }
@@ -0,0 +1,3 @@
1
+ tracdap-runtime == 0.10.*
2
+ dulwich ~= 1.2.5
3
+ urllib3 >= 2.2.0
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,16 @@
1
+ # Licensed to the Fintech Open Source Foundation (FINOS) under one or
2
+ # more contributor license agreements. See the NOTICE file distributed
3
+ # with this work for additional information regarding copyright ownership.
4
+ # FINOS licenses this file to you under the Apache License, Version 2.0
5
+ # (the "License"); you may not use this file except in compliance with the
6
+ # License. You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ __version__ = "0.10.0"
@@ -0,0 +1,367 @@
1
+ # Licensed to the Fintech Open Source Foundation (FINOS) under one or
2
+ # more contributor license agreements. See the NOTICE file distributed
3
+ # with this work for additional information regarding copyright ownership.
4
+ # FINOS licenses this file to you under the Apache License, Version 2.0
5
+ # (the "License"); you may not use this file except in compliance with the
6
+ # License. You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ import pathlib
17
+ import re
18
+ import subprocess as sp
19
+ import urllib.parse
20
+ import time
21
+
22
+ import dulwich.repo as git_repo
23
+ import dulwich.client as git_client
24
+ import dulwich.index as git_index
25
+ import urllib3.exceptions # noqa
26
+
27
+ import tracdap.rt.config as cfg
28
+ import tracdap.rt.metadata as meta
29
+ import tracdap.rt.exceptions as ex
30
+ import tracdap.rt.ext.plugins as plugins
31
+ import tracdap.rt.ext.util as util
32
+
33
+ # Import repo interfaces
34
+ from tracdap.rt.ext.repos import *
35
+ from tracdap.rt.ext.util import hide_http_credentials
36
+
37
+
38
+ class GitRepository(IModelRepository):
39
+
40
+ REPO_URL_KEY = "repoUrl"
41
+ NATIVE_GIT_KEY = "nativeGit"
42
+ USERNAME_KEY = "username"
43
+ PASSWORD_KEY = "password"
44
+ TOKEN_KEY = "token"
45
+
46
+ NATIVE_GIT_DEFAULT = False
47
+
48
+ GIT_TIMEOUT_SECONDS = 30
49
+
50
+ GIT_CONFIG_PATTERN = re.compile("^git\\.([^.]+)\\.(.+)")
51
+ SHA1_PATTERN = re.compile("^[0-9a-f]{40}$")
52
+
53
+ def __init__(
54
+ self, config: cfg.PluginConfig,
55
+ network_manager: plugins.INetworkManager,
56
+ log_provider: plugins.ILogProvider):
57
+
58
+ self._config = config
59
+ self._pool_manager = network_manager.use_shared_urllib3_pool_manager(config)
60
+ self._log = log_provider.logger_for_object(self)
61
+
62
+ repo_url_str = util.read_plugin_config(self._config, self.REPO_URL_KEY)
63
+ repo_url = urllib.parse.urlparse(repo_url_str)
64
+ credentials = self._get_http_credentials(repo_url)
65
+
66
+ self._repo_url = util.apply_http_credentials(repo_url, credentials)
67
+
68
+ # Whether to use the system native Git, instead of Python Dulwich
69
+ self._native_git = util.read_plugin_config(
70
+ self._config, self.NATIVE_GIT_KEY,
71
+ convert=bool, default=self.NATIVE_GIT_DEFAULT)
72
+
73
+ def get_checkout_path(
74
+ self, model_def: meta.ModelDefinition,
75
+ checkout_dir: pathlib.Path) -> pathlib.Path:
76
+
77
+ return checkout_dir.joinpath(model_def.path)
78
+
79
+ def checkout(self, model_def: meta.ModelDefinition, checkout_dir: pathlib.Path) -> pathlib.Path:
80
+
81
+ try:
82
+
83
+ self._log.info(
84
+ f"Git checkout: repo = [{model_def.repository}], " +
85
+ f"group = [{model_def.packageGroup}], package = [{model_def.package}], version = [{model_def.version}]")
86
+
87
+ self._log.info(f"Checkout location: [{checkout_dir}]")
88
+
89
+ if self._native_git:
90
+ package_path = self._do_native_checkout(model_def, checkout_dir)
91
+ else:
92
+ package_path = self._do_python_checkout(model_def, checkout_dir)
93
+
94
+ self._log.info(f"Git checkout succeeded for {model_def.package} {model_def.version}")
95
+
96
+ return package_path
97
+
98
+ except Exception as e:
99
+
100
+ error = e
101
+
102
+ # For retry failures, try to find the original cause
103
+ while e.__cause__ is not None:
104
+ if isinstance(e, urllib3.exceptions.MaxRetryError):
105
+ error = e.__cause__
106
+ break
107
+ else:
108
+ e = e.__cause__
109
+
110
+ # Try to sanitize error messages from urllib3
111
+ if isinstance(error, urllib3.exceptions.HTTPError):
112
+ detail = self._clean_urllib3_error(error)
113
+ else:
114
+ detail = str(error)
115
+
116
+ message = f"Failed to check out [{model_def.repository}]: {detail}"
117
+
118
+ self._log.error(message)
119
+ raise ex.EModelRepo(message) from error
120
+
121
+ def _do_native_checkout(self, model_def: meta.ModelDefinition, checkout_dir: pathlib.Path) -> pathlib.Path:
122
+
123
+ self._log.info(f"Checkout mechanism: [native]")
124
+
125
+ # Using windows_safe_path() to create UNC paths does not always work with Windows native Git
126
+ # So, use the regular checkout_dir, and set core.longpaths = true once the repo is created
127
+ # This will fail if the path for the repo config file exceeds the Windows MAX_PATH length
128
+ # I.e. checkout_dir/.git/config
129
+
130
+ git_cli = ["git", "-C", str(checkout_dir)]
131
+
132
+ git_cmds = [
133
+ ["init"],
134
+ ["remote", "add", "origin", self._repo_url.geturl()],
135
+ ["fetch", "--depth=1", "origin", model_def.version],
136
+ ["reset", "--hard", "FETCH_HEAD"]]
137
+
138
+ # Flag to track when git config is written to the repo
139
+ config_written = False
140
+
141
+ # Work around Windows issues
142
+ if util.is_windows():
143
+
144
+ # Some machines may still be setup without long path support in Windows and/or the Git client
145
+ # Workaround: Enable the core.longpaths flag for each individual Git command (do not rely on system config)
146
+ git_cli += ["-c", "core.longpaths=true"]
147
+
148
+ # On some systems, directories created by the TRAC runtime process may not be owned by the process owner
149
+ # This will cause Git to report an unsafe repo directory
150
+ # Finding the current owner requires either batch scripting or using the win32_api package
151
+ # Workaround: Explicitly take ownership of the repo directory, always, before starting the checkout
152
+ try:
153
+ self._log.info(f"Fixing filesystem permissions for [{checkout_dir}]")
154
+ sp.run(f"takeown /f \"{checkout_dir}\"")
155
+ except Exception: # noqa
156
+ self._log.info(f"Failed to fix filesystem permissions, this might prevent checkout from succeeding")
157
+
158
+ for git_cmd in git_cmds:
159
+
160
+ safe_cmd = map(self._log_safe, git_cmd)
161
+ self._log.info(f"=> git {' '.join(safe_cmd)}")
162
+
163
+ cmd = [*git_cli, *git_cmd]
164
+ cmd_result = sp.run(cmd, cwd=checkout_dir, stdout=sp.PIPE, stderr=sp.PIPE, timeout=self.GIT_TIMEOUT_SECONDS)
165
+
166
+ if cmd_result.returncode != 0:
167
+ time.sleep(1)
168
+ self._log.warning(f"git {' '.join(git_cmd)} (retrying)")
169
+ cmd_result = sp.run(cmd, cwd=checkout_dir, stdout=sp.PIPE, stderr=sp.PIPE, timeout=self.GIT_TIMEOUT_SECONDS) # noqa
170
+
171
+ cmd_out = str(cmd_result.stdout, 'utf-8').splitlines()
172
+ cmd_err = str(cmd_result.stderr, 'utf-8').splitlines()
173
+
174
+ for line in cmd_out:
175
+ self._log.info(line)
176
+
177
+ if cmd_result.returncode == 0:
178
+
179
+ for line in cmd_err:
180
+ self._log.info(line)
181
+
182
+ # After the init command, use dulwich to write config into the repo folder
183
+ # This is a regular .gitconfig file, so it will be understood by the native commands
184
+ if not config_written:
185
+ repo = git_repo.Repo(str(checkout_dir))
186
+ self._apply_config_from_properties(repo)
187
+ config_written = True
188
+
189
+ elif cmd_err:
190
+
191
+ for line in cmd_err:
192
+ self._log.error(line)
193
+
194
+ raise ex.EModelRepo(cmd_err[-1])
195
+
196
+ else:
197
+
198
+ error_msg = f"Git checkout failed for {model_def.package} {model_def.version}"
199
+ self._log.error(error_msg)
200
+ raise ex.EModelRepo(error_msg)
201
+
202
+ return self.get_checkout_path(model_def, checkout_dir)
203
+
204
+ def _do_python_checkout(self, model_def: meta.ModelDefinition, checkout_dir: pathlib.Path) -> pathlib.Path:
205
+
206
+ self._log.info(f"Checkout mechanism: [python]")
207
+
208
+ # Create a new repo
209
+
210
+ self._log.info("=> git init")
211
+
212
+ repo = git_repo.Repo.init(str(checkout_dir))
213
+ self._apply_config_from_properties(repo)
214
+
215
+ # Set up origin
216
+
217
+ self._log.info(f"=> git remote add origin {util.hide_http_credentials(self._repo_url)}")
218
+
219
+ self._add_remote(repo, "origin", self._repo_url.geturl())
220
+
221
+ # Set up the ref keys to look for in the fetch response
222
+ commit_hash = self._ref_key(model_def.version) if self.SHA1_PATTERN.match(model_def.version) else None
223
+ tag_key = self._ref_key(f"refs/tags/{model_def.version}")
224
+ branch_key = self._ref_key(f"refs/heads/{model_def.version}")
225
+
226
+ # This is how dulwich filters what comes back from a fetch
227
+ # Commit hash is first preference, then tag, then branch
228
+ # We are only ever going to request a single commit
229
+ def select_commit_hash(refs, depth): # noqa
230
+ if commit_hash is not None:
231
+ return [commit_hash]
232
+ if tag_key in refs:
233
+ return [refs[tag_key]]
234
+ if branch_key in refs:
235
+ return [refs[branch_key]]
236
+ raise ex.EModelRepo(f"Model version not found: [{model_def.version}]")
237
+
238
+ # Run the Git fetch command
239
+
240
+ self._log.info(f"=> git fetch --depth=1 origin {model_def.version}")
241
+
242
+ credentials = self._get_http_credentials(self._repo_url)
243
+ username, password = self._split_http_credentials(credentials)
244
+
245
+ client = git_client.HttpGitClient(
246
+ self._repo_url.geturl(),
247
+ config=repo.get_config(),
248
+ pool_manager=self._pool_manager,
249
+ username=username,
250
+ password=password)
251
+
252
+ fetch = client.fetch(self._repo_url.path, repo, select_commit_hash, depth=1)
253
+
254
+ # Look for the ref that came back from the fetch command and set it as HEAD
255
+
256
+ self._log.info("=> git reset --hard FETCH_HEAD")
257
+
258
+ if commit_hash is not None:
259
+ repo[b"HEAD"] = commit_hash
260
+ elif tag_key in fetch.refs:
261
+ repo[b"HEAD"] = fetch.refs[tag_key]
262
+ elif branch_key in fetch.refs:
263
+ repo[b"HEAD"] = fetch.refs[branch_key]
264
+ else:
265
+ raise ex.EModelRepo(f"Model version not found: [{model_def.version}]")
266
+
267
+ # This checks out HEAD into the repo folder
268
+ index_file = repo.index_path()
269
+ tree = repo[b"HEAD"].tree
270
+ git_index.build_index_from_tree(repo.path, index_file, repo.object_store, tree)
271
+
272
+ return self.get_checkout_path(model_def, checkout_dir)
273
+
274
+ def _get_http_credentials(self, url: urllib.parse.ParseResult) -> str | None:
275
+
276
+ token = util.read_plugin_config(self._config, self.TOKEN_KEY, optional=True)
277
+ username = util.read_plugin_config(self._config, self.USERNAME_KEY, optional=True)
278
+ password = util.read_plugin_config(self._config, self.PASSWORD_KEY, optional=True)
279
+
280
+ if token is not None:
281
+ return token
282
+
283
+ if username is not None and password is not None:
284
+ return f"{username}:{password}"
285
+
286
+ # If credentials are not explicit in the config, try looking in the URL
287
+ return util.extract_http_credentials(url)
288
+
289
+ @classmethod
290
+ def _split_http_credentials(cls, credentials: str) -> (str | None, str | None):
291
+
292
+ if credentials is None:
293
+ return None, None
294
+
295
+ elif ":" in credentials:
296
+ sep = credentials.index(":")
297
+ username = credentials[:sep]
298
+ password = credentials[sep + 1:]
299
+ return username, password
300
+
301
+ else:
302
+ return credentials, None
303
+
304
+ def _apply_config_from_properties(self, repo: git_repo.Repo):
305
+
306
+ config = repo.get_config()
307
+
308
+ for key, value in self._config.properties.items():
309
+
310
+ match = self.GIT_CONFIG_PATTERN.match(key)
311
+
312
+ if match:
313
+ section = match.group(1)
314
+ name = match.group(2)
315
+ config.set(section, name, value)
316
+
317
+ config.write_to_path()
318
+
319
+ @staticmethod
320
+ def _add_remote(repo: git_repo.Repo, remote_name: str, remote_location):
321
+
322
+ config = repo.get_config()
323
+
324
+ config.set(f"remote \"{remote_name}\"", "url", remote_location)
325
+
326
+ config.write_to_path()
327
+
328
+ @staticmethod
329
+ def _ref_key(key):
330
+ return bytes(key, "ascii")
331
+
332
+ @classmethod
333
+ def _clean_urllib3_error(cls, error: urllib3.exceptions.HTTPError):
334
+
335
+ match = cls._URLLIB3_ERROR_PATTERN.match(str(error))
336
+
337
+ # Best efforts to clean up the message, fall back on str(error)
338
+ if match:
339
+ return match.group(1)
340
+ else:
341
+ return str(error)
342
+
343
+ # Error message format is like this:
344
+ # <pkg.ClassName object at 0xXXXXXXX>: Message
345
+ _URLLIB3_ERROR_PATTERN = re.compile(r"<[^>]*>: (.*)")
346
+
347
+ @classmethod
348
+ def _log_safe(cls, param):
349
+
350
+ if isinstance(param, urllib.parse.ParseResult) or isinstance(param, urllib.parse.ParseResultBytes):
351
+ return util.hide_http_credentials(param)
352
+
353
+ if isinstance(param, str):
354
+ try:
355
+ url = urllib.parse.urlparse(param)
356
+ return hide_http_credentials(url)
357
+ except ValueError:
358
+ return param
359
+
360
+ if isinstance(param, list):
361
+ return list(map(cls._log_safe, param))
362
+
363
+ return param
364
+
365
+
366
+ # Register plugin
367
+ plugins.PluginManager.register_plugin(IModelRepository, GitRepository, ["git"])
@@ -0,0 +1,118 @@
1
+ Metadata-Version: 2.4
2
+ Name: tracdap-ext-git
3
+ Version: 0.10.0
4
+ Summary: An extension for TRAC D.A.P. that loads models from Git repositories
5
+ Author-email: Martin Traverse <martin@fintrac.co.uk>
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://tracdap.finos.org/
8
+ Project-URL: Documentation, https://tracdap.readthedocs.io/
9
+ Project-URL: Source Code, https://github.com/finos/tracdap
10
+ Project-URL: Issue Tracker, https://github.com/finos/tracdap/issues
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: 3.14
18
+ Classifier: Intended Audience :: Developers
19
+ Classifier: Intended Audience :: End Users/Desktop
20
+ Classifier: Intended Audience :: Financial and Insurance Industry
21
+ Classifier: Topic :: Office/Business
22
+ Classifier: Topic :: Office/Business :: Financial
23
+ Classifier: Topic :: Software Development
24
+ Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
25
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
26
+ Requires-Python: >=3.10
27
+ Description-Content-Type: text/markdown
28
+ License-File: LICENSE
29
+ Requires-Dist: tracdap-runtime==0.10.*
30
+ Requires-Dist: dulwich~=1.2.5
31
+ Requires-Dist: urllib3>=2.2.0
32
+ Dynamic: license-file
33
+
34
+ <div align="center">
35
+
36
+ ![TRAC the modern model platform](https://github.com/finos/tracdap/raw/main/doc/_images/tracmmp_horizontal_400.png)
37
+
38
+ <br />
39
+
40
+ <div>
41
+ <a href="https://pypi.org/project/tracdap-ext-git"><img alt="PyPI Version" src="https://img.shields.io/pypi/v/tracdap-ext-git.svg?maxAge=3600" /></a>
42
+ <a href="https://pypi.org/project/tracdap-ext-git"><img alt="Python Versions" src="https://img.shields.io/pypi/pyversions/tracdap-ext-git.svg?maxAge=3600" /></a>
43
+ <a href="https://github.com/finos/tracdap/actions/workflows/packaging.yaml?query=branch%3Amain"><img alt="Packaging status" src="https://github.com/finos/tracdap/actions/workflows/packaging.yaml/badge.svg?branch:main&workflow:CI" /></a>
44
+ <a href="https://github.com/finos/tracdap/actions/workflows/compliance.yaml?query=branch%3Amain"><img alt="Compliance status" src="https://github.com/finos/tracdap/actions/workflows/compliance.yaml/badge.svg?branch:main&workflow:CI" /></a>
45
+ <a href="https://github.com/finos/tracdap/blob/main/LICENSE"><img alt="License - Apache-2.0" src="https://img.shields.io/pypi/l/tracdap-ext-git.svg" /></a>
46
+ <a href="https://community.finos.org/docs/governance/software-projects/stages/incubating/"><img alt="FINOS - Incubating" src="https://cdn.jsdelivr.net/gh/finos/contrib-toolbox@master/images/badge-incubating.svg" /></a>
47
+ </div>
48
+
49
+ <p>
50
+ <a href="https://www.fintrac.co.uk/">Homepage</a>
51
+ ◆ <a href="https://docs.fintrac.co.uk/versions/latest/modelling">Documentation</a>
52
+ ◆ <a href="https://github.com/fintrac-hub/examples">Examples</a>
53
+ ◆ <a href="https://github.com/finos/tracdap">Source Code</a>
54
+ ◆ <a href="https://github.com/finos/tracdap/issues">Issue Tracker</a>
55
+ </p>
56
+ </div>
57
+
58
+
59
+ # Git Extension for the TRAC Model Runtime
60
+
61
+ This extension allows TRAC to load models dynamically from Git repositories.
62
+
63
+ - Includes a pure-Python implementation using the excellent [dulwich](https://pypi.org/project/dulwich/) library
64
+ - Includes a native Git implementation that wraps a Git binaries on the host system
65
+ - Support for private repositories using tokens
66
+ - Handles corporate firewalls, proxies and SSL
67
+
68
+ This extension is a pre-release and will be finalized inTRAC 0.10.
69
+
70
+
71
+ ## Installing
72
+
73
+ The HTTP extension can be installed with [pip](https://pip.pypa.io):
74
+
75
+ ```shell
76
+ $ pip install tracdap-ext-git
77
+ ```
78
+
79
+ The package has the following dependencies:
80
+
81
+ - tracdap-runtime (version 0.10.0-beta2 or later)
82
+ - dulwich (0.24.x series)
83
+ - urllib3 (version 2.2 or later)
84
+
85
+
86
+ ## Using the Git model repository
87
+
88
+ With the Git extension installed, you can add a Git model repository as a resource in sys_config.yaml like this:
89
+
90
+ ```yaml
91
+ resources:
92
+
93
+ my_repository:
94
+ resourceType: MODEL_REPOSITORY
95
+ protocol: git
96
+ properties:
97
+ repoUrl: https://github.com/a-user/my-repository
98
+ ```
99
+
100
+ By default the extension will use the pure-python implementation of Git, to use native Git binaries set
101
+ `nativeGit: true` as a property on the repository. To supply credentials, use either the `username` and
102
+ `password` properties, or the `token` property. In production deployments these properties should be
103
+ supplied using the TRAC secrets mechanism.
104
+
105
+ Using the pure-Python implementation, all of TRAC's network properties are respected.
106
+ In particular, to supply an enterprise root trust certificate you can set
107
+ `network.ssl.caCertificates` to the path of a certificate in PEM format.
108
+ Setting `network.ssl.publicCertificates: true` will include the global, public CAs
109
+ in addition to the enterprise root.
110
+
111
+ All properties starting with the prefix `git.` are treated as Git configuration and
112
+ written into the Git config file for the repository when it is checked out. For example,
113
+ setting `git.http.sslCAInfo` will set the `sslCAInfo` property in the `http` section of the
114
+ Git configuration. This is an alternate way of specifying SSL details that works with the
115
+ native Git implementation, but can also be used to set arbitrary Git configuration values
116
+ with either implementation. Some Git config values may not be respected by Dulwich, so it
117
+ is recommended to use the TRAC config settings with the pure-Python implementation and
118
+ native Git config settings with the native Git implementation.
@@ -0,0 +1,11 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ requirements.txt
5
+ src/tracdap/ext/git/__init__.py
6
+ src/tracdap/ext/git/git_plugin.py
7
+ src/tracdap_ext_git.egg-info/PKG-INFO
8
+ src/tracdap_ext_git.egg-info/SOURCES.txt
9
+ src/tracdap_ext_git.egg-info/dependency_links.txt
10
+ src/tracdap_ext_git.egg-info/requires.txt
11
+ src/tracdap_ext_git.egg-info/top_level.txt
@@ -0,0 +1,3 @@
1
+ tracdap-runtime==0.10.*
2
+ dulwich~=1.2.5
3
+ urllib3>=2.2.0