Skip to content

Commit aa178e7

Browse files
authored
Merge pull request #78 from browserbase/miguel/stg-467-linting-workflow
linting workflow
2 parents cbbabdc + 3f9df91 commit aa178e7

File tree

13 files changed

+130
-49
lines changed

13 files changed

+130
-49
lines changed

.bumpversion.cfg

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
[bumpversion]
2-
current_version = 0.3.8
2+
current_version = 0.0.1
33
commit = True
44
tag = True
55

6-
[bumpversion:file:setup.py]
7-
search = version="{current_version}"
8-
replace = version="{new_version}"
6+
[bumpversion:file:pyproject.toml]
7+
search = version = "{current_version}"
8+
replace = version = "{new_version}"
99

1010
[bumpversion:file:stagehand/__init__.py]
1111
search = __version__ = "{current_version}"

.github/README_PUBLISHING.md

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,7 @@ This project uses Ruff for linting and formatting. The workflow enforces these s
5353

5454
To run the same checks locally:
5555
```bash
56-
# Install Ruff
57-
pip install ruff
58-
59-
# Run linting
60-
ruff check .
61-
62-
# Check formatting
63-
ruff format --check .
64-
65-
# Auto-fix issues where possible
66-
ruff check --fix .
67-
ruff format .
68-
69-
# Use Black to format the code
70-
black .
56+
./format.sh
7157
```
7258

7359
## Troubleshooting

.github/pull_request_template

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# why
2+
3+
# what changed
4+
5+
# test plan

.github/workflows/linting.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Format Check
2+
3+
on:
4+
pull_request:
5+
branches: [ main, master ]
6+
paths:
7+
- '**.py'
8+
- 'stagehand/**'
9+
- 'pyproject.toml'
10+
11+
jobs:
12+
format-check:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Check out repository
16+
uses: actions/checkout@v4
17+
18+
- name: Set up Python
19+
uses: actions/setup-python@v4
20+
with:
21+
python-version: '3.10'
22+
23+
- name: Install formatting dependencies
24+
run: |
25+
python -m pip install --upgrade pip
26+
pip install black ruff
27+
28+
- name: Check Black formatting
29+
run: |
30+
echo "Checking Black formatting..."
31+
black --check --diff stagehand
32+
33+
- name: Run Ruff linting
34+
run: |
35+
echo "Running Ruff linting..."
36+
ruff check stagehand

