Skip to content

Commit a95b351

Browse files
dmitriplotnikovcopybara-github
authored andcommitted
Rename "PyCelEnv" class to "PyCelEnvInternal"
This is done in preparation for renaming PyCel to PyCelEnv PiperOrigin-RevId: 854362711
1 parent ff7bb6c commit a95b351

15 files changed

Lines changed: 86 additions & 76 deletions

BUILD

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ pybind_extension(
1818
"py_cel_activation.h",
1919
"py_cel_arena.cc",
2020
"py_cel_arena.h",
21-
"py_cel_env.cc",
22-
"py_cel_env.h",
21+
"py_cel_env_internal.cc",
22+
"py_cel_env_internal.h",
2323
"py_cel_expression.cc",
2424
"py_cel_expression.h",
2525
"py_cel_function.cc",

py_cel.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include "absl/status/statusor.h"
2828
#include "py_cel_activation.h"
2929
#include "py_cel_arena.h"
30-
#include "py_cel_env.h"
30+
#include "py_cel_env_internal.h"
3131
#include "py_cel_expression.h"
3232
#include "py_cel_type.h"
3333
#include <pybind11/pybind11.h>
@@ -106,9 +106,9 @@ void PyCel::DefinePythonBindings(pybind11::module& m) {
106106
PyCel::PyCel(PyObject* descriptor_pool,
107107
std::unordered_map<std::string, PyCelType> variable_types,
108108
const std::vector<PyObject*>& extensions, std::string container)
109-
: env_(std::make_unique<PyCelEnv>(descriptor_pool,
110-
std::move(variable_types), extensions,
111-
std::move(container))) {
109+
: env_(std::make_unique<PyCelEnvInternal>(
110+
descriptor_pool, std::move(variable_types), extensions,
111+
std::move(container))) {
112112
ABSL_CHECK(PyGILState_Check());
113113
}
114114

py_cel.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ class PyCel {
6666
const std::vector<std::shared_ptr<PyCelFunction>>& functions,
6767
const std::shared_ptr<PyCelArena>& arena);
6868

69-
std::shared_ptr<PyCelEnv> GetEnv() { return env_; }
69+
std::shared_ptr<PyCelEnvInternal> GetEnv() { return env_; }
7070

7171
private:
72-
std::shared_ptr<PyCelEnv> env_;
72+
std::shared_ptr<PyCelEnvInternal> env_;
7373
};
7474

7575
} // namespace cel_python

py_cel_activation.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
#include "absl/strings/string_view.h"
2727
#include "common/function_descriptor.h"
2828
#include "common/kind.h"
29-
#include "py_cel_env.h"
29+
#include "py_cel_arena.h"
30+
#include "py_cel_env_internal.h"
3031
#include "py_cel_function.h"
3132
#include "py_cel_value_provider.h"
3233
#include "google/protobuf/arena.h"
@@ -46,7 +47,7 @@ void PyCelActivation::DefinePythonBindings(py::module& m) {
4647
}
4748

4849
PyCelActivation::PyCelActivation(
49-
std::shared_ptr<PyCelEnv> env,
50+
std::shared_ptr<PyCelEnvInternal> env,
5051
const std::unordered_map<std::string, PyObject*>& data,
5152
const std::vector<std::shared_ptr<PyCelFunction>>& functions,
5253
const std::shared_ptr<PyCelArena>& arena)
@@ -79,6 +80,8 @@ PyCelActivation::PyCelActivation(
7980

8081
PyCelActivation::~PyCelActivation() = default;
8182

82-
std::shared_ptr<PyCelEnv> PyCelActivation::GetEnv() const { return env_; }
83+
std::shared_ptr<PyCelEnvInternal> PyCelActivation::GetEnv() const {
84+
return env_;
85+
}
8386

8487
} // namespace cel_python

py_cel_activation.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,26 @@
2828

2929
namespace cel_python {
3030

31-
class PyCelEnv;
31+
class PyCelEnvInternal;
3232
class PyCelFunction;
3333

3434
// Wraps a CelActivation. Supports evaluation of CEL expressions.
3535
class PyCelActivation {
3636
public:
3737
static void DefinePythonBindings(pybind11::module& m);
3838

39-
PyCelActivation(std::shared_ptr<PyCelEnv> env,
39+
PyCelActivation(std::shared_ptr<PyCelEnvInternal> env,
4040
const std::unordered_map<std::string, PyObject*>& data,
4141
const std::vector<std::shared_ptr<PyCelFunction>>& functions,
4242
const std::shared_ptr<PyCelArena>& arena);
4343
~PyCelActivation();
4444

45-
std::shared_ptr<PyCelEnv> GetEnv() const;
45+
std::shared_ptr<PyCelEnvInternal> GetEnv() const;
4646
std::shared_ptr<PyCelArena> GetArena() const { return arena_; }
4747
const cel::Activation* GetActivation() const { return &activation_; }
4848

4949
private:
50-
std::shared_ptr<PyCelEnv> env_;
50+
std::shared_ptr<PyCelEnvInternal> env_;
5151
std::shared_ptr<PyCelArena> arena_;
5252
cel::Activation activation_;
5353
};

py_cel_env.cc renamed to py_cel_env_internal.cc

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#include "py_cel_env.h"
15+
#include "py_cel_env_internal.h"
1616

1717
#include <memory>
1818
#include <string>
@@ -47,10 +47,10 @@
4747

4848
namespace cel_python {
4949

50-
PyCelEnv::PyCelEnv(PyObject* descriptor_pool,
51-
std::unordered_map<std::string, PyCelType> variableTypes,
52-
const std::vector<PyObject*>& extensions,
53-
std::string container)
50+
PyCelEnvInternal::PyCelEnvInternal(
51+
PyObject* descriptor_pool,
52+
std::unordered_map<std::string, PyCelType> variableTypes,
53+
const std::vector<PyObject*>& extensions, std::string container)
5454
: py_descriptor_database_(descriptor_pool),
5555
descriptor_pool_(&py_descriptor_database_),
5656
message_factory_(&descriptor_pool_),
@@ -62,10 +62,8 @@ PyCelEnv::PyCelEnv(PyObject* descriptor_pool,
6262
}
6363
}
6464

65-
// TODO(b/462745713): change the parameter to a const reference once we no
66-
// longer need to pass in a `shared_ptr<PyCelEnv>` to extensions.
67-
absl::StatusOr<const cel::Compiler*> PyCelEnv::GetCompiler(
68-
const std::shared_ptr<PyCelEnv>& env) {
65+
absl::StatusOr<const cel::Compiler*> PyCelEnvInternal::GetCompiler(
66+
const std::shared_ptr<PyCelEnvInternal>& env) {
6967
if (env->compiler_) {
7068
return env->compiler_.get();
7169
}
@@ -100,8 +98,8 @@ absl::StatusOr<const cel::Compiler*> PyCelEnv::GetCompiler(
10098
return env->compiler_.get();
10199
}
102100

103-
absl::StatusOr<const cel::Runtime*> PyCelEnv::GetRuntime(
104-
const std::shared_ptr<PyCelEnv>& env, RuntimeMode runtime_mode) {
101+
absl::StatusOr<const cel::Runtime*> PyCelEnvInternal::GetRuntime(
102+
const std::shared_ptr<PyCelEnvInternal>& env, RuntimeMode runtime_mode) {
105103
if (auto it = env->runtimes_.find(runtime_mode); it != env->runtimes_.end()) {
106104
return it->second.get();
107105
}
@@ -136,7 +134,8 @@ absl::StatusOr<const cel::Runtime*> PyCelEnv::GetRuntime(
136134
return runtime_ptr;
137135
}
138136

139-
const PyCelType& PyCelEnv::GetVariableType(const std::string& name) const {
137+
const PyCelType& PyCelEnvInternal::GetVariableType(
138+
const std::string& name) const {
140139
ABSL_CHECK(PyGILState_Check());
141140
auto it = variable_types_.find(name);
142141
if (it != variable_types_.end()) {
@@ -158,7 +157,7 @@ PyCelExtensionHandle::~PyCelExtensionHandle() {
158157
}
159158

160159
absl::StatusOr<PyCelExtension*> PyCelExtensionHandle::GetExtension(
161-
const std::shared_ptr<PyCelEnv>& env) {
160+
const std::shared_ptr<PyCelEnvInternal>& env) {
162161
if (cel_extension_) {
163162
return cel_extension_;
164163
}

py_cel_env.h renamed to py_cel_env_internal.h

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#ifndef THIRD_PARTY_CEL_PYTHON_PY_CEL_ENV_H_
16-
#define THIRD_PARTY_CEL_PYTHON_PY_CEL_ENV_H_
15+
#ifndef THIRD_PARTY_CEL_PYTHON_PY_CEL_ENV_INTERNAL_H_
16+
#define THIRD_PARTY_CEL_PYTHON_PY_CEL_ENV_INTERNAL_H_
1717

1818
#include <Python.h> // IWYU pragma: keep - Needed for PyObject
1919

@@ -27,7 +27,8 @@
2727
#include "absl/status/statusor.h"
2828
#include "compiler/compiler.h"
2929
#include "runtime/runtime.h"
30-
#include "py_cel.h"
30+
#include "runtime/runtime_builder.h"
31+
#include "runtime/runtime_options.h"
3132
#include "py_cel_extension.h"
3233
#include "py_cel_type.h"
3334
#include "py_descriptor_database.h"
@@ -38,13 +39,15 @@
3839

3940
namespace cel_python {
4041

42+
class PyCelEnvInternal;
43+
4144
class PyCelExtensionHandle {
4245
public:
4346
explicit PyCelExtensionHandle(PyObject* extension);
4447
~PyCelExtensionHandle();
4548

4649
absl::StatusOr<PyCelExtension*> GetExtension(
47-
const std::shared_ptr<PyCelEnv>& env);
50+
const std::shared_ptr<PyCelEnvInternal>& env);
4851

4952
private:
5053
// The Python object that was passed to the constructor and is retained for
@@ -56,17 +59,18 @@ class PyCelExtensionHandle {
5659
PyCelExtension* cel_extension_;
5760
};
5861

59-
// PyCelEnv is a container for internal CEL components not exposed to the python
60-
// side.
61-
class PyCelEnv {
62+
// PyCelEnvInternal is a container for internal CEL components not exposed to
63+
// the python side.
64+
class PyCelEnvInternal {
6265
public:
63-
PyCelEnv(PyObject* descriptor_pool,
64-
std::unordered_map<std::string, PyCelType> variableTypes,
65-
const std::vector<PyObject*>& extensions, std::string container);
66-
~PyCelEnv() = default;
66+
PyCelEnvInternal(PyObject* descriptor_pool,
67+
std::unordered_map<std::string, PyCelType> variableTypes,
68+
const std::vector<PyObject*>& extensions,
69+
std::string container);
70+
~PyCelEnvInternal() = default;
6771

6872
static absl::StatusOr<const cel::Compiler*> GetCompiler(
69-
const std::shared_ptr<PyCelEnv>& env);
73+
const std::shared_ptr<PyCelEnvInternal>& env);
7074

7175
enum RuntimeMode {
7276
// Standard CEL runtime with warnings treated as errors.
@@ -77,7 +81,7 @@ class PyCelEnv {
7781
};
7882

7983
static absl::StatusOr<const cel::Runtime*> GetRuntime(
80-
const std::shared_ptr<PyCelEnv>& env, RuntimeMode runtime_mode);
84+
const std::shared_ptr<PyCelEnvInternal>& env, RuntimeMode runtime_mode);
8185

8286
const google::protobuf::DescriptorPool* GetDescriptorPool() const {
8387
return &descriptor_pool_;
@@ -116,4 +120,4 @@ class PyCelEnv {
116120

117121
} // namespace cel_python
118122

119-
#endif // THIRD_PARTY_CEL_PYTHON_PY_CEL_ENV_H_
123+
#endif // THIRD_PARTY_CEL_PYTHON_PY_CEL_ENV_INTERNAL_H_

py_cel_expression.cc

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
#include "runtime/runtime.h"
4343
#include "py_cel_activation.h"
4444
#include "py_cel_arena.h"
45-
#include "py_cel_env.h"
45+
#include "py_cel_env_internal.h"
4646
#include "py_cel_type.h"
4747
#include "py_cel_value.h"
4848
#include "py_error_status.h"
@@ -71,12 +71,12 @@ void PyCelExpression::DefinePythonBindings(py::module& m) {
7171
}
7272

7373
absl::StatusOr<PyCelExpression> PyCelExpression::Compile(
74-
const std::shared_ptr<PyCelEnv>& env, const std::string& cel_expr,
74+
const std::shared_ptr<PyCelEnvInternal>& env, const std::string& cel_expr,
7575
bool disable_check) {
7676
ABSL_CHECK(PyGILState_Check());
7777

7878
PY_CEL_ASSIGN_OR_RETURN(const cel::Compiler* compiler,
79-
PyCelEnv::GetCompiler(env));
79+
PyCelEnvInternal::GetCompiler(env));
8080

8181
if (disable_check) {
8282
PY_CEL_ASSIGN_OR_RETURN(auto s, cel::NewSource(cel_expr, "<input>"));
@@ -121,21 +121,22 @@ absl::StatusOr<PyCelValue> PyCelExpression::Eval(
121121
if (std::holds_alternative<ParsedExpr>(expr_)) {
122122
CEL_PYTHON_ASSIGN_OR_RETURN(
123123
const cel::Runtime* runtime,
124-
PyCelEnv::GetRuntime(env_, PyCelEnv::kStandardIgnoreWarnings));
124+
PyCelEnvInternal::GetRuntime(
125+
env_, PyCelEnvInternal::kStandardIgnoreWarnings));
125126
CEL_PYTHON_ASSIGN_OR_RETURN(
126127
cel_program_, cel::extensions::ProtobufRuntimeAdapter::CreateProgram(
127128
*runtime, std::get<ParsedExpr>(expr_)));
128129
} else {
129130
CEL_PYTHON_ASSIGN_OR_RETURN(
130131
const cel::Runtime* runtime,
131-
PyCelEnv::GetRuntime(env_, PyCelEnv::kStandard));
132+
PyCelEnvInternal::GetRuntime(env_, PyCelEnvInternal::kStandard));
132133
CEL_PYTHON_ASSIGN_OR_RETURN(
133134
cel_program_, cel::extensions::ProtobufRuntimeAdapter::CreateProgram(
134135
*runtime, std::get<CheckedExpr>(expr_)));
135136
}
136137
}
137138
std::shared_ptr<PyCelArena> arena = activation.GetArena();
138-
std::shared_ptr<PyCelEnv> env = activation.GetEnv();
139+
std::shared_ptr<PyCelEnvInternal> env = activation.GetEnv();
139140
cel::EmbedderContext embedder_context = cel::EmbedderContext::From(&env);
140141
cel::EvaluateOptions options;
141142
options.message_factory = env->GetMessageFactory();
@@ -158,7 +159,8 @@ std::string PyCelExpression::Serialize() const {
158159
}
159160

160161
absl::StatusOr<PyCelExpression> PyCelExpression::Deserialize(
161-
const std::shared_ptr<PyCelEnv>& env, const std::string& serialized_expr) {
162+
const std::shared_ptr<PyCelEnvInternal>& env,
163+
const std::string& serialized_expr) {
162164
ABSL_CHECK(PyGILState_Check());
163165
google::protobuf::Any any;
164166
if (!any.ParseFromString(serialized_expr)) {

py_cel_expression.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
namespace cel_python {
3333

34-
class PyCelEnv;
34+
class PyCelEnvInternal;
3535

3636
// Wraps a CelExpression. Supports serialization and deserialization.
3737
class PyCelExpression {
@@ -41,10 +41,10 @@ class PyCelExpression {
4141
PyCelExpression(PyCelExpression&& other) = default;
4242

4343
PyCelExpression(const cel::expr::ParsedExpr& parsed_expr,
44-
std::shared_ptr<PyCelEnv> env)
44+
std::shared_ptr<PyCelEnvInternal> env)
4545
: expr_(std::move(parsed_expr)), env_(std::move(env)) {}
4646
PyCelExpression(const cel::expr::CheckedExpr& checked_expr,
47-
std::shared_ptr<PyCelEnv> env)
47+
std::shared_ptr<PyCelEnvInternal> env)
4848
: expr_(std::move(checked_expr)), env_(std::move(env)) {}
4949

5050
PyCelType GetReturnType();
@@ -54,16 +54,17 @@ class PyCelExpression {
5454
std::string Serialize() const;
5555

5656
static absl::StatusOr<PyCelExpression> Compile(
57-
const std::shared_ptr<PyCelEnv>& env, const std::string& cel_expr,
57+
const std::shared_ptr<PyCelEnvInternal>& env, const std::string& cel_expr,
5858
bool disable_check);
5959

6060
static absl::StatusOr<PyCelExpression> Deserialize(
61-
const std::shared_ptr<PyCelEnv>& env, const std::string& serialized_expr);
61+
const std::shared_ptr<PyCelEnvInternal>& env,
62+
const std::string& serialized_expr);
6263

6364
private:
6465
std::variant<cel::expr::ParsedExpr, cel::expr::CheckedExpr>
6566
expr_;
66-
std::shared_ptr<PyCelEnv> env_;
67+
std::shared_ptr<PyCelEnvInternal> env_;
6768
std::unique_ptr<cel::Program> cel_program_;
6869
};
6970

py_cel_function.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
#include "common/value.h"
3030
#include "runtime/embedder_context.h"
3131
#include "runtime/function.h"
32-
#include "py_cel_env.h"
32+
#include "py_cel_arena.h"
33+
#include "py_cel_env_internal.h"
3334
#include "py_cel_type.h"
3435
#include "py_cel_value.h"
3536
#include "py_error_status.h"
@@ -44,11 +45,11 @@ namespace py = ::pybind11;
4445

4546
namespace {
4647

47-
static std::shared_ptr<PyCelEnv> GetEnvFromContext(
48+
static std::shared_ptr<PyCelEnvInternal> GetEnvFromContext(
4849
const cel::Function::InvokeContext& context) {
4950
ABSL_CHECK(context.embedder_context()); // Crash OK: all call sites are local
5051
// to the library.
51-
return *context.embedder_context()->Get<std::shared_ptr<PyCelEnv>*>();
52+
return *context.embedder_context()->Get<std::shared_ptr<PyCelEnvInternal>*>();
5253
}
5354

5455
} // namespace
@@ -94,7 +95,7 @@ absl::StatusOr<cel::Value> PyCelFunctionAdapter::Invoke(
9495
const cel::Function::InvokeContext& context) const {
9596
ABSL_CHECK(PyGILState_Check());
9697

97-
std::shared_ptr<PyCelEnv> env = GetEnvFromContext(context);
98+
std::shared_ptr<PyCelEnvInternal> env = GetEnvFromContext(context);
9899
PY_CEL_ASSIGN_OR_RETURN(auto py_arena,
99100
PyCelArena::FromProtoArena(context.arena()));
100101
PyObject* py_args = PyTuple_New(args.size());

0 commit comments

Comments
 (0)