pact-python-cli 0.0.0__tar.gz → 2.4.26.2__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/.gitignore +4 -0
- pact_python_cli-2.4.26.2/LICENSE +21 -0
- pact_python_cli-2.4.26.2/PKG-INFO +41 -0
- pact_python_cli-2.4.26.2/README.md +32 -0
- pact_python_cli-2.4.26.2/cliff.toml +113 -0
- pact_python_cli-2.4.26.2/hatch_build.py +225 -0
- pact_python_cli-2.4.26.2/pyproject.toml +203 -0
- pact_python_cli-2.4.26.2/src/pact_cli/.gitkeep +0 -0
- pact_python_cli-2.4.26.2/src/pact_cli/__init__.py +162 -0
- pact_python_cli-2.4.26.2/src/pact_cli/__version__.py +21 -0
- pact_python_cli-2.4.26.2/src/pact_cli/py.typed +0 -0
- pact_python_cli-2.4.26.2/tests/.ruff.toml +10 -0
- pact_python_cli-2.4.26.2/tests/test_init.py +175 -0
- pact_python_cli-0.0.0/PKG-INFO +0 -7
- pact_python_cli-0.0.0/pact_python_cli.egg-info/PKG-INFO +0 -7
- pact_python_cli-0.0.0/pact_python_cli.egg-info/SOURCES.txt +0 -5
- pact_python_cli-0.0.0/pact_python_cli.egg-info/dependency_links.txt +0 -1
- pact_python_cli-0.0.0/pact_python_cli.egg-info/top_level.txt +0 -1
- pact_python_cli-0.0.0/pyproject.toml +0 -10
- pact_python_cli-0.0.0/setup.cfg +0 -4
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Pact Foundation
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pact-python-cli
|
|
3
|
+
Version: 2.4.26.2
|
|
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
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
15
|
+
Classifier: Environment :: Console
|
|
16
|
+
Classifier: Intended Audience :: Developers
|
|
17
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
18
|
+
Classifier: Operating System :: MacOS :: MacOS X
|
|
19
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
20
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
21
|
+
Classifier: Programming Language :: Python
|
|
22
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
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: Topic :: Software Development :: Testing
|
|
29
|
+
Requires-Python: >=3.9
|
|
30
|
+
Provides-Extra: devel
|
|
31
|
+
Requires-Dist: mypy==1.17.0; extra == 'devel'
|
|
32
|
+
Requires-Dist: pytest-cov~=6.0; extra == 'devel'
|
|
33
|
+
Requires-Dist: pytest-mock~=3.0; extra == 'devel'
|
|
34
|
+
Requires-Dist: pytest~=8.0; extra == 'devel'
|
|
35
|
+
Requires-Dist: ruff==0.12.4; extra == 'devel'
|
|
36
|
+
Provides-Extra: devel-test
|
|
37
|
+
Requires-Dist: pytest-cov~=6.0; extra == 'devel-test'
|
|
38
|
+
Requires-Dist: pytest-mock~=3.0; extra == 'devel-test'
|
|
39
|
+
Requires-Dist: pytest~=8.0; extra == 'devel-test'
|
|
40
|
+
Provides-Extra: devel-types
|
|
41
|
+
Requires-Dist: mypy==1.17.0; extra == 'devel-types'
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
---
|
|
9
|
+
|
|
10
|
+
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-ruby-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).
|
|
11
|
+
|
|
12
|
+
It is used by version 2 of Pact Python, and can be used to install the Pact CLI in Python environments.
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
You can install this package via pip:
|
|
17
|
+
|
|
18
|
+
```console
|
|
19
|
+
pip install pact-python-cli
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Contributing
|
|
23
|
+
|
|
24
|
+
Contributions to this package are generally not required as it contains minimal Python functionality and generally only requires updating the version number. To contribute to the Pact CLI itself, please refer to the [Pact Ruby Standalone repository](https://github.com/pact-foundation/pact-ruby-standalone).
|
|
25
|
+
|
|
26
|
+
For contributing to Pact Python, see the [main contributing guide](https://github.com/pact-foundation/pact-python/blob/main/CONTRIBUTING.md).
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
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).
|
|
31
|
+
|
|
32
|
+
---
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
#:schema https://json.schemastore.org/any.json
|
|
2
|
+
# git-cliff ~ default configuration file
|
|
3
|
+
# https://git-cliff.org/docs/configuration
|
|
4
|
+
|
|
5
|
+
[changelog]
|
|
6
|
+
# template for the changelog header
|
|
7
|
+
header = """
|
|
8
|
+
# Pact Python CLI Changelog
|
|
9
|
+
|
|
10
|
+
All notable changes to this project will be documented in this file.
|
|
11
|
+
|
|
12
|
+
Note that this _only_ includes changes to the Python re-packaging of the Pact CLI. For changes to the Pact CLI itself, see the [Pact CLI changelog](https://github.com/pact-foundation/pact-ruby-standalone/blob/master/CHANGELOG.md).
|
|
13
|
+
|
|
14
|
+
<!-- markdownlint-disable no-duplicate-heading -->
|
|
15
|
+
<!-- markdownlint-disable emph-style -->
|
|
16
|
+
<!-- markdownlint-disable strong-style -->
|
|
17
|
+
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
# template for the changelog body
|
|
21
|
+
# https://keats.github.io/tera/docs/#introduction
|
|
22
|
+
body = """
|
|
23
|
+
{% if version %}\
|
|
24
|
+
## [{{ version | trim_start_matches(pat="v") }}] _{{ timestamp | date(format="%Y-%m-%d") }}_
|
|
25
|
+
{% else %}\
|
|
26
|
+
## [unreleased]
|
|
27
|
+
{% endif %}\
|
|
28
|
+
{% for group, commits in commits | group_by(attribute="group") %}
|
|
29
|
+
### {{ group | striptags | trim | upper_first }}
|
|
30
|
+
{% for commit in commits %}
|
|
31
|
+
- {% if commit.scope %}_({{ commit.scope }})_ {% endif %}\
|
|
32
|
+
{% if commit.breaking %}[**breaking**] {% endif %}\
|
|
33
|
+
{{ commit.message | upper_first }}\
|
|
34
|
+
{% if commit.breaking and commit.breaking_description %}
|
|
35
|
+
{{ " " }}\
|
|
36
|
+
> {{
|
|
37
|
+
commit.breaking_description
|
|
38
|
+
| split(pat="\n")
|
|
39
|
+
| join(sep=" ")
|
|
40
|
+
| replace(from=" ", to=" ")
|
|
41
|
+
| replace(from=" ", to=" ")
|
|
42
|
+
| replace(from=" ", to=" ")
|
|
43
|
+
| upper_first
|
|
44
|
+
}}\
|
|
45
|
+
{% endif %}\
|
|
46
|
+
{% endfor %}
|
|
47
|
+
{% endfor %}
|
|
48
|
+
{% if github.contributors %}\
|
|
49
|
+
### Contributors
|
|
50
|
+
{% for contributor in github.contributors %}\
|
|
51
|
+
{% if contributor.username and contributor.username is ending_with("[bot]") %}{% continue %}{% endif %}
|
|
52
|
+
- @{{ contributor.username }}\
|
|
53
|
+
{% endfor %}
|
|
54
|
+
{% endif %}
|
|
55
|
+
|
|
56
|
+
"""
|
|
57
|
+
|
|
58
|
+
# template for the changelog footer
|
|
59
|
+
footer = """\
|
|
60
|
+
<!-- generated by git-cliff on {{ now() | date(format="%Y-%m-%d") }}-->
|
|
61
|
+
"""
|
|
62
|
+
|
|
63
|
+
# remove the leading and trailing s
|
|
64
|
+
trim = true
|
|
65
|
+
# postprocessors
|
|
66
|
+
postprocessors = []
|
|
67
|
+
# render body even when there are no releases to process
|
|
68
|
+
# render_always = true
|
|
69
|
+
# output file path
|
|
70
|
+
output = "CHANGELOG.md"
|
|
71
|
+
|
|
72
|
+
[git]
|
|
73
|
+
tag_pattern = "pact-python-cli/.*"
|
|
74
|
+
# parse the commits based on https://www.conventionalcommits.org
|
|
75
|
+
conventional_commits = true
|
|
76
|
+
# filter out the commits that are not conventional
|
|
77
|
+
filter_unconventional = true
|
|
78
|
+
# process each line of a commit as an individual commit
|
|
79
|
+
split_commits = false
|
|
80
|
+
# regex for preprocessing the commit messages
|
|
81
|
+
commit_preprocessors = [
|
|
82
|
+
# Remove the PR number added by GitHub when merging PR in UI
|
|
83
|
+
{ pattern = '\s*\(#([0-9]+)\)$', replace = "" },
|
|
84
|
+
# Check spelling of the commit with https://github.com/crate-ci/typos
|
|
85
|
+
{ pattern = '.*', replace_command = 'typos --write-changes -' },
|
|
86
|
+
]
|
|
87
|
+
# regex for parsing and grouping commits
|
|
88
|
+
commit_parsers = [
|
|
89
|
+
# Ignore deps commits from the changelog
|
|
90
|
+
{ message = "^(chore|fix)\\(deps.*\\)", skip = true },
|
|
91
|
+
{ message = "^chore: update changelog.*", skip = true },
|
|
92
|
+
# Group commits by type
|
|
93
|
+
{ group = "<!-- 00 -->🚀 Features", message = "^feat" },
|
|
94
|
+
{ group = "<!-- 01 -->🐛 Bug Fixes", message = "^fix" },
|
|
95
|
+
{ group = "<!-- 50 -->🚜 Refactor", message = "^refactor" },
|
|
96
|
+
{ group = "<!-- 51 -->⚡ Performance", message = "^perf" },
|
|
97
|
+
{ group = "<!-- 52 -->🎨 Styling", message = "^style" },
|
|
98
|
+
{ group = "<!-- 60 -->📚 Documentation", message = "^docs" },
|
|
99
|
+
{ group = "<!-- 80 -->🧪 Testing", message = "^test" },
|
|
100
|
+
{ group = "<!-- 98 -->◀️ Revert", message = "^revert" },
|
|
101
|
+
{ group = "<!-- 99 -->⚙️ Miscellaneous Tasks", message = "^chore" },
|
|
102
|
+
{ group = "<!-- 99 -->� Other", message = ".*" },
|
|
103
|
+
]
|
|
104
|
+
# filter out the commits that are not matched by commit parsers
|
|
105
|
+
filter_commits = false
|
|
106
|
+
# sort the tags topologically
|
|
107
|
+
topo_order = false
|
|
108
|
+
# sort the commits inside sections by oldest/newest order
|
|
109
|
+
sort_commits = "oldest"
|
|
110
|
+
|
|
111
|
+
[remote.github]
|
|
112
|
+
owner = "pact-foundation"
|
|
113
|
+
repo = "pact-python"
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Hatchling build hook for binary downloads.
|
|
3
|
+
|
|
4
|
+
Pact Python is built on top of the Ruby Pact binaries and the Rust Pact library.
|
|
5
|
+
This build script downloads the binaries and library for the current platform
|
|
6
|
+
and installs them in the `pact` directory under `/bin` and `/lib`.
|
|
7
|
+
|
|
8
|
+
The version of the binaries and library can be controlled with the
|
|
9
|
+
`PACT_BIN_VERSION` and `PACT_LIB_VERSION` environment variables. If these are
|
|
10
|
+
not set, a pinned version will be used instead.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
import logging
|
|
16
|
+
import os
|
|
17
|
+
import shutil
|
|
18
|
+
import sys
|
|
19
|
+
import tarfile
|
|
20
|
+
import tempfile
|
|
21
|
+
import urllib.request
|
|
22
|
+
import zipfile
|
|
23
|
+
from pathlib import Path
|
|
24
|
+
from typing import Any
|
|
25
|
+
|
|
26
|
+
from hatchling.builders.config import BuilderConfig
|
|
27
|
+
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
|
|
28
|
+
from packaging.tags import sys_tags
|
|
29
|
+
|
|
30
|
+
logger = logging.getLogger(__name__)
|
|
31
|
+
|
|
32
|
+
EXE = ".exe" if os.name == "nt" else ""
|
|
33
|
+
PKG_DIR = Path(__file__).parent.resolve() / "src" / "pact_cli"
|
|
34
|
+
PACT_BIN_URL = "https://github.com/pact-foundation/pact-ruby-standalone/releases/download/v{version}/pact-{version}-{os}-{machine}.{ext}"
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class UnsupportedPlatformError(RuntimeError):
|
|
38
|
+
"""Raised when the current platform is not supported."""
|
|
39
|
+
|
|
40
|
+
def __init__(self, platform: str) -> None:
|
|
41
|
+
"""
|
|
42
|
+
Initialize the exception.
|
|
43
|
+
|
|
44
|
+
Args:
|
|
45
|
+
platform: The unsupported platform.
|
|
46
|
+
"""
|
|
47
|
+
self.platform = platform
|
|
48
|
+
super().__init__(f"Unsupported platform {platform}")
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class PactCliBuildHook(BuildHookInterface[BuilderConfig]):
|
|
52
|
+
"""Custom hook to download Pact binaries."""
|
|
53
|
+
|
|
54
|
+
PLUGIN_NAME = "pact-cli"
|
|
55
|
+
|
|
56
|
+
def __init__(self, *args: object, **kwargs: object) -> None:
|
|
57
|
+
"""
|
|
58
|
+
Initialize the build hook.
|
|
59
|
+
|
|
60
|
+
For this hook, we additionally define the lib extension based on the
|
|
61
|
+
current platform.
|
|
62
|
+
"""
|
|
63
|
+
super().__init__(*args, **kwargs)
|
|
64
|
+
self.tmpdir = Path(tempfile.TemporaryDirectory().name)
|
|
65
|
+
|
|
66
|
+
def clean(self, versions: list[str]) -> None: # noqa: ARG002
|
|
67
|
+
"""Clean up any files created by the build hook."""
|
|
68
|
+
for subdir in ["bin", "lib", "data"]:
|
|
69
|
+
shutil.rmtree(PKG_DIR / subdir, ignore_errors=True)
|
|
70
|
+
|
|
71
|
+
def initialize(
|
|
72
|
+
self,
|
|
73
|
+
version: str, # noqa: ARG002
|
|
74
|
+
build_data: dict[str, Any],
|
|
75
|
+
) -> None:
|
|
76
|
+
"""Hook into Hatchling's build process."""
|
|
77
|
+
cli_version = ".".join(self.metadata.version.split(".")[:3])
|
|
78
|
+
if not cli_version:
|
|
79
|
+
self.app.display_error("Failed to determine Pact CLI version.")
|
|
80
|
+
|
|
81
|
+
try:
|
|
82
|
+
self._pact_bin_install(cli_version)
|
|
83
|
+
except UnsupportedPlatformError as err:
|
|
84
|
+
msg = f"Pact CLI is not available for {err.platform}."
|
|
85
|
+
logger.exception(msg, RuntimeWarning, stacklevel=2)
|
|
86
|
+
|
|
87
|
+
build_data["tag"] = self._infer_tag()
|
|
88
|
+
|
|
89
|
+
def _sys_tag_platform(self) -> str:
|
|
90
|
+
"""
|
|
91
|
+
Get the platform tag from the current system tags.
|
|
92
|
+
|
|
93
|
+
This is used to determine the target platform for the Pact binaries.
|
|
94
|
+
"""
|
|
95
|
+
return next(t.platform for t in sys_tags())
|
|
96
|
+
|
|
97
|
+
def _pact_bin_install(self, version: str) -> None:
|
|
98
|
+
"""
|
|
99
|
+
Install the Pact standalone binaries.
|
|
100
|
+
|
|
101
|
+
The binaries are installed in `src/pact_cli/bin`, and the relevant
|
|
102
|
+
version for the current operating system is determined automatically.
|
|
103
|
+
|
|
104
|
+
Args:
|
|
105
|
+
version:
|
|
106
|
+
The Pact CLI version to install.
|
|
107
|
+
"""
|
|
108
|
+
url = self._pact_bin_url(version)
|
|
109
|
+
artifact = self._download(url)
|
|
110
|
+
self._pact_bin_extract(artifact)
|
|
111
|
+
|
|
112
|
+
def _pact_bin_url(self, version: str) -> str:
|
|
113
|
+
"""
|
|
114
|
+
Generate the download URL for the Pact binaries.
|
|
115
|
+
|
|
116
|
+
Args:
|
|
117
|
+
version:
|
|
118
|
+
The Pact CLI version to download.
|
|
119
|
+
|
|
120
|
+
Returns:
|
|
121
|
+
The URL to download the Pact binaries from. If the platform is not
|
|
122
|
+
supported, the resulting URL may be invalid.
|
|
123
|
+
"""
|
|
124
|
+
platform = self._sys_tag_platform()
|
|
125
|
+
|
|
126
|
+
if platform.startswith("macosx"):
|
|
127
|
+
os = "osx"
|
|
128
|
+
ext = "tar.gz"
|
|
129
|
+
elif "linux" in platform:
|
|
130
|
+
os = "linux"
|
|
131
|
+
ext = "tar.gz"
|
|
132
|
+
elif platform.startswith("win"):
|
|
133
|
+
os = "windows"
|
|
134
|
+
ext = "zip"
|
|
135
|
+
else:
|
|
136
|
+
raise UnsupportedPlatformError(platform)
|
|
137
|
+
|
|
138
|
+
if platform.endswith(("arm64", "aarch64")):
|
|
139
|
+
machine = "arm64"
|
|
140
|
+
elif platform.endswith(("x86_64", "amd64")):
|
|
141
|
+
machine = "x86_64"
|
|
142
|
+
elif platform.endswith(("i386", "i686", "x86", "win32")):
|
|
143
|
+
machine = "x86"
|
|
144
|
+
else:
|
|
145
|
+
raise UnsupportedPlatformError(platform)
|
|
146
|
+
|
|
147
|
+
return PACT_BIN_URL.format(
|
|
148
|
+
version=version,
|
|
149
|
+
os=os,
|
|
150
|
+
machine=machine,
|
|
151
|
+
ext=ext,
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
def _pact_bin_extract(self, artifact: Path) -> None:
|
|
155
|
+
"""
|
|
156
|
+
Extract the Pact binaries.
|
|
157
|
+
|
|
158
|
+
The binaries in the `bin` directory require the underlying Ruby runtime
|
|
159
|
+
to be present, which is included in the `lib` directory.
|
|
160
|
+
|
|
161
|
+
Args:
|
|
162
|
+
artifact: The path to the downloaded artifact.
|
|
163
|
+
"""
|
|
164
|
+
if str(artifact).endswith(".zip"):
|
|
165
|
+
with zipfile.ZipFile(artifact) as f:
|
|
166
|
+
f.extractall(self.tmpdir) # noqa: S202
|
|
167
|
+
|
|
168
|
+
if str(artifact).endswith(".tar.gz"):
|
|
169
|
+
with tarfile.open(artifact) as f:
|
|
170
|
+
f.extractall(self.tmpdir) # noqa: S202
|
|
171
|
+
|
|
172
|
+
for d in ["bin", "lib"]:
|
|
173
|
+
if (PKG_DIR / d).is_dir():
|
|
174
|
+
shutil.rmtree(PKG_DIR / d)
|
|
175
|
+
shutil.copytree(
|
|
176
|
+
Path(self.tmpdir) / "pact" / d,
|
|
177
|
+
PKG_DIR / d,
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
def _download(self, url: str) -> Path:
|
|
181
|
+
"""
|
|
182
|
+
Download the target URL.
|
|
183
|
+
|
|
184
|
+
This will download the target URL to the `pact/data` directory. If the
|
|
185
|
+
download artifact is already present, its path will be returned.
|
|
186
|
+
|
|
187
|
+
Args:
|
|
188
|
+
url: The URL to download
|
|
189
|
+
|
|
190
|
+
Return:
|
|
191
|
+
The path to the downloaded artifact.
|
|
192
|
+
"""
|
|
193
|
+
filename = url.split("/")[-1]
|
|
194
|
+
artifact = PKG_DIR / "data" / filename
|
|
195
|
+
artifact.parent.mkdir(parents=True, exist_ok=True)
|
|
196
|
+
|
|
197
|
+
if not artifact.exists():
|
|
198
|
+
urllib.request.urlretrieve(url, artifact) # noqa: S310
|
|
199
|
+
|
|
200
|
+
return artifact
|
|
201
|
+
|
|
202
|
+
def _infer_tag(self) -> str:
|
|
203
|
+
"""
|
|
204
|
+
Infer the tag for the current build.
|
|
205
|
+
|
|
206
|
+
Since we have a pure Python wrapper around a binary CLI, we are not
|
|
207
|
+
tied to any specific Python version or ABI. As a result, we generate
|
|
208
|
+
`py3-none-{platform}` tags for the wheels.
|
|
209
|
+
"""
|
|
210
|
+
platform = self._sys_tag_platform()
|
|
211
|
+
|
|
212
|
+
# On macOS, the version needs to be set based on the deployment target
|
|
213
|
+
# (i.e., the version of the system libraries).
|
|
214
|
+
if sys.platform == "darwin" and (
|
|
215
|
+
deployment_target := os.environ.get("MACOSX_DEPLOYMENT_TARGET")
|
|
216
|
+
):
|
|
217
|
+
target = deployment_target.replace(".", "_")
|
|
218
|
+
if platform.endswith("_arm64"):
|
|
219
|
+
platform = f"macosx_{target}_arm64"
|
|
220
|
+
elif platform.endswith("_x86_64"):
|
|
221
|
+
platform = f"macosx_{target}_x86_64"
|
|
222
|
+
else:
|
|
223
|
+
raise UnsupportedPlatformError(platform)
|
|
224
|
+
|
|
225
|
+
return f"py3-none-{platform}"
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
#:schema https://json.schemastore.org/pyproject.json
|
|
2
|
+
[project]
|
|
3
|
+
description = "Pact CLI bundle for Python"
|
|
4
|
+
name = "pact-python-cli"
|
|
5
|
+
|
|
6
|
+
dynamic = ["version"]
|
|
7
|
+
license = "MIT"
|
|
8
|
+
|
|
9
|
+
authors = [{ name = "Joshua Ellis", email = "josh@jpellis.me" }]
|
|
10
|
+
maintainers = [{ name = "Joshua Ellis", email = "josh@jpellis.me" }]
|
|
11
|
+
|
|
12
|
+
classifiers = [
|
|
13
|
+
"Development Status :: 5 - Production/Stable",
|
|
14
|
+
"Environment :: Console",
|
|
15
|
+
"Intended Audience :: Developers",
|
|
16
|
+
"License :: OSI Approved :: MIT License",
|
|
17
|
+
"Operating System :: MacOS :: MacOS X",
|
|
18
|
+
"Operating System :: Microsoft :: Windows",
|
|
19
|
+
"Operating System :: POSIX :: Linux",
|
|
20
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
21
|
+
"Programming Language :: Python :: 3.10",
|
|
22
|
+
"Programming Language :: Python :: 3.11",
|
|
23
|
+
"Programming Language :: Python :: 3.12",
|
|
24
|
+
"Programming Language :: Python :: 3.13",
|
|
25
|
+
"Programming Language :: Python :: 3.9",
|
|
26
|
+
"Programming Language :: Python",
|
|
27
|
+
"Topic :: Software Development :: Testing",
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
requires-python = ">=3.9"
|
|
31
|
+
|
|
32
|
+
[project.urls]
|
|
33
|
+
"Bug Tracker" = "https://github.com/pact-foundation/pact-python/issues"
|
|
34
|
+
"Changelog" = "https://github.com/pact-foundation/pact-python/blob/main/pact-python-cli/CHANGELOG.md"
|
|
35
|
+
"Documentation" = "https://docs.pact.io"
|
|
36
|
+
"Homepage" = "https://pact.io"
|
|
37
|
+
"Repository" = "https://github.com/pact-foundation/pact-python"
|
|
38
|
+
|
|
39
|
+
[project.scripts]
|
|
40
|
+
pact = "pact_cli:_exec"
|
|
41
|
+
pact-broker = "pact_cli:_exec"
|
|
42
|
+
pact-message = "pact_cli:_exec"
|
|
43
|
+
pact-mock-service = "pact_cli:_exec"
|
|
44
|
+
pact-plugin-cli = "pact_cli:_exec"
|
|
45
|
+
pact-provider-verifier = "pact_cli:_exec"
|
|
46
|
+
pact-stub-service = "pact_cli:_exec"
|
|
47
|
+
pactflow = "pact_cli:_exec"
|
|
48
|
+
|
|
49
|
+
[project.optional-dependencies]
|
|
50
|
+
# Linting and formatting tools use a more narrow specification to ensure
|
|
51
|
+
# developper consistency. All other dependencies are as above.
|
|
52
|
+
devel = [
|
|
53
|
+
"pact-python-cli[devel-test]",
|
|
54
|
+
"pact-python-cli[devel-types]",
|
|
55
|
+
"ruff==0.12.4",
|
|
56
|
+
]
|
|
57
|
+
devel-test = ["pytest-cov~=6.0", "pytest-mock~=3.0", "pytest~=8.0"]
|
|
58
|
+
devel-types = ["mypy==1.17.0"]
|
|
59
|
+
|
|
60
|
+
################################################################################
|
|
61
|
+
## Build System
|
|
62
|
+
################################################################################
|
|
63
|
+
[build-system]
|
|
64
|
+
build-backend = "hatchling.build"
|
|
65
|
+
requires = [
|
|
66
|
+
"hatch-vcs",
|
|
67
|
+
"hatchling",
|
|
68
|
+
"packaging",
|
|
69
|
+
# "setuptools ; python_version >= '3.12'",
|
|
70
|
+
]
|
|
71
|
+
|
|
72
|
+
[tool.hatch]
|
|
73
|
+
|
|
74
|
+
[tool.hatch.version]
|
|
75
|
+
source = "vcs"
|
|
76
|
+
tag-pattern = "^pact-python-cli/(?P<version>[vV]?\\d+(?:\\.\\d+)*)$"
|
|
77
|
+
|
|
78
|
+
[tool.hatch.version.raw-options]
|
|
79
|
+
git_describe_command = [
|
|
80
|
+
"git",
|
|
81
|
+
"describe",
|
|
82
|
+
"--tags",
|
|
83
|
+
"--dirty",
|
|
84
|
+
"--always",
|
|
85
|
+
"--long",
|
|
86
|
+
"--match",
|
|
87
|
+
"pact-python-cli/*",
|
|
88
|
+
]
|
|
89
|
+
root = ".."
|
|
90
|
+
version_scheme = "no-guess-dev"
|
|
91
|
+
|
|
92
|
+
[tool.hatch.build]
|
|
93
|
+
|
|
94
|
+
[tool.hatch.build.hooks.vcs]
|
|
95
|
+
version-file = "src/pact_cli/__version__.py"
|
|
96
|
+
|
|
97
|
+
[tool.hatch.build.targets.wheel]
|
|
98
|
+
artifacts = ["src/pact_cli/bin", "src/pact_cli/lib"]
|
|
99
|
+
packages = ["src/pact_cli"]
|
|
100
|
+
|
|
101
|
+
[tool.hatch.build.targets.wheel.hooks.custom]
|
|
102
|
+
patch = "hatch_build.py"
|
|
103
|
+
|
|
104
|
+
########################################
|
|
105
|
+
## Hatch Environment Configuration
|
|
106
|
+
########################################
|
|
107
|
+
[tool.hatch.envs]
|
|
108
|
+
|
|
109
|
+
# Install dev dependencies in the default environment to simplify the developer
|
|
110
|
+
# workflow.
|
|
111
|
+
[tool.hatch.envs.default]
|
|
112
|
+
extra-dependencies = [
|
|
113
|
+
"hatchling",
|
|
114
|
+
"packaging",
|
|
115
|
+
"requests",
|
|
116
|
+
"setuptools ; python_version >= '3.12'",
|
|
117
|
+
]
|
|
118
|
+
features = ["devel"]
|
|
119
|
+
installer = "uv"
|
|
120
|
+
|
|
121
|
+
[tool.hatch.envs.default.scripts]
|
|
122
|
+
all = ["format", "lint", "test", "typecheck"]
|
|
123
|
+
format = "ruff format {args}"
|
|
124
|
+
lint = "ruff check --show-fixes {args}"
|
|
125
|
+
test = "pytest tests/ {args}"
|
|
126
|
+
typecheck = ["typecheck-src", "typecheck-tests"]
|
|
127
|
+
typecheck-src = "mypy src/ {args}"
|
|
128
|
+
typecheck-tests = "mypy tests/ {args}"
|
|
129
|
+
|
|
130
|
+
# Test environment for running unit tests. This automatically tests against all
|
|
131
|
+
# supported Python versions.
|
|
132
|
+
[tool.hatch.envs.test]
|
|
133
|
+
features = ["devel-test"]
|
|
134
|
+
installer = "uv"
|
|
135
|
+
|
|
136
|
+
[[tool.hatch.envs.test.matrix]]
|
|
137
|
+
python = ["3.10", "3.11", "3.12", "3.13", "3.9"]
|
|
138
|
+
|
|
139
|
+
################################################################################
|
|
140
|
+
## PyTest Configuration
|
|
141
|
+
################################################################################
|
|
142
|
+
[tool.pytest]
|
|
143
|
+
|
|
144
|
+
[tool.pytest.ini_options]
|
|
145
|
+
addopts = [
|
|
146
|
+
"--import-mode=importlib",
|
|
147
|
+
# Coverage options
|
|
148
|
+
"--cov-config=pyproject.toml",
|
|
149
|
+
"--cov-report=xml",
|
|
150
|
+
"--cov=pact_cli",
|
|
151
|
+
]
|
|
152
|
+
|
|
153
|
+
log_date_format = "%H:%M:%S"
|
|
154
|
+
log_format = "%(asctime)s.%(msecs)03d [%(levelname)-8s] %(name)s: %(message)s"
|
|
155
|
+
log_level = "NOTSET"
|
|
156
|
+
|
|
157
|
+
################################################################################
|
|
158
|
+
## Coverage
|
|
159
|
+
################################################################################
|
|
160
|
+
[tool.coverage]
|
|
161
|
+
|
|
162
|
+
[tool.coverage.paths]
|
|
163
|
+
pact-cli = ["/src/pact_cli"]
|
|
164
|
+
tests = ["/tests"]
|
|
165
|
+
|
|
166
|
+
[tool.coverage.report]
|
|
167
|
+
exclude_lines = [
|
|
168
|
+
"@(abc\\.)?abstractmethod", # Ignore abstract methods
|
|
169
|
+
"if TYPE_CHECKING:", # Ignore typing
|
|
170
|
+
"if __name__ == .__main__.:", # Ignore non-runnable code
|
|
171
|
+
"raise NotImplementedError", # Ignore defensive assertions
|
|
172
|
+
]
|
|
173
|
+
|
|
174
|
+
################################################################################
|
|
175
|
+
## Ruff Configuration
|
|
176
|
+
################################################################################
|
|
177
|
+
[tool.ruff]
|
|
178
|
+
extend = "../pyproject.toml"
|
|
179
|
+
|
|
180
|
+
exclude = []
|
|
181
|
+
|
|
182
|
+
################################################################################
|
|
183
|
+
## Mypy Configuration
|
|
184
|
+
################################################################################
|
|
185
|
+
[tool.mypy]
|
|
186
|
+
# Overwrite the exclusions from the root pyproject.toml.
|
|
187
|
+
exclude = ''
|
|
188
|
+
|
|
189
|
+
################################################################################
|
|
190
|
+
## CI Build Wheel
|
|
191
|
+
################################################################################
|
|
192
|
+
[tool.cibuildwheel]
|
|
193
|
+
# The repair tool unfortunately did not like the bundled Ruby distributable,
|
|
194
|
+
# with false-positives missing libraries despite being bundled.
|
|
195
|
+
repair-wheel-command = ""
|
|
196
|
+
|
|
197
|
+
[[tool.cibuildwheel.overrides]]
|
|
198
|
+
environment.MACOSX_DEPLOYMENT_TARGET = "10.13"
|
|
199
|
+
select = "*-macosx_x86_64"
|
|
200
|
+
|
|
201
|
+
[[tool.cibuildwheel.overrides]]
|
|
202
|
+
environment.MACOSX_DEPLOYMENT_TARGET = "11.0"
|
|
203
|
+
select = "*-macosx_arm64"
|
|
File without changes
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Locate and provide paths to bundled or system Pact CLI executables.
|
|
3
|
+
|
|
4
|
+
This module exists solely to bundle and distribute the Pact CLI tools as a
|
|
5
|
+
Python package. It does not provide any substantive functionality beyond
|
|
6
|
+
locating the Pact CLI executables and providing their paths for use in Python
|
|
7
|
+
code.
|
|
8
|
+
|
|
9
|
+
The module exposes constants for the absolute paths to the Pact CLI executables (such as
|
|
10
|
+
`pact-broker`, `pact-message`, `pact-mock-service`, and `pact-provider-verifier`).
|
|
11
|
+
|
|
12
|
+
By default, the module will use the binaries bundled with the package. If the
|
|
13
|
+
environment variable `PACT_USE_SYSTEM_BINS` is set to `TRUE` or `YES`, or if the bundled
|
|
14
|
+
binaries are unavailable, it will fall back to using the system-installed Pact CLI tools
|
|
15
|
+
if found in the system PATH.
|
|
16
|
+
|
|
17
|
+
This package is intended for use as a dependency to ensure the Pact CLI is available in
|
|
18
|
+
Python environments, such as CI pipelines or local development, without requiring a
|
|
19
|
+
separate installation step.
|
|
20
|
+
|
|
21
|
+
For more information, see the project README or
|
|
22
|
+
https://github.com/pact-foundation/pact-python.
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
from __future__ import annotations
|
|
26
|
+
|
|
27
|
+
__author__ = "Pact Foundation"
|
|
28
|
+
__license__ = "MIT"
|
|
29
|
+
__url__ = "https://github.com/pact-foundation/pact-python"
|
|
30
|
+
|
|
31
|
+
import os
|
|
32
|
+
import shutil
|
|
33
|
+
import warnings
|
|
34
|
+
from pathlib import Path
|
|
35
|
+
|
|
36
|
+
from pact_cli.__version__ import (
|
|
37
|
+
__version__ as __version__,
|
|
38
|
+
)
|
|
39
|
+
from pact_cli.__version__ import (
|
|
40
|
+
__version_tuple__ as __version_tuple__,
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
_USE_SYSTEM_BINS = os.getenv("PACT_USE_SYSTEM_BINS", "").upper() in ("TRUE", "YES")
|
|
44
|
+
_BIN_DIR = Path(__file__).parent.resolve() / "bin"
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _exec() -> None:
|
|
48
|
+
"""
|
|
49
|
+
A minimal wrapper to execute the Pact CLI tools.
|
|
50
|
+
|
|
51
|
+
This is designed to be used as an entry point the scripts defined in the
|
|
52
|
+
`pyproject.toml` file. It simply passes the command line arguments to the
|
|
53
|
+
appropriate Pact CLI tool based on the executable name.
|
|
54
|
+
|
|
55
|
+
"""
|
|
56
|
+
import sys # noqa: PLC0415
|
|
57
|
+
|
|
58
|
+
command = Path(sys.argv[0]).name
|
|
59
|
+
args = sys.argv[1:] if len(sys.argv) > 1 else []
|
|
60
|
+
|
|
61
|
+
if command not in (
|
|
62
|
+
"pact",
|
|
63
|
+
"pact-broker",
|
|
64
|
+
"pact-message",
|
|
65
|
+
"pact-mock-service",
|
|
66
|
+
"pact-provider-verifier",
|
|
67
|
+
"pact-plugin-cli",
|
|
68
|
+
"pact-publish",
|
|
69
|
+
"pact-stub-service",
|
|
70
|
+
"pactflow",
|
|
71
|
+
):
|
|
72
|
+
print("Unknown command:", command, file=sys.stderr) # noqa: T201
|
|
73
|
+
sys.exit(1)
|
|
74
|
+
|
|
75
|
+
if not _USE_SYSTEM_BINS:
|
|
76
|
+
executable = _find_executable(command)
|
|
77
|
+
else:
|
|
78
|
+
# To avoid finding the same executable, we have to process the PATH
|
|
79
|
+
# variable and remove the current executable's directory.
|
|
80
|
+
script_dir = Path(sys.argv[0]).parent.resolve()
|
|
81
|
+
os.environ["PATH"] = os.pathsep.join(
|
|
82
|
+
p
|
|
83
|
+
for p in os.getenv("PATH", "").split(os.pathsep)
|
|
84
|
+
if Path(p).resolve() != script_dir
|
|
85
|
+
)
|
|
86
|
+
executable = _find_executable(command)
|
|
87
|
+
|
|
88
|
+
if not executable:
|
|
89
|
+
print(f"Command '{command}' not found.", file=sys.stderr) # noqa: T201
|
|
90
|
+
sys.exit(1)
|
|
91
|
+
|
|
92
|
+
os.execv(executable, [executable, *args]) # noqa: S606
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def _find_executable(executable: str) -> str | None:
|
|
96
|
+
"""
|
|
97
|
+
Find the path to an executable.
|
|
98
|
+
|
|
99
|
+
This inspects the environment variable `PACT_USE_SYSTEM_BINS` to determine
|
|
100
|
+
whether to use the bundled Pact binaries or the system ones. Note that if
|
|
101
|
+
the local executables are not found, this will fall back to the system
|
|
102
|
+
executables (if found).
|
|
103
|
+
|
|
104
|
+
Args:
|
|
105
|
+
executable:
|
|
106
|
+
The name of the executable to find without the extension. Python
|
|
107
|
+
will automatically append the correct extension for the current
|
|
108
|
+
platform.
|
|
109
|
+
|
|
110
|
+
Returns:
|
|
111
|
+
The absolute path to the executable.
|
|
112
|
+
|
|
113
|
+
Warns:
|
|
114
|
+
RuntimeWarning:
|
|
115
|
+
If the executable cannot be found in the system path.
|
|
116
|
+
"""
|
|
117
|
+
if _USE_SYSTEM_BINS:
|
|
118
|
+
bin_path = shutil.which(executable)
|
|
119
|
+
else:
|
|
120
|
+
bin_path = shutil.which(executable, path=_BIN_DIR)
|
|
121
|
+
if bin_path is None:
|
|
122
|
+
msg = f"Unable to find {executable} binary executable."
|
|
123
|
+
warnings.warn(msg, RuntimeWarning, stacklevel=2)
|
|
124
|
+
return bin_path
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
PACT_PATH = _find_executable("pact")
|
|
128
|
+
"""
|
|
129
|
+
Path to the Pact executable
|
|
130
|
+
"""
|
|
131
|
+
BROKER_PATH = _find_executable("pact-broker")
|
|
132
|
+
"""
|
|
133
|
+
Path to the Pact Broker executable
|
|
134
|
+
"""
|
|
135
|
+
BROKER_CLIENT_PATH = _find_executable("pact-broker")
|
|
136
|
+
"""
|
|
137
|
+
Path to the Pact Broker executable
|
|
138
|
+
"""
|
|
139
|
+
MESSAGE_PATH = _find_executable("pact-message")
|
|
140
|
+
"""
|
|
141
|
+
Path to the Pact Message executable
|
|
142
|
+
"""
|
|
143
|
+
MOCK_SERVICE_PATH = _find_executable("pact-mock-service")
|
|
144
|
+
"""
|
|
145
|
+
Path to the Pact Mock Service executable
|
|
146
|
+
"""
|
|
147
|
+
PLUGIN_CLI_PATH = _find_executable("pact-plugin-cli")
|
|
148
|
+
"""
|
|
149
|
+
Path to the Pact Plugin CLI executable
|
|
150
|
+
"""
|
|
151
|
+
VERIFIER_PATH = _find_executable("pact-provider-verifier")
|
|
152
|
+
"""
|
|
153
|
+
Path to the Pact Provider Verifier executable
|
|
154
|
+
"""
|
|
155
|
+
STUB_SERVICE_PATH = _find_executable("pact-stub-service")
|
|
156
|
+
"""
|
|
157
|
+
Path to the Pact Stub Service executable
|
|
158
|
+
"""
|
|
159
|
+
PACTFLOW_PATH = _find_executable("pactflow")
|
|
160
|
+
"""
|
|
161
|
+
Path to the PactFlow CLI executable
|
|
162
|
+
"""
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# file generated by setuptools-scm
|
|
2
|
+
# don't change, don't track in version control
|
|
3
|
+
|
|
4
|
+
__all__ = ["__version__", "__version_tuple__", "version", "version_tuple"]
|
|
5
|
+
|
|
6
|
+
TYPE_CHECKING = False
|
|
7
|
+
if TYPE_CHECKING:
|
|
8
|
+
from typing import Tuple
|
|
9
|
+
from typing import Union
|
|
10
|
+
|
|
11
|
+
VERSION_TUPLE = Tuple[Union[int, str], ...]
|
|
12
|
+
else:
|
|
13
|
+
VERSION_TUPLE = object
|
|
14
|
+
|
|
15
|
+
version: str
|
|
16
|
+
__version__: str
|
|
17
|
+
__version_tuple__: VERSION_TUPLE
|
|
18
|
+
version_tuple: VERSION_TUPLE
|
|
19
|
+
|
|
20
|
+
__version__ = version = '2.4.26.2'
|
|
21
|
+
__version_tuple__ = version_tuple = (2, 4, 26, 2)
|
|
File without changes
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#:schema https://json.schemastore.org/ruff.json
|
|
2
|
+
extend = "../pyproject.toml"
|
|
3
|
+
|
|
4
|
+
[lint]
|
|
5
|
+
ignore = [
|
|
6
|
+
"D103", # Require docstrings on public functions
|
|
7
|
+
"INP001", # Forbid implicit namespaces
|
|
8
|
+
"PLR2004", # Forbid magic numbers
|
|
9
|
+
"S101", # Disable assert
|
|
10
|
+
]
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
"""Test the values in exported constants."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
import shutil
|
|
7
|
+
import subprocess
|
|
8
|
+
import sys
|
|
9
|
+
import time
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
from typing import TYPE_CHECKING
|
|
12
|
+
|
|
13
|
+
import pytest
|
|
14
|
+
|
|
15
|
+
import pact_cli
|
|
16
|
+
|
|
17
|
+
if TYPE_CHECKING:
|
|
18
|
+
from unittest.mock import MagicMock
|
|
19
|
+
|
|
20
|
+
import pytest_mock
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def bin_to_sitepackages(exec_path: str | Path) -> Path:
|
|
24
|
+
"""
|
|
25
|
+
Find the expected site-packages directory for the given executable.
|
|
26
|
+
"""
|
|
27
|
+
if os.name == "nt":
|
|
28
|
+
return Path(exec_path).parents[1] / "Lib" / "site-packages"
|
|
29
|
+
return (
|
|
30
|
+
Path(exec_path).parents[1]
|
|
31
|
+
/ "lib"
|
|
32
|
+
/ f"python{sys.version_info.major}.{sys.version_info.minor}"
|
|
33
|
+
/ "site-packages"
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def assert_in_sys_path(p: str | Path) -> None:
|
|
38
|
+
"""
|
|
39
|
+
Assert that a given path is in sys.path.
|
|
40
|
+
|
|
41
|
+
This performs some normalization on platform where the filesystem is
|
|
42
|
+
case-insensitive.
|
|
43
|
+
"""
|
|
44
|
+
if os.name == "nt":
|
|
45
|
+
assert str(p).lower() in (path.lower() for path in sys.path)
|
|
46
|
+
else:
|
|
47
|
+
assert str(p) in sys.path
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
@pytest.mark.parametrize(
|
|
51
|
+
("constant", "expected"),
|
|
52
|
+
[
|
|
53
|
+
pytest.param("PACT_PATH", "pact", id="pact"),
|
|
54
|
+
pytest.param("BROKER_PATH", "pact-broker", id="pact-broker"),
|
|
55
|
+
pytest.param("BROKER_CLIENT_PATH", "pact-broker", id="pact-broker"),
|
|
56
|
+
pytest.param("MESSAGE_PATH", "pact-message", id="pactmessage"),
|
|
57
|
+
pytest.param("MOCK_SERVICE_PATH", "pact-mock-service", id="pact-message"),
|
|
58
|
+
pytest.param("PLUGIN_CLI_PATH", "pact-plugin-cli", id="pact-plugin-cli"),
|
|
59
|
+
pytest.param(
|
|
60
|
+
"VERIFIER_PATH", "pact-provider-verifier", id="pact-provider-verifier"
|
|
61
|
+
),
|
|
62
|
+
pytest.param("STUB_SERVICE_PATH", "pact-stub-service", id="pact-stub-service"),
|
|
63
|
+
pytest.param("PACTFLOW_PATH", "pactflow", id="pactflow"),
|
|
64
|
+
],
|
|
65
|
+
)
|
|
66
|
+
def test_constants(constant: str, expected: str) -> None:
|
|
67
|
+
"""Test the values of constants in pact.constants."""
|
|
68
|
+
value: str = getattr(pact_cli, constant)
|
|
69
|
+
if os.name == "nt":
|
|
70
|
+
# As the Windows filesystem is case insensitive, we must normalize it.
|
|
71
|
+
assert value.lower().endswith((f"{expected}.bat", f"{expected}.exe"))
|
|
72
|
+
else:
|
|
73
|
+
assert value.endswith(expected)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
@pytest.mark.parametrize(
|
|
77
|
+
"executable",
|
|
78
|
+
[
|
|
79
|
+
pytest.param("pact", id="pact"),
|
|
80
|
+
pytest.param("pact-broker", id="pact-broker"),
|
|
81
|
+
pytest.param("pact-message", id="pact-message"),
|
|
82
|
+
pytest.param("pact-plugin-cli", id="pact-plugin-cli"),
|
|
83
|
+
pytest.param("pact-provider-verifier", id="pact-provider-verifier"),
|
|
84
|
+
pytest.param("pact-stub-service", id="pact-stub-service"),
|
|
85
|
+
pytest.param("pactflow", id="pactflow"),
|
|
86
|
+
],
|
|
87
|
+
)
|
|
88
|
+
def test_exec_wrapper(executable: str) -> None:
|
|
89
|
+
exec_path = shutil.which(executable)
|
|
90
|
+
assert exec_path
|
|
91
|
+
|
|
92
|
+
site_packages = bin_to_sitepackages(exec_path)
|
|
93
|
+
assert site_packages.is_dir()
|
|
94
|
+
assert_in_sys_path(site_packages)
|
|
95
|
+
|
|
96
|
+
result = subprocess.run( # noqa: S603
|
|
97
|
+
[exec_path, "--help"],
|
|
98
|
+
check=False, # Some CLIs return non-zero for --help
|
|
99
|
+
text=True,
|
|
100
|
+
capture_output=True,
|
|
101
|
+
)
|
|
102
|
+
assert "pact" in (result.stdout + result.stderr).lower()
|
|
103
|
+
|
|
104
|
+
result = subprocess.run( # noqa: S603
|
|
105
|
+
[exec_path],
|
|
106
|
+
check=False, # Some CLIs return non-zero for --help
|
|
107
|
+
text=True,
|
|
108
|
+
capture_output=True,
|
|
109
|
+
)
|
|
110
|
+
assert "pact" in (result.stdout + result.stderr).lower()
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def test_exec_wrapper_mock_service() -> None:
|
|
114
|
+
"""
|
|
115
|
+
Analogous to test_exec_wrapper, but specifically for pact-mock-service.
|
|
116
|
+
|
|
117
|
+
This is necessary because pact-mock-service is a long running service, so we
|
|
118
|
+
spawn the process, terminate it after a delay, and check the output.
|
|
119
|
+
"""
|
|
120
|
+
executable = "pact-mock-service"
|
|
121
|
+
exec_path = shutil.which(executable)
|
|
122
|
+
assert exec_path
|
|
123
|
+
site_packages = bin_to_sitepackages(exec_path)
|
|
124
|
+
assert site_packages.is_dir()
|
|
125
|
+
assert_in_sys_path(site_packages)
|
|
126
|
+
|
|
127
|
+
process = subprocess.Popen( # noqa: S603
|
|
128
|
+
[exec_path],
|
|
129
|
+
stdout=subprocess.PIPE,
|
|
130
|
+
stderr=subprocess.PIPE,
|
|
131
|
+
text=True,
|
|
132
|
+
)
|
|
133
|
+
time.sleep(1)
|
|
134
|
+
process.terminate()
|
|
135
|
+
process.wait()
|
|
136
|
+
|
|
137
|
+
stdout, stderr = process.communicate()
|
|
138
|
+
assert "pact" in (stdout + stderr).lower()
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
@pytest.mark.parametrize(
|
|
142
|
+
"executable",
|
|
143
|
+
[
|
|
144
|
+
pytest.param("pact", id="pact"),
|
|
145
|
+
pytest.param("pact-broker", id="pact-broker"),
|
|
146
|
+
pytest.param("pact-message", id="pact-message"),
|
|
147
|
+
pytest.param("pact-mock-service", id="pact-mock-service"),
|
|
148
|
+
pytest.param("pact-plugin-cli", id="pact-plugin-cli"),
|
|
149
|
+
pytest.param("pact-provider-verifier", id="pact-provider-verifier"),
|
|
150
|
+
pytest.param("pact-stub-service", id="pact-stub-service"),
|
|
151
|
+
pytest.param("pactflow", id="pactflow"),
|
|
152
|
+
],
|
|
153
|
+
)
|
|
154
|
+
def test_exec_directly(executable: str, mocker: pytest_mock.MockerFixture) -> None:
|
|
155
|
+
"""
|
|
156
|
+
Test pact_cli._exec with --help, mocking sys.argv and capturing output.
|
|
157
|
+
"""
|
|
158
|
+
cmd: str
|
|
159
|
+
args: list[str]
|
|
160
|
+
|
|
161
|
+
mocker.patch.object(sys, "argv", new=[executable, "--help"])
|
|
162
|
+
mock_execv: MagicMock = mocker.patch("os.execv")
|
|
163
|
+
pact_cli._exec() # noqa: SLF001
|
|
164
|
+
mock_execv.assert_called_once()
|
|
165
|
+
cmd, args = mock_execv.call_args[0]
|
|
166
|
+
assert (os.sep + executable) in cmd
|
|
167
|
+
assert args == [cmd, "--help"]
|
|
168
|
+
|
|
169
|
+
mocker.patch.object(sys, "argv", new=[executable])
|
|
170
|
+
mock_execv.reset_mock()
|
|
171
|
+
pact_cli._exec() # noqa: SLF001
|
|
172
|
+
mock_execv.assert_called_once()
|
|
173
|
+
cmd, args = mock_execv.call_args[0]
|
|
174
|
+
assert (os.sep + executable) in cmd
|
|
175
|
+
assert args == [cmd]
|
pact_python_cli-0.0.0/PKG-INFO
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
#:schema = "https://json.schemastore.org/pyproject.json"
|
|
2
|
-
[project]
|
|
3
|
-
description = "Pact CLI bundle for Python"
|
|
4
|
-
name = "pact-python-cli"
|
|
5
|
-
|
|
6
|
-
license = "MIT"
|
|
7
|
-
version = "0.0.0"
|
|
8
|
-
|
|
9
|
-
authors = [{ name = "Joshua Ellis", email = "josh@jpellis.me" }]
|
|
10
|
-
maintainers = [{ name = "Joshua Ellis", email = "josh@jpellis.me" }]
|
pact_python_cli-0.0.0/setup.cfg
DELETED