Skip to content

Commit

Permalink
style(web,search,main,atlassian): improve codestyle
Browse files Browse the repository at this point in the history
  • Loading branch information
helmut-hoffer-von-ankershoffen committed Jan 4, 2025
1 parent c9185e4 commit 72815d6
Show file tree
Hide file tree
Showing 22 changed files with 477 additions and 169 deletions.
14 changes: 14 additions & 0 deletions .fixme
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
============================= test session starts ==============================
platform darwin -- Python 3.11.6, pytest-8.3.4, pluggy-1.5.0 -- /Users/helmut/Code/starbridge/.venv/bin/python
cachedir: .pytest_cache
rootdir: /Users/helmut/Code/starbridge
configfile: pyproject.toml
testpaths: tests
plugins: datadir-1.5.0, cov-6.0.0, env-1.1.5, logfire-2.11.1, regressions-2.6.0, anyio-4.6.2.post1, xdist-3.6.1, asyncio-0.25.1, docker-3.1.1
asyncio: mode=Mode.AUTO, asyncio_default_fixture_loop_scope=function
collecting ... collected 0 items

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! KeyboardInterrupt !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
/Users/helmut/.local/share/uv/python/cpython-3.11.6-macos-aarch64-none/lib/python3.11/ast.py:273: KeyboardInterrupt
(to show a full traceback on KeyboardInterrupt use --full-trace)
============================ no tests ran in 1.22s =============================
40 changes: 18 additions & 22 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[project]
name = "starbridge"
version = "0.0.67"
description = "⭐ Integrates Claude Desktop with the web, Google workspace and Atlassian workspaces"
description = "⭐ Integrates Claude Desktop with the web, Google and Atlassian workspaces."
readme = "README.md"
authors = [
{ name = "Helmut Hoffer von Ankershoffen", email = "helmuthva@googlemail.com" },
Expand Down Expand Up @@ -143,33 +143,29 @@ target-version = "py311"
preview = true
fix = true
line-length = 120
exclude = [".fixme"]


[tool.ruff.lint]
# select = ["ALL"]
select = [
# "E", # pycodestyle errors
"F", # pyflakes
"I", # isort
"UP", # pyupgrade
"B", # flake8-bugbear
"C", # flake8-comprehensions
]
select = ["ALL"]

# sekect= [
ignore = [
"ANN002", # Missing type annotation for `*args`
"ANN003", # Missing type annotation for `**kwargs``
"CPY001", # missing copyright notice
"DOC502", # docstrings with exceptions not raised in the code of the function
"D203", # incomptatible with D211
"D212", # incompatible with #D213
"FBT001", # boolean positional arguments
"FBT002", # boolean defautl value positionl arguments
"PGH003", # Use specific rule codes when ignoring type issues
"TRY300", # else instead of return before except. Simply disagree this is more readable.
"COM812", # conflicts with ruff formatter
"ISC001", # conflicts with ruff formatter
"ANN002", # Missing type annotation for `*args`
"ANN003", # Missing type annotation for `**kwargs``
"ASYNC109", # Async function definition with a `timeout` parameter
"CPY001", # missing copyright notice
"DOC502", # docstrings with exceptions not raised in the code of the function
"D203", # incomptatible with D211
"D212", # incompatible with #D213
"FBT001", # boolean positional arguments
"FBT002", # boolean defautl value positionl arguments
"FBT003", # Boolean positional value in function call
"PGH003", # Use specific rule codes when ignoring type issues
"TRY300", # else instead of return before except. Simply disagree this is more readable.
"COM812", # conflicts with ruff formatter
"ISC001", # conflicts with ruff formatter
"S404", # preciew rule: subprocess` module is possibly insecure
]

[tool.ruff.lint.per-file-ignores]
Expand Down
11 changes: 9 additions & 2 deletions src/starbridge/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""⭐ Integrates Claude Desktop with the web, Google and Atlassian workspaces."""

import importlib.metadata
import os
import pathlib
Expand Down Expand Up @@ -38,13 +40,18 @@ def _amend_library_path() -> None:
def _log_boot_message() -> None:
# Local import as this initializes logging and instrumentation
# which might depend on environment arguments parsed from argv
from starbridge.utils import get_logger, get_process_info
from starbridge.utils import get_logger, get_process_info # noqa: PLC0415

logger = get_logger(__name__)

process_info = get_process_info()
logger.debug(
f"⭐ Booting Starbridge v{__version__} (project root {process_info.project_root}, pid {process_info.pid}), parent '{process_info.parent.name}' (pid {process_info.parent.pid})",
"⭐ Booting Starbridge v%s (project root %s, pid %s), parent '%s' (pid %s)",
__version__,
process_info.project_root,
process_info.pid,
process_info.parent.name,
process_info.parent.pid,
)


Expand Down
2 changes: 2 additions & 0 deletions src/starbridge/atlassian/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Package containing Atlassian-related functionality and settings."""

from .settings import Settings

__all__ = [
Expand Down
7 changes: 6 additions & 1 deletion src/starbridge/atlassian/settings.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Module containing Atlassian-related settings and configuration."""

from typing import Annotated

from pydantic import AnyHttpUrl, EmailStr, Field, SecretStr
Expand All @@ -7,6 +9,8 @@


class Settings(BaseSettings):
"""Configuration settings for Atlassian services including Confluence and Jira authentication."""

model_config = SettingsConfigDict(
env_prefix=f"{__project_name__.upper()}_ATLASSIAN_",
extra="ignore",
Expand All @@ -33,7 +37,8 @@ class Settings(BaseSettings):
api_token: Annotated[
SecretStr,
Field(
description="API token of your Atlassian account. Go to https://id.atlassian.com/manage-profile/security/api-tokens to create a token.",
description="API token of your Atlassian account. "
"Go to https://id.atlassian.com/manage-profile/security/api-tokens to create a token.",
examples=["YOUR_TOKEN"],
),
]
42 changes: 32 additions & 10 deletions src/starbridge/cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
"""Command-line interface module for Starbridge, providing various commands for service management and configuration."""

import sys
from pathlib import Path
from typing import Annotated

import typer
Expand Down Expand Up @@ -47,11 +50,16 @@ def main(
help="Debug mode",
),
] = True,
env: Annotated[
env: Annotated[ # noqa: ARG001
list[str] | None,
typer.Option(
"--env",
help='Environment variables in key=value format. Can be used multiple times in one call. Only STARBRIDGE_ prefixed vars are evaluated. Example --env STARBRIDGE_ATLASSIAN_URL="https://your-domain.atlassian.net" --env STARBRIDGE_ATLASSIAN_EMAIL="YOUR_EMAIL"',
help=(
"Environment variables in key=value format. Can be used multiple times in one call. "
"Only STARBRIDGE_ prefixed vars are evaluated. Example --env "
'STARBRIDGE_ATLASSIAN_URL="https://your-domain.atlassian.net" --env '
'STARBRIDGE_ATLASSIAN_EMAIL="YOUR_EMAIL"'
),
),
] = None,
) -> None:
Expand All @@ -66,7 +74,7 @@ def health(json: Annotated[bool, typer.Option(help="Output health as JSON")] = F
"""Check health of services and their dependencies."""
health = MCPServer().health()
if not health.healthy:
logger.warning(f"health: {health}")
logger.warning("health: %s", health)
if json:
console.print(health.model_dump_json())
else:
Expand All @@ -83,14 +91,20 @@ def info() -> None:

@cli.command()
def create_dot_env() -> None:
"""Create .env file for Starbridge. You will be prompted for settings."""
"""
Create .env file for Starbridge. You will be prompted for settings.
Raises:
RuntimeError: If not running in development mode.
"""
if not __is_development_mode__:
msg = "This command is only available in development mode"
raise RuntimeError(msg)

with open(".env", "w", encoding="utf-8") as f:
with Path(".env").open("w", encoding="utf-8") as f:
for key, value in iter(prompt_for_env().items()):
f.write(f"{key}={value}\n")
f.write(f"{key}={value}\n")


@cli.command()
Expand All @@ -108,7 +122,11 @@ def install(
),
] = "helmuthva/starbridge:latest",
) -> None:
"""Install starbridge within Claude Desktop application by adding to configuration and restarting Claude Desktop app."""
"""
Install starbridge within Claude Desktop application.
Adds starbridge configuration and restarts Claude Desktop app.
"""
if ClaudeService.install_mcp_server(
generate_mcp_server_config(prompt_for_env(), image),
restart=restart_claude,
Expand All @@ -131,7 +149,11 @@ def uninstall(
),
] = ClaudeService.platform_supports_restart(),
) -> None:
"""Install starbridge from Claude Desktop application by removing from configuration and restarting Claude Desktop app."""
"""
Uninstall starbridge from Claude Desktop application.
Removes starbridge configuration and restarts Claude Desktop app.
"""
if ClaudeService.uninstall_mcp_server(restart=restart_claude):
console.print("Starbridge uninstalled from Claude Destkop application.")
else:
Expand All @@ -143,7 +165,7 @@ def uninstall(
if __name__ == "__main__":
try:
cli()
except Exception as e:
logger.critical(f"Fatal error occurred: {e}")
except Exception as e: # noqa: BLE001
logger.critical("Fatal error occurred: %s", e)
console.print(f"Fatal error occurred: {e}", style="error")
sys.exit(1)
2 changes: 2 additions & 0 deletions src/starbridge/hello/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Hello World module of Starbridge serving as an example."""

from .cli import cli
from .service import Service

Expand Down
16 changes: 9 additions & 7 deletions src/starbridge/hello/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import subprocess
import sys
import tempfile
import time
from pathlib import Path
from typing import Annotated

Expand Down Expand Up @@ -32,7 +33,7 @@ def info() -> None:

@cli.command()
def hello(locale: Annotated[str, typer.Option(help="Locale to use")] = "en_US") -> None:
"""Print Hello World!"""
"""Print Hello World."""
console.print(Service().hello(locale))


Expand All @@ -43,7 +44,8 @@ def bridge(
dump: Annotated[
bool,
typer.Option(
help="If set, will dump to file starbridge.png in current working directory. Defaults to opening viewer to show the image.",
help="If set, will dump to file starbridge.png in current working directory. "
"Defaults to opening viewer to show the image.",
),
] = False,
) -> None:
Expand Down Expand Up @@ -77,7 +79,8 @@ def pdf(
dump: Annotated[
bool,
typer.Option(
help="If set, will dump to file starbridge.pdf in current working directory. Defaults to opening viewer to show the document.",
help="If set, will dump to file starbridge.pdf in current working directory. "
"Defaults to opening viewer to show the document.",
),
] = False,
) -> None:
Expand All @@ -94,14 +97,13 @@ def pdf(
tmp_path = Path(tmp.name)
try:
if sys.platform == "darwin": # macOS
subprocess.run(["open", tmp_path], check=True)
subprocess.run(["/usr/bin/open", tmp_path], check=True) # noqa: S603
elif sys.platform == "win32": # Windows
os.startfile(tmp_path) # type: ignore
os.startfile(tmp_path) # type: ignore # noqa: S606
else: # Linux and others
subprocess.run(["xdg-open", tmp_path], check=True)
subprocess.run(["xdg-open", tmp_path], check=True) # noqa: S607, S603

# Give the viewer some time to open the file
import time

time.sleep(2)
finally:
Expand Down
Loading

0 comments on commit 72815d6

Please sign in to comment.