File tree Expand file tree Collapse file tree 5 files changed +28
-15
lines changed
Expand file tree Collapse file tree 5 files changed +28
-15
lines changed Original file line number Diff line number Diff line change 2727 run : python -m pip install ".[test]"
2828
2929 - name : Run tests
30- run : >
31- export MPP_DIRECTORY=$(pwd) &&
32- export MPP_DATA_DIRECTORY=$MPP_DIRECTORY/data &&
33- pytest
30+ run : pytest
Original file line number Diff line number Diff line change 2020 run : python -m pip install ".[test]"
2121
2222 - name : Run tests
23- run : >
24- export MPP_DIRECTORY=$(pwd) &&
25- export MPP_DATA_DIRECTORY=$MPP_DIRECTORY/data &&
26- pytest
23+ run : pytest
2724
2825 test_mac :
2926 runs-on : macos-latest
4037 run : python -m pip install ".[test]"
4138
4239 - name : Run tests
43- run : >
44- export MPP_DIRECTORY=$(pwd) &&
45- export MPP_DATA_DIRECTORY=$MPP_DIRECTORY/data &&
46- pytest
40+ run : pytest
4741
4842 linux_wheels :
4943 strategy :
Original file line number Diff line number Diff line change @@ -14,3 +14,5 @@ target_link_libraries(_mutationpp PRIVATE mutation++)
1414install (DIRECTORY mutationpp DESTINATION .)
1515
1616install (TARGETS _mutationpp DESTINATION mutationpp)
17+
18+ install (DIRECTORY "${CMAKE_SOURCE_DIR} /data" DESTINATION mutationpp)
Original file line number Diff line number Diff line change @@ -7,8 +7,26 @@ namespace py = pybind11;
77 * Python wrapper definition for the GlobalOptions class.
88 */
99
10+ namespace {
11+
12+ inline void setDefaultDataDirectory (const std::string& datadir) {
13+ if (std::getenv (" MPP_DATA_DIRECTORY" ) == nullptr ) {
14+ Mutation::GlobalOptions::dataDirectory (datadir);
15+ }
16+ };
17+
18+ }
19+
1020void py_export_GlobalOptions (py::module &m) {
1121
22+ const py::object resources = py::module_::import (" importlib.resources" );
23+ const py::object pkgname = m.attr (" __spec__" ).attr (" parent" );
24+ const py::object rootdir = resources.attr (" files" )(pkgname);
25+ const py::object datadir = rootdir / py::str (" data" );
26+ const std::string data_directory = py::str (datadir).cast <std::string>();
27+
28+ setDefaultDataDirectory (data_directory);
29+
1230 /* *
1331 * Overloaded member functions wrappers
1432 */
@@ -29,8 +47,9 @@ void py_export_GlobalOptions(py::module &m) {
2947 .def_static (" workingDirectory" , []() {
3048 return Mutation::GlobalOptions::workingDirectory ();
3149 })
32- .def_static (" reset" , []() {
50+ .def_static (" reset" , [data_directory ]() {
3351 Mutation::GlobalOptions::reset ();
52+ setDefaultDataDirectory (data_directory);
3453 })
3554 ;
3655}
Original file line number Diff line number Diff line change 44import unittest .mock as mock
55import mutationpp as mpp
66
7- INITIAL_DATADIR = os .environ .get ("MPP_DATA_DIRECTORY" , "" )
7+ PACKAGE_DATADIR = os .fspath (importlib .resources .files (mpp ) / "data" )
8+ INITIAL_DATADIR = os .environ .get ("MPP_DATA_DIRECTORY" , PACKAGE_DATADIR )
89
910
1011def test_options_datadir_initial ():
@@ -62,6 +63,6 @@ def test_options_reset(datadir):
6263 with mock .patch .dict (os .environ , clear = True ):
6364 mpp .GlobalOptions .reset ()
6465 set_datadir = mpp .GlobalOptions .dataDirectory ()
65- assert set_datadir == ""
66+ assert set_datadir == PACKAGE_DATADIR
6667 set_workdir = mpp .GlobalOptions .workingDirectory ()
6768 assert set_workdir == ""
You can’t perform that action at this time.
0 commit comments