Skip to content

Commit 1581663

Browse files
committed
Release build: e89c054
0 parents  commit 1581663

16 files changed

Lines changed: 530 additions & 0 deletions

File tree

.github/workflows/publish.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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: Build the package
31+
run: uv run --with build python -m build
32+
33+
- name: Publish to PyPI
34+
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.12"
4+
description = "Bridge to Go client for Teams API"
5+
readme = "README.md"
6+
requires-python = ">=3.12"
7+
dependencies = [
8+
"python-dotenv>=1.0.0",
9+
]
10+
11+
[dependency-groups]
12+
dev = [
13+
"pytest>=9.0.0",
14+
"ruff>=0.14.4",
15+
"pytest-httpserver>=1.1.3",
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.4 MB
Binary file not shown.
36.1 MB
Binary file not shown.

teams_lib_pzsp2_z1/client.py

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

0 commit comments

Comments
 (0)