Skip to content

Commit 2d3fea6

Browse files
committed
Correct the release chart package workflow
1 parent 98d24f5 commit 2d3fea6

24 files changed

+129
-64
lines changed

.github/workflows/charts_tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- name: Set up Python
2121
uses: actions/setup-python@v4
2222
with:
23-
python-version: '3.8'
23+
python-version: '3.10'
2424

2525
- name: Install and configure Poetry
2626
uses: snok/install-poetry@v1
@@ -37,4 +37,4 @@ jobs:
3737
run: poetry build
3838

3939
- name: Run tests
40-
run: poetry run pytest -n 4 --verbose -x
40+
run: poetry run pytest --verbose -x

.github/workflows/pr.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ jobs:
5656
uses: ./.github/workflows/js_tests.yml
5757
secrets: inherit
5858

59-
js-tests:
59+
charts-tests:
6060
needs: [ changes ]
61-
name: Tests JS package
61+
name: Tests Chart package
6262
# If the PR does not have the label 'js-rc', the code is already tested in the prerelease workflow
6363
if: needs.changes.outputs.charts == 'true' && !contains( github.event.pull_request.labels.*.name, 'charts-rc')
6464
uses: ./.github/workflows/charts_tests.yml

.github/workflows/release.yml

Lines changed: 55 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ jobs:
5656
outputs:
5757
js: ${{ steps.filter.outputs.js }}
5858
python: ${{ steps.filter.outputs.python }}
59+
charts: ${{ steps.filter.outputs.charts }}
60+
template: ${{ steps.filter.outputs.template }}
5961
steps:
6062
- name: Checkout repository
6163
uses: actions/checkout@v3
@@ -82,6 +84,10 @@ jobs:
8284
- 'js/**'
8385
python:
8486
- 'python/**'
87+
charts:
88+
- 'chart_data_extractor/**'
89+
template:
90+
- 'template/**'
8591
8692
charts-tests:
8793
name: Charts tests
@@ -93,34 +99,59 @@ jobs:
9399
name: Charts release
94100
needs: [charts-tests]
95101
if: needs.changes.outputs.charts == 'true'
96-
defaults:
97-
run:
98-
working-directory: ./charts
99102
runs-on: ubuntu-latest
100103
steps:
101104
- name: Checkout Repo
102105
uses: actions/checkout@v3
103106

107+
- name: Install pnpm
108+
uses: pnpm/action-setup@v3
109+
id: pnpm-install
110+
with:
111+
version: 9.5
112+
113+
- name: Set up Python
114+
uses: actions/setup-python@v4
115+
with:
116+
python-version: '3.10'
117+
118+
- name: Install and configure Poetry
119+
uses: snok/install-poetry@v1
120+
with:
121+
version: 1.5.1
122+
virtualenvs-create: true
123+
virtualenvs-in-project: true
124+
installer-parallel: true
125+
126+
- name: Configure pnpm
127+
run: |
128+
pnpm config set auto-install-peers true
129+
pnpm config set exclude-links-from-lockfile true
130+
131+
- name: Install dependencies
132+
run: pnpm install --frozen-lockfile
133+
104134
- name: Create new versions
105135
run: pnpm run version
106136
env:
107137
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
108138

109139
- name: Release new versions
110-
uses: changesets/action@v1
111-
with:
112-
publish: pnpm run publish
113-
createGithubReleases: true
140+
run: |
141+
poetry build
142+
poetry config pypi-token.pypi ${PYPI_TOKEN}
143+
poetry publish --skip-existing
144+
working-directory: ./chart_data_extractor
114145
env:
115146
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
116-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
147+
PYPI_TOKEN: ${{ secrets.CHARTS_PYPI_TOKEN }}
117148

118149

