compose-runner 0.6.4rc2__py2.py3-none-any.whl → 0.6.6__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -28,7 +28,7 @@ version_tuple: VERSION_TUPLE
28
28
  commit_id: COMMIT_ID
29
29
  __commit_id__: COMMIT_ID
30
30
 
31
- __version__ = version = '0.6.4rc2'
32
- __version_tuple__ = version_tuple = (0, 6, 4, 'rc2')
31
+ __version__ = version = '0.6.6'
32
+ __version_tuple__ = version_tuple = (0, 6, 6)
33
33
 
34
34
  __commit_id__ = commit_id = None
@@ -0,0 +1,71 @@
1
+ from __future__ import annotations
2
+
3
+ import datetime as _dt
4
+ import logging
5
+ import os
6
+ from decimal import Decimal
7
+ from typing import Any, Dict
8
+
9
+ import boto3
10
+ from botocore.exceptions import BotoCoreError, ClientError
11
+
12
+ logger = logging.getLogger(__name__)
13
+ logger.setLevel(logging.INFO)
14
+
15
+ _CE_CLIENT = boto3.client("ce", region_name=os.environ.get("AWS_REGION", "us-east-1"))
16
+
17
+ COST_LIMIT_ENV = "COST_LIMIT_USD"
18
+
19
+
20
+ def _month_range(today: _dt.date) -> Dict[str, str]:
21
+ start = today.replace(day=1)
22
+ # Cost Explorer end date is exclusive; add a day to include today.
23
+ end = today + _dt.timedelta(days=1)
24
+ return {"Start": start.isoformat(), "End": end.isoformat()}
25
+
26
+
27
+ def _current_month_cost() -> Dict[str, Any]:
28
+ period = _month_range(_dt.date.today())
29
+ response = _CE_CLIENT.get_cost_and_usage(
30
+ TimePeriod=period,
31
+ Granularity="MONTHLY",
32
+ Metrics=["UnblendedCost"],
33
+ )
34
+ results = response.get("ResultsByTime", [])
35
+ total = results[0]["Total"]["UnblendedCost"] if results else {"Amount": "0", "Unit": "USD"}
36
+ amount = float(Decimal(total.get("Amount", "0")))
37
+ currency = total.get("Unit", "USD")
38
+ return {"amount": amount, "currency": currency, "time_period": period}
39
+
40
+
41
+ def handler(event: Dict[str, Any], context: Any) -> Dict[str, Any]:
42
+ limit_raw = os.environ.get(COST_LIMIT_ENV)
43
+ if not limit_raw:
44
+ raise RuntimeError(f"{COST_LIMIT_ENV} environment variable must be set.")
45
+
46
+ try:
47
+ limit = float(limit_raw)
48
+ except ValueError as exc: # noqa: PERF203
49
+ raise RuntimeError(f"Invalid {COST_LIMIT_ENV}: {limit_raw}") from exc
50
+
51
+ try:
52
+ cost = _current_month_cost()
53
+ except (ClientError, BotoCoreError) as exc:
54
+ logger.error("Failed to query Cost Explorer: %s", exc)
55
+ return {
56
+ "status": "ERROR",
57
+ "allowed": False,
58
+ "error": "cost_explorer_unavailable",
59
+ "limit": limit,
60
+ }
61
+
62
+ amount = cost["amount"]
63
+ allowed = amount < limit
64
+ return {
65
+ "status": "OK",
66
+ "allowed": allowed,
67
+ "current_spend": amount,
68
+ "limit": limit,
69
+ "currency": cost.get("currency", "USD"),
70
+ "time_period": cost.get("time_period"),
71
+ }
compose_runner/run.py CHANGED
@@ -198,6 +198,10 @@ class Runner:
198
198
  weights = self.cached_specification.get("weights", [])
199
199
  weight_conditions = {w: c for c, w in zip(conditions, weights)}
200
200
 
201
+ # since we added "order" to annotations
202
+ if isinstance(column_type, dict):
203
+ column_type = column_type.get("type")
204
+
201
205
  if not (conditions or weights) and column_type != "boolean":
