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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ dmypy.json
.DS_STORE

ref/

py.typed
5 changes: 4 additions & 1 deletion packages/cards/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[project]
name = "cards"
name = "microsoft-teams-cards"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
Expand All @@ -16,3 +16,6 @@ dependencies = [
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.hatch.build.targets.wheel]
packages = ["src/microsoft"]
5 changes: 4 additions & 1 deletion packages/common/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[project]
name = "common"
name = "microsoft-teams-common"
version = "0.0.0"
description = "Add your description here"
readme = "README.md"
Expand Down Expand Up @@ -30,3 +30,6 @@ Homepage = "https://github.com/microsoft/teams.py/tree/main/packages/common"
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.hatch.build.targets.wheel]
packages = ["src/microsoft"]
5 changes: 3 additions & 2 deletions packages/common/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@

import httpx
import pytest
from common.http.client import Client, ClientOptions
from common.http.client_token import StringLike

from microsoft.teams.common.http.client import Client, ClientOptions
from microsoft.teams.common.http.client_token import StringLike


class DummyAsyncInterceptor:
Expand Down
2 changes: 1 addition & 1 deletion packages/common/tests/test_logging_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import logging
from unittest.mock import MagicMock

from common.logging import ConsoleFilter
from microsoft.teams.common.logging import ConsoleFilter


def test_default_pattern() -> None:
Expand Down
2 changes: 1 addition & 1 deletion packages/common/tests/test_logging_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import logging
from typing import Collection, Union

from common.logging import ANSI, ConsoleFormatter
from microsoft.teams.common.logging import ANSI, ConsoleFormatter


def create_record(
Expand Down
10 changes: 5 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
[project]
name = "teams-py"
name = "microsoft-teams"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
"common",
"cards",
"microsoft-teams-common",
"microsoft-teams-cards",
"pytest-asyncio>=1.0.0",
]

[tool.uv.sources]
common = { workspace = true }
cards = { workspace = true }
"microsoft-teams-common" = { workspace = true }
"microsoft-teams-cards" = { workspace = true }

[tool.uv.workspace]
members = ["packages/*"]
Expand Down
112 changes: 112 additions & 0 deletions scripts/create_package.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#!/usr/bin/env python3

"""
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the MIT License.
"""

import argparse
import shutil
import subprocess
import sys
from pathlib import Path
from typing import Optional


def run_command(cmd: list[str], cwd: Optional[str] = None) -> None:
"""Run a command and raise an exception if it fails."""
result = subprocess.run(cmd, cwd=cwd, capture_output=True, text=True)
if result.returncode != 0:
print(f"Error running command: {' '.join(cmd)}")
print(f"Error output: {result.stderr}")
sys.exit(1)


def create_package(package_name: str) -> None:
"""Create a new package with the specified name."""
# Convert package name to lowercase for directory name
package_dir = package_name.lower()
package_path = Path("packages") / package_dir
full_package_name = f"microsoft-teams-{package_name.lower()}"

if package_path.exists():
print(f"Error: Package directory {package_path} already exists")
sys.exit(1)

# Step 1: Run uv init
print(f"Creating new package {package_name}...")
run_command(["uv", "init", "--lib", str(package_path), "--author-from", "none"])

# Step 2: Move and restructure the source directory
src_dir = package_path / "src"
original_package_dir = src_dir / package_name
target_dir = src_dir / "microsoft" / "teams" / package_name.lower()

# Create the new directory structure
target_dir.parent.mkdir(parents=True, exist_ok=True)

# Move the package directory
if original_package_dir.exists():
shutil.move(str(original_package_dir), str(target_dir))

# Step 3 & 4: Update pyproject.toml
pyproject_path = package_path / "pyproject.toml"
if pyproject_path.exists():
with open(pyproject_path, "r") as f:
content = f.read()

# Update package name
content = content.replace(f'name = "{package_name}"', f'name = "{full_package_name}"')

# Add authors field if not present
if "authors = [" not in content:
content = content.replace(
'description = "Add your description here"',
'description = "Add your description here"\nauthors = [{ name = "Microsoft", email = "teams@microsoft.com" }]', # noqa: E501
)

# Add wheel build configuration
if "[tool.hatch.build.targets.wheel]" not in content:
content += '\n[tool.hatch.build.targets.wheel]\npackages = ["src/microsoft"]\n'

with open(pyproject_path, "w") as f:
f.write(content)

# Step 5: Update root pyproject.toml
root_pyproject_path = Path("pyproject.toml")
if root_pyproject_path.exists():
with open(root_pyproject_path, "r") as f:
content = f.read()

# Add the new package to uv.sources if not already present
source_entry = f'"{full_package_name}" = {{ workspace = true }}'
if source_entry not in content:
# Find the [tool.uv.sources] section
if "[tool.uv.sources]" in content:
# Add the new source after the section header
content = content.replace("[tool.uv.sources]", f"[tool.uv.sources]\n{source_entry}")
else:
# Add the entire section if it doesn't exist
content += f"\n[tool.uv.sources]\n{source_entry}\n"

with open(root_pyproject_path, "w") as f:
f.write(content)

print(f"\nPackage {package_name} created successfully!")
print(f"Location: {package_path}")
print("\nNext steps:")
print("1. Add your package code in src/microsoft/teams/{package_name.lower()}")
print("2. Update the package description in pyproject.toml")
print("3. Add any required dependencies to pyproject.toml")


def main():
parser = argparse.ArgumentParser(description="Create a new package in the teams.py project")
parser.add_argument("package_name", help="Name of the package to create")
args = parser.parse_args()

create_package(args.package_name)


if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion src/teams_py/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Licensed under the MIT License.
"""

from common.logging import ConsoleLogger
from microsoft.teams.common.logging import ConsoleLogger

logger = ConsoleLogger().create_logger(__name__)

Expand Down
108 changes: 54 additions & 54 deletions uv.lock

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