119150
build-docker-image:
120151
name: Build Docker Image
121152
runs-on: ubuntu-latest
122153
needs: [changes, charts-release]
123-
if: !cancelled() && needs.changes.outputs.template == 'true' || needs.changes.outputs.charts == 'true'
154+
if: needs.changes.outputs.template == 'true' || needs.changes.outputs.charts == 'true'
124155
steps:
125156
- name: Checkout repository
126157
uses: actions/checkout@v3
@@ -147,10 +178,10 @@ jobs:
147178
--tag ${{ secrets.DOCKERHUB_USERNAME }}/code-interpreter:latest .
148179
149180
build-template:
150-
name: Build Docker Image
181+
name: Build E2B template
151182
runs-on: ubuntu-latest
152183
needs: [build-docker-image]
153-
if: !cancelled() && needs.changes.outputs.template == 'true' || needs.changes.outputs.charts == 'true'
184+
if: needs.changes.outputs.template == 'true' || needs.changes.outputs.charts == 'true'
154185
steps:
155186
- name: Checkout repository
156187
uses: actions/checkout@v3
@@ -168,20 +199,29 @@ jobs:
168199
python-tests:
169200
name: Python Tests
170201
needs: [changes, build-template]
171-
if: !cancelled() && needs.changes.outputs.python == 'true' || needs.changes.outputs.template == 'true'
202+
if: always() &&
203+
!contains(needs.*.result, 'failure') &&
204+
!contains(needs.*.result, 'cancelled') &&
205+
(needs.changes.outputs.python == 'true' || needs.changes.outputs.template == 'true')
172206
uses: ./.github/workflows/python_tests.yml
173207
secrets: inherit
174208

175209
js-tests:
176210
name: JS Tests
177-
needs: [changes]
178-
if: !cancelled() && needs.changes.outputs.js == 'true' || needs.changes.outputs.template == 'true'
211+
needs: [changes, build-template]
212+
if: always() &&
213+
!contains(needs.*.result, 'failure') &&
214+
!contains(needs.*.result, 'cancelled') &&
215+
(needs.changes.outputs.js == 'true' || needs.changes.outputs.template == 'true')
179216
uses: ./.github/workflows/js_tests.yml
180217
secrets: inherit
181218

182219
release:
183220
needs: [python-tests, js-tests]
184-
if: (!cancelled()) && !contains(needs.*.result, 'failure') && needs.is_release.outputs.release == 'true'
221+
if: always() &&
222+
!contains(needs.*.result, 'failure') &&
223+
!contains(needs.*.result, 'cancelled') &&
224+
(needs.changes.outputs.js == 'true' || needs.changes.outputs.python == 'true')
185225
name: Release
186226
runs-on: ubuntu-latest
187227
steps:

chart_data_extractor/e2b_charts/graphs/bars.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from pydantic import BaseModel, Field
55

66
from .base import Graph2D, GraphType
7+
from ..utils.rounding import dynamic_round
78

89

910
class BarData(BaseModel):
@@ -48,6 +49,7 @@ class BoxAndWhiskerData(BaseModel):
4849
median: float
4950
third_quartile: float
5051
max: float
52+
outliers: List[float]
5153

5254

5355
class BoxAndWhiskerGraph(Graph2D):
@@ -57,21 +59,23 @@ class BoxAndWhiskerGraph(Graph2D):
5759

5860
def _extract_info(self, ax: Axes) -> None:
5961
super()._extract_info(ax)
62+
labels = [item.get_text() for item in ax.get_xticklabels()]
6063

6164
boxes = []
62-
for box in ax.patches:
65+
for label, box in zip(labels, ax.patches):
6366
vertices = box.get_path().vertices
64-
x_vertices = vertices[:, 0]
65-
y_vertices = vertices[:, 1]
67+
x_vertices = [dynamic_round(x) for x in vertices[:, 0]]
68+
y_vertices = [dynamic_round(y) for y in vertices[:, 1]]
6669
x = min(x_vertices)
6770
y = min(y_vertices)
6871
boxes.append(
6972
{
7073
"x": x,
7174
"y": y,
72-
"label": box.get_label(),
73-
"width": round(max(x_vertices) - x, 4),
74-
"height": round(max(y_vertices) - y, 4),
75+
"label": label,
76+
"width": max(x_vertices) - x,
77+
"height": max(y_vertices) - y,
78+
"outliers": [],
7579
}
7680
)
7781

@@ -85,13 +89,21 @@ def _extract_info(self, ax: Axes) -> None:
8589
box["x"], box["y"] = box["y"], box["x"]
8690
box["width"], box["height"] = box["height"], box["width"]
8791

