From a958227ff566ec1e4d1653eb373d83aa1eacdf93 Mon Sep 17 00:00:00 2001
From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de>
Date: Wed, 25 Nov 2020 08:58:28 +0100
Subject: [PATCH] export: hard-code "get_sample"

---
 Base/Utils/PyFmt.cpp                         |  4 ----
 Base/Utils/PyFmt.h                           |  1 -
 Core/Export/SampleToPython.cpp               |  2 +-
 Core/Export/SimulationToPython.cpp           | 18 ++++++++----------
 Tests/Functional/Python/PyEmbedded/Tests.cpp |  4 ++--
 auto/Wrap/doxygenBase.i                      |  5 +----
 6 files changed, 12 insertions(+), 22 deletions(-)

diff --git a/Base/Utils/PyFmt.cpp b/Base/Utils/PyFmt.cpp
index 3305797a1ce..32afe9740ae 100644
--- a/Base/Utils/PyFmt.cpp
+++ b/Base/Utils/PyFmt.cpp
@@ -28,10 +28,6 @@ std::string scriptPreamble() {
     return result;
 }
 
-std::string getSampleFunctionName() {
-    return "get_sample";
-}
-
 std::string printBool(double value) {
     return value ? "True" : "False";
 }
diff --git a/Base/Utils/PyFmt.h b/Base/Utils/PyFmt.h
index 5dc8f17e09e..ffa4069bd19 100644
--- a/Base/Utils/PyFmt.h
+++ b/Base/Utils/PyFmt.h
@@ -25,7 +25,6 @@ class RealLimits;
 namespace pyfmt {
 
 std::string scriptPreamble();
-std::string getSampleFunctionName();
 
 std::string printInt(int value);
 std::string printBool(double value);
diff --git a/Core/Export/SampleToPython.cpp b/Core/Export/SampleToPython.cpp
index 4dd93ef4ad0..d87d939b08e 100644
--- a/Core/Export/SampleToPython.cpp
+++ b/Core/Export/SampleToPython.cpp
@@ -85,7 +85,7 @@ SampleToPython::SampleToPython() = default;
 SampleToPython::~SampleToPython() = default;
 
 std::string SampleToPython::defineGetSample() const {
-    return "def " + pyfmt::getSampleFunctionName() + "():\n" + defineMaterials() + defineLayers()
+    return "def get_sample():\n" + defineMaterials() + defineLayers()
            + defineFormFactors() + defineParticles() + defineCoreShellParticles()
            + defineParticleCompositions() + defineLattices2D() + defineLattices3D()
            + defineCrystals() + defineMesoCrystals() + defineParticleDistributions()
diff --git a/Core/Export/SimulationToPython.cpp b/Core/Export/SimulationToPython.cpp
index 21faf8c194f..b3990f84f9d 100644
--- a/Core/Export/SimulationToPython.cpp
+++ b/Core/Export/SimulationToPython.cpp
@@ -38,16 +38,6 @@
 using pyfmt::indent;
 
 namespace {
-const std::string defineSimulate = "def run_simulation():\n"
-                                   "    sample = "
-                                   + pyfmt::getSampleFunctionName()
-                                   + "()\n"
-                                     "    simulation = get_simulation()\n"
-                                     "    simulation.setSample(sample)\n"
-                                     "    simulation.runSimulation()\n"
-                                     "    return simulation.result()\n"
-                                     "\n\n";
-
 //! Returns a function that converts a coordinate to a Python code snippet with appropiate unit
 std::function<std::string(double)> printFunc(const IDetector* detector) {
     if (detector->defaultAxesUnits() == Axes::Units::MM)
@@ -64,6 +54,14 @@ bool isDefaultDirection(const kvector_t direction) {
            && algo::almostEqual(direction.z(), 0.0);
 }
 
+const std::string defineSimulate = "def run_simulation():\n"
+    "    sample = get_sample()\n"
+    "    simulation = get_simulation()\n"
+    "    simulation.setSample(sample)\n"
+                                     "    simulation.runSimulation()\n"
+                                     "    return simulation.result()\n"
+                                     "\n\n";
+
 } // namespace
 
 //! Returns a Python script that sets up a simulation and runs it if invoked as main program.
diff --git a/Tests/Functional/Python/PyEmbedded/Tests.cpp b/Tests/Functional/Python/PyEmbedded/Tests.cpp
index 2ce7b659551..96923699561 100644
--- a/Tests/Functional/Python/PyEmbedded/Tests.cpp
+++ b/Tests/Functional/Python/PyEmbedded/Tests.cpp
@@ -367,7 +367,7 @@ TEST_F(PyEmbedded, ExportToPythonAndBack) {
     std::stringstream snippet;
     snippet << pyfmt::scriptPreamble() << code;
 
-    auto multilayer = PyImport::createFromPython(snippet.str(), pyfmt::getSampleFunctionName(),
+    auto multilayer = PyImport::createFromPython(snippet.str(), "get_sample",
                                                  BABuild::buildLibDir());
     auto new_code = ExportToPython::generateSampleCode(*multilayer);
 
@@ -375,7 +375,7 @@ TEST_F(PyEmbedded, ExportToPythonAndBack) {
 }
 
 //! Retrieves list of functions from the imported script and checks, that there is
-//! one function in a dictioonary with name "get_simulation".
+//! one function in a dictionary with name "get_simulation".
 
 TEST_F(PyEmbedded, ModuleFunctionsList) {
     // compile our function
diff --git a/auto/Wrap/doxygenBase.i b/auto/Wrap/doxygenBase.i
index e7af05b5a5d..08b65977e12 100644
--- a/auto/Wrap/doxygenBase.i
+++ b/auto/Wrap/doxygenBase.i
@@ -1219,7 +1219,7 @@ Creates a new clipped axis.
 ";
 
 
-// File: namespace_0D16.xml
+// File: namespace_0d16.xml
 
 
 // File: namespacealgo.xml
@@ -1461,9 +1461,6 @@ Returns string representing python stack trace.
 %feature("docstring")  pyfmt::scriptPreamble "std::string pyfmt::scriptPreamble()
 ";
 
-%feature("docstring")  pyfmt::getSampleFunctionName "std::string pyfmt::getSampleFunctionName()
-";
-
 %feature("docstring")  pyfmt::printBool "std::string pyfmt::printBool(double value)
 ";
 
-- 
GitLab