Skip to content

Add CLI tool scaffolding #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Jun 9, 2025
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
6 changes: 5 additions & 1 deletion .cursor/rules/overview.mdc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ There is an existing project in `legacy/ios/sizeAnalysis/`. THIS IS CONSIDERED L

The new project will be purely in python. Create a project structure that you think makes sense following the Sentry python guidelines and modern python practices. Keep in mind that there will be both iOS and Android size analysis projects, so consider that when organizing code and what might be shared between them.

The iOS analysis code ONLY has to work with `.xcarchive.zip` files as input.

# Python rules

For the Python code make sure to follow all of Sentry's best practices, as well as modern Python best practices. Try to use types as much as possible. If standard repo setup is not present, feel free to configure it and add it to the repo since this is currently a bare setup.
Expand All @@ -28,4 +30,6 @@ For the Mach-O handling, use the `lief` library and follow best practices for th

# Testing

Included is a `test/artifacts` directory which contains sample "clean room" apps that can be used for writing integration tests and validating the output of this tool. Always write new tests to validate behavior and functionality. Prefer to write integration tests using the sample apps instead of writing smaller unit tests or using mocks.
Included is a `test/artifacts` directory which contains sample "clean room" apps that can be used for writing integration tests and validating the output of this tool. Always write new tests to validate behavior and functionality. Prefer to write integration tests using the sample apps instead of writing smaller unit tests or using mocks.

Make sure to write tests using `pytest`.
36 changes: 33 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,34 @@
*.egg-info
*.pyc
__pycache__\
# Python
*.pyc
__pycache__/
*.egg-info/
dist/
build/
.pytest_cache/
.coverage
htmlcov/

# Virtual environments
venv/
.venv/
env/

# IDE
.vscode/
.idea/
*.swp
*.swo

# OS
.DS_Store
Thumbs.db

# Temporary files
*.tmp
*.temp
.temporary/

ios-analysis-report.json
android-analysis-report.json


36 changes: 36 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- id: check-merge-conflict
- id: debug-statements

- repo: https://github.com/psf/black
rev: 23.9.1
hooks:
- id: black
language_version: python3.11
args: [--line-length=100]

- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
args: [--profile=black, --line-length=100]

- repo: https://github.com/pycqa/flake8
rev: 6.1.0
hooks:
- id: flake8
args: [--max-line-length=100, --extend-ignore=E203,W503]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.5.1
hooks:
- id: mypy
additional_dependencies: [types-all]
args: [--strict, --ignore-missing-imports]
100 changes: 100 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# App Size Analyzer

A CLI tool for analyzing iOS and Android app bundle sizes, providing detailed insights into file composition, binary structure, and optimization opportunities.

## Installation

### From Source

```bash
# Clone the repository
git clone <repository-url>
cd app-size-analyzer

# Install in development mode
pip install -e ".[dev]"
```

## Quick Start

### Analyze an iOS App

```bash
# Analyze a bundle
app-size-analyzer ios MyApp.xcarchive.zip

# Analyze a bundle with custom output location
app-size-analyzer ios MyApp.xcarchive.zip -o detailed-report.json

# Skip expensive operations for faster analysis
app-size-analyzer ios MyApp.xcarchive.zip --skip-swift-metadata --skip-symbols
```

### Command Line Options

```bash
app-size-analyzer ios [OPTIONS] INPUT_PATH

Options:
-o, --output PATH Output path for JSON report [default: analysis-report.json]
--working-dir PATH Working directory for temporary files
--platform [ios|android] Target platform (auto-detected if not specified)
--skip-swift-metadata Skip Swift metadata parsing
--skip-symbols Skip symbol extraction
--format [json|table] Output format [default: json]
-v, --verbose Enable verbose logging
-q, --quiet Suppress all output except errors
--help Show this message and exit
```

## Development

### Setup

```bash
# Clone and setup development environment
git clone <repository-url>
cd app-size-analyzer
pip install -e ".[dev]"

# Install pre-commit hooks
pre-commit install
```

### Code Quality

This project uses several tools to maintain code quality:

- **Black**: Code formatting
- **isort**: Import sorting
- **mypy**: Static type checking
- **flake8**: Linting
- **pytest**: Testing

Run all checks:

```bash
# Format code
black src tests
isort src tests

# Type checking
mypy src

# Linting
flake8 src tests

# Tests
pytest
```

### Testing

```bash
# Run all tests
pytest

# Run specific test categories
pytest tests/unit/
pytest tests/integration/
```
102 changes: 102 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "app-size-analyzer"
version = "1.0.0"
description = "CLI tool for analyzing iOS and Android app bundle sizes"
readme = "README.md"
license = {file = "LICENSE"}
authors = [
{name = "Sentry Team", email = "[email protected]"},
]
classifiers = [
"Development Status :: 4 - Beta",
"Environment :: Console",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Operating System :: MacOS",
"Operating System :: POSIX :: Linux",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Software Development :: Build Tools",
"Topic :: System :: Archiving",
]
requires-python = ">=3.11"
dependencies = [
"click>=8.1.0",
"lief>=0.14.0",
"pydantic>=2.0.0",
"rich>=13.0.0",
"typing-extensions>=4.8.0",
]

[project.optional-dependencies]
dev = [
"pytest>=7.4.0",
"pytest-mock>=3.11.0",
"black>=23.0.0",
"isort>=5.12.0",
"flake8>=6.0.0",
"mypy>=1.5.0",
"pre-commit>=3.4.0",
]

[project.scripts]
app-size-analyzer = "app_size_analyzer.cli:main"

[project.urls]
Repository = "https://github.com/getsentry/app-size-analyzer"
Issues = "https://github.com/getsentry/app-size-analyzer/issues"

[tool.hatch.build.targets.wheel]
packages = ["src/app_size_analyzer"]

[tool.hatch.build.targets.sdist]
include = [
"/src",
"/tests",
"/README.md",
"/LICENSE",
]

[tool.black]
line-length = 100
target-version = ["py311"]
include = '\\.pyi?$'

[tool.isort]
profile = "black"
line_length = 100
known_first_party = ["app_size_analyzer"]

[tool.mypy]
python_version = "3.11"
strict = true
warn_return_any = true
warn_unused_configs = true
disallow_untyped_defs = true
disallow_incomplete_defs = true
check_untyped_defs = true
disallow_untyped_decorators = true
no_implicit_optional = true
warn_redundant_casts = true
warn_unused_ignores = true
warn_no_return = true
warn_unreachable = true

[[tool.mypy.overrides]]
module = ["lief.*"]
ignore_missing_imports = true

[tool.pytest.ini_options]
testpaths = ["tests"]
python_files = "test_*.py"
python_classes = "Test*"
python_functions = "test_*"
addopts = [
"--strict-markers",
"--strict-config",
]
Empty file removed requirements-dev.txt
Empty file.
12 changes: 12 additions & 0 deletions src/app_size_analyzer/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""App Size Analyzer - CLI tool for analyzing iOS and Android app bundle sizes."""

__version__ = "0.0.1"

from .models import AnalysisResults, AppInfo, FileAnalysis, BinaryAnalysis

__all__ = [
"AnalysisResults",
"AppInfo",
"FileAnalysis",
"BinaryAnalysis",
]
7 changes: 7 additions & 0 deletions src/app_size_analyzer/analyzers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""Platform-specific analyzers for app bundles."""

from .ios import IOSAnalyzer

__all__ = [
"IOSAnalyzer",
]
Loading