Skip to content

Commit 161e369

Browse files
authored
Python Modules (#13728)
* Python Modules Tests added - tests - dlls * Upstream Master Merge * Update to License.rtf - added python modules back to the license file after merge issue * Missing closing tag added back - added back a missing closing tag to DSCPython.csproj * Removed package-lock.json and package.json - removed package-lock.json and package.json as instructed * Further removed files * Update pythonnet - updated dll files * Removed unused modules from license.txt - removed 2 modules that are not going to be used at this moment from the license.txt (already removed from License.rtf) * IfcOpenShell removed due to license issues - IfcOpenShell not being used due to license type - updated with the correct .dll from the updated pythnonet - removed IfcOpenShell test * Removed any IfcOpenShell-related code - any leftover code from the implementation of IfcOpenShell module has been removed
1 parent 5570cde commit 161e369

File tree

7 files changed

+880
-600
lines changed

7 files changed

+880
-600
lines changed

LICENSE.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,14 @@ Python Standard Library
558558
https://docs.python.org/2.7/library/
559559
https://docs.python.org/2.7/license.html
560560

561+
Python Modules
562+
https://numpy.org/ License: Distributed under a liberal BSD license
563+
https://pandas.pydata.org/ License: BSD 3-Clause "New" or "Revised" License
564+
https://scipy.org/ License: Distributed under a liberal BSD license
565+
https://pypi.org/project/openpyxl/ License: MIT License (MIT)
566+
https://matplotlib.org/ License: Matplotlib only uses BSD compatible code, and its license is based on the PSF license
567+
https://pypi.org/project/Pillow/ License: Historical Permission Notice and Disclaimer (HPND)
568+
561569
SimplexNoise
562570
https://unlicense.org/
563571

doc/distrib/License.rtf

Lines changed: 643 additions & 600 deletions
Large diffs are not rendered by default.

extern/Python/Python.Included.dll

76.6 MB
Binary file not shown.

extern/Python/Python.Runtime.dll

0 Bytes
Binary file not shown.

src/Libraries/DSCPython/DSCPython.csproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@
99
<RootNamespace>DSCPython</RootNamespace>
1010
<AssemblyName>DSCPython</AssemblyName>
1111
</PropertyGroup>
12+
<ItemGroup>
13+
<Reference Include="Python.Included, Version=2.5.2.7195, Culture=neutral, processorArchitecture=MSIL">
14+
<SpecificVersion>False</SpecificVersion>
15+
<HintPath>..\..\..\extern\Python\Python.Included.dll</HintPath>
16+
</Reference>
17+
<Reference Include="Python.Runtime, Version=2.5.2.7195, Culture=neutral, processorArchitecture=MSIL">
18+
<SpecificVersion>False</SpecificVersion>
19+
<HintPath>..\..\..\extern\Python\Python.Runtime.dll</HintPath>
20+
</Reference>
21+
</ItemGroup>
1222
<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' ">
1323
<Reference Include="Python.Included, Version=2.5.2.6664, Culture=neutral, processorArchitecture=MSIL">
1424
<SpecificVersion>False</SpecificVersion>
Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
using Dynamo;
2+
using System;
3+
using System.Collections;
4+
using System.Collections.Generic;
5+
using System.IO;
6+
using System.Numerics;
7+
using CoreNodeModels.Input;
8+
using Dynamo;
9+
using NUnit.Framework;
10+
using static DSPythonTests.PythonEvalTests;
11+
using Directory = CoreNodeModels.Input.Directory;
12+
13+
14+
namespace DynamoPythonTests
15+
{
16+
internal class PythonModulesTests : DynamoModelTestBase
17+
{
18+
protected override void GetLibrariesToPreload(List<string> libraries)
19+
{
20+
libraries.Add("FFITarget.dll");
21+
libraries.Add("DSCoreNodes.dll");
22+
}
23+
24+
public IEnumerable<PythonEvaluatorDelegate> Evaluators = new List<PythonEvaluatorDelegate> {
25+
DSCPython.CPythonEvaluator.EvaluatePythonScript
26+
};
27+
28+
#region Python Modules
29+
30+
[Test]
31+
public void TestNumpyPythonModuleEncoding()
32+
{
33+
string code = @"
34+
import sys
35+
import clr
36+
37+
import numpy as np
38+
a = np.arange(15).reshape(3, 5)
39+
result = []
40+
for list in a:
41+
sub_result = []
42+
for b in list:
43+
# Cast to int, otherwise getting DynamoCPythonHandle
44+
sub_result.append(int(b))
45+
result.append(sub_result)
46+
OUT = result
47+
";
48+
var empty = new ArrayList();
49+
var expected = new ArrayList { new ArrayList { 0, 1, 2, 3, 4 }, new ArrayList { 5, 6, 7, 8, 9 }, new ArrayList { 10, 11, 12, 13, 14 } };
50+
51+
foreach (var pythonEvaluator in Evaluators)
52+
{
53+
var result = pythonEvaluator(code, empty, empty);
54+
Assert.IsTrue(result is IEnumerable);
55+
CollectionAssert.AreEqual(expected, result as IEnumerable);
56+
}
57+
}
58+
59+
60+
[Test]
61+
public void TestPandasPythonModuleEncoding()
62+
{
63+
string code = @"
64+
import sys
65+
import clr
66+
67+
import numpy as np
68+
import pandas as pd
69+
dates = pd.date_range(""20130101"", periods=6)
70+
a = [str(i) for i in dates]
71+
OUT = a
72+
";
73+
var empty = new ArrayList();
74+
var expected = new ArrayList
75+
{
76+
"2013-01-01 00:00:00",
77+
"2013-01-02 00:00:00",
78+
"2013-01-03 00:00:00",
79+
"2013-01-04 00:00:00",
80+
"2013-01-05 00:00:00",
81+
"2013-01-06 00:00:00",
82+
};
83+
84+
foreach (var pythonEvaluator in Evaluators)
85+
{
86+
var result = pythonEvaluator(code, empty, empty);
87+
Assert.IsTrue(result is IEnumerable);
88+
CollectionAssert.AreEqual(expected, result as IEnumerable);
89+
}
90+
}
91+
92+
[Test]
93+
public void TestScypiPythonModuleEncoding()
94+
{
95+
string code = @"
96+
import sys
97+
import clr
98+
99+
import numpy as np
100+
from scipy import linalg
101+
A = np.array([[1,2],[3,4]])
102+
B = linalg.inv(A)
103+
C = [[round(i) for i in b] for b in B]
104+
OUT = C
105+
";
106+
var empty = new ArrayList();
107+
var expected = new ArrayList { new ArrayList { -2, 1 }, new ArrayList { 1, 0 } };
108+
109+
foreach (var pythonEvaluator in Evaluators)
110+
{
111+
var result = pythonEvaluator(code, empty, empty);
112+
Assert.IsTrue(result is IEnumerable);
113+
CollectionAssert.AreEqual(expected, result as IEnumerable);
114+
}
115+
}
116+
117+
[Test]
118+
public void TestOpenpyxlPythonModuleEncoding()
119+
{
120+
string code = @"
121+
import sys
122+
import clr
123+
124+
from openpyxl import Workbook
125+
126+
wb = Workbook()
127+
ws = wb.active
128+
129+
ws1 = wb.create_sheet(""Mysheet"") # insert at the end (default)
130+
ws.title = ""New Title""
131+
ws.sheet_properties.tabColor = ""1072BA""
132+
133+
result = wb.sheetnames
134+
OUT = result
135+
";
136+
var empty = new ArrayList();
137+
var expected = new ArrayList { "New Title", "Mysheet" };
138+
139+
foreach (var pythonEvaluator in Evaluators)
140+
{
141+
var result = pythonEvaluator(code, empty, empty);
142+
Assert.IsTrue(result is IEnumerable);
143+
CollectionAssert.AreEqual(expected, result as IEnumerable);
144+
}
145+
}
146+
147+
148+
[Test]
149+
public void TestPillowPythonModuleEncoding()
150+
{
151+
var examplePath = Path.Combine(TestDirectory, @"core\python\python_modules", "test.png");
152+
Assert.NotNull(examplePath);
153+
Assert.IsTrue(File.Exists(examplePath));
154+
examplePath = examplePath.Replace("\\", "/"); // Convert to python file path
155+
156+
string code = string.Format(@"
157+
import sys
158+
import clr
159+
160+
from PIL import Image
161+
162+
im = Image.open('{0}')
163+
OUT = im.format, im.size, im.mode
164+
", examplePath);
165+
166+
167+
var empty = new ArrayList();
168+
var expected = new ArrayList{ "PNG", new ArrayList { 640, 480 }, "RGBA" };
169+
170+
foreach (var pythonEvaluator in Evaluators)
171+
{
172+
var result = pythonEvaluator(code, empty, empty);
173+
Assert.IsTrue(result is IEnumerable);
174+
CollectionAssert.AreEqual(expected, result as IEnumerable);
175+
}
176+
}
177+
178+
179+
[Test]
180+
public void TestMatplotlibPythonModuleEncoding()
181+
{
182+
var examplePath = Path.Combine(TestDirectory, @"core\python\python_modules", "test_export.png");
183+
Assert.NotNull(examplePath);
184+
Assert.IsFalse(File.Exists(examplePath)); // Make sure the file is not there when we start
185+
examplePath = examplePath.Replace("\\", "/"); // Convert to python file path
186+
187+
string code = string.Format(@"
188+
import sys
189+
import clr
190+
191+
import matplotlib.pyplot as plt
192+
import numpy as np
193+
194+
x = np.linspace(0, 2 * np.pi, 200)
195+
y = np.sin(x)
196+
197+
fig, ax = plt.subplots()
198+
ax.plot(x, y)
199+
plt.show()
200+
image = plt.savefig('{0}')
201+
202+
OUT = ''
203+
", examplePath);
204+
205+
206+
var empty = new ArrayList();
207+
208+
foreach (var pythonEvaluator in Evaluators)
209+
{
210+
var result = pythonEvaluator(code, empty, empty);
211+
Assert.IsTrue(File.Exists(examplePath)); // We should have exported an image now
212+
File.Delete(examplePath);
213+
Assert.IsFalse(File.Exists(examplePath)); // Make sure the file is not there when we finish
214+
}
215+
}
216+
217+
#endregion
218+
}
219+
}
23.3 KB
Loading

0 commit comments

Comments
 (0)