concoursetools 0.8.1__tar.gz → 0.9.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.
- {concoursetools-0.8.1 → concoursetools-0.9.0}/PKG-INFO +11 -8
- {concoursetools-0.8.1 → concoursetools-0.9.0}/README.md +6 -2
- {concoursetools-0.8.1 → concoursetools-0.9.0}/concoursetools/__init__.py +1 -1
- {concoursetools-0.8.1 → concoursetools-0.9.0}/concoursetools/additional.py +3 -3
- {concoursetools-0.8.1 → concoursetools-0.9.0}/concoursetools/cli/commands.py +4 -3
- {concoursetools-0.8.1 → concoursetools-0.9.0}/concoursetools/cli/parser.py +6 -6
- {concoursetools-0.8.1 → concoursetools-0.9.0}/concoursetools/importing.py +5 -6
- {concoursetools-0.8.1 → concoursetools-0.9.0}/concoursetools/metadata.py +14 -11
- {concoursetools-0.8.1 → concoursetools-0.9.0}/concoursetools/mocking.py +16 -1
- {concoursetools-0.8.1 → concoursetools-0.9.0}/concoursetools/parsing.py +9 -9
- {concoursetools-0.8.1 → concoursetools-0.9.0}/concoursetools/resource.py +4 -4
- {concoursetools-0.8.1 → concoursetools-0.9.0}/concoursetools/testing.py +3 -3
- {concoursetools-0.8.1 → concoursetools-0.9.0}/concoursetools/typing.py +3 -3
- {concoursetools-0.8.1 → concoursetools-0.9.0}/concoursetools/version.py +1 -1
- {concoursetools-0.8.1 → concoursetools-0.9.0}/concoursetools.egg-info/PKG-INFO +11 -8
- {concoursetools-0.8.1 → concoursetools-0.9.0}/pyproject.toml +4 -5
- {concoursetools-0.8.1 → concoursetools-0.9.0}/tests/test_additional.py +30 -22
- {concoursetools-0.8.1 → concoursetools-0.9.0}/tests/test_cli_commands.py +4 -3
- {concoursetools-0.8.1 → concoursetools-0.9.0}/tests/test_cli_parsing.py +1 -1
- {concoursetools-0.8.1 → concoursetools-0.9.0}/tests/test_examples.py +24 -39
- {concoursetools-0.8.1 → concoursetools-0.9.0}/tests/test_metadata.py +65 -0
- {concoursetools-0.8.1 → concoursetools-0.9.0}/tests/test_resource.py +1 -1
- {concoursetools-0.8.1 → concoursetools-0.9.0}/tests/test_version.py +1 -1
- {concoursetools-0.8.1 → concoursetools-0.9.0}/LICENSE.md +0 -0
- {concoursetools-0.8.1 → concoursetools-0.9.0}/concoursetools/__main__.py +0 -0
- {concoursetools-0.8.1 → concoursetools-0.9.0}/concoursetools/cli/__init__.py +0 -0
- {concoursetools-0.8.1 → concoursetools-0.9.0}/concoursetools/cli/docstring.py +0 -0
- {concoursetools-0.8.1 → concoursetools-0.9.0}/concoursetools/colour.py +0 -0
- {concoursetools-0.8.1 → concoursetools-0.9.0}/concoursetools/dockertools.py +0 -0
- {concoursetools-0.8.1 → concoursetools-0.9.0}/concoursetools/py.typed +0 -0
- {concoursetools-0.8.1 → concoursetools-0.9.0}/concoursetools.egg-info/SOURCES.txt +0 -0
- {concoursetools-0.8.1 → concoursetools-0.9.0}/concoursetools.egg-info/dependency_links.txt +0 -0
- {concoursetools-0.8.1 → concoursetools-0.9.0}/concoursetools.egg-info/top_level.txt +0 -0
- {concoursetools-0.8.1 → concoursetools-0.9.0}/setup.cfg +0 -0
- {concoursetools-0.8.1 → concoursetools-0.9.0}/setup.py +0 -0
- {concoursetools-0.8.1 → concoursetools-0.9.0}/tests/test_dockertools.py +0 -0
- {concoursetools-0.8.1 → concoursetools-0.9.0}/tests/test_importing.py +0 -0
- {concoursetools-0.8.1 → concoursetools-0.9.0}/tests/test_parsing.py +0 -0
- {concoursetools-0.8.1 → concoursetools-0.9.0}/tests/test_testing.py +0 -0
|
@@ -1,27 +1,26 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: concoursetools
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.9.0
|
|
4
4
|
Summary: Easily create Concourse resource types in Python.
|
|
5
5
|
Author-email: GCHQ <oss@gchq.gov.uk>
|
|
6
|
-
License: Apache
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
7
|
Project-URL: Homepage, https://github.com/gchq/ConcourseTools/
|
|
8
8
|
Project-URL: Documentation, https://concoursetools.readthedocs.io/en/stable/
|
|
9
9
|
Project-URL: Repository, https://github.com/gchq/ConcourseTools/
|
|
10
10
|
Project-URL: Bug Tracker, https://github.com/gchq/ConcourseTools/issues
|
|
11
|
-
Project-URL: Changelog, https://concoursetools.readthedocs.io/en/
|
|
11
|
+
Project-URL: Changelog, https://concoursetools.readthedocs.io/en/stable/changelog.html
|
|
12
12
|
Keywords: concourse,ci,cd
|
|
13
13
|
Classifier: Development Status :: 4 - Beta
|
|
14
14
|
Classifier: Intended Audience :: Developers
|
|
15
|
-
Classifier: License :: OSI Approved :: Apache Software License
|
|
16
15
|
Classifier: Natural Language :: English
|
|
17
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
18
16
|
Classifier: Programming Language :: Python :: 3.11
|
|
19
17
|
Classifier: Programming Language :: Python :: 3.12
|
|
20
18
|
Classifier: Programming Language :: Python :: 3.13
|
|
21
19
|
Classifier: Programming Language :: Python :: 3.14
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
22
21
|
Classifier: Topic :: Software Development
|
|
23
22
|
Classifier: Typing :: Typed
|
|
24
|
-
Requires-Python: >=3.
|
|
23
|
+
Requires-Python: >=3.11
|
|
25
24
|
Description-Content-Type: text/markdown
|
|
26
25
|
License-File: LICENSE.md
|
|
27
26
|
Dynamic: license-file
|
|
@@ -32,7 +31,7 @@ Dynamic: license-file
|
|
|
32
31
|
<img alt="ConcourseTools logo" src="https://raw.githubusercontent.com/gchq/ConcourseTools/main/docs/source/_static/logo.png">
|
|
33
32
|
</picture>
|
|
34
33
|
|
|
35
|
-

|
|
36
35
|

|
|
37
36
|

|
|
38
37
|

