Skip to content

Commit 4051448

Browse files
Python51888gitee-org
authored andcommitted
!2 添加了一些项目文件
Merge pull request !2 from Python51888/midscene_python
2 parents 8e80c0c + da152d8 commit 4051448

19 files changed

+4842
-166
lines changed

Makefile

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,45 @@
1-
.PHONY: help install dev test lint format clean build docs
1+
.PHONY: help install dev test lint format clean build docs requirements-freeze requirements-check
22

33
# Default target
44
help:
55
@echo "Available commands:"
6-
@echo " install Install package and dependencies"
7-
@echo " dev Install development dependencies"
8-
@echo " test Run tests"
9-
@echo " lint Run linting"
10-
@echo " format Format code"
11-
@echo " clean Clean build artifacts"
12-
@echo " build Build package"
13-
@echo " docs Build documentation"
14-
15-
# Install package
6+
@echo " install Install package and dependencies"
7+
@echo " dev Install development dependencies"
8+
@echo " requirements-freeze Generate complete requirements.txt"
9+
@echo " requirements-check Verify dependencies integrity"
10+
@echo " requirements-quick-check Quick requirements validation"
11+
@echo " test Run tests"
12+
@echo " lint Run linting"
13+
@echo " format Format code"
14+
@echo " clean Clean build artifacts"
15+
@echo " build Build package"
16+
@echo " docs Build documentation"
17+
18+
# Generate complete requirements.txt with all dependencies
19+
requirements-freeze:
20+
uv pip compile --all-extras pyproject.toml -o requirements.txt
21+
22+
# Verify dependencies integrity
23+
requirements-check:
24+
uv pip check
25+
@python scripts/validate_requirements.py
26+
27+
# Quick requirements validation
28+
requirements-quick-check:
29+
@scripts/quick_validate.bat
30+
31+
# Install package from requirements.txt
1632
install:
17-
pip install -e .
33+
pip install -r requirements.txt
1834

19-
# Install development dependencies
20-
dev:
35+
# Install package in development mode
36+
install-dev:
2137
pip install -e ".[dev,docs]"
2238
pre-commit install
2339

40+
# Install development dependencies (alias for backward compatibility)
41+
dev: install-dev
42+
2443
# Run tests
2544
test:
2645
pytest tests/ -v --cov=midscene --cov-report=html --cov-report=term-missing

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Midscene Python
22

3-
Midscene Python 实现版本 - 基于 AI 的自动化框架,支持 Web 和 Android 平台的 UI 自动化操作。
3+
Midscene Python 是一个基于 AI 的自动化框架,支持 Web 和 Android 平台的 UI 自动化操作。
44

55
## 概述
66

7-
Midscene Python 是原 TypeScript/JavaScript 版本的完整移植,保持相同的核心架构和功能特性
7+
Midscene Python 提供全面的 UI 自动化能力,具有以下核心特性
88

99
- **自然语言驱动**:使用自然语言描述自动化任务
1010
- **多平台支持**:支持 Web(Selenium/Playwright)和 Android(ADB)

midscene/cli/main.py