202
206
  raise ValueError(
203
207
  f"Column type {column_type} requires a conditions and weights."
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: compose-runner
3
- Version: 0.6.4rc2
3
+ Version: 0.6.6
4
4
  Summary: A package for running neurosynth-compose analyses
5
5
  Project-URL: Repository, https://github.com/neurostuff/compose-runner
6
6
  Author-email: James Kent <jamesdkent21@gmail.com>
@@ -1,11 +1,12 @@
1
1
  compose_runner/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- compose_runner/_version.py,sha256=cybk8XYVdWK2Je29E0k4lwZfcW6ZxTZItOHcu6hpJqk,714
2
+ compose_runner/_version.py,sha256=36Xr9Xxe1YvCx4D9dhOO3FJ9uBAofY81kJm_SZPwDIQ,704
3
3
  compose_runner/cli.py,sha256=1tkxFgEe8Yk7VkzE8qxGmCGqLU7UbGin2VaP0AiZkVg,1101
4
4
  compose_runner/ecs_task.py,sha256=15CyLsaf2xrvWM-gGPDOXj_Hq8eJJPiH7xyRas93zn0,5352
5
- compose_runner/run.py,sha256=yIh8Fj8dfVKvahRl483qGOsDUoAS1FdsYrKZp_HknGo,18525
5
+ compose_runner/run.py,sha256=wNAm8_fKoBJElMVlY7GTODqjZJG8S6y8K-QCUljL6Ko,18666
6
6
  compose_runner/sentry.py,sha256=pjqwsZrXrKB0cCy-TL-_2eYJIqUU0aV-8e0SWUk-9Xw,320
7
7
  compose_runner/aws_lambda/__init__.py,sha256=yZNXXv7gCPSrtLCEX5Qf4cnzSTS3fHPV6k-SyZwiZIA,48
8
8
  compose_runner/aws_lambda/common.py,sha256=cA2G5lO4P8uVBqJaYcU6Y3P3t3syoTmk4SpLKZhAFo8,1688
9
+ compose_runner/aws_lambda/cost_check_handler.py,sha256=TjzlnXLOT7kW6RfYfXuFFpmusIckGjOeUM6y0_NztBw,2213
9
10
  compose_runner/aws_lambda/log_poll_handler.py,sha256=eEU-Ra_-17me3e4eqSTd2Nv_qoaOl7zi3kIxD58Tbek,1905
10
11
  compose_runner/aws_lambda/results_handler.py,sha256=vSxs4nbWyBmkFFKRGIp5-T4W2hPh9zgj7uNH-e18aW8,2107
11
12
  compose_runner/aws_lambda/run_handler.py,sha256=WbaoRp5hsWNqAgDamW9BPihp1tfVVTM94_HKHL4Uawg,6562
@@ -22,8 +23,8 @@ compose_runner/tests/cassettes/test_run/test_run_database_workflow.yaml,sha256=a
22
23
  compose_runner/tests/cassettes/test_run/test_run_group_comparison_workflow.yaml,sha256=FaZpMdcaM7TMgyueyZBGftm6ywUh1HhtGmCegXUmRFA,4029712
23
24
  compose_runner/tests/cassettes/test_run/test_run_string_group_comparison_workflow.yaml,sha256=pcn6tQwrimhDtP8yJ3jFlsfEOnk8FWybYQr9IQ5A_KA,3233839
24
25
  compose_runner/tests/cassettes/test_run/test_run_workflow.yaml,sha256=0Nk7eJWAmgYALG2ODrezbRhpYsc00JiuYVjXt3TUm5c,3857234
25
- compose_runner-0.6.4rc2.dist-info/METADATA,sha256=Q2Eb4lIUAgE88_wxf5xjxcBeL2r3EEvKqHzP7pC2CWc,3435
26
- compose_runner-0.6.4rc2.dist-info/WHEEL,sha256=tkmg4JIqwd9H8mL30xA7crRmoStyCtGp0VWshokd1Jc,105
27
- compose_runner-0.6.4rc2.dist-info/entry_points.txt,sha256=TyPmB9o2tSWw8L3mcach9r2EL7inRVXE9ew3_XReMIY,55
28
- compose_runner-0.6.4rc2.dist-info/licenses/LICENSE,sha256=PeiWxrrRme2rIpPMV9vjgGe7UHEKCIcTb0KagYhnyqo,1313
29
- compose_runner-0.6.4rc2.dist-info/RECORD,,
26
+ compose_runner-0.6.6.dist-info/METADATA,sha256=rL0VGkiWKExkNpJhLq4_Kh5ZfbezoVUIeo5d_ein7lc,3432
27
+ compose_runner-0.6.6.dist-info/WHEEL,sha256=aha0VrrYvgDJ3Xxl3db_g_MDIW-ZexDdrc_m-Hk8YY4,105
28
+ compose_runner-0.6.6.dist-info/entry_points.txt,sha256=TyPmB9o2tSWw8L3mcach9r2EL7inRVXE9ew3_XReMIY,55
29
+ compose_runner-0.6.6.dist-info/licenses/LICENSE,sha256=PeiWxrrRme2rIpPMV9vjgGe7UHEKCIcTb0KagYhnyqo,1313
30
+ compose_runner-0.6.6.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.27.0
2
+ Generator: hatchling 1.28.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py2-none-any
5
5
  Tag: py3-none-any