|
|
@@ -128,6 +127,10 @@ For more information - and for more in-depth examples - see the [documentation](
|
|
|
128
127
|
|
|
129
128
|
## Bugs and Contributions
|
|
130
129
|
|
|
131
|
-
|
|
130
|
+
> [!IMPORTANT]
|
|
131
|
+
> GCHQ is pausing contributions from those outside of the organisation who are not approved collaborators.
|
|
132
|
+
> Please consider [filing an issue](https://github.com/gchq/ConcourseTools/issues) instead.
|
|
133
|
+
|
|
134
|
+
Concourse Tools is in beta, and still under somewhat-active development. Suggestions and bug
|
|
132
135
|
reports are all welcome: Please familiarise yourself with our
|
|
133
136
|
[contribution guidelines](https://github.com/gchq/ConcourseTools/blob/main/CONTRIBUTING.md).
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
<img alt="ConcourseTools logo" src="https://raw.githubusercontent.com/gchq/ConcourseTools/main/docs/source/_static/logo.png">
|
|
5
5
|
</picture>
|
|
6
6
|
|
|
7
|
-

|
|
8
8
|

|
|
9
9
|

|
|
10
10
|

|
|
@@ -100,6 +100,10 @@ For more information - and for more in-depth examples - see the [documentation](
|
|
|
100
100
|
|
|
101
101
|
## Bugs and Contributions
|
|
102
102
|
|
|
103
|
-
|
|
103
|
+
> [!IMPORTANT]
|
|
104
|
+
> GCHQ is pausing contributions from those outside of the organisation who are not approved collaborators.
|
|
105
|
+
> Please consider [filing an issue](https://github.com/gchq/ConcourseTools/issues) instead.
|
|
106
|
+
|
|
107
|
+
Concourse Tools is in beta, and still under somewhat-active development. Suggestions and bug
|
|
104
108
|
reports are all welcome: Please familiarise yourself with our
|
|
105
109
|
[contribution guidelines](https://github.com/gchq/ConcourseTools/blob/main/CONTRIBUTING.md).
|
|
@@ -64,8 +64,8 @@ class InOnlyConcourseResource(ConcourseResource[DatetimeVersion]):
|
|
|
64
64
|
:meth:`~concoursetools.resource.ConcourseResource.download_version`.
|
|
65
65
|
|
|
66
66
|
The correct use case of this resource is to execute a
|
|
67
|
-
:concourse:`
|
|
68
|
-
in the :concourse:`
|
|
67
|
+
:concourse:`steps.put`, and then place parameters
|
|
68
|
+
in the :concourse:`steps.put#get_params` section:
|
|
69
69
|
|
|
70
70
|
.. code:: yaml
|
|
71
71
|
|
|
@@ -286,7 +286,7 @@ class MultiVersionConcourseResource(TriggerOnChangeConcourseResource[MultiVersio
|
|
|
286
286
|
|
|
287
287
|
.. tip::
|
|
288
288
|
This resource class is best suited to resources used in conjunction
|
|
289
|
-
with the :concourse:`
|
|
289
|
+
with the :concourse:`steps.set_pipeline` step.
|
|
290
290
|
"""
|
|
291
291
|
def __init__(self, key: str, sub_version_class: type[SortableVersionT]):
|
|
292
292
|
self.key = key
|
|
@@ -17,10 +17,11 @@ from concoursetools.resource import ConcourseResource
|
|
|
17
17
|
cli = CLI()
|
|
18
18
|
|
|
19
19
|
DEFAULT_PYTHON_VERSION = f"{sys.version_info.major}.{sys.version_info.minor}"
|
|
20
|
+
DEFAULT_RESOURCE_FILE = "concourse.py"
|
|
20
21
|
|
|
21
22
|
|
|
22
23
|
@cli.register(allow_short={"executable", "class_name", "resource_file"})
|
|
23
|
-
def assets(path: str, /, *, executable: str | None = None, resource_file: str =
|
|
24
|
+
def assets(path: str, /, *, executable: str | None = None, resource_file: str = DEFAULT_RESOURCE_FILE,
|
|
24
25
|
class_name: str | None = None) -> None:
|
|
25
26
|
"""
|
|
26
27
|
Create the assets script directory.
|
|
@@ -49,7 +50,7 @@ def assets(path: str, /, *, executable: str | None = None, resource_file: str =
|
|
|
49
50
|
|
|
50
51
|
@cli.register(allow_short={"executable", "class_name", "resource_file"})
|
|
51
52
|
def dockerfile(path: str, /, *, executable: str | None = None, image: str = "python", tag: str | None = None,
|
|
52
|
-
suffix: str | None = None, resource_file: str =
|
|
53
|
+
suffix: str | None = None, resource_file: str = DEFAULT_RESOURCE_FILE, class_name: str | None = None,
|
|
53
54
|
pip_args: str | None = None, include_rsa: bool = False, include_netrc: bool = False,
|
|
54
55
|
encoding: str | None = None, no_venv: bool = False, dev: bool = False) -> None:
|
|
55
56
|
"""
|
|
@@ -182,7 +183,7 @@ def dockerfile(path: str, /, *, executable: str | None = None, image: str = "pyt
|
|
|
182
183
|
|
|
183
184
|
|
|
184
185
|
@cli.register(allow_short={"executable", "class_name", "resource_file"})
|
|
185
|
-
def legacy(path: str, /, *, executable: str | None = None, resource_file: str =
|
|
186
|
+
def legacy(path: str, /, *, executable: str | None = None, resource_file: str = DEFAULT_RESOURCE_FILE,
|
|
186
187
|
class_name: str | None = None, docker: bool = False, include_rsa: bool = False) -> None:
|
|
187
188
|
"""
|
|
188
189
|
Invoke the legacy CLI.
|
|
@@ -355,7 +355,7 @@ class Parameter(ABC, Generic[T]):
|
|
|
355
355
|
|
|
356
356
|
@property
|
|
357
357
|
@abstractmethod
|
|
358
|
-
def aliases(self) ->
|
|
358
|
+
def aliases(self) -> list[str]:
|
|
359
359
|
"""The aliases for the option."""
|
|
360
360
|
...
|
|
361
361
|
|
|
@@ -410,9 +410,9 @@ class PositionalArgument(Parameter[T]):
|
|
|
410
410
|
:param description: An optional description of the argument.
|
|
411
411
|
"""
|
|
412
412
|
@property
|
|
413
|
-
def aliases(self) ->
|
|
413
|
+
def aliases(self) -> list[str]:
|
|
414
414
|
"""The aliases for the option."""
|
|
415
|
-
return
|
|
415
|
+
return [self.name]
|
|
416
416
|
|
|
417
417
|
def add_to_parser(self, parser: ArgumentParser) -> None:
|
|
418
418
|
parser.add_argument(*self.aliases, type=self.param_type, help=self.description)
|
|
@@ -433,10 +433,10 @@ class Option(Parameter[T]):
|
|
|
433
433
|
allow_short: bool = False
|
|
434
434
|
|
|
435
435
|
@property
|
|
436
|
-
def aliases(self) ->
|
|
436
|
+
def aliases(self) -> list[str]:
|
|
437
437
|
if self.allow_short:
|
|
438
|
-
return
|
|
439
|
-
return
|
|
438
|
+
return [self.short_alias, self.long_alias]
|
|
439
|
+
return [self.long_alias]
|
|
440
440
|
|
|
441
441
|
def add_to_parser(self, parser: ArgumentParser) -> None:
|
|
442
442
|
parser.add_argument(*self.aliases, type=self.param_type, default=self.default, help=self.description)
|
|
@@ -57,17 +57,16 @@ def import_classes_from_module(file_path: Path, parent_class: type[T]) -> dict[s
|
|
|
57
57
|
import_path = file_path_to_import_path(file_path)
|
|
58
58
|
module = import_py_file(import_path, file_path)
|
|
59
59
|
|
|
60
|
-
possible_resource_classes = {}
|
|
60
|
+
possible_resource_classes: dict[str, type[T]] = {}
|
|
61
61
|
for _, cls in inspect.getmembers(module, predicate=inspect.isclass):
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
class_is_subclass_of_parent = False
|
|
62
|
+
|
|
63
|
+
if not issubclass(cls, parent_class):
|
|
64
|
+
continue
|
|
66
65
|
|
|
67
66
|
class_is_defined_in_this_module = (cls.__module__ == import_path)
|
|
68
67
|
class_is_not_private = (not cls.__name__.startswith("_"))
|
|
69
68
|
|
|
70
|
-
if
|
|
69
|
+
if class_is_defined_in_this_module and class_is_not_private:
|
|
71
70
|
possible_resource_classes[cls.__name__] = cls
|
|
72
71
|
|
|
73
72
|
return possible_resource_classes
|
|
@@ -10,7 +10,8 @@ The :meth:`~concoursetools.resource.ConcourseResource.download_version` and
|
|
|
10
10
|
Build metadata is deliberately not passed to :meth:`~concoursetools.resource.ConcourseResource.fetch_new_versions`,
|
|
11
11
|
as none of this metadata is passed to the check environment by Concourse, to avoid antipatterns.
|
|
12
12
|
|
|
13
|
-
See the Concourse :concourse:`
|
|
13
|
+
See the Concourse :concourse:`resource types metadata <resource_types.implementing#build-metadata>` documentation
|
|
14
|
+
for more information.
|
|
14
15
|
"""
|
|
15
16
|
from __future__ import annotations
|
|
16
17
|
|
|
@@ -32,8 +33,9 @@ class BuildMetadata: # pylint: disable=invalid-name
|
|
|
32
33
|
:param BUILD_NAME: The build number within the build's job.
|
|
33
34
|
:param BUILD_JOB_NAME: The name of the build's job.
|
|
34
35
|
:param BUILD_PIPELINE_NAME: The name of the pipeline that the build's job lives in.
|
|
35
|
-
:param BUILD_PIPELINE_INSTANCE_VARS: The instance vars of the :concourse:`instanced pipeline
|
|
36
|
-
that the build's
|
|
36
|
+
:param BUILD_PIPELINE_INSTANCE_VARS: The instance vars of the :concourse:`instanced pipeline
|
|
37
|
+
<pipelines.grouping-pipelines#managing-instanced-pipelines>` that the build's
|
|
38
|
+
job lives in, serialized as JSON.
|
|
37
39
|
|
|
38
40
|
.. note::
|
|
39
41
|
A few variables are often present in the build environment, but are **not** documented by Concourse:
|
|
@@ -66,14 +68,14 @@ class BuildMetadata: # pylint: disable=invalid-name
|
|
|
66
68
|
|
|
67
69
|
.. warning::
|
|
68
70
|
By default this information is **not** available. To enable it, you need to set
|
|
69
|
-
:concourse:`resources
|
|
71
|
+
:concourse:`resources#expose_build_created_by` in your resource schema.
|
|
70
72
|
"""
|
|
71
73
|
try:
|
|
72
74
|
return os.environ["BUILD_CREATED_BY"]
|
|
73
75
|
except KeyError as error:
|
|
74
76
|
raise PermissionError("The 'BUILD_CREATED_BY' variable has not been made available. This must be enabled "
|
|
75
77
|
"with the 'expose_build_created_by' variable within the resource schema: "
|
|
76
|
-
"https://concourse-ci.org/resources
|
|
78
|
+
"https://concourse-ci.org/docs/resources/#expose_build_created_by") from error
|
|
77
79
|
|
|
78
80
|
@property
|
|
79
81
|
def is_one_off_build(self) -> bool:
|
|
@@ -81,7 +83,7 @@ class BuildMetadata: # pylint: disable=invalid-name
|
|
|
81
83
|
Return :data:`True` if this build is one-off, and :data:`False` otherwise.
|
|
82
84
|
|
|
83
85
|
A build is a "one-off" is it is triggered via the Concourse CLI
|
|
84
|
-
:concourse:`execute command <tasks
|
|
86
|
+
:concourse:`execute command <tasks#running-tasks-with-fly-execute>`.
|
|
85
87
|
It is determined by the absence of all of the following attributes:
|
|
86
88
|
|
|
87
89
|
* ``BUILD_JOB_NAME``
|
|
@@ -96,14 +98,15 @@ class BuildMetadata: # pylint: disable=invalid-name
|
|
|
96
98
|
|
|
97
99
|
@property
|
|
98
100
|
def is_instanced_pipeline(self) -> bool:
|
|
99
|
-
"""Return :data:`True` if this is an :concourse:`instanced pipeline <instanced-pipelines>`."""
|
|
101
|
+
"""Return :data:`True` if this is an :concourse:`instanced pipeline <pipelines.grouping-pipelines#managing-instanced-pipelines>`."""
|
|
100
102
|
return self.BUILD_PIPELINE_INSTANCE_VARS is not None
|
|
101
103
|
|
|
102
104
|
def instance_vars(self) -> dict[str, object]:
|
|
103
105
|
"""
|
|
104
106
|
Return the instance vars set on this pipeline as a mapping.
|
|
105
107
|
|
|
106
|
-
When working with an :concourse:`instanced pipeline
|
|
108
|
+
When working with an :concourse:`instanced pipeline
|
|
109
|
+
<pipelines.grouping-pipelines#managing-instanced-pipelines>`, it is much more convenient to
|
|
107
110
|
work with the instance vars as a mapping instead of a JSON string.
|
|
108
111
|
|
|
109
112
|
.. note::
|
|
@@ -113,7 +116,7 @@ class BuildMetadata: # pylint: disable=invalid-name
|
|
|
113
116
|
:Example:
|
|
114
117
|
|
|
115
118
|
If a instanced pipeline has been created from within another pipeline
|
|
116
|
-
(using the :concourse:`
|
|
119
|
+
(using the :concourse:`steps.set_pipeline` step), such as this:
|
|
117
120
|
|
|
118
121
|
.. code:: yaml
|
|
119
122
|
|
|
@@ -169,7 +172,7 @@ class BuildMetadata: # pylint: disable=invalid-name
|
|
|
169
172
|
Format a string with metadata using standard bash ``$`` notation.
|
|
170
173
|
|
|
171
174
|
Only a handful of "safe" values will be interpolated, not arbitrary attributes on the instance.
|
|
172
|
-
These are the :concourse:`original environment variables <implementing-
|
|
175
|
+
These are the :concourse:`original environment variables <resource_types.implementing#build-metadata>`,
|
|
173
176
|
including :attr:`BUILD_CREATED_BY` if it exists. object missing environment variable (such as in the case of a
|
|
174
177
|
one-off build) will be empty. A ``$BUILD_URL`` variable is also added for ease.
|
|
175
178
|
|
|
@@ -210,7 +213,7 @@ class BuildMetadata: # pylint: disable=invalid-name
|
|
|
210
213
|
possible_values.update(additional_values)
|
|
211
214
|
|
|
212
215
|
try:
|
|
213
|
-
possible_values["
|
|
216
|
+
possible_values["BUILD_CREATED_BY"] = self.BUILD_CREATED_BY
|
|
214
217
|
except PermissionError:
|
|
215
218
|
pass
|
|
216
219
|
|
|
@@ -79,11 +79,26 @@ class TestBuildMetadata(BuildMetadata):
|
|
|
79
79
|
|
|
80
80
|
:param one_off_build: Set to :data:`True` if you are testing a one-off build.
|
|
81
81
|
:param instance_vars: Pass optional instance vars to emulate an instanced pipeline.
|
|
82
|
+
:param build_created_by: Pass to enable the
|
|
83
|
+
:attr:`~concoursetools.metadata.BuildMetadata.BUILD_CREATED_BY` property.
|
|
82
84
|
:param env_vars: Pass additional environment variables, or overload the default ones.
|
|
85
|
+
|
|
86
|
+
.. version-changed:: 0.9.0
|
|
87
|
+
Added support for the ``build_created_by`` parameter.
|
|
83
88
|
"""
|
|
84
|
-
def __init__(self, one_off_build: bool = False, instance_vars: dict[str, str] | None = None,
|
|
89
|
+
def __init__(self, one_off_build: bool = False, instance_vars: dict[str, str] | None = None,
|
|
90
|
+
build_created_by: str | None = None, **env_vars: str):
|
|
85
91
|
test_env_vars = create_env_vars(one_off_build, instance_vars, **env_vars)
|
|
86
92
|
super().__init__(**test_env_vars)
|
|
93
|
+
self._build_created_by = build_created_by
|
|
94
|
+
|
|
95
|
+
@property
|
|
96
|
+
def BUILD_CREATED_BY(self) -> str:
|
|
97
|
+
if self._build_created_by is None:
|
|
98
|
+
raise PermissionError("The 'BUILD_CREATED_BY' variable has not been made available. This must be enabled "
|
|
99
|
+
"with the 'expose_build_created_by' variable within the resource schema: "
|
|
100
|
+
"https://concourse-ci.org/docs/resources/#expose_build_created_by")
|
|
101
|
+
return self._build_created_by
|
|
87
102
|
|
|
88
103
|
|
|
89
104
|
class TemporaryDirectoryState:
|
|
@@ -13,7 +13,7 @@ from concoursetools.typing import Metadata, MetadataPair, Params, ResourceConfig
|
|
|
13
13
|
|
|
14
14
|
def parse_check_payload(raw_json: str) -> tuple[ResourceConfig, VersionConfig | None]:
|
|
15
15
|
"""
|
|
16
|
-
Parse raw input JSON for a :concourse:`check payload <
|
|
16
|
+
Parse raw input JSON for a :concourse:`check payload <resource-types.implementing#check-check-for-new-versions>`.
|
|
17
17
|
|
|
18
18
|
:param raw_json: A JSON string of the following form:
|
|
19
19
|
|
|
@@ -46,7 +46,7 @@ def parse_check_payload(raw_json: str) -> tuple[ResourceConfig, VersionConfig |
|
|
|
46
46
|
|
|
47
47
|
def parse_in_payload(raw_json: str) -> tuple[ResourceConfig, VersionConfig, Params]:
|
|
48
48
|
"""
|
|
49
|
-
Parse raw input JSON for an :concourse:`in payload <
|
|
49
|
+
Parse raw input JSON for an :concourse:`in payload <resource-types.implementing#in-fetch-a-given-resource>`.
|
|
50
50
|
|
|
51
51
|
:param raw_json: A JSON string of the following form:
|
|
52
52
|
|
|
@@ -78,7 +78,7 @@ def parse_in_payload(raw_json: str) -> tuple[ResourceConfig, VersionConfig, Para
|
|
|
78
78
|
|
|
79
79
|
def parse_out_payload(raw_json: str) -> tuple[ResourceConfig, Params]:
|
|
80
80
|
"""
|
|
81
|
-
Parse raw input JSON for an :concourse:`out payload <
|
|
81
|
+
Parse raw input JSON for an :concourse:`out payload <resource-types.implementing#out-update-a-resource>`.
|
|
82
82
|
|
|
83
83
|
:param raw_json: A JSON string of the following form:
|
|
84
84
|
|
|
@@ -116,7 +116,7 @@ def parse_metadata(metadata_pairs: list[MetadataPair]) -> Metadata:
|
|
|
116
116
|
|
|
117
117
|
def format_check_output(version_configs: list[VersionConfig], **json_kwargs: Any) -> str:
|
|
118
118
|
"""
|
|
119
|
-
Format :concourse:`check output <
|
|
119
|
+
Format :concourse:`check output <resource-types.implementing#check-check-for-new-versions>` as a JSON string.
|
|
120
120
|
|
|
121
121
|
:param version_configs: A list of version configurations.
|
|
122
122
|
:param json_kwargs: Additional keyword arguments to pass to :func:`json.dumps`.
|
|
@@ -136,8 +136,8 @@ def format_check_output(version_configs: list[VersionConfig], **json_kwargs: Any
|
|
|
136
136
|
|
|
137
137
|
def format_in_out_output(version_config: VersionConfig, metadata: Metadata, **json_kwargs: Any) -> str:
|
|
138
138
|
"""
|
|
139
|
-
Format :concourse:`in output <
|
|
140
|
-
:concourse:`out output <
|
|
139
|
+
Format :concourse:`in output <resource-types.implementing#in-fetch-a-given-resource>` or
|
|
140
|
+
:concourse:`out output <resource-types.implementing#out-update-a-resource>` as a JSON string.
|
|
141
141
|
|
|
142
142
|
:param version_config: A version configuration.
|
|
143
143
|
:param metadata: A key-value mapping of metadata.
|
|
@@ -175,7 +175,7 @@ def format_metadata(metadata: Metadata) -> list[MetadataPair]:
|
|
|
175
175
|
|
|
176
176
|
def format_check_input(resource_config: ResourceConfig, version_config: VersionConfig | None = None, **json_kwargs: Any) -> str:
|
|
177
177
|
"""
|
|
178
|
-
Format :concourse:`check input <
|
|
178
|
+
Format :concourse:`check input <resource-types.implementing#check-check-for-new-versions>` as a JSON string.
|
|
179
179
|
|
|
180
180
|
:param resource_config: A resource configuration.
|
|
181
181
|
:param version_config: A version configuration, or :data:`None` if no version currently exists.
|
|
@@ -201,7 +201,7 @@ def format_check_input(resource_config: ResourceConfig, version_config: VersionC
|
|
|
201
201
|
|
|
202
202
|
def format_in_input(resource_config: ResourceConfig, version_config: VersionConfig, params: Params | None = None, **json_kwargs: Any) -> str:
|
|
203
203
|
"""
|
|
204
|
-
Format :concourse:`in input <
|
|
204
|
+
Format :concourse:`in input <resource-types.implementing#in-fetch-a-given-resource>` as a JSON string.
|
|
205
205
|
|
|
206
206
|
:param resource_config: A resource configuration.
|
|
207
207
|
:param version_config: A version configuration.
|
|
@@ -232,7 +232,7 @@ def format_in_input(resource_config: ResourceConfig, version_config: VersionConf
|
|
|
232
232
|
|
|
233
233
|
def format_out_input(resource_config: ResourceConfig, params: Params | None = None, **json_kwargs: Any) -> str:
|
|
234
234
|
"""
|
|
235
|
-
Format :concourse:`out input <
|
|
235
|
+
Format :concourse:`out input <resource-types.implementing#out-update-a-resource>` as a JSON string.
|
|
236
236
|
|
|
237
237
|
:param resource_config: A resource configuration.
|
|
238
238
|
:param params: Optional parameters to be passed.
|
|
@@ -7,12 +7,12 @@ Each resource represents a versioned artifact with an external source of truth.
|
|
|
7
7
|
Configuring the same resource in any pipeline on any Concourse cluster will
|
|
8
8
|
behave the exact same way. Concourse will continuously check each configured
|
|
9
9
|
resource to discover new versions. These versions then flow through the pipeline
|
|
10
|
-
via :concourse:`get steps <
|
|
10
|
+
via :concourse:`get steps <steps.get>` configured on jobs.
|
|
11
11
|
|
|
12
12
|
Find out more about resources in the :concourse:`Concourse resource documentation <resources>`.
|
|
13
13
|
|
|
14
14
|
To learn more about how Concourse resource types are actually implemented under the hood,
|
|
15
|
-
check out :concourse:`implementing
|
|
15
|
+
check out :concourse:`implementing resource types <resource-types.implementing>` in Concourse.
|
|
16
16
|
"""
|
|
17
17
|
from __future__ import annotations
|
|
18
18
|
|
|
@@ -32,7 +32,7 @@ class ConcourseResource(ABC, Generic[VersionT]):
|
|
|
32
32
|
"""
|
|
33
33
|
Represents an external input or output to a pipeline.
|
|
34
34
|
|
|
35
|
-
The :concourse:`resource-types
|
|
35
|
+
The :concourse:`resource-types#source`
|
|
36
36
|
defined in a Concourse :concourse:`pipeline <pipelines>` is
|
|
37
37
|
parsed into JSON by Concourse, and will be passed to the initialiser
|
|
38
38
|
of the :class:`ConcourseResource` class.
|
|
@@ -94,7 +94,7 @@ class ConcourseResource(ABC, Generic[VersionT]):
|
|
|
94
94
|
|
|
95
95
|
This folder may not always exist, depending on how the Concourse runner was configured.
|
|
96
96
|
|
|
97
|
-
See the :concourse:`
|
|
97
|
+
See the :concourse:`resource-types.implementing#certificate-propagation` documentation for more information.
|
|
98
98
|
"""
|
|
99
99
|
return Path("/etc/ssl/certs")
|
|
100
100
|
|
|
@@ -395,13 +395,13 @@ class FileTestResourceWrapper(TestResourceWrapper[Version]):
|
|
|
395
395
|
This is best to use if your resource uses external scripts for any of the steps.
|
|
396
396
|
|
|
397
397
|
:param inner_resource_config: The JSON configuration for the resource.
|
|
398
|
-
:param check_script: The path to the external script for the :concourse:`check <
|
|
398
|
+
:param check_script: The path to the external script for the :concourse:`check <resource-types.implementing#check-check-for-new-versions>`.
|
|
399
399
|
Setting to :data:`None` (default) means that :meth:`fetch_new_versions`
|
|
400
400
|
raises :class:`NotImplementedError`.
|
|
401
|
-
:param in_script: The path to the external script for the :concourse:`check <
|
|
401
|
+
:param in_script: The path to the external script for the :concourse:`check <resource-types.implementing#in-fetch-a-given-resource>`.
|
|
402
402
|
Setting to :data:`None` (default) means that :meth:`download_version`
|
|
403
403
|
raises :class:`NotImplementedError`.
|
|
404
|
-
:param out_script: The path to the external script for the :concourse:`check <
|
|
404
|
+
:param out_script: The path to the external script for the :concourse:`check <resource-types.implementing#out-update-a-resource>`.
|
|
405
405
|
Setting to :data:`None` (default) means that :meth:`publish_new_version`
|
|
406
406
|
raises :class:`NotImplementedError`.
|
|
407
407
|
:param directory_dict: The initial state of the resource directory. See :class:`~concoursetools.mocking.TemporaryDirectoryState`
|
|
@@ -18,13 +18,13 @@ T = TypeVar("T")
|
|
|
18
18
|
ResourceConfig = dict[str, Any]
|
|
19
19
|
"""
|
|
20
20
|
Represents arbitrary configuration passed to a Concourse resource.
|
|
21
|
-
See the :concourse:`config-basics
|
|
21
|
+
See the :concourse:`config-basics#config-schema` for more information.
|
|
22
22
|
"""
|
|
23
23
|
|
|
24
24
|
Params = dict[str, Any]
|
|
25
25
|
"""
|
|
26
26
|
Represents arbitrary parameters passed to a Concourse resource.
|
|
27
|
-
See the :concourse:`config-basics
|
|
27
|
+
See the :concourse:`config-basics#config-schema` for more information.
|
|
28
28
|
"""
|
|
29
29
|
|
|
30
30
|
Metadata = dict[str, str]
|
|
@@ -48,7 +48,7 @@ class MetadataPair(TypedDict):
|
|
|
48
48
|
VersionConfig = dict[str, str]
|
|
49
49
|
"""
|
|
50
50
|
Represents a version of a Concourse resource.
|
|
51
|
-
See the :concourse:`config-basics
|
|
51
|
+
See the :concourse:`config-basics#version-schema` for more information.
|
|
52
52
|
"""
|
|
53
53
|
|
|
54
54
|
VersionT = TypeVar("VersionT", bound="VersionProtocol")
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
A resource version represents the exact state of a resource at a given point in time. The resource is responsible for
|
|
4
4
|
defining what a version *actually is*, and this is defined with Concourse Tools using a :class:`Version` subclass.
|
|
5
5
|
|
|
6
|
-
More information on versions can be found in the :concourse:`Concourse documentation <resource-versions>`.
|
|
6
|
+
More information on versions can be found in the :concourse:`Concourse documentation <resources.resource-versions>`.
|
|
7
7
|
"""
|
|
8
8
|
from __future__ import annotations
|
|
9
9
|
|
|
@@ -1,27 +1,26 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: concoursetools
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.9.0
|
|
4
4
|
Summary: Easily create Concourse resource types in Python.
|
|
5
5
|
Author-email: GCHQ <oss@gchq.gov.uk>
|
|
6
|
-
License: Apache
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
7
|
Project-URL: Homepage, https://github.com/gchq/ConcourseTools/
|
|
8
8
|
Project-URL: Documentation, https://concoursetools.readthedocs.io/en/stable/
|
|
9
9
|
Project-URL: Repository, https://github.com/gchq/ConcourseTools/
|
|
10
10
|
Project-URL: Bug Tracker, https://github.com/gchq/ConcourseTools/issues
|
|
11
|
-
Project-URL: Changelog, https://concoursetools.readthedocs.io/en/
|
|
11
|
+
Project-URL: Changelog, https://concoursetools.readthedocs.io/en/stable/changelog.html
|
|
12
12
|
Keywords: concourse,ci,cd
|
|
13
13
|
Classifier: Development Status :: 4 - Beta
|
|
14
14
|
Classifier: Intended Audience :: Developers
|
|
15
|
-
Classifier: License :: OSI Approved :: Apache Software License
|
|
16
15
|
Classifier: Natural Language :: English
|
|
17
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
18
16
|
Classifier: Programming Language :: Python :: 3.11
|
|
19
17
|
Classifier: Programming Language :: Python :: 3.12
|
|
20
18
|
Classifier: Programming Language :: Python :: 3.13
|
|
21
19
|
Classifier: Programming Language :: Python :: 3.14
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
22
21
|
Classifier: Topic :: Software Development
|
|
23
22
|
Classifier: Typing :: Typed
|
|
24
|
-
Requires-Python: >=3.
|
|
23
|
+
Requires-Python: >=3.11
|
|
25
24
|
Description-Content-Type: text/markdown
|
|
26
25
|
License-File: LICENSE.md
|
|
27
26
|
Dynamic: license-file
|
|
@@ -32,7 +31,7 @@ Dynamic: license-file
|
|
|
32
31
|
<img alt="ConcourseTools logo" src="https://raw.githubusercontent.com/gchq/ConcourseTools/main/docs/source/_static/logo.png">
|
|
33
32
|
</picture>
|
|
34
33
|
|
|
35
|
-

|
|
36
35
|

|
|
37
36
|

|
|
38
37
|

|
|
@@ -128,6 +127,10 @@ For more information - and for more in-depth examples - see the [documentation](
|
|
|
128
127
|
|
|
129
128
|
## Bugs and Contributions
|
|
130
129
|
|
|
131
|
-
|
|
130
|
+
> [!IMPORTANT]
|
|
131
|
+
> GCHQ is pausing contributions from those outside of the organisation who are not approved collaborators.
|
|
132
|
+
> Please consider [filing an issue](https://github.com/gchq/ConcourseTools/issues) instead.
|
|
133
|
+
|
|
134
|
+
Concourse Tools is in beta, and still under somewhat-active development. Suggestions and bug
|
|
132
135
|
reports are all welcome: Please familiarise yourself with our
|
|
133
136
|
[contribution guidelines](https://github.com/gchq/ConcourseTools/blob/main/CONTRIBUTING.md).
|
|
@@ -7,7 +7,7 @@ name = "concoursetools"
|
|
|
7
7
|
dynamic = ["version"]
|
|
8
8
|
description = "Easily create Concourse resource types in Python."
|
|
9
9
|
readme = "README.md"
|
|
10
|
-
requires-python = ">=3.
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
11
|
keywords = [
|
|
12
12
|
"concourse",
|
|
13
13
|
"ci",
|
|
@@ -16,27 +16,26 @@ keywords = [
|
|
|
16
16
|
classifiers = [
|
|
17
17
|
"Development Status :: 4 - Beta",
|
|
18
18
|
"Intended Audience :: Developers",
|
|
19
|
-
"License :: OSI Approved :: Apache Software License",
|
|
20
19
|
"Natural Language :: English",
|
|
21
|
-
"Programming Language :: Python :: 3.10",
|
|
22
20
|
"Programming Language :: Python :: 3.11",
|
|
23
21
|
"Programming Language :: Python :: 3.12",
|
|
24
22
|
"Programming Language :: Python :: 3.13",
|
|
25
23
|
"Programming Language :: Python :: 3.14",
|
|
24
|
+
"Programming Language :: Python :: 3.15",
|
|
26
25
|
"Topic :: Software Development",
|
|
27
26
|
"Typing :: Typed",
|
|
28
27
|
]
|
|
29
28
|
authors = [
|
|
30
29
|
{name = "GCHQ", email = "oss@gchq.gov.uk"},
|
|
31
30
|
]
|
|
32
|
-
license =
|
|
31
|
+
license = "Apache-2.0"
|
|
33
32
|
|
|
34
33
|
[project.urls]
|
|
35
34
|
"Homepage" = "https://github.com/gchq/ConcourseTools/"
|
|
36
35
|
"Documentation" = "https://concoursetools.readthedocs.io/en/stable/"
|
|
37
36
|
"Repository" = "https://github.com/gchq/ConcourseTools/"
|
|
38
37
|
"Bug Tracker" = "https://github.com/gchq/ConcourseTools/issues"
|
|
39
|
-
"Changelog" = "https://concoursetools.readthedocs.io/en/
|
|
38
|
+
"Changelog" = "https://concoursetools.readthedocs.io/en/stable/changelog.html"
|
|
40
39
|
|
|
41
40
|
[tool.setuptools]
|
|
42
41
|
packages = [
|
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
# (C) Crown Copyright GCHQ
|
|
2
2
|
from __future__ import annotations
|
|
3
3
|
|
|
4
|
-
from http.client import HTTPResponse
|
|
5
4
|
import json
|
|
6
5
|
from pathlib import Path
|
|
7
|
-
import ssl
|
|
8
|
-
from typing import cast
|
|
9
6
|
from unittest import TestCase
|
|
10
|
-
import urllib.request
|
|
11
7
|
|
|
12
8
|
from concoursetools import BuildMetadata, ConcourseResource
|
|
13
9
|
from concoursetools.additional import (DatetimeVersion, InOnlyConcourseResource, MultiVersionConcourseResource, OutOnlyConcourseResource,
|
|
@@ -203,24 +199,16 @@ class MultiVersionTests(TestCase):
|
|
|
203
199
|
self.assertDictEqual(directory_state.final_state, {"repos.json": expected_payload})
|
|
204
200
|
|
|
205
201
|
|
|
206
|
-
class
|
|
202
|
+
class FileDownloadResource(InOnlyConcourseResource):
|
|
207
203
|
|
|
208
|
-
def
|
|
209
|
-
|
|
210
|
-
|
|
204
|
+
def download_data(self, destination_dir: Path, build_metadata: BuildMetadata, name: str = "file.txt") -> Metadata:
|
|
205
|
+
file_path = destination_dir / name
|
|
206
|
+
file_path.write_text("Hello, world!")
|
|
211
207
|
|
|
212
|
-
|
|
213
|
-
image_path = destination_dir / name
|
|
214
|
-
request = urllib.request.Request(url=self.image_url)
|
|
215
|
-
|
|
216
|
-
ssl_context = ssl._create_unverified_context()
|
|
217
|
-
with urllib.request.urlopen(request, context=ssl_context) as response:
|
|
218
|
-
response = cast(HTTPResponse, response)
|
|
219
|
-
with open(image_path, "wb") as wf:
|
|
220
|
-
wf.write(response.read())
|
|
208
|
+
print(f"Writing file {name!r} for job {build_metadata.BUILD_NAME}")
|
|
221
209
|
|
|
222
210
|
metadata = {
|
|
223
|
-
"HTTP Status":
|
|
211
|
+
"HTTP Status": "200",
|
|
224
212
|
}
|
|
225
213
|
return metadata
|
|
226
214
|
|
|
@@ -229,16 +217,36 @@ class InOnlyTests(TestCase):
|
|
|
229
217
|
"""
|
|
230
218
|
Tests for the InOnlyConcourseResource class.
|
|
231
219
|
"""
|
|
220
|
+
def test_check_versions(self) -> None:
|
|
221
|
+
resource = FileDownloadResource()
|
|
222
|
+
wrapper = SimpleTestResourceWrapper(resource)
|
|
223
|
+
self.assertListEqual(wrapper.fetch_new_versions(), [])
|
|
224
|
+
self.assertListEqual(wrapper.fetch_new_versions(DatetimeVersion.now()), [])
|
|
225
|
+
|
|
232
226
|
def test_data_download(self) -> None:
|
|
233
|
-
resource =
|
|
227
|
+
resource = FileDownloadResource()
|
|
234
228
|
wrapper = SimpleTestResourceWrapper(resource)
|
|
229
|
+
self.assertEqual(wrapper.mocked_build_metadata.BUILD_NAME, "42")
|
|
230
|
+
|
|
231
|
+
version, publish_metadata = wrapper.publish_new_version()
|
|
232
|
+
self.assertDictEqual(publish_metadata, {})
|
|
233
|
+
|
|
235
234
|
with wrapper.capture_debugging() as debugging:
|
|
236
235
|
with wrapper.capture_directory_state() as directory_state:
|
|
237
|
-
wrapper.download_version(
|
|
236
|
+
wrapper.download_version(version)
|
|
238
237
|
|
|
239
|
-
self.assertEqual(debugging, "")
|
|
238
|
+
self.assertEqual(debugging, "Writing file 'file.txt' for job 42\n")
|
|
239
|
+
self.assertDictEqual(directory_state.final_state, {
|
|
240
|
+
"file.txt": "Hello, world!",
|
|
241
|
+
})
|
|
242
|
+
|
|
243
|
+
with wrapper.capture_debugging() as debugging:
|
|
244
|
+
with wrapper.capture_directory_state() as directory_state:
|
|
245
|
+
wrapper.download_version(version, name="other.txt")
|
|
246
|
+
|
|
247
|
+
self.assertEqual(debugging, "Writing file 'other.txt' for job 42\n")
|
|
240
248
|
self.assertDictEqual(directory_state.final_state, {
|
|
241
|
-
"
|
|
249
|
+
"other.txt": "Hello, world!",
|
|
242
250
|
})
|
|
243
251
|
|
|
244
252
|
|
|
@@ -11,6 +11,7 @@ import unittest
|
|
|
11
11
|
import unittest.mock
|
|
12
12
|
|
|
13
13
|
from concoursetools.cli import cli
|
|
14
|
+
from concoursetools.cli.commands import DEFAULT_RESOURCE_FILE
|
|
14
15
|
from concoursetools.colour import Colour, colourise
|
|
15
16
|
|
|
16
17
|
|
|
@@ -26,7 +27,7 @@ class AssetTests(unittest.TestCase):
|
|
|
26
27
|
|
|
27
28
|
path_to_this_file = Path(__file__)
|
|
28
29
|
path_to_test_resource_module = path_to_this_file.parent / "resource.py"
|
|
29
|
-
shutil.copyfile(path_to_test_resource_module, self.temp_dir /
|
|
30
|
+
shutil.copyfile(path_to_test_resource_module, self.temp_dir / DEFAULT_RESOURCE_FILE)
|
|
30
31
|
os.chdir(self.temp_dir)
|
|
31
32
|
|
|
32
33
|
def tearDown(self) -> None:
|
|
@@ -60,7 +61,7 @@ class DockerfileTests(unittest.TestCase):
|
|
|
60
61
|
|
|
61
62
|
path_to_this_file = Path(__file__)
|
|
62
63
|
path_to_test_resource_module = path_to_this_file.parent / "resource.py"
|
|
63
|
-
shutil.copyfile(path_to_test_resource_module, self.temp_dir /
|
|
64
|
+
shutil.copyfile(path_to_test_resource_module, self.temp_dir / DEFAULT_RESOURCE_FILE)
|
|
64
65
|
self.dockerfile_path = self.temp_dir / "Dockerfile"
|
|
65
66
|
self.assertFalse(self.dockerfile_path.exists())
|
|
66
67
|
|
|
@@ -115,7 +116,7 @@ class LegacyTests(unittest.TestCase):
|
|
|
115
116
|
|
|
116
117
|
path_to_this_file = Path(__file__)
|
|
117
118
|
path_to_test_resource_module = path_to_this_file.parent / "resource.py"
|
|
118
|
-
shutil.copyfile(path_to_test_resource_module, self.temp_dir /
|
|
119
|
+
shutil.copyfile(path_to_test_resource_module, self.temp_dir / DEFAULT_RESOURCE_FILE)
|
|
119
120
|
self.dockerfile_path = self.temp_dir / "Dockerfile"
|
|
120
121
|
self.assertFalse(self.dockerfile_path.exists())
|
|
121
122
|
|
|
@@ -141,7 +141,7 @@ class HelpTests(unittest.TestCase):
|
|
|
141
141
|
|
|
142
142
|
""").lstrip())
|
|
143
143
|
|
|
144
|
-
def
|
|
144
|
+
def test_first_command_help(self) -> None:
|
|
145
145
|
with self._mock_terminal_width(120):
|
|
146
146
|
width, _ = shutil.get_terminal_size()
|
|
147
147
|
self.assertGreaterEqual(width, 120)
|
|
@@ -7,7 +7,7 @@ import json
|
|
|
7
7
|
import os
|
|
8
8
|
from pathlib import Path
|
|
9
9
|
from tempfile import TemporaryDirectory
|
|
10
|
-
from typing import
|
|
10
|
+
from typing import Any
|
|
11
11
|
import unittest
|
|
12
12
|
import unittest.mock
|
|
13
13
|
import urllib.parse
|
|
@@ -18,7 +18,9 @@ try:
|
|
|
18
18
|
import botocore # noqa: F401
|
|
19
19
|
from dateutil.tz import tzlocal
|
|
20
20
|
from moto import mock_aws
|
|
21
|
-
from moto.
|
|
21
|
+
from moto.core import DEFAULT_ACCOUNT_ID
|
|
22
|
+
from moto.sagemaker.models import sagemaker_backends
|
|
23
|
+
from moto.sagemaker.utils import get_pipeline_execution_from_arn, get_pipeline_from_name
|
|
22
24
|
import requests # noqa: F401
|
|
23
25
|
import urllib3 # noqa: F401
|
|
24
26
|
except ImportError:
|
|
@@ -37,9 +39,6 @@ from examples.secrets import Resource as SecretsResource
|
|
|
37
39
|
from examples.secrets import SecretVersion
|
|
38
40
|
from examples.xkcd import ComicVersion, XKCDResource
|
|
39
41
|
|
|
40
|
-
if TYPE_CHECKING:
|
|
41
|
-
from moto.sagemaker.responses import TYPE_RESPONSE, SageMakerResponse
|
|
42
|
-
|
|
43
42
|
|
|
44
43
|
def setUpModule() -> None:
|
|
45
44
|
"""Code to run before any single test in the module is run."""
|
|
@@ -280,7 +279,7 @@ class XKCDInTests(unittest.TestCase):
|
|
|
280
279
|
self.assertDictEqual(self.expected_response, json.loads(folder_state["info.json"]))
|
|
281
280
|
|
|
282
281
|
image_contents = folder_state["image.png"]
|
|
283
|
-
hashed_image_contents = hashlib.sha1(image_contents).hexdigest()
|
|
282
|
+
hashed_image_contents = hashlib.sha1(image_contents, usedforsecurity=False).hexdigest()
|
|
284
283
|
self.assertEqual(hashed_image_contents, "22f545ac6b50163ce39bac49094c3f64e0858403")
|
|
285
284
|
|
|
286
285
|
def test_file_downloads_without_files(self) -> None:
|
|
@@ -448,6 +447,7 @@ class PipelineCheckTests(unittest.TestCase):
|
|
|
448
447
|
pipeline_arn = "arn:aws:sagemaker:eu-west-1:<account>:pipeline:my-pipeline"
|
|
449
448
|
self.resource = PipelineResource(pipeline_arn)
|
|
450
449
|
client = self.resource._client
|
|
450
|
+
self._moto_backend = sagemaker_backends[DEFAULT_ACCOUNT_ID][client.meta.region_name]
|
|
451
451
|
|
|
452
452
|
pipeline_definition = {
|
|
453
453
|
"Version": "2020-12-01",
|
|
@@ -479,35 +479,29 @@ class PipelineCheckTests(unittest.TestCase):
|
|
|
479
479
|
|
|
480
480
|
self.execution_arns = execution_arns[::-1] # reverse these to force moto to yield in descending order
|
|
481
481
|
|
|
482
|
-
def
|
|
482
|
+
def test_fetch_no_version(self) -> None:
|
|
483
483
|
version, = self.resource.fetch_new_versions()
|
|
484
484
|
expected_version = ExecutionVersion(self.execution_arns[-1])
|
|
485
485
|
self.assertEqual(version, expected_version)
|
|
486
486
|
|
|
487
|
-
def
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
487
|
+
def test_fetch_no_available_versions(self) -> None:
|
|
488
|
+
pipeline = get_pipeline_from_name(self._moto_backend.pipelines, self.resource.pipeline_name)
|
|
489
|
+
pipeline.pipeline_executions.clear()
|
|
490
|
+
versions = self.resource.fetch_new_versions()
|
|
491
491
|
self.assertListEqual(versions, [])
|
|
492
492
|
|
|
493
|
-
def
|
|
494
|
-
fake_pipeline_executions: list[FakePipelineExecution] = FakePipelineExecution.instances
|
|
495
|
-
execution_mapping = {execution.pipeline_execution_arn: execution for execution in fake_pipeline_executions}
|
|
496
|
-
|
|
493
|
+
def test_fetch_no_version_with_pending(self) -> None:
|
|
497
494
|
for execution_arn in self.execution_arns[3:]:
|
|
498
|
-
execution =
|
|
495
|
+
execution = get_pipeline_execution_from_arn(self._moto_backend.pipelines, execution_arn)
|
|
499
496
|
execution.pipeline_execution_status = "Executing"
|
|
500
497
|
|
|
501
498
|
version, = self.resource.fetch_new_versions()
|
|
502
499
|
expected_version = ExecutionVersion(self.execution_arns[2])
|
|
503
500
|
self.assertEqual(version, expected_version)
|
|
504
501
|
|
|
505
|
-
def
|
|
506
|
-
fake_pipeline_executions: list[FakePipelineExecution] = FakePipelineExecution.instances
|
|
507
|
-
execution_mapping = {execution.pipeline_execution_arn: execution for execution in fake_pipeline_executions}
|
|
508
|
-
|
|
502
|
+
def test_fetch_no_version_with_pending_and_all_statuses(self) -> None:
|
|
509
503
|
for execution_arn in self.execution_arns[3:]:
|
|
510
|
-
execution =
|
|
504
|
+
execution = get_pipeline_execution_from_arn(self._moto_backend.pipelines, execution_arn)
|
|
511
505
|
execution.pipeline_execution_status = "Executing"
|
|
512
506
|
|
|
513
507
|
self.resource.statuses.append("Executing")
|
|
@@ -516,13 +510,13 @@ class PipelineCheckTests(unittest.TestCase):
|
|
|
516
510
|
expected_version = ExecutionVersion(self.execution_arns[-1])
|
|
517
511
|
self.assertEqual(version, expected_version)
|
|
518
512
|
|
|
519
|
-
def
|
|
513
|
+
def test_fetch_latest_version(self) -> None:
|
|
520
514
|
previous_version, = self.resource.fetch_new_versions()
|
|
521
515
|
version, = self.resource.fetch_new_versions(previous_version)
|
|
522
516
|
expected_version = ExecutionVersion(self.execution_arns[-1])
|
|
523
517
|
self.assertEqual(version, expected_version)
|
|
524
518
|
|
|
525
|
-
def
|
|
519
|
+
def test_fetch_old_version(self) -> None:
|
|
526
520
|
previous_version = ExecutionVersion(self.execution_arns[2])
|
|
527
521
|
versions = self.resource.fetch_new_versions(previous_version)
|
|
528
522
|
expected_versions = [ExecutionVersion(arn) for arn in self.execution_arns[2:]]
|
|
@@ -542,6 +536,7 @@ class PipelineInTests(unittest.TestCase):
|
|
|
542
536
|
pipeline_name = "my-pipeline"
|
|
543
537
|
resource = PipelineResource("arn:aws:sagemaker:eu-west-1:<account>:pipeline:my-pipeline")
|
|
544
538
|
client = resource._client
|
|
539
|
+
self._moto_backend = sagemaker_backends[DEFAULT_ACCOUNT_ID][client.meta.region_name]
|
|
545
540
|
|
|
546
541
|
self.pipeline_definition = {
|
|
547
542
|
"Version": "2020-12-01",
|
|
@@ -611,11 +606,8 @@ class PipelineInTests(unittest.TestCase):
|
|
|
611
606
|
self.assertDictEqual(metadata, expected_metadata)
|
|
612
607
|
|
|
613
608
|
def test_download_failed_execution(self) -> None:
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
fake_execution = execution_mapping[self.version_minimum.execution_arn]
|
|
618
|
-
fake_execution.pipeline_execution_status = "Failed"
|
|
609
|
+
execution = get_pipeline_execution_from_arn(self._moto_backend.pipelines, self.version_minimum.execution_arn)
|
|
610
|
+
execution.pipeline_execution_status = "Failed"
|
|
619
611
|
|
|
620
612
|
resource = PipelineResource(pipeline="arn:aws:sagemaker:eu-west-1:<account>:pipeline:my-pipeline")
|
|
621
613
|
wrapper = SimpleTestResourceWrapper(resource)
|
|
@@ -675,20 +667,13 @@ class PipelineOutTests(unittest.TestCase):
|
|
|
675
667
|
)
|
|
676
668
|
|
|
677
669
|
def test_execution_creation(self) -> None:
|
|
678
|
-
|
|
679
|
-
initial_execution_mapping = {execution.pipeline_execution_arn: execution for execution in fake_pipeline_executions}
|
|
670
|
+
intitial_executions = {version.execution_arn for version in self.resource._yield_potential_execution_versions()}
|
|
680
671
|
|
|
681
672
|
resource = PipelineResource(pipeline="arn:aws:sagemaker:eu-west-1:<account>:pipeline:my-pipeline")
|
|
682
673
|
wrapper = SimpleTestResourceWrapper(resource)
|
|
683
674
|
new_version, _ = wrapper.publish_new_version()
|
|
684
675
|
|
|
685
|
-
|
|
686
|
-
self.assertNotIn(new_version.execution_arn, initial_execution_mapping)
|
|
687
|
-
self.assertIn(new_version.execution_arn, execution_mapping)
|
|
688
|
-
|
|
676
|
+
new_executions = {version.execution_arn for version in self.resource._yield_potential_execution_versions()}
|
|
689
677
|
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
"PipelineExecutionSummaries": [],
|
|
693
|
-
}
|
|
694
|
-
return 200, {}, json.dumps(response)
|
|
678
|
+
self.assertNotIn(new_version.execution_arn, intitial_executions)
|
|
679
|
+
self.assertIn(new_version.execution_arn, new_executions)
|
|
@@ -152,6 +152,28 @@ class MetadataTests(TestCase):
|
|
|
152
152
|
}
|
|
153
153
|
self.assertDictEqual(_flatten_dict(nested_dict), flattened_dict)
|
|
154
154
|
|
|
155
|
+
def test_build_created_by(self) -> None:
|
|
156
|
+
metadata = BuildMetadata(
|
|
157
|
+
BUILD_ID="12345678",
|
|
158
|
+
BUILD_TEAM_NAME="my-team",
|
|
159
|
+
ATC_EXTERNAL_URL="https://ci.myconcourse.com",
|
|
160
|
+
BUILD_NAME="42",
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
with self.assertRaises(PermissionError):
|
|
164
|
+
metadata.BUILD_CREATED_BY
|
|
165
|
+
|
|
166
|
+
with mock_environ({"BUILD_CREATED_BY": "dev-1"}):
|
|
167
|
+
self.assertEqual(metadata.BUILD_CREATED_BY, "dev-1")
|
|
168
|
+
|
|
169
|
+
def test_build_created_by_in_test_metadata(self) -> None:
|
|
170
|
+
metadata = TestBuildMetadata()
|
|
171
|
+
with self.assertRaises(PermissionError):
|
|
172
|
+
metadata.BUILD_CREATED_BY
|
|
173
|
+
|
|
174
|
+
metadata = TestBuildMetadata(build_created_by="dev-1")
|
|
175
|
+
self.assertEqual(metadata.BUILD_CREATED_BY, "dev-1")
|
|
176
|
+
|
|
155
177
|
|
|
156
178
|
class MetadataFormattingTests(TestCase):
|
|
157
179
|
"""
|
|
@@ -186,3 +208,46 @@ class MetadataFormattingTests(TestCase):
|
|
|
186
208
|
new_string = self.metadata.format_string("The build id is $OTHER.", additional_values={"OTHER": "value"},
|
|
187
209
|
ignore_missing=True)
|
|
188
210
|
self.assertEqual(new_string, "The build id is value.")
|
|
211
|
+
|
|
212
|
+
def test_interpolation_with_build_created_by_not_set(self) -> None:
|
|
213
|
+
string = "Created by $BUILD_CREATED_BY"
|
|
214
|
+
|
|
215
|
+
with self.assertRaises(KeyError):
|
|
216
|
+
self.metadata.format_string(string)
|
|
217
|
+
|
|
218
|
+
self.assertEqual(self.metadata.format_string(string, ignore_missing=True), string)
|
|
219
|
+
|
|
220
|
+
def test_interpolation_with_build_created_by_set(self) -> None:
|
|
221
|
+
metadata = TestBuildMetadata(build_created_by="dev-1")
|
|
222
|
+
self.assertEqual(metadata.BUILD_CREATED_BY, "dev-1")
|
|
223
|
+
self.assertEqual(metadata.format_string("Created by $BUILD_CREATED_BY"), "Created by dev-1")
|
|
224
|
+
|
|
225
|
+
def test_interpolation_with_everything(self) -> None:
|
|
226
|
+
string = """
|
|
227
|
+
This is build number $BUILD_ID named $BUILD_NAME.
|
|
228
|
+
Job $BUILD_JOB_NAME from pipeline $BUILD_PIPELINE_NAME.
|
|
229
|
+
Started by $BUILD_CREATED_BY for team $BUILD_TEAM_NAME.
|
|
230
|
+
On server $ATC_EXTERNAL_URL.
|
|
231
|
+
|
|
232
|
+
Build accessible at $BUILD_URL.
|
|
233
|
+
|
|
234
|
+
Raw instance vars: $BUILD_PIPELINE_INSTANCE_VARS.
|
|
235
|
+
|
|
236
|
+
Custom vegetable: $VEGETABLE!
|
|
237
|
+
"""
|
|
238
|
+
|
|
239
|
+
expected = """
|
|
240
|
+
This is build number 12345678 named 42.
|
|
241
|
+
Job my-job from pipeline my-pipeline.
|
|
242
|
+
Started by dev-1 for team my-team.
|
|
243
|
+
On server https://ci.myconcourse.com.
|
|
244
|
+
|
|
245
|
+
Build accessible at https://ci.myconcourse.com/teams/my-team/pipelines/my-pipeline/jobs/my-job/builds/42?vars.instance=%22my-instance%22.
|
|
246
|
+
|
|
247
|
+
Raw instance vars: {"instance": "my-instance"}.
|
|
248
|
+
|
|
249
|
+
Custom vegetable: carrot!
|
|
250
|
+
"""
|
|
251
|
+
|
|
252
|
+
metadata = TestBuildMetadata(instance_vars={"instance": "my-instance"}, build_created_by="dev-1")
|
|
253
|
+
self.assertEqual(metadata.format_string(string, additional_values={"VEGETABLE": "carrot"}), expected)
|
|
@@ -735,7 +735,7 @@ def _build_test_resource_docker_image() -> str:
|
|
|
735
735
|
# '3.14.0b1 (main, May 9 2025, 23:49:24) [GCC 12.2.0]'
|
|
736
736
|
# ^^^^^^^^
|
|
737
737
|
tag, *_ = sys.version.split()
|
|
738
|
-
cli_commands.dockerfile(str(temp_dir), resource_file=
|
|
738
|
+
cli_commands.dockerfile(str(temp_dir), resource_file=temporary_resource_file.name, class_name=TestResource.__name__,
|
|
739
739
|
tag=tag, dev=True)
|
|
740
740
|
|
|
741
741
|
stdout, _ = run_command("docker", ["build", ".", "-q"], cwd=temp_dir)
|
|
@@ -118,7 +118,7 @@ class ComparisonTests(TestCase):
|
|
|
118
118
|
version_3 = BasicVersion("image.png")
|
|
119
119
|
|
|
120
120
|
with self.assertRaises(TypeError):
|
|
121
|
-
|
|
121
|
+
[version_1, version_2, version_3].sort() # type: ignore[call-arg]
|
|
122
122
|
|
|
123
123
|
def test_complex_sorting(self) -> None:
|
|
124
124
|
version_1 = ComplexVersion("file.txt")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|