Skip to content

Commit 7af8e88

Browse files
fix: python release attempt 3 (#242)
* fix: maybe the classifier is deprecated * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * ruff * bump version for release --------- Co-authored-by: Oliver Browne <[email protected]>
1 parent 90d3fca commit 7af8e88

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+2496
-820
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
- uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684
2222
with:
2323
path: ~/.cache/pip
24-
key: ${{ runner.os }}-pip-${{ hashFiles('setup.py') }}
24+
key: ${{ runner.os }}-pip-${{ hashFiles('pyproject.toml') }}
2525
restore-keys: |
2626
${{ runner.os }}-pip-
2727
@@ -30,17 +30,9 @@ jobs:
3030
python -m pip install -e .[dev]
3131
if: steps.cache.outputs.cache-hit != 'true'
3232

33-
- name: Check formatting with black
33+
- name: Check formatting with ruff
3434
run: |
35-
black --check .
36-
37-
- name: Lint with flake8
38-
run: |
39-
flake8 posthog
40-
41-
- name: Check import order with isort
42-
run: |
43-
isort --check-only .
35+
ruff format --check .
4436
4537
- name: Check types with mypy
4638
run: |

.pre-commit-config.yaml

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
repos:
2-
- repo: https://github.com/psf/black
3-
rev: 25.1.0
4-
hooks:
5-
- id: black
6-
- repo: https://github.com/pycqa/isort
7-
rev: 6.0.1
8-
hooks:
9-
- id: isort
10-
- repo: https://github.com/pycqa/flake8
11-
rev: 7.2.0
12-
hooks:
13-
- id: flake8
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
# Ruff version.
4+
rev: v0.11.12
5+
hooks:
6+
# Run the linter.
7+
- id: ruff-check
8+
args: [ --fix ]
9+
# Run the formatter.
10+
- id: ruff-format

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## 4.3.0 - 2025-06-06
1+
## 4.3.1 - 2025-06-06
22

33
Add context management:
44
- New context manager with `posthog.new_context()`

Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
lint:
2-
pylint --rcfile=.pylintrc --reports=y --exit-zero analytics | tee pylint.out
3-
flake8 --max-complexity=10 --statistics analytics > flake8.out || true
2+
uvx ruff format
43

54
test:
65
coverage run -m pytest

example.py

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
# Add argument parsing
77
parser = argparse.ArgumentParser(description="PostHog Python library example")
88
parser.add_argument(
9-
"--flag", default="person-on-events-enabled", help="Feature flag key to check (default: person-on-events-enabled)"
9+
"--flag",
10+
default="person-on-events-enabled",
11+
help="Feature flag key to check (default: person-on-events-enabled)",
1012
)
1113
args = parser.parse_args()
1214

@@ -38,10 +40,19 @@
3840

3941

4042
# Capture an event
41-
posthog.capture("distinct_id", "event", {"property1": "value", "property2": "value"}, send_feature_flags=True)
43+
posthog.capture(
44+
"distinct_id",
45+
"event",
46+
{"property1": "value", "property2": "value"},
47+
send_feature_flags=True,
48+
)
4249

4350
print(posthog.feature_enabled("beta-feature", "distinct_id"))
44-
print(posthog.feature_enabled("beta-feature-groups", "distinct_id", groups={"company": "id:5"}))
51+
print(
52+
posthog.feature_enabled(
53+
"beta-feature-groups", "distinct_id", groups={"company": "id:5"}
54+
)
55+
)
4556

4657
print(posthog.feature_enabled("beta-feature", "distinct_id"))
4758

@@ -53,9 +64,14 @@
5364

5465
posthog.alias("distinct_id", "new_distinct_id")
5566

56-
posthog.capture("new_distinct_id", "event2", {"property1": "value", "property2": "value"})
5767
posthog.capture(
58-
"new_distinct_id", "event-with-groups", {"property1": "value", "property2": "value"}, groups={"company": "id:5"}
68+
"new_distinct_id", "event2", {"property1": "value", "property2": "value"}
69+
)
70+
posthog.capture(
71+
"new_distinct_id",
72+
"event-with-groups",
73+
{"property1": "value", "property2": "value"},
74+
groups={"company": "id:5"},
5975
)
6076

6177
# # Add properties to the person
@@ -82,7 +98,13 @@
8298
# Local Evaluation
8399

84100
# If flag has City=Sydney, this call doesn't go to `/decide`
85-
print(posthog.feature_enabled("test-flag", "distinct_id_random_22", person_properties={"$geoip_city_name": "Sydney"}))
101+
print(
102+
posthog.feature_enabled(
103+
"test-flag",
104+
"distinct_id_random_22",
105+
person_properties={"$geoip_city_name": "Sydney"},
106+
)
107+
)
86108

87109
print(
88110
posthog.feature_enabled(
@@ -98,7 +120,9 @@
98120
print(posthog.get_all_flags("distinct_id_random_22", only_evaluate_locally=True))
99121
print(
100122
posthog.get_all_flags(
101-
"distinct_id_random_22", person_properties={"$geoip_city_name": "Sydney"}, only_evaluate_locally=True
123+
"distinct_id_random_22",
124+
person_properties={"$geoip_city_name": "Sydney"},
125+
only_evaluate_locally=True,
102126
)
103127
)
104128
print(posthog.get_remote_config_payload("encrypted_payload_flag_key"))

mypy.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ check_untyped_defs = True
99
warn_unreachable = True
1010
strict_equality = True
1111
ignore_missing_imports = True
12-
exclude = env/.*|venv/.*
12+
exclude = env/.*|venv/.*|build/.*
1313

1414
[mypy-django.*]
1515
ignore_missing_imports = True

posthog/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ def capture_exception(
323323
timestamp=None, # type: Optional[datetime.datetime]
324324
uuid=None, # type: Optional[str]
325325
groups=None, # type: Optional[Dict]
326-
**kwargs
326+
**kwargs,
327327
):
328328
# type: (...) -> Tuple[bool, dict]
329329
"""
@@ -366,7 +366,7 @@ def capture_exception(
366366
timestamp=timestamp,
367367
uuid=uuid,
368368
groups=groups,
369-
**kwargs
369+
**kwargs,
370370
)
371371

372372

posthog/ai/anthropic/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
from .anthropic import Anthropic
22
from .anthropic_async import AsyncAnthropic
3-
from .anthropic_providers import AnthropicBedrock, AnthropicVertex, AsyncAnthropicBedrock, AsyncAnthropicVertex
3+
from .anthropic_providers import (
4+
AnthropicBedrock,
5+
AnthropicVertex,
6+
AsyncAnthropicBedrock,
7+
AsyncAnthropicVertex,
8+
)
49

510
__all__ = [
611
"Anthropic",

posthog/ai/anthropic/anthropic.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,20 @@
22
import anthropic
33
from anthropic.resources import Messages
44
except ImportError:
5-
raise ModuleNotFoundError("Please install the Anthropic SDK to use this feature: 'pip install anthropic'")
5+
raise ModuleNotFoundError(
6+
"Please install the Anthropic SDK to use this feature: 'pip install anthropic'"
7+
)
68

79
import time
810
import uuid
911
from typing import Any, Dict, Optional
1012

11-
from posthog.ai.utils import call_llm_and_track_usage, get_model_params, merge_system_prompt, with_privacy_mode
13+
from posthog.ai.utils import (
14+
call_llm_and_track_usage,
15+
get_model_params,
16+
merge_system_prompt,
17+
with_privacy_mode,
18+
)
1219
from posthog.client import Client as PostHogClient
1320

1421

@@ -186,8 +193,12 @@ def _capture_streaming_event(
186193
"$ai_http_status": 200,
187194
"$ai_input_tokens": usage_stats.get("input_tokens", 0),
188195
"$ai_output_tokens": usage_stats.get("output_tokens", 0),
189-
"$ai_cache_read_input_tokens": usage_stats.get("cache_read_input_tokens", 0),
190-
"$ai_cache_creation_input_tokens": usage_stats.get("cache_creation_input_tokens", 0),
196+
"$ai_cache_read_input_tokens": usage_stats.get(
197+
"cache_read_input_tokens", 0
198+
),
199+
"$ai_cache_creation_input_tokens": usage_stats.get(
200+
"cache_creation_input_tokens", 0
201+
),
191202
"$ai_latency": latency,
192203
"$ai_trace_id": posthog_trace_id,
193204
"$ai_base_url": str(self._client.base_url),

posthog/ai/anthropic/anthropic_async.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,20 @@
22
import anthropic
33
from anthropic.resources import AsyncMessages
44
except ImportError:
5-
raise ModuleNotFoundError("Please install the Anthropic SDK to use this feature: 'pip install anthropic'")
5+
raise ModuleNotFoundError(
6+
"Please install the Anthropic SDK to use this feature: 'pip install anthropic'"
7+
)
68

79
import time
810
import uuid
911
from typing import Any, Dict, Optional
1012

11-
from posthog.ai.utils import call_llm_and_track_usage_async, get_model_params, merge_system_prompt, with_privacy_mode
13+
from posthog.ai.utils import (
14+
call_llm_and_track_usage_async,
15+
get_model_params,
16+
merge_system_prompt,
17+
with_privacy_mode,
18+
)
1219
from posthog.client import Client as PostHogClient
1320

1421

@@ -186,8 +193,12 @@ async def _capture_streaming_event(
186193
"$ai_http_status": 200,
187194
"$ai_input_tokens": usage_stats.get("input_tokens", 0),
188195
"$ai_output_tokens": usage_stats.get("output_tokens", 0),
189-
"$ai_cache_read_input_tokens": usage_stats.get("cache_read_input_tokens", 0),
190-
"$ai_cache_creation_input_tokens": usage_stats.get("cache_creation_input_tokens", 0),
196+
"$ai_cache_read_input_tokens": usage_stats.get(
197+
"cache_read_input_tokens", 0
198+
),
199+
"$ai_cache_creation_input_tokens": usage_stats.get(
200+
"cache_creation_input_tokens", 0
201+
),
191202
"$ai_latency": latency,
192203
"$ai_trace_id": posthog_trace_id,
193204
"$ai_base_url": str(self._client.base_url),

0 commit comments

Comments
 (0)