Skip to content
Open
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
5 changes: 5 additions & 0 deletions DSPythonNet3/DSPythonNet3Evaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
internal class DynamoCPythonHandleComparer : IEqualityComparer<DynamoCPythonHandle>
{

public bool Equals(DynamoCPythonHandle x, DynamoCPythonHandle y)

Check warning on line 23 in DSPythonNet3/DSPythonNet3Evaluator.cs

View workflow job for this annotation

GitHub Actions / Build and Test

Nullability of reference types in type of parameter 'y' of 'bool DynamoCPythonHandleComparer.Equals(DynamoCPythonHandle x, DynamoCPythonHandle y)' doesn't match implicitly implemented member 'bool IEqualityComparer<DynamoCPythonHandle>.Equals(DynamoCPythonHandle? x, DynamoCPythonHandle? y)' (possibly because of nullability attributes).

Check warning on line 23 in DSPythonNet3/DSPythonNet3Evaluator.cs

View workflow job for this annotation

GitHub Actions / Build and Test

Nullability of reference types in type of parameter 'x' of 'bool DynamoCPythonHandleComparer.Equals(DynamoCPythonHandle x, DynamoCPythonHandle y)' doesn't match implicitly implemented member 'bool IEqualityComparer<DynamoCPythonHandle>.Equals(DynamoCPythonHandle? x, DynamoCPythonHandle? y)' (possibly because of nullability attributes).
{
return x.PythonObjectID.Equals(y.PythonObjectID);
}
Expand Down Expand Up @@ -74,7 +74,7 @@
try
{
var pyobj = DSPythonNet3Evaluator.globalScope.Get(PythonObjectID.ToString());
return pyobj.ToString();

Check warning on line 77 in DSPythonNet3/DSPythonNet3Evaluator.cs

View workflow job for this annotation

GitHub Actions / Build and Test

Possible null reference return.
}
catch (Exception e)
{
Expand Down Expand Up @@ -143,8 +143,8 @@
{ // Session is null when running unit tests.
if (ExecutionEvents.ActiveSession != null)
{
dynamoLogger = ExecutionEvents.ActiveSession.GetParameterValue(ParameterKeys.Logger) as DynamoLogger;

Check warning on line 146 in DSPythonNet3/DSPythonNet3Evaluator.cs

View workflow job for this annotation

GitHub Actions / Build and Test

Possible null reference assignment.
return dynamoLogger;

Check warning on line 147 in DSPythonNet3/DSPythonNet3Evaluator.cs

View workflow job for this annotation

GitHub Actions / Build and Test

Possible null reference return.
}
return dynamoLogger;
}
Expand Down Expand Up @@ -426,6 +426,11 @@
Runtime.PythonDLL = Path.Join(Python.Included.Installer.EmbeddedPythonHome, Python.Included.Installer.PYTHON_VERSION + ".dll");
}

// Detect current .NET thread apartment and make comtypes match it
var apt = System.Threading.Thread.CurrentThread.GetApartmentState();
var comApt = (apt == System.Threading.ApartmentState.STA) ? "STA" : "MTA";
Environment.SetEnvironmentVariable("COMTYPES_APARTMENT", comApt, EnvironmentVariableTarget.Process);

PythonEngine.Initialize();
PythonEngine.BeginAllowThreads();

Expand Down
921 changes: 918 additions & 3 deletions DSPythonNet3/THIRD_PARTY_NOTICES.txt

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
6 changes: 6 additions & 0 deletions DSPythonNet3Wheels/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@ python-dateutil == 2.*
pandas == 2.*
openpyxl == 3.*
scipy == 1.*
shapely == 2.*
alphashape == 1.*
comtypes == 1.*
scikit-learn == 1.*
ifcopenshell == 0.*
tabulate == 0.*
72 changes: 72 additions & 0 deletions DSpythonNet3Tests/PythonLibraryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,5 +194,77 @@ from openpyxl import Workbook
var result = DSPythonNet3Evaluator.EvaluatePythonScript(code, empty, empty);
Assert.That(result, Is.EqualTo(3));
}

[Test]
public void TestShapelyAvailable()
{
string code = @"
from shapely.geometry import Point
# Circle-like buffer (radius=1) -> area ~= pi; round to 2dp for stability
area = Point(0,0).buffer(1.0).area
OUT = round(area, 2)
";
var empty = new ArrayList();
var result = DSPythonNet3Evaluator.EvaluatePythonScript(code, empty, empty);
Assert.That(result, Is.EqualTo(3.14));
}

[Test]
public void TestAlphaShapeAvailable()
{
string code = @"
import alphashape
from shapely.geometry import Point
pts = [(0,0), (1,0), (1,1), (0,1), (0.5,0.5)]
alpha = 1.5
poly = alphashape.alphashape(pts, alpha)
OUT = poly.is_valid and poly.area > 0
";
var empty = new ArrayList();
var result = DSPythonNet3Evaluator.EvaluatePythonScript(code, empty, empty);
Assert.That(result, Is.EqualTo(true));
}

[Test]
public void TestScikitLearnAvailable()
{
string code = @"
from sklearn.cluster import KMeans
import numpy as np
X = np.array([[0,0],[0,1],[9,9],[9,8]], dtype=float)
km = KMeans(n_clusters=2, n_init=5, random_state=0).fit(X)
OUT = len(set(km.labels_))
";
var empty = new ArrayList();
var result = DSPythonNet3Evaluator.EvaluatePythonScript(code, empty, empty);
Assert.That(result, Is.EqualTo(2));
}

[Test]
public void TestIfcopenshellAvailable()
{
string code = @"
import ifcopenshell
# Simple smoke: module import + version attribute exists
OUT = hasattr(ifcopenshell, '__version__')
";
var empty = new ArrayList();
var result = DSPythonNet3Evaluator.EvaluatePythonScript(code, empty, empty);
Assert.That(result, Is.EqualTo(true));
}

[Test]
public void TestTabulateAvailable()
{
string code = @"
from tabulate import tabulate
tbl = tabulate([[1,'a'],[2,'b']], headers=['n','c'], tablefmt='plain')
# Expect two data rows -> 2 newline characters (plain format produces 2 lines)
OUT = ('1' in tbl) and ('2' in tbl) and ('a' in tbl) and ('b' in tbl)
";
var empty = new ArrayList();
var result = DSPythonNet3Evaluator.EvaluatePythonScript(code, empty, empty);
Assert.That(result, Is.EqualTo(true));
}
}
}
Loading