.github/workflows/publish.yml

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
- name: Install dependencies
3636
run: |
3737
python -m pip install --upgrade pip
38-
pip install build twine wheel setuptools bumpversion ruff
38+
pip install build twine wheel setuptools ruff
3939
pip install -r requirements.txt
4040
if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi
4141
@@ -51,19 +51,67 @@ jobs:
5151
run: |
5252
pytest
5353
54-
- name: Update version
54+
- name: Calculate new version
55+
id: version
56+
run: |
57+
# Get current version from pyproject.toml
58+
CURRENT_VERSION=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])")
59+
echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
60+
61+
# Parse version components
62+
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION"
63+
64+
# Calculate new version based on release type
65+
case "${{ github.event.inputs.release_type }}" in
66+
"major")
67+
NEW_MAJOR=$((MAJOR + 1))
68+
NEW_MINOR=0
69+
NEW_PATCH=0
70+
;;
71+
"minor")
72+
NEW_MAJOR=$MAJOR
73+
NEW_MINOR=$((MINOR + 1))
74+
NEW_PATCH=0
75+
;;
76+
"patch")
77+
NEW_MAJOR=$MAJOR
78+
NEW_MINOR=$MINOR
79+
NEW_PATCH=$((PATCH + 1))
80+
;;
81+
esac
82+
83+
NEW_VERSION="${NEW_MAJOR}.${NEW_MINOR}.${NEW_PATCH}"
84+
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
85+
echo "Bumping version from $CURRENT_VERSION to $NEW_VERSION"
86+
87+
- name: Update version files
88+
run: |
89+
CURRENT_VERSION="${{ steps.version.outputs.current_version }}"
90+
NEW_VERSION="${{ steps.version.outputs.new_version }}"
91+
92+
# Update pyproject.toml
93+
sed -i "s/version = \"$CURRENT_VERSION\"/version = \"$NEW_VERSION\"/" pyproject.toml
94+
95+
# Update __init__.py
96+
sed -i "s/__version__ = \"$CURRENT_VERSION\"/__version__ = \"$NEW_VERSION\"/" stagehand/__init__.py
97+
98+
echo "Updated version to $NEW_VERSION in pyproject.toml and __init__.py"
99+
100+
- name: Commit version bump
55101
run: |
56102
git config --local user.email "[email protected]"
57103
git config --local user.name "GitHub Action"
58-
bumpversion ${{ github.event.inputs.release_type }}
104+
git add pyproject.toml stagehand/__init__.py
105+
git commit -m "Bump version to ${{ steps.version.outputs.new_version }}"
106+
git tag "v${{ steps.version.outputs.new_version }}"
59107
60108
- name: Build package
61109
run: |
62110
python -m build
63111
64112
- name: Upload to PyPI
65113
env:
66-
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
114+
TWINE_USERNAME: __token__
67115
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
68116
run: |
69117
twine upload dist/*
@@ -77,6 +125,6 @@ jobs:
77125
if: ${{ github.event.inputs.create_release == 'true' }}
78126
uses: softprops/action-gh-release@v1
79127
with:
80-
tag_name: v$(python setup.py --version)
81-
name: Release v$(python setup.py --version)
128+
tag_name: v${{ steps.version.outputs.new_version }}
129+
name: Release v${{ steps.version.outputs.new_version }}
82130
generate_release_notes: true

format.sh

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
#!/bin/bash
22

33
# Define source directories (adjust as needed)
4-
SOURCE_DIRS="evals stagehand"
4+
SOURCE_DIRS="stagehand"
55

6-
# Apply Black formatting only to source directories
6+
# Apply Black formatting first
77
echo "Applying Black formatting..."
88
black $SOURCE_DIRS
99

10-
# Fix import sorting (addresses I001 errors)
11-
echo "Sorting imports..."
12-
isort $SOURCE_DIRS
13-
14-
# Apply Ruff with autofix for remaining issues
15-
echo "Applying Ruff autofixes..."
10+
# Apply Ruff with autofix for all issues (including import sorting)
11+
echo "Applying Ruff autofixes (including import sorting)..."
1612
ruff check --fix $SOURCE_DIRS
1713

1814
echo "Checking for remaining issues..."

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ requires = ["setuptools>=61.0", "wheel"]
33
build-backend = "setuptools.build_meta"
44

55
[project]
6-
name = "stagehand-py"
7-
version = "0.3.10"
6+
name = "stagehand"
7+
version = "0.0.1"
88
description = "Python SDK for Stagehand"
99
readme = "README.md"
1010
license = {text = "MIT"}

stagehand/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
)
2020
from .utils import configure_logging
2121

22-
__version__ = "0.3.9" #for pypi "stagehand"
22+
__version__ = "0.0.1"
2323

2424
__all__ = [
2525
"Stagehand",

stagehand/client.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,23 +76,23 @@ def __init__(
7676
# Start with provided config or default config
7777
if config is None:
7878
config = default_config
79-
79+
8080
# Apply any overrides
8181
overrides = {}
8282
if api_url is not None:
8383
# api_url isn't in config, handle separately
8484
pass
8585
if model_api_key is not None:
86-
# model_api_key isn't in config, handle separately
86+
# model_api_key isn't in config, handle separately
8787
pass
8888
if session_id is not None:
89-
overrides['browserbase_session_id'] = session_id
89+
overrides["browserbase_session_id"] = session_id
9090
if env is not None:
91-
overrides['env'] = env
92-
91+
overrides["env"] = env
92+
9393
# Add any additional config overrides
9494
overrides.update(config_overrides)
95-
95+
9696
# Create final config with overrides
9797
if overrides:
9898
self.config = config.with_overrides(**overrides)
@@ -102,10 +102,14 @@ def __init__(
102102
# Handle non-config parameters
103103
self.api_url = api_url or os.getenv("STAGEHAND_API_URL")
104104
self.model_api_key = model_api_key or os.getenv("MODEL_API_KEY")
105-
105+
106106
# Extract frequently used values from config for convenience
107-
self.browserbase_api_key = self.config.api_key or os.getenv("BROWSERBASE_API_KEY")
108-
self.browserbase_project_id = self.config.project_id or os.getenv("BROWSERBASE_PROJECT_ID")
107+
self.browserbase_api_key = self.config.api_key or os.getenv(
108+
"BROWSERBASE_API_KEY"
109+
)
110+
self.browserbase_project_id = self.config.project_id or os.getenv(
111+
"BROWSERBASE_PROJECT_ID"
112+
)
109113
self.session_id = self.config.browserbase_session_id
110114
self.model_name = self.config.model_name
111115
self.dom_settle_timeout_ms = self.config.dom_settle_timeout_ms
@@ -114,7 +118,9 @@ def __init__(
114118
self.system_prompt = self.config.system_prompt
115119
self.verbose = self.config.verbose
116120
self.env = self.config.env.upper() if self.config.env else "BROWSERBASE"
117-
self.local_browser_launch_options = self.config.local_browser_launch_options or {}
121+
self.local_browser_launch_options = (
122+
self.config.local_browser_launch_options or {}
123+
)
118124

119125
# Handle model-related settings
120126
self.model_client_options = {}

stagehand/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ class StagehandConfig(BaseModel):
8888
def with_overrides(self, **overrides) -> "StagehandConfig":
8989
"""
9090
Create a new config instance with the specified overrides.
91-
91+
9292
Args:
9393
**overrides: Key-value pairs to override in the config
94-
94+
9595
Returns:
9696
StagehandConfig: New config instance with overrides applied
9797
"""

0 commit comments

Comments
 (0)