Skip to content

Commit 44e09d7

Browse files
committed
More tweaks
1 parent ade7ca4 commit 44e09d7

5 files changed

Lines changed: 41 additions & 10 deletions

File tree

cmake/yup_python.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ function (yup_prepare_python_stdlib target_name python_tools_path output_variabl
3131
set (ignored_library_patterns ${default_ignored_library_patterns})
3232
list (APPEND ignored_library_patterns ${YUP_ARG_IGNORED_LIBRARY_PATTERNS})
3333

34+
get_filename_component (python_tools_path "${python_tools_path}" REALPATH)
35+
3436
set (python_standard_library "${CMAKE_CURRENT_BINARY_DIR}/python${Python_VERSION_MAJOR}${Python_VERSION_MINOR}.zip")
3537

3638
_yup_message (STATUS "Executing python stdlib archive generator tool")

python/MANIFEST.in

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
include README.md
2-
include LICENSE
1+
include ../README.md
2+
include ../LICENSE
33

44
graft yup
55
graft yup.pyi
66

7-
global-exclude *.py[cod] __pycache__ .DS_Store CMakeLists.txt
7+
global-exclude *.py[cod] __pycache__ tools .DS_Store CMakeLists.txt

tests/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,10 @@ else()
7575
GTest::gmock_main)
7676
endif()
7777

78-
if (YUP_PLATFORM_DESKTOP)
78+
if (YUP_PLATFORM_MACOS OR YUP_PLATFORM_WINDOWS)
7979
set (python_tools_path "${CMAKE_CURRENT_LIST_DIR}/../python/tools")
8080
set (python_target_name "${target_name}_python_stdlib")
81+
8182
yup_prepare_python_stdlib (${python_target_name} ${python_tools_path} python_standard_library)
8283

8384
yup_add_embedded_binary_resources (

tests/yup_python/yup_ScriptEngine.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@
2323

2424
#include <gtest/gtest.h>
2525

26+
#if __has_include(<PythonStandardLibrary.h>)
27+
#define YUP_HAS_EMBEDDED_PYTHON_STANDARD_LIBRARY 1
2628
#include <PythonStandardLibrary.h>
29+
#endif
2730

2831
using namespace yup;
2932

@@ -436,6 +439,7 @@ TEST_F (ScriptEngineTest, RunScriptWithLambdaFunctions)
436439
EXPECT_TRUE (result.wasOk());
437440
}
438441

442+
#if YUP_HAS_EMBEDDED_PYTHON_STANDARD_LIBRARY
439443
TEST_F (ScriptEngineTest, RunScriptWithStdLibImports)
440444
{
441445
ScriptEngine engine (ScriptEngine::prepareScriptingHome (
@@ -446,9 +450,7 @@ TEST_F (ScriptEngineTest, RunScriptWithStdLibImports)
446450
return { PythonStandardLibrary_data, PythonStandardLibrary_size };
447451
}));
448452

449-
auto result = engine.runScript (String (R"(
450-
import argparse
451-
)")
452-
.dedentLines());
453+
auto result = engine.runScript ("import argparse");
453454
EXPECT_TRUE (result.wasOk());
454455
}
456+
#endif

tests/yup_python/yup_ScriptPython.cpp

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@
2323

2424
#include <gtest/gtest.h>
2525

26+
#if __has_include(<PythonStandardLibrary.h>)
27+
#define YUP_HAS_EMBEDDED_PYTHON_STANDARD_LIBRARY 1
2628
#include <PythonStandardLibrary.h>
29+
#endif
2730

2831
using namespace yup;
2932

@@ -42,13 +45,17 @@ class ScriptPythonTest : public ::testing::Test
4245

4346
void SetUp() override
4447
{
48+
#if YUP_HAS_EMBEDDED_PYTHON_STANDARD_LIBRARY
4549
engine = std::make_unique<ScriptEngine> (ScriptEngine::prepareScriptingHome (
4650
YUPApplication::getInstance()->getApplicationName(),
4751
File::getSpecialLocation (File::tempDirectory),
4852
[] (const char*) -> MemoryBlock
4953
{
5054
return { PythonStandardLibrary_data, PythonStandardLibrary_size };
5155
}));
56+
#else
57+
engine = std::make_unique<ScriptEngine>();
58+
#endif
5259
}
5360

5461
void TearDown() override
@@ -67,6 +74,25 @@ TEST_F (ScriptPythonTest, RunPythonTests)
6774
currentWorkingDirectory.setAsCurrentWorkingDirectory();
6875
});
6976

77+
auto scriptingVersion = engine->getScriptingVersion();
78+
auto scriptingVersionCompact = scriptingVersion.upToLastOccurrenceOf (".", false, false);
79+
80+
auto scriptingHome = engine->getScriptingHome();
81+
if (scriptingHome == File())
82+
{
83+
scriptingHome = File::getSpecialLocation (File::userHomeDirectory).getChildFile ("yup_python");
84+
scriptingHome.createDirectory();
85+
86+
auto binDirectory = scriptingHome.getChildFile ("bin");
87+
binDirectory.createDirectory();
88+
89+
auto sitePackages = scriptingHome
90+
.getChildFile ("lib")
91+
.getChildFile ("python" + scriptingVersionCompact)
92+
.getChildFile ("site-packages");
93+
sitePackages.createDirectory();
94+
}
95+
7096
auto baseFolder = getPytestTestFolder().getParentDirectory();
7197
baseFolder.setAsCurrentWorkingDirectory();
7298

@@ -91,8 +117,8 @@ TEST_F (ScriptPythonTest, RunPythonTests)
91117

92118
script = script
93119
.dedentLines()
94-
.replace ("{{version}}", engine->getScriptingVersion().upToLastOccurrenceOf (".", false, false))
95-
.replace ("{{root_path}}", engine->getScriptingHome().getFullPathName())
120+
.replace ("{{version}}", scriptingVersionCompact)
121+
.replace ("{{root_path}}", scriptingHome.getFullPathName())
96122
.replace ("{{test_path}}", getPytestTestFolder().getFullPathName());
97123

98124
auto result = engine->runScript (script);

0 commit comments

Comments
 (0)