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

[python] Remove contents of proxsuite-nlp/python/deprecaton-policy #111

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

* Increase minimum version of eigenpy to 3.8.0
* [python] Header `proxsuite-nlp/python/deprecation-policy.hpp` is now deprecated and simply using-declares the templates from eigenpy's corresponding header (introduced in [3.6.0](https://github.com/stack-of-tasks/eigenpy/releases/tag/v3.6.0))

## [0.8.0] - 2024-09-16

Expand Down
14 changes: 9 additions & 5 deletions bindings/python/expose-solver.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "proxsuite-nlp/python/fwd.hpp"
#include "proxsuite-nlp/python/deprecation-policy.hpp"
#include "proxsuite-nlp/prox-solver.hpp"
#include <eigenpy/std-unique-ptr.hpp>
#include <eigenpy/deprecation-policy.hpp>

namespace proxsuite {
namespace nlp {
Expand All @@ -15,6 +15,8 @@ void exposeSolver() {
using context::ConstVectorRef;
using context::Problem;
using context::VectorRef;
using eigenpy::deprecated_member;
using eigenpy::DeprecationType;
using eigenpy::ReturnInternalStdUniquePtr;

bp::enum_<VerboseLevel>("VerboseLevel", "Verbose level for the solver.")
Expand Down Expand Up @@ -118,12 +120,14 @@ void exposeSolver() {
.def("setup", &ProxNLPSolver::setup, ("self"_a),
"Initialize the solver workspace and results.")
.def("getResults", &ProxNLPSolver::getResults, ("self"_a),
deprecation_warning_policy<DeprecationType::DEPRECATION,
bp::return_internal_reference<>>(),
deprecated_member<DeprecationType::DEPRECATION,
bp::return_internal_reference<>>(
"This getter has been deprecated."),
"Get a reference to the results object.")
.def("getWorkspace", &ProxNLPSolver::getWorkspace, ("self"_a),
deprecation_warning_policy<DeprecationType::DEPRECATION,
bp::return_internal_reference<>>(),
deprecated_member<DeprecationType::DEPRECATION,
bp::return_internal_reference<>>(
"This getter has been deprecated."),
"Get a reference to the workspace object.")
.add_property("workspace", bp::make_getter(&ProxNLPSolver::workspace_,
ReturnInternalStdUniquePtr{}))
Expand Down
60 changes: 10 additions & 50 deletions bindings/python/include/proxsuite-nlp/python/deprecation-policy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,57 +3,17 @@
//
#pragma once

namespace proxsuite {
namespace nlp {
namespace bp = boost::python;

enum class DeprecationType { DEPRECATION, FUTURE };

namespace detail {

constexpr PyObject *deprecationTypeToPyObj(DeprecationType dep) {
switch (dep) {
case DeprecationType::DEPRECATION:
return PyExc_DeprecationWarning;
case DeprecationType::FUTURE:
return PyExc_FutureWarning;
}
}

} // namespace detail

constexpr char defaultDeprecationMessage[] =
"This function or attribute has been marked as deprecated, and will be "
"removed in the "
"future.";
#include "proxsuite-nlp/deprecated.hpp"
#include <eigenpy/deprecation-policy.hpp>

/// @brief A Boost.Python call policy which triggers a Python warning on
/// precall.
template <DeprecationType deprecation_type = DeprecationType::DEPRECATION,
class BasePolicy = bp::default_call_policies>
struct deprecation_warning_policy : BasePolicy {
using result_converter = typename BasePolicy::result_converter;
using argument_package = typename BasePolicy::argument_package;

deprecation_warning_policy(
const std::string &warning_msg = defaultDeprecationMessage)
: BasePolicy(), m_what(warning_msg) {}

std::string what() const { return m_what; }

const BasePolicy *derived() const {
return static_cast<const BasePolicy *>(this);
}

template <class ArgPackage> bool precall(const ArgPackage &args) const {
PyErr_WarnEx(detail::deprecationTypeToPyObj(deprecation_type),
m_what.c_str(), 1);
return derived()->precall(args);
}

private:
const std::string m_what;
};
PROXSUITE_NLP_DEPRECATED_HEADER("This header has been deprecated. Use "
"<eigenpy/deprecation-policy.hpp> instead.")

namespace proxsuite {
namespace nlp {
using eigenpy::deprecated_function;
using eigenpy::deprecated_member;
using eigenpy::deprecation_warning_policy;
using eigenpy::DeprecationType;
} // namespace nlp
} // namespace proxsuite
Loading