Skip to content

Commit 1da64f8

Browse files
committed
Release build: 23d9958
0 parents  commit 1da64f8

16 files changed

Lines changed: 543 additions & 0 deletions

File tree

.github/workflows/publish.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Publish to PyPI
2+
3+
on:
4+
push:
5+
branches:
6+
- python-release
7+
8+
jobs:
9+
pypi-publish:
10+
name: Upload release to PyPI
11+
runs-on: ubuntu-latest
12+
13+
permissions:
14+
contents: read
15+
id-token: write
16+
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v4
20+
21+
- name: Install uv
22+
uses: astral-sh/setup-uv@v5
23+
with:
24+
enable-cache: true
25+
cache-dependency-glob: "uv.lock"
26+
27+
- name: Setup Python
28+
run: uv python install 3.12
29+
30+
- name: Install build tools
31+
run: |
32+
uv pip install --system build
33+
34+
- name: Build the package
35+
run: uv run python -m build
36+
37+
- name: Publish to PyPI
38+
uses: pypa/gh-action-pypi-publish@release/v1

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 teams_lib_pzsp2_z1
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.

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
recursive-include teams_lib_pzsp2_z1/bin *

README.md

Whitespace-only changes.

pyproject.toml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
[project]
2+
name = "teams_lib_pzsp2_z1"
3+
version = "0.1.5"
4+
description = "Bridge to Go client for Teams API"
5+
readme = "README.md"
6+
requires-python = ">=3.12"
7+
dependencies = [
8+
"dotenv>=0.9.9",
9+
"pytest-httpserver>=1.1.3",
10+
]
11+
12+
[dependency-groups]
13+
dev = [
14+
"pytest>=9.0.0",
15+
"ruff>=0.14.4",
16+
]
17+
18+
[tool.ruff]
19+
line-length = 88
20+
indent-width = 4
21+
target-version = "py312"
22+
fix = true
23+
show-fixes = true
24+
src = ["teams_lib_pzsp2_z1"]
25+
exclude = ["test_*.py", "tests/*"]
26+
27+
28+
[tool.ruff.lint]
29+
extend-select = ["I", "E", "W", "F", "C90", "B", "S", "UP", "PL"]
30+
31+
[tool.setuptools]
32+
include-package-data = true

requirements.txt

Whitespace-only changes.

teams_lib_pzsp2_z1/__init__.py

Whitespace-only changes.
35.3 MB
Binary file not shown.
36.1 MB
Binary file not shown.

teams_lib_pzsp2_z1/client.py

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
import json
2+
import pathlib
3+
import platform
4+
import subprocess
5+
import threading
6+
from typing import Any
7+
8+
from teams_lib_pzsp2_z1 import config
9+
from teams_lib_pzsp2_z1.services.channels import ChannelsService
10+
11+
12+
class TeamsClient:
13+
def __init__(
14+
self,
15+
auto_init: bool = True,
16+
cache_enabled: bool = False,
17+
cache_path: str | None = None,
18+
):
19+
self._lock = threading.Lock()
20+
21+
self.proc = subprocess.Popen( # noqa: S603
22+
[str(self._binary())],
23+
stdin=subprocess.PIPE,
24+
stdout=subprocess.PIPE,
25+
stderr=subprocess.DEVNULL,
26+
text=True,
27+
bufsize=1,
28+
)
29+
30+
self.channels = ChannelsService(self)
31+
32+
if auto_init:
33+
self.init_client(cache_enabled, cache_path)
34+
35+
def _binary(self):
36+
base = pathlib.Path(__file__).parent / "bin"
37+
osname = platform.system()
38+
39+
if osname == "Windows":
40+
return base / "teamsClientLib_windows.exe"
41+
elif osname == "Linux":
42+
return base / "teamsClientLib_linux"
43+
else:
44+
raise RuntimeError("Unsupported OS")
45+
46+
def init_client(
47+
self, cache_enabled: bool = False, cache_path: str | None = None
48+
) -> Any:
49+
sender_config = config.SenderConfig()
50+
auth_config = config.load_auth_config()
51+
return self.execute(
52+
cmd_type="init",
53+
config={
54+
"senderConfig": {
55+
"maxRetries": sender_config.max_retries,
56+
"nextRetryDelay": sender_config.next_retry_delay,
57+
"timeout": sender_config.timeout,
58+
},
59+
"authConfig": {
60+
"clientID": auth_config.client_id,
61+
"tenant": auth_config.tenant,
62+
"email": auth_config.email,
63+
"scopes": auth_config.scopes,
64+
"authMethod": auth_config.auth_method,
65+
},
66+
"cacheEnabled": cache_enabled,
67+
"cachePath": cache_path,
68+
},
69+
)
70+
71+
def init_fake_client(self, mock_server_url: str) -> Any:
72+
return self.execute(
73+
cmd_type="init",
74+
params={
75+
"mockServerUrl": mock_server_url,
76+
},
77+
)
78+
79+
def execute(
80+
self,
81+
cmd_type: str,
82+
method: str | None = None,
83+
config: dict[str, Any] | None = None,
84+
params: dict[str, Any] | None = None,
85+
) -> Any:
86+
payload = {"type": cmd_type}
87+
if method:
88+
payload["method"] = method
89+
if params:
90+
payload["params"] = params
91+
if config:
92+
payload["config"] = config
93+
94+
json_payload = json.dumps(payload)
95+
96+
# Critical section to avoid interleaving requests/responses
97+
with self._lock:
98+
try:
99+
self.proc.stdin.write(json_payload + "\n")
100+
self.proc.stdin.flush()
101+
102+
raw_response = self.proc.stdout.readline()
103+
except BrokenPipeError:
104+
raise RuntimeError("Go process crashed or closed connection") # noqa: B904
105+
106+
if not raw_response:
107+
raise RuntimeError("Go process returned empty response")
108+
109+
res = json.loads(raw_response)
110+
111+
if "error" in res and res["error"]:
112+
raise RuntimeError(f"Go Error: {res['error']}")
113+
114+
return res.get("result")
115+
116+
def close(self):
117+
self.proc.terminate()

0 commit comments

Comments
 (0)