pact-python-cli 2.4.26.2__tar.gz → 2.6.0.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.
- {pact_python_cli-2.4.26.2 → pact_python_cli-2.6.0.0}/.gitignore +0 -1
- pact_python_cli-2.6.0.0/PKG-INFO +151 -0
- pact_python_cli-2.6.0.0/README.md +119 -0
- pact_python_cli-2.6.0.0/hatch_build.py +366 -0
- {pact_python_cli-2.4.26.2/src → pact_python_cli-2.6.0.0}/pact_cli/__init__.py +104 -20
- pact_python_cli-2.6.0.0/pact_cli/__version__.py +10 -0
- pact_python_cli-2.6.0.0/pyproject.toml +155 -0
- pact_python_cli-2.4.26.2/PKG-INFO +0 -41
- pact_python_cli-2.4.26.2/README.md +0 -32
- pact_python_cli-2.4.26.2/cliff.toml +0 -113
- pact_python_cli-2.4.26.2/hatch_build.py +0 -225
- pact_python_cli-2.4.26.2/pyproject.toml +0 -203
- pact_python_cli-2.4.26.2/src/pact_cli/__version__.py +0 -21
- pact_python_cli-2.4.26.2/tests/.ruff.toml +0 -10
- pact_python_cli-2.4.26.2/tests/test_init.py +0 -175
- {pact_python_cli-2.4.26.2 → pact_python_cli-2.6.0.0}/LICENSE +0 -0
- {pact_python_cli-2.4.26.2/src → pact_python_cli-2.6.0.0}/pact_cli/.gitkeep +0 -0
- {pact_python_cli-2.4.26.2/src → pact_python_cli-2.6.0.0}/pact_cli/py.typed +0 -0
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pact-python-cli
|
|
3
|
+
Version: 2.6.0.0
|
|
4
|
+
Summary: Pact CLI bundle for Python
|
|
5
|
+
Project-URL: Bug Tracker, https://github.com/pact-foundation/pact-python/issues
|
|
6
|
+
Project-URL: Changelog, https://github.com/pact-foundation/pact-python/blob/main/pact-python-cli/CHANGELOG.md
|
|
7
|
+
Project-URL: Documentation, https://docs.pact.io
|
|
8
|
+
Project-URL: Homepage, https://pact.io
|
|
9
|
+
Project-URL: Repository, https://github.com/pact-foundation/pact-python
|
|
10
|
+
Author-email: Joshua Ellis <josh@jpellis.me>
|
|
11
|
+
Maintainer-email: Joshua Ellis <josh@jpellis.me>
|
|
12
|
+
License-Expression: MIT
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Keywords: cli,contract-testing,pact,pact-python
|
|
15
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
16
|
+
Classifier: Environment :: Console
|
|
17
|
+
Classifier: Intended Audience :: Developers
|
|
18
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
19
|
+
Classifier: Operating System :: MacOS :: MacOS X
|
|
20
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
21
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
22
|
+
Classifier: Programming Language :: Python
|
|
23
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
26
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
27
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
28
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
29
|
+
Classifier: Topic :: Software Development :: Testing
|
|
30
|
+
Requires-Python: >=3.10
|
|
31
|
+
Description-Content-Type: text/markdown
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
# Pact Python CLI
|
|
35
|
+
|
|
36
|
+
> [!NOTE]
|
|
37
|
+
>
|
|
38
|
+
> This package is used to package and bundle the Pact CLI _only_. It does not provide any Python functionality or API.
|
|
39
|
+
|
|
40
|
+
<!-- markdownlint-disable no-inline-html -->
|
|
41
|
+
<div align="center"><table>
|
|
42
|
+
<tr>
|
|
43
|
+
<td>Package</td>
|
|
44
|
+
<td>
|
|
45
|
+
<a href="https://pypi.python.org/pypi/pact-python-cli"><img src="https://img.shields.io/pypi/v/pact-python-cli.svg" alt="Version"></a>
|
|
46
|
+
<a href="https://pypi.python.org/pypi/pact-python-cli"><img src="https://img.shields.io/pypi/pyversions/pact-python-cli.svg" alt="Python Versions"></a>
|
|
47
|
+
<a href="https://pypi.python.org/pypi/pact-python-cli"><img src="https://img.shields.io/pypi/dm/pact-python-cli.svg" alt="Downloads"></a>
|
|
48
|
+
</td>
|
|
49
|
+
</tr>
|
|
50
|
+
<tr>
|
|
51
|
+
<td>CI/CD</td>
|
|
52
|
+
<td>
|
|
53
|
+
<a
|
|
54
|
+
href="https://github.com/pact-foundation/pact-python/actions/workflows/test.yml?query=branch:main"><img
|
|
55
|
+
src="https://img.shields.io/github/actions/workflow/status/pact-foundation/pact-python/test.yml?branch=main&label=test"
|
|
56
|
+
alt="Test Status"></a>
|
|
57
|
+
<a
|
|
58
|
+
href="https://github.com/pact-foundation/pact-python/actions/workflows/build-cli.yml?query=branch:main"><img
|
|
59
|
+
src="https://img.shields.io/github/actions/workflow/status/pact-foundation/pact-python/build-cli.yml?branch=main&label=build"
|
|
60
|
+
alt="Build Status"></a>
|
|
61
|
+
<a
|
|
62
|
+
href="https://github.com/pact-foundation/pact-python/actions/workflows/docs.yml?query=branch:main"><img
|
|
63
|
+
src="https://img.shields.io/github/actions/workflow/status/pact-foundation/pact-python/docs.yml?branch=main&label=docs"
|
|
64
|
+
alt="Build Status"></a>
|
|
65
|
+
</td>
|
|
66
|
+
</tr>
|
|
67
|
+
<tr>
|
|
68
|
+
<td>Meta</td>
|
|
69
|
+
<td>
|
|
70
|
+
<a
|
|
71
|
+
href="https://github.com/pypa/hatch"><img
|
|
72
|
+
src="https://img.shields.io/badge/%F0%9F%A5%9A-Hatch-4051b5.svg"
|
|
73
|
+
alt="Hatch project"></a>
|
|
74
|
+
<a href="https://github.com/astral-sh/ruff"><img
|
|
75
|
+
src="https://img.shields.io/badge/ruff-ruff?label=linting&color=%23261230"
|
|
76
|
+
alt="linting - Ruff"></a>
|
|
77
|
+
<a href="https://github.com/astral-sh/ruff"><img
|
|
78
|
+
src="https://img.shields.io/badge/ruff-ruff?label=style&color=%23261230"
|
|
79
|
+
alt="style - Ruff"></a>
|
|
80
|
+
<a
|
|
81
|
+
href="https://github.com/python/mypy"><img
|
|
82
|
+
src="https://img.shields.io/badge/types-Mypy-blue.svg"
|
|
83
|
+
alt="types - Mypy"></a>
|
|
84
|
+
<a
|
|
85
|
+
href="https://pypi.python.org/pypi/pact-python-cli"><img
|
|
86
|
+
src="https://img.shields.io/pypi/l/pact-python-cli.svg"
|
|
87
|
+
alt="License"></a>
|
|
88
|
+
</td>
|
|
89
|
+
</tr>
|
|
90
|
+
<tr>
|
|
91
|
+
<td>Community</td>
|
|
92
|
+
<td>
|
|
93
|
+
<a
|
|
94
|
+
href="https://github.com/pact-foundation/pact-python/issues"><img
|
|
95
|
+
src="https://img.shields.io/github/issues/pact-foundation/pact-python.svg"
|
|
96
|
+
alt="Issues"></a>
|
|
97
|
+
<a
|
|
98
|
+
href="https://github.com/pact-foundation/pact-python/discussions"><img
|
|
99
|
+
src="https://img.shields.io/github/discussions/pact-foundation/pact-python.svg"
|
|
100
|
+
alt="Discussions"></a>
|
|
101
|
+
<a
|
|
102
|
+
href="https://github.com/pact-foundation/pact-python"><img
|
|
103
|
+
src="https://img.shields.io/github/stars/pact-foundation/pact-python.svg?style=flat"
|
|
104
|
+
alt="GitHub Stars"></a>
|
|
105
|
+
<br/>
|
|
106
|
+
<a
|
|
107
|
+
href="http://slack.pact.io"><img
|
|
108
|
+
src="https://img.shields.io/badge/slack-pact--foundation-4A154B.svg"
|
|
109
|
+
alt="Slack"></a>
|
|
110
|
+
<a
|
|
111
|
+
href="https://stackoverflow.com/questions/tagged/pact"><img
|
|
112
|
+
src="https://img.shields.io/badge/stackoverflow-pact-F48024.svg"
|
|
113
|
+
alt="Stack Overflow"></a>
|
|
114
|
+
<a
|
|
115
|
+
href="https://twitter.com/pact_up"><img
|
|
116
|
+
src="https://img.shields.io/badge/X-@pact__up-black.svg"
|
|
117
|
+
alt="Twitter"></a>
|
|
118
|
+
</td>
|
|
119
|
+
</tr>
|
|
120
|
+
</table></div>
|
|
121
|
+
<!-- markdownlint-enable no-inline-html -->
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
This sub-package is part of the [Pact Python](https://github.com/pact-foundation/pact-python) project and exists solely to distribute the [Pact CLI](https://github.com/pact-foundation/pact-standalone) as a Python package. If you are looking for the main Pact Python library for contract testing, please see the [root package](https://github.com/pact-foundation/pact-python#pact-python).
|
|
126
|
+
|
|
127
|
+
It is used by version 2 of Pact Python, and can be used to install the Pact CLI in Python environments.
|
|
128
|
+
|
|
129
|
+
The versionining of `pact-python-cli` is aligned with the Pact CLI versioning. For example, version `2.4.26.2` corresponds to Pact CLI version `2.4.26`, with the `.2` indicating that this is the third release of that Pact CLI version in the Python package (with the first release being `.0`).
|
|
130
|
+
|
|
131
|
+
## Installation
|
|
132
|
+
|
|
133
|
+
You can install this package via pip:
|
|
134
|
+
|
|
135
|
+
```console
|
|
136
|
+
pip install pact-python-cli
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Contributing
|
|
140
|
+
|
|
141
|
+
Contributions to this package are generally not required as it contains minimal Python functionality and generally only requires updating the version number. This is done by pushing a tag of the form `pact-python-cli/<version>` which will automatically trigger a release build in the CI pipeline.
|
|
142
|
+
|
|
143
|
+
To contribute to the Pact CLI itself, please refer to the [Pact Ruby Standalone repository](https://github.com/pact-foundation/pact-standalone).
|
|
144
|
+
|
|
145
|
+
For contributing to Pact Python, see the [main contributing guide](https://github.com/pact-foundation/pact-python/blob/main/CONTRIBUTING.md).
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
For questions or support, please visit the [Pact Foundation Slack](https://slack.pact.io) or [GitHub Discussions](https://github.com/pact-foundation/pact-python/discussions).
|
|
150
|
+
|
|
151
|
+
---
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
|
|
2
|
+
# Pact Python CLI
|
|
3
|
+
|
|
4
|
+
> [!NOTE]
|
|
5
|
+
>
|
|
6
|
+
> This package is used to package and bundle the Pact CLI _only_. It does not provide any Python functionality or API.
|
|
7
|
+
|
|
8
|
+
<!-- markdownlint-disable no-inline-html -->
|
|
9
|
+
<div align="center"><table>
|
|
10
|
+
<tr>
|
|
11
|
+
<td>Package</td>
|
|
12
|
+
<td>
|
|
13
|
+
<a href="https://pypi.python.org/pypi/pact-python-cli"><img src="https://img.shields.io/pypi/v/pact-python-cli.svg" alt="Version"></a>
|
|
14
|
+
<a href="https://pypi.python.org/pypi/pact-python-cli"><img src="https://img.shields.io/pypi/pyversions/pact-python-cli.svg" alt="Python Versions"></a>
|
|
15
|
+
<a href="https://pypi.python.org/pypi/pact-python-cli"><img src="https://img.shields.io/pypi/dm/pact-python-cli.svg" alt="Downloads"></a>
|
|
16
|
+
</td>
|
|
17
|
+
</tr>
|
|
18
|
+
<tr>
|
|
19
|
+
<td>CI/CD</td>
|
|
20
|
+
<td>
|
|
21
|
+
<a
|
|
22
|
+
href="https://github.com/pact-foundation/pact-python/actions/workflows/test.yml?query=branch:main"><img
|
|
23
|
+
src="https://img.shields.io/github/actions/workflow/status/pact-foundation/pact-python/test.yml?branch=main&label=test"
|
|
24
|
+
alt="Test Status"></a>
|
|
25
|
+
<a
|
|
26
|
+
href="https://github.com/pact-foundation/pact-python/actions/workflows/build-cli.yml?query=branch:main"><img
|
|
27
|
+
src="https://img.shields.io/github/actions/workflow/status/pact-foundation/pact-python/build-cli.yml?branch=main&label=build"
|
|
28
|
+
alt="Build Status"></a>
|
|
29
|
+
<a
|
|
30
|
+
href="https://github.com/pact-foundation/pact-python/actions/workflows/docs.yml?query=branch:main"><img
|
|
31
|
+
src="https://img.shields.io/github/actions/workflow/status/pact-foundation/pact-python/docs.yml?branch=main&label=docs"
|
|
32
|
+
alt="Build Status"></a>
|
|
33
|
+
</td>
|
|
34
|
+
</tr>
|
|
35
|
+
<tr>
|
|
36
|
+
<td>Meta</td>
|
|
37
|
+
<td>
|
|
38
|
+
<a
|
|
39
|
+
href="https://github.com/pypa/hatch"><img
|
|
40
|
+
src="https://img.shields.io/badge/%F0%9F%A5%9A-Hatch-4051b5.svg"
|
|
41
|
+
alt="Hatch project"></a>
|
|
42
|
+
<a href="https://github.com/astral-sh/ruff"><img
|
|
43
|
+
src="https://img.shields.io/badge/ruff-ruff?label=linting&color=%23261230"
|
|
44
|
+
alt="linting - Ruff"></a>
|
|
45
|
+
<a href="https://github.com/astral-sh/ruff"><img
|
|
46
|
+
src="https://img.shields.io/badge/ruff-ruff?label=style&color=%23261230"
|
|
47
|
+
alt="style - Ruff"></a>
|
|
48
|
+
<a
|
|
49
|
+
href="https://github.com/python/mypy"><img
|
|
50
|
+
src="https://img.shields.io/badge/types-Mypy-blue.svg"
|
|
51
|
+
alt="types - Mypy"></a>
|
|
52
|
+
<a
|
|
53
|
+
href="https://pypi.python.org/pypi/pact-python-cli"><img
|
|
54
|
+
src="https://img.shields.io/pypi/l/pact-python-cli.svg"
|
|
55
|
+
alt="License"></a>
|
|
56
|
+
</td>
|
|
57
|
+
</tr>
|
|
58
|
+
<tr>
|
|
59
|
+
<td>Community</td>
|
|
60
|
+
<td>
|
|
61
|
+
<a
|
|
62
|
+
href="https://github.com/pact-foundation/pact-python/issues"><img
|
|
63
|
+
src="https://img.shields.io/github/issues/pact-foundation/pact-python.svg"
|
|
64
|
+
alt="Issues"></a>
|
|
65
|
+
<a
|
|
66
|
+
href="https://github.com/pact-foundation/pact-python/discussions"><img
|
|
67
|
+
src="https://img.shields.io/github/discussions/pact-foundation/pact-python.svg"
|
|
68
|
+
alt="Discussions"></a>
|
|
69
|
+
<a
|
|
70
|
+
href="https://github.com/pact-foundation/pact-python"><img
|
|
71
|
+
src="https://img.shields.io/github/stars/pact-foundation/pact-python.svg?style=flat"
|
|
72
|
+
alt="GitHub Stars"></a>
|
|
73
|
+
<br/>
|
|
74
|
+
<a
|
|
75
|
+
href="http://slack.pact.io"><img
|
|
76
|
+
src="https://img.shields.io/badge/slack-pact--foundation-4A154B.svg"
|
|
77
|
+
alt="Slack"></a>
|
|
78
|
+
<a
|
|
79
|
+
href="https://stackoverflow.com/questions/tagged/pact"><img
|
|
80
|
+
src="https://img.shields.io/badge/stackoverflow-pact-F48024.svg"
|
|
81
|
+
alt="Stack Overflow"></a>
|
|
82
|
+
<a
|
|
83
|
+
href="https://twitter.com/pact_up"><img
|
|
84
|
+
src="https://img.shields.io/badge/X-@pact__up-black.svg"
|
|
85
|
+
alt="Twitter"></a>
|
|
86
|
+
</td>
|
|
87
|
+
</tr>
|
|
88
|
+
</table></div>
|
|
89
|
+
<!-- markdownlint-enable no-inline-html -->
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
This sub-package is part of the [Pact Python](https://github.com/pact-foundation/pact-python) project and exists solely to distribute the [Pact CLI](https://github.com/pact-foundation/pact-standalone) as a Python package. If you are looking for the main Pact Python library for contract testing, please see the [root package](https://github.com/pact-foundation/pact-python#pact-python).
|
|
94
|
+
|
|
95
|
+
It is used by version 2 of Pact Python, and can be used to install the Pact CLI in Python environments.
|
|
96
|
+
|
|
97
|
+
The versionining of `pact-python-cli` is aligned with the Pact CLI versioning. For example, version `2.4.26.2` corresponds to Pact CLI version `2.4.26`, with the `.2` indicating that this is the third release of that Pact CLI version in the Python package (with the first release being `.0`).
|
|
98
|
+
|
|
99
|
+
## Installation
|
|
100
|
+
|
|
101
|
+
You can install this package via pip:
|
|
102
|
+
|
|
103
|
+
```console
|
|
104
|
+
pip install pact-python-cli
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Contributing
|
|
108
|
+
|
|
109
|
+
Contributions to this package are generally not required as it contains minimal Python functionality and generally only requires updating the version number. This is done by pushing a tag of the form `pact-python-cli/<version>` which will automatically trigger a release build in the CI pipeline.
|
|
110
|
+
|
|
111
|
+
To contribute to the Pact CLI itself, please refer to the [Pact Ruby Standalone repository](https://github.com/pact-foundation/pact-standalone).
|
|
112
|
+
|
|
113
|
+
For contributing to Pact Python, see the [main contributing guide](https://github.com/pact-foundation/pact-python/blob/main/CONTRIBUTING.md).
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
For questions or support, please visit the [Pact Foundation Slack](https://slack.pact.io) or [GitHub Discussions](https://github.com/pact-foundation/pact-python/discussions).
|
|
118
|
+
|
|
119
|
+
---
|
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Hatchling build hook.
|
|
3
|
+
|
|
4
|
+
This hook is responsible for downloading and packaging the Pact CLI.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import os
|
|
10
|
+
import shutil
|
|
11
|
+
import sys
|
|
12
|
+
import tarfile
|
|
13
|
+
import tempfile
|
|
14
|
+
import urllib.request
|
|
15
|
+
import zipfile
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
from typing import TYPE_CHECKING, Any
|
|
18
|
+
|
|
19
|
+
if TYPE_CHECKING:
|
|
20
|
+
from collections.abc import Mapping, MutableMapping, Sequence
|
|
21
|
+
|
|
22
|
+
from hatchling.builders.config import BuilderConfig
|
|
23
|
+
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
|
|
24
|
+
from packaging.tags import sys_tags
|
|
25
|
+
|
|
26
|
+
PKG_DIR = Path(__file__).parent.resolve() / "src" / "pact_cli"
|
|
27
|
+
|
|
28
|
+
# Remove when pact-standalone is removed
|
|
29
|
+
PACT_CLI_URL = "https://github.com/pact-foundation/pact-standalone/releases/download/v{version}/pact-{version}-{os}-{machine}.{ext}"
|
|
30
|
+
|
|
31
|
+
# Remove fixed version and infer from package metadata when pact-cli versioning
|
|
32
|
+
# is adopted.
|
|
33
|
+
PACT_RUST_CLI_VERSION = "0.9.5"
|
|
34
|
+
PACT_RUST_CLI_URL = "https://github.com/pact-foundation/pact-cli/releases/download/v{version}/pact-{arch}-{os}{ext}"
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class UnsupportedPlatformError(RuntimeError):
|
|
38
|
+
"""
|
|
39
|
+
Custom error raised when the current platform is not supported.
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
def __init__(self, platform: str) -> None:
|
|
43
|
+
"""
|
|
44
|
+
Initialize the exception.
|
|
45
|
+
|
|
46
|
+
Args:
|
|
47
|
+
platform:
|
|
48
|
+
The unsupported platform.
|
|
49
|
+
"""
|
|
50
|
+
self.platform = platform
|
|
51
|
+
super().__init__(f"Unsupported platform {platform}")
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class PactCliBuildHook(BuildHookInterface[BuilderConfig]):
|
|
55
|
+
"""
|
|
56
|
+
Custom hook to download Pact CLI binaries.
|
|
57
|
+
|
|
58
|
+
This build hook is invoked by Hatch during the build process. Within
|
|
59
|
+
`pyproject.toml`, it takes the special name of `custom` (despite the name
|
|
60
|
+
below).
|
|
61
|
+
|
|
62
|
+
For more references, see [Build hook
|
|
63
|
+
plugins](https://hatch.pypa.io/1.3/plugins/build-hook/reference/).
|
|
64
|
+
"""
|
|
65
|
+
|
|
66
|
+
PLUGIN_NAME = "pact-cli"
|
|
67
|
+
|
|
68
|
+
def __init__(self, *args: Any, **kwargs: Any) -> None: # noqa: ANN401
|
|
69
|
+
"""
|
|
70
|
+
Initialize the build hook.
|
|
71
|
+
|
|
72
|
+
For this hook, we additionally define the lib extension based on the
|
|
73
|
+
current platform.
|
|
74
|
+
"""
|
|
75
|
+
super().__init__(*args, **kwargs)
|
|
76
|
+
self.tmpdir = Path(tempfile.TemporaryDirectory().name)
|
|
77
|
+
self.tmpdir.mkdir(parents=True, exist_ok=True)
|
|
78
|
+
|
|
79
|
+
def __del__(self) -> None:
|
|
80
|
+
"""
|
|
81
|
+
Clean up temporary files.
|
|
82
|
+
"""
|
|
83
|
+
shutil.rmtree(self.tmpdir, ignore_errors=True)
|
|
84
|
+
|
|
85
|
+
def clean(self, versions: Sequence[str]) -> None: # noqa: ARG002
|
|
86
|
+
"""
|
|
87
|
+
Code called to clean.
|
|
88
|
+
|
|
89
|
+
This is called by `hatch clean` or when the `-c`/`--clean` flag is
|
|
90
|
+
passed to `hatch build`.
|
|
91
|
+
"""
|
|
92
|
+
for subdir in ["bin", "lib", "data"]:
|
|
93
|
+
# TODO(epoch-transition): Remove "lib" when standalone dropped # noqa: TD003
|
|
94
|
+
shutil.rmtree(PKG_DIR / subdir, ignore_errors=True)
|
|
95
|
+
|
|
96
|
+
def initialize(
|
|
97
|
+
self,
|
|
98
|
+
version: str, # noqa: ARG002
|
|
99
|
+
build_data: MutableMapping[str, object],
|
|
100
|
+
) -> None:
|
|
101
|
+
"""
|
|
102
|
+
Code called immediately before each build.
|
|
103
|
+
|
|
104
|
+
The CLI version is inferred from the package metadata. Specifically, the
|
|
105
|
+
first three segments of the version string are used.
|
|
106
|
+
|
|
107
|
+
Args:
|
|
108
|
+
version:
|
|
109
|
+
Not used (but required by the parent class).
|
|
110
|
+
|
|
111
|
+
build_data:
|
|
112
|
+
A mutable mapping to modify in-place used by Hatch when creating
|
|
113
|
+
the final wheel.
|
|
114
|
+
|
|
115
|
+
Raises:
|
|
116
|
+
UnsupportedPlatformError:
|
|
117
|
+
If the CLI cannot be built (presumably due to an
|
|
118
|
+
incompatible platform).
|
|
119
|
+
"""
|
|
120
|
+
cli_version = ".".join(self.metadata.version.split(".")[:3])
|
|
121
|
+
if not cli_version:
|
|
122
|
+
msg = "Failed to determine Pact CLI version."
|
|
123
|
+
self.app.display_error(msg)
|
|
124
|
+
raise ValueError(msg)
|
|
125
|
+
|
|
126
|
+
try:
|
|
127
|
+
force_include = self._install_ruby_cli(cli_version)
|
|
128
|
+
except UnsupportedPlatformError as err:
|
|
129
|
+
# The Ruby standalone is deprecated and not available on all
|
|
130
|
+
# platforms (e.g. Windows ARM). Warn and continue rather than
|
|
131
|
+
# failing the build.
|
|
132
|
+
self.app.display_warning(
|
|
133
|
+
f"Pact Ruby standalone CLI not available for {err.platform}; skipping."
|
|
134
|
+
)
|
|
135
|
+
force_include = {}
|
|
136
|
+
|
|
137
|
+
try:
|
|
138
|
+
force_include = {**force_include, **self._install_rust_cli()}
|
|
139
|
+
except UnsupportedPlatformError as err:
|
|
140
|
+
msg = f"Pact CLI is not available for {err.platform}."
|
|
141
|
+
self.app.display_error(msg)
|
|
142
|
+
raise
|
|
143
|
+
|
|
144
|
+
build_data["force_include"] = force_include
|
|
145
|
+
build_data["tag"] = self._infer_tag()
|
|
146
|
+
|
|
147
|
+
def _sys_tag_platform(self) -> str:
|
|
148
|
+
"""
|
|
149
|
+
Get the platform tag from the current system tags.
|
|
150
|
+
|
|
151
|
+
This is used to determine the target platform for the Pact binaries.
|
|
152
|
+
"""
|
|
153
|
+
return next(t.platform for t in sys_tags())
|
|
154
|
+
|
|
155
|
+
def _install_ruby_cli(self, version: str) -> Mapping[str, str]:
|
|
156
|
+
"""
|
|
157
|
+
Install the Pact Ruby standalone binaries.
|
|
158
|
+
|
|
159
|
+
The binaries are installed in `src/pact_cli/bin`, and the relevant
|
|
160
|
+
version for the current operating system is determined automatically.
|
|
161
|
+
|
|
162
|
+
Args:
|
|
163
|
+
version:
|
|
164
|
+
The Pact CLI version to install.
|
|
165
|
+
|
|
166
|
+
Returns:
|
|
167
|
+
A mapping of `src` to `dst` to be used by Hatch when creating the
|
|
168
|
+
wheel. Each `src` is a full path in the current filesystem, and the
|
|
169
|
+
`dst` is the corresponding path within the wheel.
|
|
170
|
+
"""
|
|
171
|
+
url = self._pact_ruby_bin_url(version)
|
|
172
|
+
artefact = self._download(url)
|
|
173
|
+
self._extract(artefact)
|
|
174
|
+
return {
|
|
175
|
+
str(PKG_DIR / "bin"): "pact_cli/bin",
|
|
176
|
+
str(PKG_DIR / "lib"): "pact_cli/lib",
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
def _pact_ruby_bin_url(self, version: str) -> str:
|
|
180
|
+
"""
|
|
181
|
+
Generate the download URL for the Pact Ruby binaries.
|
|
182
|
+
|
|
183
|
+
Args:
|
|
184
|
+
version:
|
|
185
|
+
The Pact CLI version to download.
|
|
186
|
+
|
|
187
|
+
Returns:
|
|
188
|
+
The URL to download the Pact Ruby binaries from. If the platform is
|
|
189
|
+
not supported, the resulting URL may be invalid.
|
|
190
|
+
"""
|
|
191
|
+
platform = self._sys_tag_platform()
|
|
192
|
+
|
|
193
|
+
if platform.startswith("macosx"):
|
|
194
|
+
os_name = "osx"
|
|
195
|
+
ext = "tar.gz"
|
|
196
|
+
elif "linux" in platform:
|
|
197
|
+
os_name = "linux"
|
|
198
|
+
ext = "tar.gz"
|
|
199
|
+
elif platform.startswith("win"):
|
|
200
|
+
if platform.endswith(("arm64", "aarch64")):
|
|
201
|
+
# The Ruby standalone has no Windows ARM release.
|
|
202
|
+
raise UnsupportedPlatformError(platform)
|
|
203
|
+
os_name = "windows"
|
|
204
|
+
ext = "zip"
|
|
205
|
+
else:
|
|
206
|
+
raise UnsupportedPlatformError(platform)
|
|
207
|
+
|
|
208
|
+
if platform.endswith(("arm64", "aarch64")):
|
|
209
|
+
machine = "arm64"
|
|
210
|
+
elif platform.endswith(("x86_64", "amd64")):
|
|
211
|
+
machine = "x86_64"
|
|
212
|
+
else:
|
|
213
|
+
raise UnsupportedPlatformError(platform)
|
|
214
|
+
|
|
215
|
+
return PACT_CLI_URL.format(
|
|
216
|
+
version=version,
|
|
217
|
+
os=os_name,
|
|
218
|
+
machine=machine,
|
|
219
|
+
ext=ext,
|
|
220
|
+
)
|
|
221
|
+
|
|
222
|
+
def _pact_rust_bin_url(self, version: str) -> str:
|
|
223
|
+
"""
|
|
224
|
+
Generate the download URL for the Rust pact binary from pact-cli.
|
|
225
|
+
|
|
226
|
+
The pact-cli release assets are plain binaries (not archives) named
|
|
227
|
+
``pact-{arch}-{os}`` (e.g. ``pact-aarch64-macos``), with ``.exe``
|
|
228
|
+
appended on Windows.
|
|
229
|
+
|
|
230
|
+
Args:
|
|
231
|
+
version:
|
|
232
|
+
The pact-cli version to download.
|
|
233
|
+
|
|
234
|
+
Returns:
|
|
235
|
+
The URL to the pact binary asset.
|
|
236
|
+
|
|
237
|
+
Raises:
|
|
238
|
+
UnsupportedPlatformError:
|
|
239
|
+
If the current platform's OS or architecture is not recognised.
|
|
240
|
+
"""
|
|
241
|
+
platform = self._sys_tag_platform()
|
|
242
|
+
|
|
243
|
+
if platform.startswith("macosx"):
|
|
244
|
+
os_name = "macos"
|
|
245
|
+
ext = ""
|
|
246
|
+
elif "linux" in platform:
|
|
247
|
+
# musl-based Linux targets (e.g. Alpine) are not distinguished;
|
|
248
|
+
# the linux-gnu binary is used for all Linux targets.
|
|
249
|
+
os_name = "linux-gnu"
|
|
250
|
+
ext = ""
|
|
251
|
+
elif platform.startswith("win"):
|
|
252
|
+
os_name = "windows-msvc"
|
|
253
|
+
ext = ".exe"
|
|
254
|
+
else:
|
|
255
|
+
raise UnsupportedPlatformError(platform)
|
|
256
|
+
|
|
257
|
+
if platform.endswith(("arm64", "aarch64")):
|
|
258
|
+
arch = "aarch64"
|
|
259
|
+
elif platform.endswith(("x86_64", "amd64")):
|
|
260
|
+
arch = "x86_64"
|
|
261
|
+
else:
|
|
262
|
+
raise UnsupportedPlatformError(platform)
|
|
263
|
+
|
|
264
|
+
return PACT_RUST_CLI_URL.format(
|
|
265
|
+
version=version,
|
|
266
|
+
arch=arch,
|
|
267
|
+
os=os_name,
|
|
268
|
+
ext=ext,
|
|
269
|
+
)
|
|
270
|
+
|
|
271
|
+
def _install_rust_cli(self) -> Mapping[str, str]:
|
|
272
|
+
"""
|
|
273
|
+
Install the Rust pact binary from pact-cli.
|
|
274
|
+
|
|
275
|
+
Overwrites the `pact` binary bundled with pact-standalone.
|
|
276
|
+
|
|
277
|
+
The binary is downloaded from the pact-cli GitHub release as a plain
|
|
278
|
+
executable (not an archive) and placed in `bin/` as `pact`
|
|
279
|
+
(or `pact.exe` on Windows).
|
|
280
|
+
"""
|
|
281
|
+
url = self._pact_rust_bin_url(PACT_RUST_CLI_VERSION)
|
|
282
|
+
artefact = self._download(url)
|
|
283
|
+
|
|
284
|
+
bin_name = "pact.exe" if sys.platform == "win32" else "pact"
|
|
285
|
+
dest = PKG_DIR / "bin" / bin_name
|
|
286
|
+
dest.parent.mkdir(parents=True, exist_ok=True)
|
|
287
|
+
shutil.copy2(artefact, dest)
|
|
288
|
+
if sys.platform != "win32":
|
|
289
|
+
dest.chmod(0o755)
|
|
290
|
+
|
|
291
|
+
return {str(PKG_DIR / "bin"): "pact_cli/bin"}
|
|
292
|
+
|
|
293
|
+
def _extract(self, artefact: Path) -> None:
|
|
294
|
+
"""
|
|
295
|
+
Extract the Pact binaries.
|
|
296
|
+
|
|
297
|
+
The binaries in the `bin` directory require the underlying Ruby runtime
|
|
298
|
+
to be present, which is included in the `lib` directory.
|
|
299
|
+
|
|
300
|
+
Args:
|
|
301
|
+
artefact:
|
|
302
|
+
The path to the downloaded artefact.
|
|
303
|
+
"""
|
|
304
|
+
if str(artefact).endswith(".zip"):
|
|
305
|
+
with zipfile.ZipFile(artefact) as f:
|
|
306
|
+
f.extractall(self.tmpdir) # noqa: S202
|
|
307
|
+
|
|
308
|
+
if str(artefact).endswith(".tar.gz"):
|
|
309
|
+
with tarfile.open(artefact) as f:
|
|
310
|
+
f.extractall(self.tmpdir) # noqa: S202
|
|
311
|
+
|
|
312
|
+
for d in ["bin", "lib"]:
|
|
313
|
+
if (PKG_DIR / d).is_dir():
|
|
314
|
+
shutil.rmtree(PKG_DIR / d)
|
|
315
|
+
shutil.copytree(
|
|
316
|
+
Path(self.tmpdir) / "pact" / d,
|
|
317
|
+
PKG_DIR / d,
|
|
318
|
+
)
|
|
319
|
+
|
|
320
|
+
def _download(self, url: str) -> Path:
|
|
321
|
+
"""
|
|
322
|
+
Download the target URL.
|
|
323
|
+
|
|
324
|
+
This will download the target URL to the `src/pact_cli/data` directory.
|
|
325
|
+
If the download artefact is already present, the existing artefact's
|
|
326
|
+
path will be returned without downloading it again.
|
|
327
|
+
|
|
328
|
+
Args:
|
|
329
|
+
url:
|
|
330
|
+
The URL to download
|
|
331
|
+
|
|
332
|
+
Returns:
|
|
333
|
+
The path to the downloaded artefact.
|
|
334
|
+
"""
|
|
335
|
+
filename = url.rsplit("/", maxsplit=1)[-1]
|
|
336
|
+
artefact = PKG_DIR / "data" / filename
|
|
337
|
+
artefact.parent.mkdir(parents=True, exist_ok=True)
|
|
338
|
+
|
|
339
|
+
if not artefact.exists():
|
|
340
|
+
urllib.request.urlretrieve(url, artefact) # noqa: S310
|
|
341
|
+
return artefact
|
|
342
|
+
|
|
343
|
+
def _infer_tag(self) -> str:
|
|
344
|
+
"""
|
|
345
|
+
Infer the tag for the current build.
|
|
346
|
+
|
|
347
|
+
Since we have a pure Python wrapper around a binary CLI, we are not
|
|
348
|
+
tied to any specific Python version or ABI. As a result, we generate
|
|
349
|
+
`py3-none-{platform}` tags for the wheels.
|
|
350
|
+
"""
|
|
351
|
+
platform = self._sys_tag_platform()
|
|
352
|
+
|
|
353
|
+
# On macOS, the version needs to be set based on the deployment target
|
|
354
|
+
# (i.e., the version of the system libraries).
|
|
355
|
+
if sys.platform == "darwin" and (
|
|
356
|
+
deployment_target := os.environ.get("MACOSX_DEPLOYMENT_TARGET")
|
|
357
|
+
):
|
|
358
|
+
target = deployment_target.replace(".", "_")
|
|
359
|
+
if platform.endswith("_arm64"):
|
|
360
|
+
platform = f"macosx_{target}_arm64"
|
|
361
|
+
elif platform.endswith("_x86_64"):
|
|
362
|
+
platform = f"macosx_{target}_x86_64"
|
|
363
|
+
else:
|
|
364
|
+
raise UnsupportedPlatformError(platform)
|
|
365
|
+
|
|
366
|
+
return f"py3-none-{platform}"
|