-
Notifications
You must be signed in to change notification settings - Fork 195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrap PythonPlugin:SearchPaths #5312
Conversation
Openstudio-resources test wanted I guess. Create a Probably make a dumb py file next to it, at In model/simualtiontests/python_plugin_search_paths.py make a python plugin script that would add the |
cppcheck failing [src/model/PythonPluginSearchPaths.hpp:52]:(style),[missingOverride],The destructor '~PythonPluginSearchPaths' overrides a destructor in a base class but is not marked with a 'override' specifier. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should take path. Or at least it should ALLOW a path.
If taking a path, you want to store it as a path.generic_string()
(forward slashes always) as this is eventually what E+ will do when addToPythonPath is called.
bool addSearchPath(const std::string& searchPath); | ||
|
||
bool setSearchPaths(const std::vector<std::string>& searchPaths); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hum, std::string
. Shouldn't this be openstudio::path
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm kinda torn on making it accept ONLY a Path, or allowing both. if allowing both, the std::string version should forward to the path one, and not the opposite
/** PythonPluginSearchPaths is a ParentObject that wraps the OpenStudio IDD object 'OS:PythonPlugin:SearchPaths'. */ | ||
class MODEL_API PythonPluginSearchPaths : public ParentObject |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, why would it be a ParentObject?!
std::vector<std::string> existingSearchPaths = this->searchPaths(); | ||
if (std::find_if(existingSearchPaths.begin(), existingSearchPaths.end(), | ||
[&searchPath](const std::string& s) { return openstudio::istringEqual(s, searchPath); }) | ||
!= existingSearchPaths.end()) { | ||
LOG(Info, "Not adding search path '" << searchPath << "' to PythonPlugin:SearchPaths since it is already present"); | ||
// Return true anyways, it's a success | ||
return true; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unix is case sensitive!
e95cb3a
to
4613368
Compare
…ddSearchPath/setSearchPaths for convenience
…o remove the std::string one
54a43e6
to
187352f
Compare
} // namespace detail | ||
|
||
/** PythonPluginSearchPaths is a ModelObject that wraps the OpenStudio IDD object 'OS:PythonPlugin:SearchPaths'. */ | ||
class MODEL_API PythonPluginSearchPaths : public ModelObject |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made it a ModelObject, since it does not parent anything
|
||
bool addepinEnvironmentVariabletoSearchPath() const; | ||
|
||
std::vector<openstudio::path> searchPaths() const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use paths
bool addSearchPath(const openstudio::path& searchPath); | ||
bool setSearchPaths(const std::vector<openstudio::path>& searchPaths); | ||
|
||
// Convenience, forwards to the openstudio::path equivalent | ||
bool setSearchPaths(const std::vector<std::string>& searchPaths); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use paths. I kept the std::vectorstd::string for convenience.
I had kept the bool addSearchPath(const std::string& searchPath);
one to begin with, but the call to addSearchPath("string litteral")
was ambiguous since const char * converts to both std::string and fs::path, so I removed it (instead of adding a third addSearchPath(const char*)
overload, and having to ignore it in SWIG...)
You can still do this in ruby:
[1] OS-build-release(main)> m = Model.new
=> #<OpenStudio::Model::Model:0x00007b0500a14d90 @__swigtype__="_p_openstudio__model__Model">
[2] OS-build-release(main)> p = m.getPythonPluginSearchPaths
=> #<OpenStudio::Model::PythonPluginSearchPaths:0x00007b05005079b0 @__swigtype__="_p_openstudio__model__PythonPluginSearchPaths">
[3] OS-build-release(main)> p.addSearchPath("lol")
=> true
[4] OS-build-release(main)> puts p
OS:PythonPlugin:SearchPaths,
{85828d9f-b7df-44f7-89c4-cbd18c92badc}, !- Handle
Yes, !- Add Current Working Directory to Search Path
Yes, !- Add Input File Directory to Search Path
Yes, !- Add epin Environment Variable to Search Path
lol; !- Search Path 1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Python:
In [1]: m = openstudio.model.Model()
In [2]: p = m.getPythonPluginSearchPaths()
In [3]: p.addSearchPath(Path('.').absolute())
Out[3]: True
In [4]: p.addSearchPath('the path')
Out[4]: True
In [5]: print(p)
OS:PythonPlugin:SearchPaths,
{c965de9e-6e78-4a6a-aa53-5041e1ac5809}, !- Handle
Yes, !- Add Current Working Directory to Search Path
Yes, !- Add Input File Directory to Search Path
Yes, !- Add epin Environment Variable to Search Path
/home/julien/Software/Others/EnergyPlus-build-release, !- Search Path 1
the path; !- Search Path 2
I have no idea why the EpwFile / SQFile tests are segfaulting on Ubuntu 24.04. I have the same machine locally and they run fine. |
CI Results for 54a43e6:
|
Pull request overview
Pull Request Author
src/model/test
)src/energyplus/Test
)src/osversion/VersionTranslator.cpp
)Labels:
IDDChange
APIChange
Pull Request - Ready for CI
so that CI builds your PRReview Checklist
This will not be exhaustively relevant to every PR.