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

Use PyConfig to initialize python #10342

Merged
merged 3 commits into from
Dec 22, 2023
Merged

Use PyConfig to initialize python #10342

merged 3 commits into from
Dec 22, 2023

Conversation

jmarrec
Copy link
Contributor

@jmarrec jmarrec commented Dec 22, 2023

Pull request overview

  • Isolate the PyConfig changes from Updated GCC/Python Support #10340 into it's own PR
  • remove blocks on python version (use PyConfig for 3.8 too),
  • Put back type_traits
  • Improve error messages via a fmt formatter for PyStatus
  • Replace C style casts with static_casts

Pull Request Author

Add to this list or remove from it as applicable. This is a simple templated set of guidelines.

  • Title of PR should be user-synopsis style (clearly understandable in a standalone changelog context)
  • Label the PR with at least one of: Defect, Refactoring, NewFeature, Performance, and/or DoNoPublish
  • Pull requests that impact EnergyPlus code must also include unit tests to cover enhancement or defect repair
  • Author should provide a "walkthrough" of relevant code changes using a GitHub code review comment process
  • If any diffs are expected, author must demonstrate they are justified using plots and descriptions
  • If changes fix a defect, the fix should be demonstrated in plots and descriptions
  • If any defect files are updated to a more recent version, upload new versions here or on DevSupport
  • If IDD requires transition, transition source, rules, ExpandObjects, and IDFs must be updated, and add IDDChange label
  • If structural output changes, add to output rules file and add OutputChange label
  • If adding/removing any LaTeX docs or figures, update that document's CMakeLists file dependencies

Reviewer

This will not be exhaustively relevant to every PR.

  • Perform a Code Review on GitHub
  • If branch is behind develop, merge develop and build locally to check for side effects of the merge
  • 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
  • Check that performance is not impacted (CI Linux results include performance check)
  • Run Unit Test(s) locally
  • Check any new function arguments for performance impacts
  • Verify IDF naming conventions and styles, memos and notes and defaults
  • If new idf included, locally check the err file and other outputs

* Isolate #10340 into it's own PR
* remove blocks on python version (use PyConfig for 3.8 too),
* Put back type_traits
* Improve error messages via a fmt formatter for PyStatus
* Replace C style casts with static_casts
@jmarrec jmarrec added the Refactoring Includes code changes that don't change the functionality of the program, just perform refactoring label Dec 22, 2023
@jmarrec jmarrec self-assigned this Dec 22, 2023
@jmarrec jmarrec changed the title Use PyConfig to initial python Use PyConfig to initialize python Dec 22, 2023
This was referenced Dec 22, 2023
Copy link
Member

@Myoldmopar Myoldmopar left a comment

Choose a reason for hiding this comment

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

This is good stuff. Thanks for bringing it over into its own dedicated PR, that's much cleaner. As long as CI and local testing is happy, this shall merge.

} else {
// PyConfig_SetBytesString takes a `const char * str` and decodes str using Py_DecodeLocale() and set the result into *config_str
// But we want to avoid doing it three times, so we PyDecodeLocale manually
// Py_DecodeLocale can be called because Python has been PreInitialized.
Copy link
Member

Choose a reason for hiding this comment

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

👍 👍

#if LINK_WITH_PYTHON
void initPython(EnergyPlusData &state, fs::path const &pathToPythonPackages)
{
PyStatus status;
Copy link
Member

Choose a reason for hiding this comment

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

I do wish I had been able to use the PyConfig method a long time ago, but at the time I think I was still using 3.7 or earlier. This is so much nicer nowadays.

@@ -379,6 +411,82 @@ void PluginManager::setupOutputVariables([[maybe_unused]] EnergyPlusData &state)
#endif
}

#if LINK_WITH_PYTHON
Copy link
Member

Choose a reason for hiding this comment

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

Making this a standalone function is fine with me, given what it does.

}
};
} // namespace fmt
#endif
Copy link
Member

Choose a reason for hiding this comment

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

Wow, didn't expect this, but a dedicated formatter for PyStatus is pretty nice.

@@ -174,6 +174,7 @@ endif()

# we are making *a Python 3.6 Interpreter* a required dependency, so find it here
# If LINK_WITH_PYTHON, also request the Development (libs) at the same time, to ensure consistent version between interpreter and Development
# and ask for at least 3.8 (for the PyConfig stuff).
Copy link
Member

Choose a reason for hiding this comment

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

I'd be almost inclined to just require 3.8 all the time, considering 3.6 died a long time ago, and 3.8 is about to go to end-of-life next year. But this is clearly laying out the needs for our CPython uses. 👍

@Myoldmopar
Copy link
Member

Everything is super happy on CI and locally. Thanks @jmarrec, merging this in!

@Myoldmopar Myoldmopar merged commit b1555b2 into develop Dec 22, 2023
10 checks passed
@Myoldmopar Myoldmopar deleted the PyConfig branch December 22, 2023 15:13
@Myoldmopar Myoldmopar added the LowComplexityApproved Used for subcontractor defect complexity requests label Apr 24, 2024
@jmarrec jmarrec added Defect Includes code to repair a defect in EnergyPlus and removed Refactoring Includes code changes that don't change the functionality of the program, just perform refactoring labels May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Defect Includes code to repair a defect in EnergyPlus LowComplexityApproved Used for subcontractor defect complexity requests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants