Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ jobs:
with:
fetch-depth: 0
ref: main
token: ${{ secrets.ADMIN_PAT }}

- name: Ensure latest main (with bump)
run: git pull origin main
Expand All @@ -212,29 +213,34 @@ jobs:
uses: actions/download-artifact@v4
with:
name: real-binary
path: python/teams_lib_pzsp2_z1/bin/
path: /tmp/real-binary

- name: Prepare Client Directory
run: |
chmod +x python/teams_lib_pzsp2_z1/bin/*

mkdir python_release
cp -r python/* python_release/

mkdir -p python_release/.github/workflows
# binaries
TARGET_BIN_DIR="python_release/teams_lib_pzsp2_z1/bin/"
mkdir -p $TARGET_BIN_DIR
find /tmp/real-binary -type f -exec cp {} $TARGET_BIN_DIR \;
chmod +x $TARGET_BIN_DIR/*

# publish workflow
mkdir -p python_release/.github/workflows
cp .github/workflows/publish.yml python_release/.github/workflows/

# license file
if [ -f "LICENSE" ]; then
cp LICENSE python_release/
fi

# clean up unneeded files
rm -rf python_release/tests
find python_release -type d -name "__pycache__" -exec rm -rf {} +
rm -rf python_release/.venv
rm -rf python_release/uv.lock

ls -R python_release/teams_lib_pzsp2_z1/bin
ls -R python_release

- name: Commit and Push to Release Branch
run: |
Expand All @@ -243,9 +249,9 @@ jobs:
git checkout --orphan python-release

git rm -rf .
cp -r python_release/* .
cp -a python_release/. .
rm -rf python_release
git add .

git add .
git commit -m "Release build: ${{ github.sha }}"
git push -f origin python-release
6 changes: 1 addition & 5 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,8 @@ jobs:
- name: Setup Python
run: uv python install 3.12

- name: Install build tools
run: |
uv pip install --system build

- name: Build the package
run: uv run python -m build
run: uv run --with build python -m build

- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ python/teams_lib_pzsp2_z1.egg-info
python/teams_lib_pzsp2_z1/bin/*
.env
example.py
.vscode
4 changes: 2 additions & 2 deletions python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ description = "Bridge to Go client for Teams API"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
"dotenv>=0.9.9",
"pytest-httpserver>=1.1.3",
"python-dotenv>=1.0.0",
]

[dependency-groups]
dev = [
"pytest>=9.0.0",
"ruff>=0.14.4",
"pytest-httpserver>=1.1.3",
]

[tool.ruff]
Expand Down
4 changes: 3 additions & 1 deletion python/teams_lib_pzsp2_z1/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class TeamsClient:
def __init__(
self,
auto_init: bool = True,
env_path: str | None = None,
cache_enabled: bool = False,
cache_path: str | None = None,
):
Expand All @@ -27,6 +28,7 @@ def __init__(
bufsize=1,
)

self.env_path = env_path
self.channels = ChannelsService(self)

if auto_init:
Expand All @@ -47,7 +49,7 @@ def init_client(
self, cache_enabled: bool = False, cache_path: str | None = None
) -> Any:
sender_config = config.SenderConfig()
auth_config = config.load_auth_config()
auth_config = config.load_auth_config(self.env_path)
return self.execute(
cmd_type="init",
config={
Expand Down
36 changes: 19 additions & 17 deletions python/teams_lib_pzsp2_z1/config.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import os
import sys
from dataclasses import dataclass

from dotenv import load_dotenv


class AuthConfigurationError(Exception):
pass


@dataclass
class SenderConfig:
max_retries: int = 3
Expand All @@ -21,17 +24,14 @@ class AuthConfig:
auth_method: str


def load_auth_config() -> AuthConfig:
load_dotenv()
def load_auth_config(env_path: str | None = None) -> AuthConfig:
load_dotenv(env_path)

cfg = AuthConfig(
client_id=get_env("CLIENT_ID", ""),
tenant=get_env("TENANT_ID", ""),
email=get_env("EMAIL", ""),
scopes=get_env(
"SCOPES",
"https://graph.microsoft.com/.default"
).split(","),
scopes=get_env("SCOPES", "https://graph.microsoft.com/.default").split(","),
auth_method=get_env("AUTH_METHOD", "DEVICE_CODE"),
)

Expand All @@ -44,18 +44,20 @@ def get_env(key: str, fallback: str) -> str:


def validate(cfg: AuthConfig):
missing = []
if not cfg.client_id:
print("Missing CLIENT ID", file=sys.stderr)
sys.exit(1)

missing.append("CLIENT_ID")
if not cfg.tenant:
print("Missing TENANT ID", file=sys.stderr)
sys.exit(1)

missing.append("TENANT_ID")
if not cfg.email:
print("Missing EMAIL", file=sys.stderr)
sys.exit(1)
missing.append("EMAIL")

if missing:
raise AuthConfigurationError(
f"Missing required environment variables: {', '.join(missing)}"
)

if cfg.auth_method not in ("DEVICE_CODE", "INTERACTIVE"):
print("AUTH METHOD must be either DEVICE_CODE or INTERACTIVE", file=sys.stderr)
sys.exit(1)
raise AuthConfigurationError(
f"Invalid AUTH_METHOD: {cfg.auth_method}. Must be DEVICE_CODE or INTERACTIVE"
)
21 changes: 4 additions & 17 deletions python/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.