Lines changed: 4 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,12 @@
22
Midscene CLI - Command line interface for automation scripts
33
"""
44

5-
import asyncio
65
import sys
7-
from pathlib import Path
8-
from typing import Optional, List
6+
from typing import Optional
97

108
import typer
11-
from loguru import logger
129
from rich.console import Console
13-
from rich.table import Table
1410

15-
from .runner import ScriptRunner
1611
from .config import CLIConfig
1712

1813
app = typer.Typer(
@@ -30,137 +25,20 @@ def run(
3025
config_file: Optional[str] = typer.Option(None, "--config", "-c", help="Configuration file path"),
3126
headless: bool = typer.Option(False, "--headless", help="Run browser in headless mode"),
3227
device_id: Optional[str] = typer.Option(None, "--device", "-d", help="Android device ID"),
33-
concurrent: int = typer.Option(1, "--concurrent", help="Number of concurrent executions"),
34-
continue_on_error: bool = typer.Option(False, "--continue-on-error", help="Continue on script errors"),
35-
generate_report: bool = typer.Option(True, "--report/--no-report", help="Generate execution report"),
3628
verbose: bool = typer.Option(False, "--verbose", "-v", help="Verbose output"),
3729
):
3830
"""Run automation script(s)"""
3931

40-
# Setup logging
41-
log_level = "DEBUG" if verbose else "INFO"
42-
logger.remove()
43-
logger.add(sys.stderr, level=log_level, format="{time} | {level} | {message}")
44-
45-
try:
46-
# Load configuration
47-
config = CLIConfig.load(config_file) if config_file else CLIConfig()
48-
49-
# Override config with CLI options
50-
if headless is not None:
51-
config.web.headless = headless
52-
if device_id is not None:
53-
config.android.device_id = device_id
54-
if concurrent is not None:
55-
config.execution.concurrent = concurrent
56-
if continue_on_error is not None:
57-
config.execution.continue_on_error = continue_on_error
58-
if generate_report is not None:
59-
config.execution.generate_report = generate_report
60-
61-
# Create runner and execute
62-
runner = ScriptRunner(config)
63-
64-
# Run synchronously
65-
result = asyncio.run(runner.run(script_path))
66-
67-
if result.success:
68-
console.print("✅ Execution completed successfully", style="green")
69-
if result.report_path:
70-
console.print(f"📊 Report: {result.report_path}")
71-
else:
72-
console.print("❌ Execution failed", style="red")
73-
if result.error:
74-
console.print(f"Error: {result.error}", style="red")
75-
sys.exit(1)
76-
77-
except Exception as e:
78-
console.print(f"❌ CLI Error: {e}", style="red")
79-
if verbose:
80-
logger.exception("CLI execution failed")
81-
sys.exit(1)
82-
83-
84-
@app.command()
85-
def validate(
86-
script_path: str = typer.Argument(..., help="Path to YAML script file"),
87-
):
88-
"""Validate automation script syntax"""
89-
90-
try:
91-
from .validator import ScriptValidator
92-
93-
validator = ScriptValidator()
94-
result = validator.validate_file(script_path)
95-
96-
if result.valid:
97-
console.print("✅ Script validation passed", style="green")
98-
else:
99-
console.print("❌ Script validation failed", style="red")
100-
for error in result.errors:
101-
console.print(f" • {error}", style="red")
102-
sys.exit(1)
103-
104-
except Exception as e:
105-
console.print(f"❌ Validation Error: {e}", style="red")
106-
sys.exit(1)
107-
108-
109-
@app.command()
110-
def devices():
111-
"""List available Android devices"""
112-
113-
try:
114-
from ..android import AndroidDevice
115-
116-
devices = asyncio.run(AndroidDevice.list_devices())
117-
118-
if not devices:
119-
console.print("No Android devices found", style="yellow")
120-
return
121-
122-
table = Table(title="Available Android Devices")
123-
table.add_column("Device ID", style="cyan")
124-
table.add_column("Status", style="green")
125-
126-
for device_id in devices:
127-
table.add_row(device_id, "Connected")
128-
129-
console.print(table)
130-
131-
except Exception as e:
132-
console.print(f"❌ Error listing devices: {e}", style="red")
133-
sys.exit(1)
134-
135-
136-
@app.command()
137-
def init(
138-
name: str = typer.Argument(..., help="Project name"),
139-
template: str = typer.Option("basic", "--template", "-t", help="Project template"),
140-
):
141-
"""Initialize new automation project"""
142-
143-
try:
144-
from .templates import ProjectTemplate
145-
146-
template_manager = ProjectTemplate()
147-
project_path = template_manager.create_project(name, template)
148-
149-
console.print(f"✅ Created project: {project_path}", style="green")
150-
console.print(f"📝 Edit {project_path}/scripts/example.yaml to get started")
151-
152-
except Exception as e:
153-
console.print(f"❌ Initialization Error: {e}", style="red")
154-
sys.exit(1)
32+
console.print(f"[yellow]Script execution not yet implemented: {script_path}[/yellow]")
33+
console.print("[blue]This is a placeholder CLI implementation[/blue]")
15534

15635

15736
@app.command()
15837
def version():
15938
"""Show version information"""
16039

16140
try:
162-
from .. import __version__
163-
console.print(f"Midscene Python v{__version__}")
41+
console.print("Midscene Python v0.1.0")
16442

16543
except Exception as e:
16644
console.print(f"❌ Error getting version: {e}", style="red")

midscene/core/types.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
from typing import Any, Dict, List, Optional, Union, Callable, Awaitable, Generic, TypeVar
99
from pydantic import BaseModel
1010

11+
# Type variables
12+
ElementType = TypeVar('ElementType', bound='BaseElement')
13+
T = TypeVar('T')
14+
1115

1216
class InterfaceType(str, Enum):
1317
"""Interface type enumeration"""
@@ -102,7 +106,7 @@ class UITree(BaseModel):
102106
children: List['UITree'] = field(default_factory=list)
103107

104108

105-
class UIContext(BaseModel, Generic[TypeVar('ElementType', bound=BaseElement)]):
109+
class UIContext(BaseModel, Generic[ElementType]):
106110
"""UI context containing screenshot and element information"""
107111
screenshot_base64: str
108112
size: Size
@@ -124,7 +128,7 @@ class LocateResult(BaseModel):
124128
rect: Optional[Rect] = None
125129

126130

127-
class ExecutionResult(BaseModel, Generic[TypeVar('T')]):
131+
class ExecutionResult(BaseModel, Generic[T]):
128132
"""Generic execution result"""
129133
success: bool = True
130134
data: Optional[Any] = None

pyproject.toml

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
[build-system]
2-
requires = ["hatchling", "hatch-vcs"]
2+
requires = ["hatchling"]
33
build-backend = "hatchling.build"
44

55
[project]
66
name = "midscene-python"
7-
description = "AI-powered automation framework for Web and Android platforms"
7+
description = "基于AI的Web和Android自动化框架,支持自然语言驱动的UI操作"
88
readme = "README.md"
99
license = "MIT"
1010
authors = [
@@ -25,26 +25,26 @@ classifiers = [
2525
]
2626
requires-python = ">=3.9"
2727
dependencies = [
28-
"pydantic>=2.0",
29-
"selenium>=4.15.0",
30-
"playwright>=1.40.0",
31-
"opencv-python>=4.8.0",
32-
"pillow>=10.0.0",
33-
"numpy>=1.24.0",
34-
"aiohttp>=3.9.0",
35-
"loguru>=0.7.0",
36-
"typer>=0.9.0",
37-
"jinja2>=3.1.0",
38-
"pyyaml>=6.0",
39-
"httpx>=0.25.0",
28+
"pydantic>=2.0,<3.0",
29+
"selenium>=4.15.0,<5.0",
30+
"playwright>=1.40.0,<2.0",
31+
"opencv-python>=4.8.0,<5.0",
32+
"pillow>=10.0.0,<11.0",
33+
"numpy>=1.24.0,<2.0",
34+
"aiohttp>=3.9.0,<4.0",
35+
"loguru>=0.7.0,<1.0",
36+
"typer>=0.9.0,<1.0",
37+
"jinja2>=3.1.0,<4.0",
38+
"pyyaml>=6.0,<7.0",
39+
"httpx>=0.25.0,<1.0",
4040
"asyncio-mqtt",
41-
"pure-python-adb>=0.3.0",
42-
"openai>=1.3.0",
43-
"anthropic>=0.7.0",
41+
"pure-python-adb>=0.3.0dev0",
42+
"openai>=1.3.0,<2.0",
43+
"anthropic>=0.7.0,<1.0",
4444
"google-generativeai",
4545
"dashscope",
4646
]
47-
dynamic = ["version"]
47+
version = "0.1.0"
4848

4949
[project.optional-dependencies]
5050
dev = [
@@ -72,11 +72,10 @@ Documentation = "https://midscenejs.com/python"
7272
[project.scripts]
7373
midscene = "midscene.cli:main"
7474

75-
[tool.hatch.version]
76-
source = "vcs"
75+
[tool.hatch.build.targets.wheel]
76+
packages = ["midscene"]
77+
7778

78-
[tool.hatch.build.hooks.vcs]
79-
version-file = "midscene/_version.py"
8079

8180
[tool.black]
8281
line-length = 88

0 commit comments

Comments
 (0)