Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SY-1438 basic calculated channels #995

Merged
merged 144 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from 79 commits
Commits
Show all changes
144 commits
Select commit Hold shift + click to select a range
2a5f339
checkpoint
emilbon99 Sep 30, 2024
823ac6e
checkpoint
emilbon99 Oct 1, 2024
a2e4012
Merge branch 'rc' of https://github.com/synnaxlabs/synnax into sy-124…
emilbon99 Oct 3, 2024
3b94589
[doodle] - doggy
emilbon99 Oct 3, 2024
bae4276
Merge branch 'rc' of https://github.com/synnaxlabs/synnax into sy-124…
emilbon99 Oct 4, 2024
e045b06
checkpoint
emilbon99 Oct 4, 2024
cd35080
Merge branch 'rc' of https://github.com/synnaxlabs/synnax into sy-124…
emilbon99 Oct 4, 2024
0be5cc3
[checkpoint]
emilbon99 Oct 4, 2024
ee753f3
checkpoint
emilbon99 Oct 7, 2024
cf0deca
Merge branch 'rc' of https://github.com/synnaxlabs/synnax into sy-124…
emilbon99 Oct 13, 2024
3401e42
[computron] - simplified package
emilbon99 Oct 13, 2024
3547ecd
[computron] - updated embedded logic
emilbon99 Oct 13, 2024
5f6a002
[computron] - improved unsafe slice data access
emilbon99 Oct 13, 2024
2fade90
[computron] - separated build files for different OSes
emilbon99 Oct 13, 2024
0004480
[computron] - mod tidy
emilbon99 Oct 13, 2024
9d1fea0
[console] - fixed modal positioning
emilbon99 Oct 14, 2024
8a19ad2
Merge branch 'rc' of https://github.com/synnaxlabs/synnax into sy-124…
emilbon99 Oct 22, 2024
2c7e9c6
Merge branch 'rc' of https://github.com/synnaxlabs/synnax into sy-124…
emilbon99 Nov 1, 2024
e8bbfcc
[computron] - simplified expressions and reduced amount of code
emilbon99 Nov 1, 2024
52de3d1
[synnax] - touch ups to calculated channel service
emilbon99 Nov 1, 2024
f62414f
[synnax] - fixed issues with renaming multiple channels of different …
emilbon99 Nov 2, 2024
40509e4
Merge branch 'rc' of https://github.com/synnaxlabs/synnax into sy-143…
emilbon99 Nov 5, 2024
a927e0e
Merge branch 'rc' of https://github.com/synnaxlabs/synnax into sy-143…
emilbon99 Nov 18, 2024
02d85e1
[console] - re-added monaco editor to package.json
emilbon99 Nov 26, 2024
74c994a
[synnax] - fixed merge conflict for calculated channels
emilbon99 Dec 4, 2024
3c1139a
[computron] update build script
Lham42 Dec 5, 2024
90b8df4
checkpoint
Lham42 Dec 5, 2024
30d034b
checkpoint
Lham42 Dec 6, 2024
b3bb6cd
builds but linking error
Lham42 Dec 6, 2024
faba424
checkpoint - encodings error
Lham42 Dec 6, 2024
75ac1b8
[computron] refactor to have seperate compturon files for windows and…
Lham42 Dec 7, 2024
5861bb5
[computron] missed change in mac build script
Lham42 Dec 7, 2024
a863b7f
Merge branch 'rc' of https://github.com/synnaxlabs/synnax into sy-143…
Lham42 Dec 7, 2024
c800d79
[pluto] remove doodle
Lham42 Dec 7, 2024
3b56418
Merge branch 'sy-1438-calculated-channels' of github.com:synnaxlabs/s…
Lham42 Dec 7, 2024
448558a
[pluto] remove doodle
Lham42 Dec 9, 2024
ff78352
[pluto] open edit channel from resource tree
Lham42 Dec 9, 2024
a694fbd
[console] load in data from the calculated channel when editing
Lham42 Dec 10, 2024
cacb53f
[api/dist] update calc channels through create pipeline
Lham42 Dec 12, 2024
b43b710
[console/client] add tests - still name doesnt get updated in tree bu…
Lham42 Dec 13, 2024
603bf80
[distribution/channel] can update name as well now
Lham42 Dec 13, 2024
92779d6
checkpoint
Lham42 Dec 13, 2024
bbec96e
checkpoint
Lham42 Dec 14, 2024
d1f7fb6
Merge branch 'main' of github.com:synnaxlabs/synnax into sy-1438-calc…
Lham42 Dec 17, 2024
9ae54ef
update tests
Lham42 Dec 17, 2024
614fa89
[dist] fix tests
Lham42 Dec 17, 2024
d6cc473
[checkpoint]
Lham42 Dec 17, 2024
59cf4bd
remove unnecessary logs
Lham42 Dec 17, 2024
540284a
remove unrelated changes to py examples
Lham42 Dec 17, 2024
0c4454f
delete empty files
Lham42 Dec 17, 2024
10f0e53
remove commented out tests
Lham42 Dec 17, 2024
d19072a
address pr comments
Lham42 Dec 18, 2024
78227c0
[x/go] add testes for embed
Lham42 Dec 18, 2024
74f6ef5
address more pr comments
Lham42 Dec 18, 2024
2ca1caa
[distribution/channel] refactor createFreVirtual
Lham42 Dec 19, 2024
3b454f6
[distribution/channel] update tests to retrieve after update:
Lham42 Dec 19, 2024
d8ffe99
[console] refactor calculated modal
Lham42 Dec 19, 2024
37501fd
pr comment:
Lham42 Dec 20, 2024
6d93fc4
unfocus test
Lham42 Dec 20, 2024
13e4433
nested expression
Lham42 Dec 20, 2024
f1fec0f
add ts test
Lham42 Dec 20, 2024
d535849
address pr comments
Lham42 Dec 21, 2024
4d199dd
test
Lham42 Dec 21, 2024
e903915
reduce code duplication
Lham42 Dec 21, 2024
e366fc3
[computron] tests pass on windows
Lham42 Dec 23, 2024
e9b44e3
[computron] removed warnings on windows build
Lham42 Dec 23, 2024
47abd16
move python install dir to temp
Lham42 Dec 23, 2024
02ae60e
[computron] clean up
Lham42 Dec 23, 2024
37bc544
use lockTHreadAndGIL
Lham42 Dec 23, 2024
fb72e83
[console/calc chans] add a hook to update requires list upon opening
Lham42 Dec 23, 2024
12aea6b
checkpoint
Lham42 Dec 26, 2024
b659e8c
checkpoint
Lham42 Dec 26, 2024
b0b0640
[console] lint
Lham42 Dec 26, 2024
282696f
pr comments
Lham42 Dec 26, 2024
906ac3f
[computron] fix windows path
Lham42 Dec 26, 2024
124a8cd
[computron] pass python error to log
Lham42 Dec 28, 2024
a138c36
[computron/calculated] log warnings
Lham42 Dec 28, 2024
b4b0db7
[console/calc] update schema
Lham42 Dec 28, 2024
3596532
[calculated] improve error handling
Lham42 Dec 29, 2024
b26ff7b
windows installer
Lham42 Jan 8, 2025
db5e1d3
update windows workflow
Lham42 Jan 9, 2025
95583cd
handle passing hyphens into the calc expression
Lham42 Jan 10, 2025
5470f9e
[pkg/service/framer/calc] tests
Lham42 Jan 10, 2025
3876174
[pkg/service/framer/calc] div by zero test
Lham42 Jan 10, 2025
c120ebc
change hyphen message
Lham42 Jan 10, 2025
ab2fab7
[pkg/service/channel and pkg/service/framer/] update calc expression …
Lham42 Jan 10, 2025
c078772
[console/src/channel] add beta tag
Lham42 Jan 11, 2025
787df13
[console/calc] add tooltip
Lham42 Jan 11, 2025
9b3085c
address pr comments
Lham42 Jan 11, 2025
8f1024d
set mac version
Lham42 Jan 11, 2025
5bb4aa2
update gitignore
Lham42 Jan 11, 2025
d705e7a
Merge branch 'rc' of github.com:synnaxlabs/synnax into sy-1438-calcul…
Lham42 Jan 11, 2025
c3d979b
[ci] update server deploy workflow
Lham42 Jan 11, 2025
e1831b6
[ci] update synnax test workflow
Lham42 Jan 11, 2025
8bb6481
[pkg/distribution/channe] return
Lham42 Jan 11, 2025
5eac7c7
[computron
Lham42 Jan 11, 2025
0ed386d
[dist/channel] update create test
Lham42 Jan 11, 2025
1b3b1d1
update workflow file
Lham42 Jan 11, 2025
6c878c7
build visual studio tools
Lham42 Jan 11, 2025
18095d8
update workflow
Lham42 Jan 11, 2025
2a4eb64
add necessary dependencies to computron earthfile
Lham42 Jan 11, 2025
955ee7b
update linux build script
Lham42 Jan 11, 2025
57f630b
[computron] add linux linking flags
Lham42 Jan 11, 2025
2607d96
fix linting errors
Lham42 Jan 11, 2025
5720ab3
lint
Lham42 Jan 11, 2025
ff90f3b
fix ci errors
Lham42 Jan 12, 2025
7cd40b1
lint
Lham42 Jan 12, 2025
d8245be
lint
Lham42 Jan 12, 2025
43c3409
change linux build steps
Lham42 Jan 12, 2025
888c64c
[console] - updated beta-tag on calculations
emilbon99 Jan 12, 2025
9dff2cf
Merge branch 'sy-1438-calculated-channels' of https://github.com/synn…
emilbon99 Jan 12, 2025
85670e8
[console] - adjusted command selection context
emilbon99 Jan 12, 2025
35cca4d
Merge branch 'rc' of https://github.com/synnaxlabs/synnax into sy-143…
emilbon99 Jan 12, 2025
caf6981
[console] - addressed pull request comments'
emilbon99 Jan 12, 2025
2d85192
Merge branch 'sy-1438-calculated-channels' of https://github.com/synn…
Lham42 Jan 12, 2025
091b04e
[computron] - a bit of tuning
emilbon99 Jan 12, 2025
34f7500
[console] - added variable channel icons
emilbon99 Jan 12, 2025
511fe2a
[pluto] - improved editor CSS styles
emilbon99 Jan 12, 2025
b20a989
[console] - fixed editor parenthesis color
emilbon99 Jan 13, 2025
720608b
[console] - removed unnecessary editor layout
emilbon99 Jan 13, 2025
01e3981
add explicit linker flags
Lham42 Jan 13, 2025
909a2a1
build against static python
Lham42 Jan 13, 2025
3c55752
add more flags and env vars
Lham42 Jan 13, 2025
66effb4
[service/framer] fix downsampling
Lham42 Jan 13, 2025
b0dba1a
fix failing ubuntu typescript test for unsigned/signed cast check
Lham42 Jan 13, 2025
38b0945
undo poetry lock chagnes
Lham42 Jan 13, 2025
f23f217
format
Lham42 Jan 13, 2025
d2de32d
pr touchups
Lham42 Jan 13, 2025
c7be586
update build python workflow
Lham42 Jan 13, 2025
f3141a3
Merge branch 'sy-1438-calculated-channels' of https://github.com/synn…
Lham42 Jan 13, 2025
a877b4e
move go step
Lham42 Jan 13, 2025
3c1b8fb
Merge branch 'sy-1438-calculated-channels' of https://github.com/synn…
Lham42 Jan 13, 2025
01a58dc
Merge branch 'rc' of https://github.com/synnaxlabs/synnax into sy-143…
emilbon99 Jan 14, 2025
8e0713a
[console] - changed editor line highlighting
emilbon99 Jan 14, 2025
121ccaa
[synnax] - implemented tests for nested calculations
emilbon99 Jan 14, 2025
92ffa68
[ci] add workflow to run computron tests
Lham42 Jan 14, 2025
7a80c7e
[ci] add step to move python dll
Lham42 Jan 14, 2025
eff33e8
[synnax] - pr touchups
emilbon99 Jan 14, 2025
46b15d6
allow none for requires or expression
Lham42 Jan 15, 2025
8431c4e
Merge branch 'sy-1438-calculated-channels' of github.com:synnaxlabs/s…
Lham42 Jan 15, 2025
c800d5f
[x/ts] change form arrow func to exported func
Lham42 Jan 15, 2025
4856a25
Merge branch 'rc' of github.com:synnaxlabs/synnax into sy-1438-calcul…
Lham42 Jan 15, 2025
b35a80f
[console] - fixed imports from unique package
emilbon99 Jan 15, 2025
d43f6a2
[synnax] - removed visual studio community installation
emilbon99 Jan 15, 2025
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,5 @@ driver/vendor/mbedtls/mbedtls

# |||| ESLINT ||||
.eslintcache

python_install
1 change: 1 addition & 0 deletions .vscode/synnax.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@
"lineplot",
"Migratable",
"msgpackr",
"mult",
"NavDrawer",
"nsis",
"OPCUA",
Expand Down
2 changes: 1 addition & 1 deletion aspen/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type Cluster interface {

// Resolver is used to resolve a reachable address for a node in the cluster.
type Resolver interface {
// Resolve resolves the address of a node with the given Name.
// Resolve resolves the address of a node with the given key.
Resolve(key node.Key) (address.Address, error)
}

Expand Down
247 changes: 101 additions & 146 deletions client/py/poetry.lock
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did this file get updated? client/py/pyproject.toml did not change.

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions client/py/synnax/channel/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ def __init__(
key: ChannelKey = 0,
virtual: bool = False,
internal: bool = False,
expression: str = "",
requires: ChannelKeys = [],
_frame_client: FrameClient | None = None,
_client: ChannelClient | None = None,
) -> None:
Expand Down Expand Up @@ -99,6 +101,8 @@ def __init__(
index=index,
internal=internal,
virtual=virtual,
expression=expression,
requires=requires,
)
self.___frame_client = _frame_client
self.__client = _client
Expand Down Expand Up @@ -231,6 +235,8 @@ def create(
index: ChannelKey = 0,
leaseholder: int = 0,
virtual: bool = False,
expression:str = "",
requires: ChannelKeys = [],
retrieve_if_name_exists: bool = False,
) -> Channel | list[Channel]:
"""Creates new channel(s) in the Synnax cluster.
Expand Down Expand Up @@ -277,6 +283,8 @@ def create(
index=index,
is_index=is_index,
virtual=virtual,
expression=expression,
requires=requires,
)
]
elif isinstance(channels, Channel):
Expand Down
2 changes: 2 additions & 0 deletions client/py/synnax/channel/payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class ChannelPayload(Payload):
index: ChannelKey = 0
internal: bool = False
virtual: bool = False
expression: str = ""
requires: ChannelKeys = []

def __str__(self):
return f"Channel(name={self.name}, key={self.key})"
Expand Down
2 changes: 2 additions & 0 deletions client/py/synnax/telem/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,15 @@ def __init__(
data_type = data_type or data.data_type
data_ = data.data
time_range = data.time_range if time_range is None else time_range
alignment = data.alignment
elif isinstance(data, MultiSeries):
if len(data.series) == 1:
data_type = data_type or data.series[0].data_type
data_ = data.series[0].data
time_range = (
data.series[0].time_range if time_range is None else time_range
)
alignment = data.series[0].alignment
else:
raise ValueError(
"[Series] - MultiSeries with more than one series cannot be converted to a Series"
Expand Down
3 changes: 2 additions & 1 deletion client/py/tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,12 @@ def test_construction_from_list(self):

def test_construction_from_series(self):
"""Should correctly construct the Series from another Series"""
d = Series([1, 2, 3], data_type=DataType.INT8)
d = Series([1, 2, 3], data_type=DataType.INT8, alignment=12)
s = Series(d)
assert len(s) == 3
assert s[2] == 3
assert s.data_type == DataType.INT8
assert s.alignment == 12

def test_construction_from_buffer(self):
"""Should correctly construct the Series from a buffer"""
Expand Down
4 changes: 4 additions & 0 deletions client/ts/src/channel/batchRetriever.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ describe("channelRetriever", () => {
leaseholder: 1,
index: 0,
virtual: false,
expression: "",
requires: [],
}));
});
const retriever = new DebouncedBatchRetriever(base, 10);
Expand Down Expand Up @@ -83,6 +85,8 @@ describe("channelRetriever", () => {
leaseholder: 1,
index: 0,
virtual: false,
expression: "",
requires: [],
}));
});
const retriever = new DebouncedBatchRetriever(base, 10);
Expand Down
92 changes: 91 additions & 1 deletion client/ts/src/channel/channel.spec.ts
Lham42 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { DataType, Rate, TimeStamp } from "@synnaxlabs/x/telem";
import { describe, expect, it, test } from "vitest";

import { Channel } from "@/channel/client";
import { NotFoundError, QueryError } from "@/errors";
import { NotFoundError, QueryError, ValidationError } from "@/errors";
import { newClient } from "@/setupspecs";

const client = newClient();
Expand All @@ -31,6 +31,26 @@ describe("Channel", () => {
expect(channel.dataType).toEqual(DataType.FLOAT32);
});

test("create calculated", async () => {
const chOne = new Channel({
name: "test",
virtual: true,
dataType: DataType.FLOAT32,
});
client.channels.create(chOne);
let calculatedCH = new Channel({
name: "test2",
virtual: true,
dataType: DataType.FLOAT32,
expression: "test * 2",
requires: [chOne.key],
});
calculatedCH = await client.channels.create(calculatedCH);
expect(calculatedCH.key).not.toEqual(0);
expect(calculatedCH.virtual).toEqual(true);
expect(calculatedCH.expression).toEqual("test * 2");
});

test("create index and indexed pair", async () => {
const one = await client.channels.create({
name: "Time",
Expand Down Expand Up @@ -279,4 +299,74 @@ describe("Channel", () => {
expect(renamed[1].name).toEqual("test4");
});
});

describe("update", () => {
test("update virtual channel expression", async () => {
const channel = await client.channels.create({
name: "virtual-calc",
dataType: DataType.FLOAT32,
virtual: true,
expression: "result = np.array([])"
});

const updated = await client.channels.create({
key: channel.key,
name: channel.name,
dataType: channel.dataType,
virtual: true,
expression: "result = np.array([1, 2, 3])"
});

const channelsWithName = await client.channels.retrieve(["virtual-calc"]);
expect(channelsWithName.length).toEqual(1);

expect(updated.expression).toEqual("result = np.array([1, 2, 3])");

const retrieved = await client.channels.retrieve(channel.key);
expect(retrieved.expression).toEqual("result = np.array([1, 2, 3])");
});

test("update virtual channel name", async () => {
const channel = await client.channels.create({
name: "virtual-calc",
dataType: DataType.FLOAT32,
virtual: true,
expression: "result = np.array([])"
});

const updated = await client.channels.create({
key: channel.key,
name: "new-name",
dataType: channel.dataType,
virtual: true,
expression: channel.expression
});
expect(updated.name).toEqual("new-name");

const retrieved = await client.channels.retrieve(channel.key);
expect(retrieved.name).toEqual("new-name");
});

test("should not allow updates to non-virtual channels", async () => {
const channel = await client.channels.create({
name: "regular-channel",
leaseholder: 1,
rate: Rate.hz(1),
dataType: DataType.FLOAT32
});

const updated = await client.channels.create({
key: channel.key,
name: "new-name",
leaseholder: channel.leaseholder,
rate: channel.rate,
dataType: channel.dataType
});

// expect(updated.name).toEqual("regular-channel"); FIXME: this check fails
emilbon99 marked this conversation as resolved.
Show resolved Hide resolved

const retrieved = await client.channels.retrieve(channel.key);
expect(retrieved.name).toEqual("regular-channel");
});
});
});
23 changes: 23 additions & 0 deletions client/ts/src/channel/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ export class Channel {
* database, but can still be used for streaming purposes.
*/
readonly virtual: boolean;
/**
* Only used for calculated channels. Specifies the python expression to evaluate
* the calculated value
*/
readonly expression: string;
Lham42 marked this conversation as resolved.
Show resolved Hide resolved
/**
* Only used for calculated channels. Specifies the channels required for calculation
*/
readonly requires: Key[];

constructor({
dataType,
Expand All @@ -120,6 +129,8 @@ export class Channel {
virtual = false,
frameClient,
alias,
expression = "",
requires = [],
}: NewPayload & {
frameClient?: framer.Client;
density?: CrudeDensity;
Expand All @@ -134,6 +145,8 @@ export class Channel {
this.internal = internal;
this.alias = alias;
this.virtual = virtual;
this.expression = expression;
this.requires = [];
this._frameClient = frameClient ?? null;
}

Expand All @@ -158,9 +171,16 @@ export class Channel {
index: this.index,
isIndex: this.isIndex,
internal: this.internal,
virtual: this.virtual,
expression: this.expression,
requires: this.requires,
});
}

get isCalculated(): boolean {
return isCalculated(this.payload);
}

/***
* @returns the ontology ID of the channel
*/
Expand Down Expand Up @@ -421,3 +441,6 @@ export class Client implements AsyncTermSearcher<string, Key, Channel> {
return new group.Group(res.group.name, res.group.key);
}
}

export const isCalculated = ({ virtual, expression }: Payload): boolean =>
virtual && expression !== "";
5 changes: 5 additions & 0 deletions client/ts/src/channel/payload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { DataType, Rate } from "@synnaxlabs/x/telem";
import { z } from "zod";

import { ontology } from "@/ontology";
import { nullableArrayZ } from "@/util/zod";

export const keyZ = z.number();
export type Key = number;
Expand All @@ -32,6 +33,8 @@ export const payload = z.object({
internal: z.boolean(),
virtual: z.boolean(),
alias: z.string().optional(),
expression: z.string(),
requires: nullableArrayZ(keyZ),
});

export type Payload = z.infer<typeof payload>;
Expand All @@ -44,6 +47,8 @@ export const newPayload = payload.extend({
isIndex: z.boolean().optional(),
internal: z.boolean().optional().default(false),
virtual: z.boolean().optional().default(false),
expression: z.string().optional().default(""),
requires: nullableArrayZ(keyZ).optional().default([]),
});

export type NewPayload = z.input<typeof newPayload>;
Expand Down
2 changes: 1 addition & 1 deletion client/ts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
export { access } from "@/access";
export { policy } from "@/access/policy";
export { channel } from "@/channel";
export { Channel } from "@/channel/client";
export { Channel, isCalculated } from "@/channel/client";
export { default as Synnax, type SynnaxProps, synnaxPropsZ } from "@/client";
export * from "@/connection";
export { control } from "@/control";
Expand Down
61 changes: 61 additions & 0 deletions computron/build-linux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/bash

set -e

# Set up variables
PYTHON_VERSION="3.9.13"
NUMPY_VERSION="1.21.6"
Lham42 marked this conversation as resolved.
Show resolved Hide resolved
PYTHON_INSTALL_DIR="$(pwd)/python_install"

# Download and build Python
curl -O https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tgz
tar xzf Python-${PYTHON_VERSION}.tgz
cd Python-${PYTHON_VERSION}

# Configure Python for static build
./configure --prefix=${PYTHON_INSTALL_DIR} \
--disable-shared \
--enable-optimizations \
--with-ensurepip=no \
LDFLAGS="-Wl,-rpath,${PYTHON_INSTALL_DIR}/lib"

# Build Python
make -j$(nproc)

# Install Python
make install

cd ..

# Install pip (required for NumPy installation)
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
${PYTHON_INSTALL_DIR}/bin/python3 get-pip.py

# Install NumPy
${PYTHON_INSTALL_DIR}/bin/pip3 install numpy==${NUMPY_VERSION}

# Combine static libraries
mkdir -p ${PYTHON_INSTALL_DIR}/lib/combined
cd ${PYTHON_INSTALL_DIR}/lib/combined

# Extract object files from Python static library
ar -x ../libpython3.9.a
Copy link
Contributor

Choose a reason for hiding this comment

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

We shouldn't hardcode all of the references to the python version here


# Extract object files from NumPy static libraries
numpy_lib_path=$(find ${PYTHON_INSTALL_DIR}/lib/python3.9/site-packages/numpy -name '*.a')
for lib in $numpy_lib_path; do
ar -x $lib
done

# Create combined static library
ar -qc libpython3.9-combined.a *.o
ranlib libpython3.9-combined.a
Copy link
Contributor

Choose a reason for hiding this comment

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

We shouldn't hardcode all of the references to the python version here


cd ../../..

# Cleanup
rm Python-${PYTHON_VERSION}.tgz
rm -r Python-${PYTHON_VERSION}
rm get-pip.py

echo "Build and installation completed successfully."
Loading