diff --git a/.gitignore b/.gitignore index c3152574..23d3027d 100644 --- a/.gitignore +++ b/.gitignore @@ -21,4 +21,4 @@ dmypy.json .DS_STORE ref/ - +py.typed \ No newline at end of file diff --git a/packages/cards/pyproject.toml b/packages/cards/pyproject.toml index d7784041..1820c802 100644 --- a/packages/cards/pyproject.toml +++ b/packages/cards/pyproject.toml @@ -1,5 +1,5 @@ [project] -name = "cards" +name = "microsoft-teams-cards" version = "0.1.0" description = "Add your description here" readme = "README.md" @@ -16,3 +16,6 @@ dependencies = [ [build-system] requires = ["hatchling"] build-backend = "hatchling.build" + +[tool.hatch.build.targets.wheel] +packages = ["src/microsoft"] \ No newline at end of file diff --git a/packages/cards/src/cards/__init__.py b/packages/cards/src/microsoft/teams/cards/__init__.py similarity index 100% rename from packages/cards/src/cards/__init__.py rename to packages/cards/src/microsoft/teams/cards/__init__.py diff --git a/packages/cards/src/cards/py.typed b/packages/cards/src/microsoft/teams/cards/py.typed similarity index 100% rename from packages/cards/src/cards/py.typed rename to packages/cards/src/microsoft/teams/cards/py.typed diff --git a/packages/common/pyproject.toml b/packages/common/pyproject.toml index 1da7391b..ac79991b 100644 --- a/packages/common/pyproject.toml +++ b/packages/common/pyproject.toml @@ -1,5 +1,5 @@ [project] -name = "common" +name = "microsoft-teams-common" version = "0.0.0" description = "Add your description here" readme = "README.md" @@ -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"] diff --git a/packages/common/src/common/__init__.py b/packages/common/src/microsoft/teams/common/__init__.py similarity index 100% rename from packages/common/src/common/__init__.py rename to packages/common/src/microsoft/teams/common/__init__.py diff --git a/packages/common/src/common/http/__init__.py b/packages/common/src/microsoft/teams/common/http/__init__.py similarity index 100% rename from packages/common/src/common/http/__init__.py rename to packages/common/src/microsoft/teams/common/http/__init__.py diff --git a/packages/common/src/common/http/client.py b/packages/common/src/microsoft/teams/common/http/client.py similarity index 100% rename from packages/common/src/common/http/client.py rename to packages/common/src/microsoft/teams/common/http/client.py diff --git a/packages/common/src/common/http/client_token.py b/packages/common/src/microsoft/teams/common/http/client_token.py similarity index 100% rename from packages/common/src/common/http/client_token.py rename to packages/common/src/microsoft/teams/common/http/client_token.py diff --git a/packages/common/src/common/http/interceptor.py b/packages/common/src/microsoft/teams/common/http/interceptor.py similarity index 100% rename from packages/common/src/common/http/interceptor.py rename to packages/common/src/microsoft/teams/common/http/interceptor.py diff --git a/packages/common/src/common/logging/__init__.py b/packages/common/src/microsoft/teams/common/logging/__init__.py similarity index 100% rename from packages/common/src/common/logging/__init__.py rename to packages/common/src/microsoft/teams/common/logging/__init__.py diff --git a/packages/common/src/common/logging/ansi.py b/packages/common/src/microsoft/teams/common/logging/ansi.py similarity index 100% rename from packages/common/src/common/logging/ansi.py rename to packages/common/src/microsoft/teams/common/logging/ansi.py diff --git a/packages/common/src/common/logging/console.py b/packages/common/src/microsoft/teams/common/logging/console.py similarity index 100% rename from packages/common/src/common/logging/console.py rename to packages/common/src/microsoft/teams/common/logging/console.py diff --git a/packages/common/src/common/logging/filter.py b/packages/common/src/microsoft/teams/common/logging/filter.py similarity index 100% rename from packages/common/src/common/logging/filter.py rename to packages/common/src/microsoft/teams/common/logging/filter.py diff --git a/packages/common/src/common/logging/formatter.py b/packages/common/src/microsoft/teams/common/logging/formatter.py similarity index 100% rename from packages/common/src/common/logging/formatter.py rename to packages/common/src/microsoft/teams/common/logging/formatter.py diff --git a/packages/common/src/common/py.typed b/packages/common/src/microsoft/teams/common/py.typed similarity index 100% rename from packages/common/src/common/py.typed rename to packages/common/src/microsoft/teams/common/py.typed diff --git a/packages/common/tests/test_client.py b/packages/common/tests/test_client.py index 2666ec4f..cb754f43 100644 --- a/packages/common/tests/test_client.py +++ b/packages/common/tests/test_client.py @@ -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: diff --git a/packages/common/tests/test_logging_filter.py b/packages/common/tests/test_logging_filter.py index 310fc1cc..0f99409e 100644 --- a/packages/common/tests/test_logging_filter.py +++ b/packages/common/tests/test_logging_filter.py @@ -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: diff --git a/packages/common/tests/test_logging_formatter.py b/packages/common/tests/test_logging_formatter.py index 9467df1c..b30923f0 100644 --- a/packages/common/tests/test_logging_formatter.py +++ b/packages/common/tests/test_logging_formatter.py @@ -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( diff --git a/pyproject.toml b/pyproject.toml index 46142421..930b11c2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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/*"] diff --git a/scripts/create_package.py b/scripts/create_package.py new file mode 100755 index 00000000..26ed50c8 --- /dev/null +++ b/scripts/create_package.py @@ -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() diff --git a/src/teams_py/main.py b/src/teams_py/main.py index d3bfc441..27854eb2 100644 --- a/src/teams_py/main.py +++ b/src/teams_py/main.py @@ -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__) diff --git a/uv.lock b/uv.lock index d4fc34bc..d8866166 100644 --- a/uv.lock +++ b/uv.lock @@ -4,8 +4,8 @@ requires-python = ">=3.12" [manifest] members = [ - "cards", - "common", + "microsoft-teams-cards", + "microsoft-teams-common", "teams-py", ] @@ -23,23 +23,6 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/a1/ee/48ca1a7c89ffec8b6a0c5d02b89c305671d5ffd8d3c94acf8b8c408575bb/anyio-4.9.0-py3-none-any.whl", hash = "sha256:9f76d541cad6e36af7beb62e978876f3b41e3e04f2c1fbf0884604c0a9c4d93c", size = 100916 }, ] -[[package]] -name = "cards" -version = "0.1.0" -source = { editable = "packages/cards" } -dependencies = [ - { name = "coverage" }, - { name = "pytest" }, - { name = "ruff" }, -] - -[package.metadata] -requires-dist = [ - { name = "coverage", specifier = ">=7.8.0" }, - { name = "pytest", specifier = ">=8.3.5" }, - { name = "ruff", specifier = ">=0.11.5" }, -] - [[package]] name = "certifi" version = "2025.4.26" @@ -67,37 +50,6 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/d1/d6/3965ed04c63042e047cb6a3e6ed1a63a35087b6a609aa3a15ed8ac56c221/colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6", size = 25335 }, ] -[[package]] -name = "common" -version = "0.0.0" -source = { editable = "packages/common" } -dependencies = [ - { name = "coverage" }, - { name = "httpx" }, - { name = "pytest" }, - { name = "ruff" }, -] - -[package.dev-dependencies] -dev = [ - { name = "pytest" }, - { name = "pytest-asyncio" }, -] - -[package.metadata] -requires-dist = [ - { name = "coverage", specifier = ">=7.8.0" }, - { name = "httpx", specifier = ">=0.28.1" }, - { name = "pytest", specifier = ">=8.3.5" }, - { name = "ruff", specifier = ">=0.11.5" }, -] - -[package.metadata.requires-dev] -dev = [ - { name = "pytest", specifier = ">=8.4.0" }, - { name = "pytest-asyncio", specifier = ">=1.0.0" }, -] - [[package]] name = "coverage" version = "7.8.2" @@ -222,6 +174,54 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/2c/e1/e6716421ea10d38022b952c159d5161ca1193197fb744506875fbb87ea7b/iniconfig-2.1.0-py3-none-any.whl", hash = "sha256:9deba5723312380e77435581c6bf4935c94cbfab9b1ed33ef8d238ea168eb760", size = 6050 }, ] +[[package]] +name = "microsoft-teams-cards" +version = "0.1.0" +source = { editable = "packages/cards" } +dependencies = [ + { name = "coverage" }, + { name = "pytest" }, + { name = "ruff" }, +] + +[package.metadata] +requires-dist = [ + { name = "coverage", specifier = ">=7.8.0" }, + { name = "pytest", specifier = ">=8.3.5" }, + { name = "ruff", specifier = ">=0.11.5" }, +] + +[[package]] +name = "microsoft-teams-common" +version = "0.0.0" +source = { editable = "packages/common" } +dependencies = [ + { name = "coverage" }, + { name = "httpx" }, + { name = "pytest" }, + { name = "ruff" }, +] + +[package.dev-dependencies] +dev = [ + { name = "pytest" }, + { name = "pytest-asyncio" }, +] + +[package.metadata] +requires-dist = [ + { name = "coverage", specifier = ">=7.8.0" }, + { name = "httpx", specifier = ">=0.28.1" }, + { name = "pytest", specifier = ">=8.3.5" }, + { name = "ruff", specifier = ">=0.11.5" }, +] + +[package.metadata.requires-dev] +dev = [ + { name = "pytest", specifier = ">=8.4.0" }, + { name = "pytest-asyncio", specifier = ">=1.0.0" }, +] + [[package]] name = "mypy" version = "1.16.0" @@ -442,8 +442,8 @@ name = "teams-py" version = "0.1.0" source = { editable = "." } dependencies = [ - { name = "cards" }, - { name = "common" }, + { name = "microsoft-teams-cards" }, + { name = "microsoft-teams-common" }, { name = "pytest-asyncio" }, ] @@ -457,8 +457,8 @@ dev = [ [package.metadata] requires-dist = [ - { name = "cards", editable = "packages/cards" }, - { name = "common", editable = "packages/common" }, + { name = "microsoft-teams-cards", editable = "packages/cards" }, + { name = "microsoft-teams-common", editable = "packages/common" }, { name = "pytest-asyncio", specifier = ">=1.0.0" }, ]