concoursetools 0.7.1__tar.gz → 0.8.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.
Files changed (49) hide show
  1. concoursetools-0.8.0/PKG-INFO +132 -0
  2. concoursetools-0.8.0/README.md +105 -0
  3. {concoursetools-0.7.1 → concoursetools-0.8.0}/concoursetools/__init__.py +1 -1
  4. concoursetools-0.8.0/concoursetools/__main__.py +19 -0
  5. {concoursetools-0.7.1 → concoursetools-0.8.0}/concoursetools/additional.py +40 -36
  6. concoursetools-0.8.0/concoursetools/cli/__init__.py +9 -0
  7. concoursetools-0.8.0/concoursetools/cli/commands.py +205 -0
  8. concoursetools-0.8.0/concoursetools/cli/docstring.py +81 -0
  9. concoursetools-0.8.0/concoursetools/cli/parser.py +468 -0
  10. {concoursetools-0.7.1 → concoursetools-0.8.0}/concoursetools/colour.py +5 -2
  11. concoursetools-0.8.0/concoursetools/dockertools.py +375 -0
  12. concoursetools-0.8.0/concoursetools/importing.py +143 -0
  13. {concoursetools-0.7.1 → concoursetools-0.8.0}/concoursetools/metadata.py +68 -12
  14. {concoursetools-0.7.1 → concoursetools-0.8.0}/concoursetools/mocking.py +32 -30
  15. {concoursetools-0.7.1 → concoursetools-0.8.0}/concoursetools/parsing.py +56 -49
  16. {concoursetools-0.7.1 → concoursetools-0.8.0}/concoursetools/resource.py +18 -16
  17. {concoursetools-0.7.1 → concoursetools-0.8.0}/concoursetools/testing.py +417 -131
  18. {concoursetools-0.7.1 → concoursetools-0.8.0}/concoursetools/typing.py +37 -32
  19. {concoursetools-0.7.1 → concoursetools-0.8.0}/concoursetools/version.py +36 -27
  20. concoursetools-0.8.0/concoursetools.egg-info/PKG-INFO +132 -0
  21. {concoursetools-0.7.1 → concoursetools-0.8.0}/concoursetools.egg-info/SOURCES.txt +8 -2
  22. concoursetools-0.8.0/pyproject.toml +91 -0
  23. concoursetools-0.8.0/setup.cfg +4 -0
  24. {concoursetools-0.7.1 → concoursetools-0.8.0}/tests/test_additional.py +27 -21
  25. concoursetools-0.8.0/tests/test_cli_commands.py +177 -0
  26. concoursetools-0.8.0/tests/test_cli_parsing.py +383 -0
  27. concoursetools-0.8.0/tests/test_dockertools.py +276 -0
  28. {concoursetools-0.7.1 → concoursetools-0.8.0}/tests/test_examples.py +32 -34
  29. concoursetools-0.8.0/tests/test_importing.py +214 -0
  30. {concoursetools-0.7.1 → concoursetools-0.8.0}/tests/test_metadata.py +36 -0
  31. {concoursetools-0.7.1 → concoursetools-0.8.0}/tests/test_parsing.py +40 -6
  32. concoursetools-0.8.0/tests/test_resource.py +1073 -0
  33. {concoursetools-0.7.1 → concoursetools-0.8.0}/tests/test_testing.py +20 -15
  34. {concoursetools-0.7.1 → concoursetools-0.8.0}/tests/test_version.py +19 -12
  35. concoursetools-0.7.1/PKG-INFO +0 -64
  36. concoursetools-0.7.1/README.md +0 -38
  37. concoursetools-0.7.1/concoursetools/__main__.py +0 -57
  38. concoursetools-0.7.1/concoursetools/dockertools.py +0 -247
  39. concoursetools-0.7.1/concoursetools.egg-info/PKG-INFO +0 -64
  40. concoursetools-0.7.1/concoursetools.egg-info/not-zip-safe +0 -1
  41. concoursetools-0.7.1/pyproject.toml +0 -39
  42. concoursetools-0.7.1/setup.cfg +0 -43
  43. concoursetools-0.7.1/tests/test_dockertools.py +0 -57
  44. concoursetools-0.7.1/tests/test_resource.py +0 -482
  45. {concoursetools-0.7.1 → concoursetools-0.8.0}/LICENSE.md +0 -0
  46. {concoursetools-0.7.1 → concoursetools-0.8.0}/concoursetools/py.typed +0 -0
  47. {concoursetools-0.7.1 → concoursetools-0.8.0}/concoursetools.egg-info/dependency_links.txt +0 -0
  48. {concoursetools-0.7.1 → concoursetools-0.8.0}/concoursetools.egg-info/top_level.txt +0 -0
  49. {concoursetools-0.7.1 → concoursetools-0.8.0}/setup.py +0 -0
