Skip to content
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

Merged
merged 17 commits into from
Dec 19, 2024
Merged

Conversation

joseph-robertson
Copy link
Collaborator

@joseph-robertson joseph-robertson commented Dec 2, 2024

Pull request overview

Pull Request Author

  • Model API Changes / Additions
  • Any new or modified fields have been implemented in the EnergyPlus ForwardTranslator (and ReverseTranslator as appropriate)
  • Model API methods are tested (in src/model/test)
  • EnergyPlus ForwardTranslator Tests (in src/energyplus/Test)
  • If a new object or method, added a test in NREL/OpenStudio-resources:
  • If needed, added VersionTranslation rules for the objects (src/osversion/VersionTranslator.cpp)
  • Verified that C# bindings built fine on Windows, partial classes used as needed, etc.
  • All new and existing tests passes
  • If methods have been deprecated, update rest of code to use the new methods

Labels:

  • If change to an IDD file, add the label IDDChange
  • If breaking existing API, add the label APIChange
  • If deemed ready, add label Pull Request - Ready for CI so that CI builds your PR

Review Checklist

This will not be exhaustively relevant to every PR.

  • Perform a Code Review on GitHub
  • Code Style, strip trailing whitespace, etc.
  • All related changes have been implemented: model changes, model tests, FT changes, FT tests, VersionTranslation, OS App
  • Labeling is ok
  • If defect, verify by running develop branch and reproducing defect, then running PR and reproducing fix
  • If feature, test running new feature, try creative ways to break it
  • CI status: all green or justified

@joseph-robertson joseph-robertson added Enhancement Request component - Model Pull Request - Ready for CI This pull request if finalized and is ready for continuous integration verification prior to merge. labels Dec 2, 2024
@joseph-robertson joseph-robertson self-assigned this Dec 2, 2024
@joseph-robertson joseph-robertson marked this pull request as ready for review December 6, 2024 22:41
@jmarrec
Copy link
Collaborator

jmarrec commented Dec 12, 2024

Openstudio-resources test wanted I guess.

Create a model/simualtiontests/python_plugin_search_paths.py

Probably make a dumb py file next to it, at model/simulationtests/python_plugin_search_paths_script.py that has a dumb function or just a print statement in it.

In model/simualtiontests/python_plugin_search_paths.py make a python plugin script that would add the Path(__file__).parent to the search paths and would do import python_plugin_search_paths_script. It should fail when the PythonPluginSearchPaths isn't used, and work with it.

@jmarrec
Copy link
Collaborator

jmarrec commented Dec 12, 2024

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.
[src/model/PythonPluginSearchPaths_Impl.hpp:54]:(style),[missingOverride],The destructor '~PythonPluginSearchPaths_Impl' overrides a destructor in a base class but is not marked with a 'override' specifier.

Copy link
Collaborator

@jmarrec jmarrec left a 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.

Comment on lines 84 to 90
bool addSearchPath(const std::string& searchPath);

bool setSearchPaths(const std::vector<std::string>& searchPaths);
Copy link
Collaborator

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?

Copy link
Collaborator

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

Comment on lines 45 to 46
/** PythonPluginSearchPaths is a ParentObject that wraps the OpenStudio IDD object 'OS:PythonPlugin:SearchPaths'. */
class MODEL_API PythonPluginSearchPaths : public ParentObject
Copy link
Collaborator

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?!

Comment on lines 113 to 119
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;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unix is case sensitive!

@jmarrec jmarrec force-pushed the python-plugin-search-paths branch from e95cb3a to 4613368 Compare December 19, 2024 12:00
@jmarrec jmarrec force-pushed the python-plugin-search-paths branch from 54a43e6 to 187352f Compare December 19, 2024 14:39
} // namespace detail

/** PythonPluginSearchPaths is a ModelObject that wraps the OpenStudio IDD object 'OS:PythonPlugin:SearchPaths'. */
class MODEL_API PythonPluginSearchPaths : public ModelObject
Copy link
Collaborator

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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use paths

Comment on lines +86 to +90
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);
Copy link
Collaborator

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

Copy link
Collaborator

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

@jmarrec
Copy link
Collaborator

jmarrec commented Dec 19, 2024

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-commercialbuildings
Copy link
Collaborator

ci-commercialbuildings commented Dec 19, 2024

CI Results for 54a43e6:

@joseph-robertson joseph-robertson merged commit 73e12b9 into develop Dec 19, 2024
2 of 6 checks passed
@joseph-robertson joseph-robertson deleted the python-plugin-search-paths branch December 19, 2024 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component - Model Enhancement Request Pull Request - Ready for CI This pull request if finalized and is ready for continuous integration verification prior to merge.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

E+ 24.2.1: Wrap PythonPlugin:SearchPaths
3 participants