Skip to content
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
15 changes: 15 additions & 0 deletions .claude/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"hooks": {
"PostToolUse": [
{
"matcher": "Write|Edit|MultiEdit",
"hooks": [
{
"type": "command",
"command": "jq -r .tool_input.file_path | { read file_path; if echo \"$file_path\" | grep -qE \"\\.(py)$\"; then scripts/lint.sh \"$file_path\"; fi; }"
}
]
}
]
}
}
19 changes: 17 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ packages = [{ include = "cvec", from = "src" }]
pytest = "^8.3.5"
mypy = "^1.15.0"
ruff = "^0.11.10"
types-requests = "^2.32.0"

[build-system]
requires = ["poetry-core>=2.0.0,<3.0.0"]
Expand Down
10 changes: 10 additions & 0 deletions scripts/csv_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from datetime import datetime
from pathlib import Path
from typing import List, Optional
import requests

from cvec import CVec
from cvec.models.metric import MetricDataPoint
Expand All @@ -30,6 +31,7 @@ def parse_timestamp(timestamp_str: str) -> datetime:
"%Y-%m-%d",
"%m/%d/%Y %H:%M:%S",
"%m/%d/%Y",
"%m/%d/%y %H:%M",
]

for fmt in formats:
Expand Down Expand Up @@ -209,6 +211,14 @@ def main() -> None:
metric_prefix=args.prefix,
)

except requests.HTTPError as e:
print(f"Error: {e}")
# Display CloudFront ID if available
if e.response is not None:
cf_id = e.response.headers.get("x-amz-cf-id")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For better maintainability and readability, it's a good practice to define magic strings like "x-amz-cf-id" as a constant at the module level (e.g., CLOUDFRONT_ID_HEADER = "x-amz-cf-id") and use the constant here. This makes it easier to find and update such values if they change.

if cf_id:
print(f"Cf-Id: {cf_id}")
sys.exit(1)
except Exception as e:
print(f"Error: {e}")
sys.exit(1)
Expand Down
14 changes: 11 additions & 3 deletions scripts/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ set -e

TARGET=${1:-.}

poetry run ruff check --fix "$TARGET"
poetry run ruff format "$TARGET"
poetry run mypy --strict "$TARGET"
echo -e "poetry run ruff check --fix" "$@"
poetry run ruff check --fix "$@"

echo -e "\npoetry run ruff format" "$@"
poetry run ruff format "$@"

echo -e "\nrun mypy --strict" "$@"
poetry run mypy --strict "$@"

echo -e "\npoetry run pytest"
poetry run pytest
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The lint.sh script is now also running tests, which is a significant change in its responsibility. More importantly, pytest is run without arguments, which means it will execute the entire test suite regardless of the file paths passed to lint.sh. This can be very inefficient, especially when linting a single file. If the intention is to run tests only for the specified files, you should pass the arguments to pytest.

Suggested change
poetry run pytest
poetry run pytest "$@"

2 changes: 1 addition & 1 deletion src/cvec/cvec.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import Any, Dict, List, Optional
from urllib.parse import urljoin

import requests # type: ignore[import-untyped]
import requests

from cvec.models.metric import Metric, MetricDataPoint
from cvec.models.span import Span
Expand Down