@@ -0,0 +1,132 @@
1
+ Metadata-Version: 2.1
2
+ Name: concoursetools
3
+ Version: 0.8.0
4
+ Summary: Easily create Concourse resource types in Python.
5
+ Author-email: GCHQ <oss@gchq.gov.uk>
6
+ License: Apache License 2.0
7
+ Project-URL: Homepage, https://github.com/gchq/ConcourseTools/
8
+ Project-URL: Documentation, https://concoursetools.readthedocs.io/en/stable/
9
+ Project-URL: Repository, https://github.com/gchq/ConcourseTools/
10
+ Project-URL: Bug Tracker, https://github.com/gchq/ConcourseTools/issues
11
+ Project-URL: Changelog, https://concoursetools.readthedocs.io/en/latest/whats_new.html
12
+ Keywords: concourse,ci,cd
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: Apache Software License
16
+ Classifier: Natural Language :: English
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Topic :: Software Development
23
+ Classifier: Typing :: Typed
24
+ Requires-Python: >=3.9
25
+ Description-Content-Type: text/markdown
26
+ License-File: LICENSE.md
27
+
28
+ <picture>
29
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/gchq/ConcourseTools/main/docs/source/_static/logo-dark.png">
30
+ <source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/gchq/ConcourseTools/main/docs/source/_static/logo.png">
31
+ <img alt="ConcourseTools logo" src="https://raw.githubusercontent.com/gchq/ConcourseTools/main/docs/source/_static/logo.png">
32
+ </picture>
33
+
34
+ ![version](https://img.shields.io/badge/version-0.8.0-informational)
35
+ ![pre-release](https://img.shields.io/badge/pre--release-beta-red)
36
+ ![python](https://img.shields.io/badge/python-%3E%3D3.9-informational)
37
+ ![coverage](https://img.shields.io/badge/coverage-96%25-brightgreen)
38
+ ![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=orange)
39
+
40
+ A Python package for easily implementing Concourse [resource types](https://concourse-ci.org/implementing-resource-types.html).
41
+
42
+
43
+ ## About
44
+
45
+ [Concourse CI](https://concourse-ci.org/) is an "open-source continuous thing-doer" designed to enable general
46
+ automation with intuitive and re-usable components. Resources represent all external inputs and outputs to and from the
47
+ pipeline, and many of these have been implemented in open source. In order to best leverage the Python ecosystem of
48
+ open-source packages, Concourse Tools abstracts away the implementation details of Concourse resource types to allow
49
+ users to focus on writing the code they want to run.
50
+
51
+
52
+ ## Installation
53
+
54
+ Install from [GitHub](https://github.com/gchq/ConcourseTools/), or from [PyPI](https://pypi.org/project/concoursetools/):
55
+
56
+ ```shell
57
+ $ pip install concoursetools
58
+ ```
59
+
60
+ ## Usage
61
+
62
+ Start by familiarising yourself with the Concourse resource "rules" in the [documentation](https://concourse-ci.org/implementing-resource-types.html). To recreate that example, start by creating a new `concourse.py` file in your repository. The first step is to create a `Version` subclass:
63
+
64
+ ```python
65
+ from dataclasses import dataclass
66
+ from concoursetools import TypedVersion
67
+
68
+
69
+ @dataclass()
70
+ class GitVersion(TypedVersion):
71
+ ref: str
72
+ ```
73
+
74
+ Next, create a subclass of `ConcourseResource`:
75
+
76
+ ```python
77
+ from concoursetools import ConcourseResource
78
+
79
+
80
+ class GitResource(ConcourseResource[GitVersion]):
81
+
82
+ def __init__(self, uri: str, branch: str, private_key: str) -> None:
83
+ super().__init__(GitVersion)
84
+ self.uri = uri
85
+ self.branch = branch
86
+ self.private_key = private_key
87
+ ```
88
+
89
+ Here, the parameters in the `__init__` method will be taken from the `source` configuration for the resource.
90
+ Now, implement the three methods required to define the behaviour of the resource:
91
+
92
+
93
+ ```python
94
+ from pathlib import Path
95
+ from typing import Any
96
+ from concoursetools import BuildMetadata
97
+
98
+
99
+ class GitResource(ConcourseResource[GitVersion]):
100
+ ...
101
+
102
+ def fetch_new_versions(self, previous_version: GitVersion | None) -> list[GitVersion]:
103
+ ...
104
+
105
+ def download_version(self, version: GitVersion, destination_dir: pathlib.Path,
106
+ build_metadata: BuildMetadata, **kwargs: Any) -> tuple[GitVersion, dict[str, str]]:
107
+ ...
108
+
109
+ def publish_new_version(self, sources_dir: pathlib.Path, build_metadata: BuildMetadata,
110
+ **kwargs: Any) -> tuple[GitVersion, dict[str, str]]:
111
+ ...
112
+ ```
113
+
114
+ The keyword arguments in `download_version` and `publish_new_version` correspond to `params` in the `get` step,
115
+ and `get_params` in the `put` step respectively.
116
+
117
+ Once you are happy with the resource, generate the `Dockerfile` using the Concourse Tools CLI:
118
+
119
+ ```shell
120
+ $ python3 -m concoursetools dockerfile .
121
+ ```
122
+
123
+ Finally, upload the Docker image to a registry, and use it in your pipelines!
124
+
125
+ For more information - and for more in-depth examples - see the [documentation](https://concoursetools.readthedocs.io/en/stable/).
126
+
127
+
128
+ ## Bugs and Contributions
129
+
130
+ Concourse Tools is in beta, and still under somewhat-active development. Contributions, fixes, suggestions and bug
131
+ reports are all welcome: Please familiarise yourself with our
132
+ [contribution guidelines](https://github.com/gchq/ConcourseTools/blob/main/CONTRIBUTING.md).
@@ -0,0 +1,105 @@
1
+ <picture>
2
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/gchq/ConcourseTools/main/docs/source/_static/logo-dark.png">
3
+ <source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/gchq/ConcourseTools/main/docs/source/_static/logo.png">
4
+ <img alt="ConcourseTools logo" src="https://raw.githubusercontent.com/gchq/ConcourseTools/main/docs/source/_static/logo.png">
5
+ </picture>
6
+
7
+ ![version](https://img.shields.io/badge/version-0.8.0-informational)
8
+ ![pre-release](https://img.shields.io/badge/pre--release-beta-red)
9
+ ![python](https://img.shields.io/badge/python-%3E%3D3.9-informational)
10
+ ![coverage](https://img.shields.io/badge/coverage-96%25-brightgreen)
11
+ ![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=orange)
12
+
13
+ A Python package for easily implementing Concourse [resource types](https://concourse-ci.org/implementing-resource-types.html).
14
+
15
+
16
+ ## About
17
+
18
+ [Concourse CI](https://concourse-ci.org/) is an "open-source continuous thing-doer" designed to enable general
19
+ automation with intuitive and re-usable components. Resources represent all external inputs and outputs to and from the
20
+ pipeline, and many of these have been implemented in open source. In order to best leverage the Python ecosystem of
21
+ open-source packages, Concourse Tools abstracts away the implementation details of Concourse resource types to allow
22
+ users to focus on writing the code they want to run.
23
+
24
+
25
+ ## Installation
26
+
27
+ Install from [GitHub](https://github.com/gchq/ConcourseTools/), or from [PyPI](https://pypi.org/project/concoursetools/):
28
+
29
+ ```shell
30
+ $ pip install concoursetools
31
+ ```
32
+
33
+ ## Usage
34
+
35
+ Start by familiarising yourself with the Concourse resource "rules" in the [documentation](https://concourse-ci.org/implementing-resource-types.html). To recreate that example, start by creating a new `concourse.py` file in your repository. The first step is to create a `Version` subclass:
36
+
37
+ ```python
38
+ from dataclasses import dataclass
39
+ from concoursetools import TypedVersion
40
+
41
+
42
+ @dataclass()
43
+ class GitVersion(TypedVersion):
44
+ ref: str
45
+ ```
46
+
47
+ Next, create a subclass of `ConcourseResource`:
48
+
49
+ ```python
50
+ from concoursetools import ConcourseResource
51
+
52
+
53
+ class GitResource(ConcourseResource[GitVersion]):
54
+
55
+ def __init__(self, uri: str, branch: str, private_key: str) -> None:
56
+ super().__init__(GitVersion)
57
+ self.uri = uri
58
+ self.branch = branch
59
+ self.private_key = private_key
60
+ ```
61
+
62
+ Here, the parameters in the `__init__` method will be taken from the `source` configuration for the resource.
63
+ Now, implement the three methods required to define the behaviour of the resource:
64
+
65
+
66
+ ```python
67
+ from pathlib import Path
68
+ from typing import Any
69
+ from concoursetools import BuildMetadata
70
+
71
+
72
+ class GitResource(ConcourseResource[GitVersion]):
73
+ ...
74
+
75
+ def fetch_new_versions(self, previous_version: GitVersion | None) -> list[GitVersion]:
76
+ ...
77
+
78
+ def download_version(self, version: GitVersion, destination_dir: pathlib.Path,
79
+ build_metadata: BuildMetadata, **kwargs: Any) -> tuple[GitVersion, dict[str, str]]:
80
+ ...
81
+
82
+ def publish_new_version(self, sources_dir: pathlib.Path, build_metadata: BuildMetadata,
83
+ **kwargs: Any) -> tuple[GitVersion, dict[str, str]]:
84
+ ...
85
+ ```
86
+
87
+ The keyword arguments in `download_version` and `publish_new_version` correspond to `params` in the `get` step,
88
+ and `get_params` in the `put` step respectively.
89
+
90
+ Once you are happy with the resource, generate the `Dockerfile` using the Concourse Tools CLI:
91
+
92
+ ```shell
93
+ $ python3 -m concoursetools dockerfile .
94
+ ```
95
+
96
+ Finally, upload the Docker image to a registry, and use it in your pipelines!
97
+
98
+ For more information - and for more in-depth examples - see the [documentation](https://concoursetools.readthedocs.io/en/stable/).
99
+
100
+
101
+ ## Bugs and Contributions
102
+
103
+ Concourse Tools is in beta, and still under somewhat-active development. Contributions, fixes, suggestions and bug
104
+ reports are all welcome: Please familiarise yourself with our
105
+ [contribution guidelines](https://github.com/gchq/ConcourseTools/blob/main/CONTRIBUTING.md).
@@ -8,4 +8,4 @@ from concoursetools.version import TypedVersion, Version
8
8
 
9
9
  __all__ = ("BuildMetadata", "ConcourseResource", "Version", "TypedVersion")
10
10
  __author__ = "GCHQ"
11
- __version__ = "0.7.1"
11
+ __version__ = "0.8.0"
@@ -0,0 +1,19 @@
1
+ # (C) Crown Copyright GCHQ
2
+ """
3
+ The main entrypoint for the Concourse Tools CLI:
4
+
5
+ $ python3 -m concoursetools --help
6
+ """
7
+ import sys
8
+
9
+ from concoursetools.cli import cli
10
+
11
+
12
+ def main() -> int:
13
+ """Run the main function."""
14
+ cli.invoke(sys.argv[1:])
15
+ return 0
16
+
17
+
18
+ if __name__ == "__main__":
19
+ main()
@@ -2,16 +2,18 @@
2
2
  """
3
3
  Concourse Tools comes with some additional resource type "patterns" to cover some common requirements.
4
4
  """
5
+ from __future__ import annotations
6
+
5
7
  from abc import abstractmethod
6
8
  from dataclasses import dataclass
7
9
  from datetime import datetime
8
10
  import json
9
- import pathlib
10
- from typing import Any, Dict, Generic, List, Optional, Set, Tuple, Type
11
+ from pathlib import Path
12
+ from typing import Generic
11
13
 
12
14
  from concoursetools import ConcourseResource
13
15
  from concoursetools.metadata import BuildMetadata
14
- from concoursetools.typing import Metadata, MultiVersionT, ResourceConfig, SortableVersionT, VersionConfig, VersionT
16
+ from concoursetools.typing import Metadata, ResourceConfig, SortableVersionT, VersionConfig, VersionT
15
17
  from concoursetools.version import TypedVersion, Version
16
18
 
17
19
 
@@ -26,11 +28,11 @@ class OutOnlyConcourseResource(ConcourseResource[VersionT]):
26
28
 
27
29
  :param version_class: The resource parses all inputs with this version class.
28
30
  """
29
- def fetch_new_versions(self, previous_version: Optional[VersionT] = None) -> List[VersionT]:
31
+ def fetch_new_versions(self, previous_version: VersionT | None = None) -> list[VersionT]:
30
32
  return []
31
33
 
32
- def download_version(self, version: VersionT, destination_dir: pathlib.Path, build_metadata: BuildMetadata) -> Tuple[VersionT, Metadata]:
33
- metadata: Dict[str, str] = {}
34
+ def download_version(self, version: VersionT, destination_dir: Path, build_metadata: BuildMetadata) -> tuple[VersionT, Metadata]:
35
+ metadata: dict[str, str] = {}
34
36
  return version, metadata
35
37
 
36
38
 
@@ -78,20 +80,20 @@ class InOnlyConcourseResource(ConcourseResource[DatetimeVersion]):
78
80
  def __init__(self) -> None:
79
81
  super().__init__(DatetimeVersion)
80
82
 
81
- def fetch_new_versions(self, previous_version: Optional[DatetimeVersion] = None) -> List[DatetimeVersion]:
83
+ def fetch_new_versions(self, previous_version: DatetimeVersion | None = None) -> list[DatetimeVersion]:
82
84
  return []
83
85
 
84
- def download_version(self, version: DatetimeVersion, destination_dir: pathlib.Path, build_metadata: BuildMetadata,
85
- **kwargs: Any) -> Tuple[DatetimeVersion, Metadata]:
86
+ def download_version(self, version: DatetimeVersion, destination_dir: Path, build_metadata: BuildMetadata,
87
+ **kwargs: object) -> tuple[DatetimeVersion, Metadata]:
86
88
  metadata = self.download_data(destination_dir, build_metadata, **kwargs)
87
89
  return version, metadata
88
90
 
89
- def publish_new_version(self, sources_dir: pathlib.Path, build_metadata: BuildMetadata) -> Tuple[DatetimeVersion, Metadata]:
91
+ def publish_new_version(self, sources_dir: Path, build_metadata: BuildMetadata) -> tuple[DatetimeVersion, Metadata]:
90
92
  version = DatetimeVersion.now()
91
93
  return version, {}
92
94
 
93
95
  @abstractmethod
94
- def download_data(self, destination_dir: pathlib.Path, build_metadata: BuildMetadata) -> Metadata:
96
+ def download_data(self, destination_dir: Path, build_metadata: BuildMetadata) -> Metadata:
95
97
  """
96
98
  Download resource data and place files within the resource directory in your pipeline.
97
99
 
@@ -158,7 +160,7 @@ class TriggerOnChangeConcourseResource(ConcourseResource[VersionT]):
158
160
 
159
161
  :param version_class: The resource parses all inputs with this version class.
160
162
  """
161
- def fetch_new_versions(self, previous_version: Optional[VersionT] = None) -> List[VersionT]:
163
+ def fetch_new_versions(self, previous_version: VersionT | None = None) -> list[VersionT]:
162
164
  latest_version = self.fetch_latest_version()
163
165
 
164
166
  if previous_version is None:
@@ -192,12 +194,14 @@ class MultiVersion(Version, Generic[SortableVersionT]):
192
194
  Two multi-versions are equal if their respective set of subversions are also equal.
193
195
  """
194
196
  _key: str = "versions"
195
- _sub_version_class: Type[SortableVersionT] = Version # type: ignore[assignment]
197
+ _sub_version_class: type[SortableVersionT] = Version # type: ignore[assignment]
196
198
 
197
- def __init__(self, versions: Set[SortableVersionT]):
199
+ def __init__(self, versions: set[SortableVersionT]):
198
200
  self.versions = versions
199
201
 
200
- def __eq__(self, other: Any) -> bool:
202
+ def __eq__(self, other: object) -> bool:
203
+ if not isinstance(other, type(self)):
204
+ return NotImplemented
201
205
  return bool(self.versions == other.versions)
202
206
 
203
207
  @property
@@ -206,12 +210,12 @@ class MultiVersion(Version, Generic[SortableVersionT]):
206
210
  return self._key
207
211
 
208
212
  @property
209
- def sub_version_class(self) -> Type[SortableVersionT]:
213
+ def sub_version_class(self) -> type[SortableVersionT]:
210
214
  """Return the class used to parse the subversions."""
211
215
  return self._sub_version_class
212
216
 
213
217
  @property
214
- def sub_version_data(self) -> List[VersionConfig]:
218
+ def sub_version_data(self) -> list[VersionConfig]:
215
219
  """
216
220
  Return a list of flattened subversions.
217
221
 
@@ -232,7 +236,7 @@ class MultiVersion(Version, Generic[SortableVersionT]):
232
236
  }
233
237
 
234
238
  @classmethod
235
- def from_flat_dict(cls: "Type[MultiVersion[SortableVersionT]]", version_dict: VersionConfig) -> "MultiVersion[SortableVersionT]":
239
+ def from_flat_dict(cls: "type[MultiVersion[SortableVersionT]]", version_dict: VersionConfig) -> "MultiVersion[SortableVersionT]":
236
240
  """
237
241
  Load an instance from a dictionary representing the version.
238
242
 
@@ -243,12 +247,12 @@ class MultiVersion(Version, Generic[SortableVersionT]):
243
247
  :param version_dict: A string-only key/value dictionary representing the multi-version.
244
248
  """
245
249
  data = version_dict[cls._key]
246
- sub_version_dicts: List[VersionConfig] = json.loads(data)
250
+ sub_version_dicts: list[VersionConfig] = json.loads(data)
247
251
  versions = {cls._sub_version_class.from_flat_dict(sub_version_dict) for sub_version_dict in sub_version_dicts}
248
252
  return cls(versions)
249
253
 
250
254
 
251
- def _create_multi_version_class(key: str, sub_version_class: Type[SortableVersionT]) -> Type[MultiVersion[SortableVersionT]]:
255
+ def _create_multi_version_class(key: str, sub_version_class: type[SortableVersionT]) -> type[MultiVersion[SortableVersionT]]:
252
256
  """Create a new version subclass containing multiple sub-versions."""
253
257
  class NewMultiVersion(MultiVersion[SortableVersionT]):
254
258
  _key = key
@@ -257,7 +261,7 @@ def _create_multi_version_class(key: str, sub_version_class: Type[SortableVersio
257
261
  return NewMultiVersion
258
262
 
259
263
 
260
- class MultiVersionConcourseResource(TriggerOnChangeConcourseResource[MultiVersionT]):
264
+ class MultiVersionConcourseResource(TriggerOnChangeConcourseResource[MultiVersion[SortableVersionT]]):
261
265
  """
262
266
  A Concourse resource type designed to trigger to a change in available versions.
263
267
 
@@ -284,27 +288,26 @@ class MultiVersionConcourseResource(TriggerOnChangeConcourseResource[MultiVersio
284
288
  This resource class is best suited to resources used in conjunction
285
289
  with the :concourse:`set-pipeline-step`.
286
290
  """
287
- def __init__(self, key: str, sub_version_class: Type[SortableVersionT]):
291
+ def __init__(self, key: str, sub_version_class: type[SortableVersionT]):
288
292
  self.key = key
289
293
  multi_version_class = _create_multi_version_class(key, sub_version_class)
290
294
  super().__init__(multi_version_class)
291
295
 
292
- def fetch_latest_version(self) -> MultiVersionT:
296
+ def fetch_latest_version(self) -> MultiVersion[SortableVersionT]:
293
297
  latest_sub_versions = self.fetch_latest_sub_versions()
294
298
  multi_version = self.version_class(latest_sub_versions)
295
299
  return multi_version
296
300
 
297
301
  @abstractmethod
298
- def fetch_latest_sub_versions(self) -> Set[Version]:
302
+ def fetch_latest_sub_versions(self) -> set[SortableVersionT]:
299
303
  """
300
304
  Fetch the latest sub versions from the resource.
301
305
 
302
306
  :returns: A set of the latest subversions from the resource.
303
307
  """
304
- ...
305
308
 
306
- def download_version(self, version: MultiVersionT, destination_dir: pathlib.Path, build_metadata: BuildMetadata,
307
- file_name: Optional[str] = None, indent: Optional[int] = None) -> Tuple[MultiVersionT, Metadata]:
309
+ def download_version(self, version: MultiVersion[SortableVersionT], destination_dir: Path, build_metadata: BuildMetadata,
310
+ file_name: str | None = None, indent: int | None = None) -> tuple[MultiVersion[SortableVersionT], Metadata]:
308
311
  """
309
312
  Download a JSON file containing the sub-version data.
310
313
 
@@ -319,7 +322,7 @@ class MultiVersionConcourseResource(TriggerOnChangeConcourseResource[MultiVersio
319
322
  file_path.write_text(json.dumps(version.sub_version_data, indent=indent))
320
323
  return version, {}
321
324
 
322
- def publish_new_version(self, sources_dir: pathlib.Path, build_metadata: BuildMetadata) -> Tuple[MultiVersionT, Metadata]:
325
+ def publish_new_version(self, sources_dir: Path, build_metadata: BuildMetadata) -> tuple[MultiVersion[SortableVersionT], Metadata]:
323
326
  raise TypeError("Publishing new versions of this resource is not permitted.")
324
327
 
325
328
 
@@ -345,7 +348,7 @@ class SelfOrganisingConcourseResource(ConcourseResource[SortableVersionT]):
345
348
 
346
349
  :param version_class: The resource parses all inputs with this version class.
347
350
  """
348
- def fetch_new_versions(self, previous_version: Optional[SortableVersionT] = None) -> List[SortableVersionT]:
351
+ def fetch_new_versions(self, previous_version: SortableVersionT | None = None) -> list[SortableVersionT]:
349
352
  all_versions = self.fetch_all_versions()
350
353
  try:
351
354
  newest_version = max(all_versions)
@@ -364,7 +367,7 @@ class SelfOrganisingConcourseResource(ConcourseResource[SortableVersionT]):
364
367
  return versions
365
368
 
366
369
  @abstractmethod
367
- def fetch_all_versions(self) -> Set[SortableVersionT]:
370
+ def fetch_all_versions(self) -> set[SortableVersionT]:
368
371
  """
369
372
  Fetch every available version of the resource.
370
373
 
@@ -383,8 +386,8 @@ class _PseudoConcourseResource(ConcourseResource[VersionT]):
383
386
  raise TypeError(f"Cannot instantiate a {cls.__name__} type")
384
387
 
385
388
 
386
- def combine_resource_types(resources: Dict[str, Type[ConcourseResource[VersionT]]],
387
- param_key: str = "resource") -> Type[_PseudoConcourseResource[VersionT]]:
389
+ def combine_resource_types(resources: dict[str, type[ConcourseResource[VersionT]]],
390
+ param_key: str = "resource") -> type[_PseudoConcourseResource[VersionT]]:
388
391
  """
389
392
  Return a pseudo-resource which will delegate to other resources depending on a flag.
390
393
 
@@ -425,14 +428,15 @@ def combine_resource_types(resources: Dict[str, Type[ConcourseResource[VersionT]
425
428
  def _from_resource_config(cls, resource_config: ResourceConfig) -> "ConcourseResource[VersionT]":
426
429
  try:
427
430
  resource_key = resource_config.pop(param_key)
428
- except KeyError:
429
- raise ValueError(f"Missing flag: {param_key!r}")
431
+ except KeyError as error:
432
+ raise ValueError(f"Missing flag: {param_key!r}") from error
430
433
 
431
434
  try:
432
435
  resource_class = resources[resource_key]
433
- except KeyError:
436
+ except KeyError as error:
434
437
  possible = set(resources)
435
- raise KeyError(f"Couldn't find resource matching {resource_key!r}: possible options: {possible}")
438
+ raise KeyError(f"Couldn't find resource matching {resource_key!r}: "
439
+ f"possible options: {possible}") from error
436
440
 
437
441
  return resource_class(**resource_config)
438
442
 
@@ -0,0 +1,9 @@
1
+ # (C) Crown Copyright GCHQ
2
+ """
3
+ Contains the Concourse Tools CLI.
4
+ """
5
+ from __future__ import annotations
6
+
7
+ from concoursetools.cli.commands import cli
8
+
9
+ __all__ = ("cli",)