88-
for line in ax.lines:
89-
xdata = line.get_xdata()
90-
ydata = line.get_ydata()
92+
for i, line in enumerate(ax.lines):
93+
xdata = [dynamic_round(x) for x in line.get_xdata()]
94+
ydata = [dynamic_round(y) for y in line.get_ydata()]
9195

9296
if orientation == "vertical":
9397
xdata, ydata = ydata, xdata
9498

99+
if len(xdata) == 1:
100+
for box in boxes:
101+
if box["x"] <= xdata[0] <= box["x"] + box["width"]:
102+
break
103+
else:
104+
continue
105+
106+
box["outliers"].append(ydata[0])
95107
if len(ydata) != 2:
96108
continue
97109
for box in boxes:
@@ -101,6 +113,7 @@ def _extract_info(self, ax: Axes) -> None:
101113
continue
102114

103115
if (
116+
# Check if the line is inside the box, prevent floating point errors
104117
ydata[0] == ydata[1]
105118
and box["y"] <= ydata[0] <= box["y"] + box["height"]
106119
):
@@ -122,6 +135,7 @@ def _extract_info(self, ax: Axes) -> None:
122135
median=box["median"],
123136
third_quartile=box["y"] + box["height"],
124137
max=box["whisker_upper"],
138+
outliers=box["outliers"],
125139
)
126140
for box in boxes
127141
]

chart_data_extractor/e2b_charts/graphs/pie.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
from decimal import Decimal
12
from typing import Literal, List
23

34
from matplotlib.axes import Axes
45
from pydantic import BaseModel, Field
56

67
from .base import Graph, GraphType
8+
from ..utils.rounding import dynamic_round
79

810

911
class PieData(BaseModel):
@@ -23,7 +25,7 @@ def _extract_info(self, ax: Axes) -> None:
2325
for wedge in ax.patches:
2426
pie_data = PieData(
2527
label=wedge.get_label(),
26-
angle=abs(round(wedge.theta2 - wedge.theta1, 4)),
28+
angle=abs(dynamic_round(Decimal(wedge.theta2) - Decimal(wedge.theta1))),
2729
radius=wedge.r,
2830
)
2931

chart_data_extractor/e2b_charts/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from matplotlib.text import Text
1010
from pydantic import Field
1111

12-
from e2b_data_extraction.graphs import (
12+
from .graphs import (
1313
GraphType,
1414
Graph,
1515
LineGraph,
@@ -18,7 +18,7 @@
1818
PieGraph,
1919
ScatterGraph,
2020
)
21-
from e2b_data_extraction.utils.filtering import is_grid_line
21+
from .utils.filtering import is_grid_line
2222

2323

2424
class SuperGraph(Graph):
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from decimal import Decimal, localcontext
2+
3+
4+
def dynamic_round(number):
5+
# Convert to Decimal for precise control
6+
decimal_number = Decimal(str(number))
7+
8+
# Dynamically determine precision based on magnitude
9+
precision = max(1, 8 - decimal_number.adjusted()) # 8 digits of precision
10+
11+
with localcontext() as ctx:
12+
ctx.prec = precision # Set the dynamic precision
13+
return +decimal_number # The + operator applies rounding

chart_data_extractor/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
{
22
"name": "@e2b/data-extractor",
33
"private": true,
4-
"version": "0.0.0",
4+
"version": "0.0.1",
55
"scripts": {
66
"test": "poetry run pytest -n 4 --verbose -x",
77
"example": "poetry run python3 example.py",
88
"postVersion": "poetry version $(pnpm pkg get version --workspaces=false | tr -d \\\")",
9-
"postPublish": "poetry build && poetry config pypi-token.pypi ${PYPI_TOKEN} && poetry publish --skip-existing",
109
"pretest": "poetry install"
1110
}
1211
}

chart_data_extractor/pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
2-
name = "e2b-code-interpreter-data-extraction"
3-
version = "0.0.0"
2+
name = "e2b-charts"
3+
version = "0.0.1"
44
description = "Package for extracting data for E2B Code Interpreter"
55
authors = ["e2b <[email protected]>"]
66
license = "Apache-2.0"

chart_data_extractor/pytest.ini

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)