Skip to content

Commit

Permalink
make thrift structures hashable
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinVenus committed Oct 8, 2019
1 parent 4361fcc commit 3757b72
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 1 deletion.
4 changes: 4 additions & 0 deletions api/src/main/thrift/org/apache/aurora/gen/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ python_thrift_library(
],
dependencies = [
'3rdparty/python:thrift',
'src/main/python/apache/aurora/thrift:protocol',
],
)

Expand All @@ -29,6 +30,7 @@ python_thrift_library(
sources = globs('*test.thrift'),
dependencies = [
'3rdparty/python:thrift',
'src/main/python/apache/aurora/thrift:protocol',
],
)

Expand All @@ -38,6 +40,7 @@ python_thrift_library(
dependencies = [
'3rdparty/python:thrift',
':_api',
'src/main/python/apache/aurora/thrift:protocol',
],
)

Expand All @@ -46,6 +49,7 @@ python_library(
':_api',
':_test',
':_storage',
'src/main/python/apache/aurora/thrift:protocol',
],
provides = setup_py(
name = 'apache.aurora.thrift',
Expand Down
1 change: 1 addition & 0 deletions api/src/main/thrift/org/apache/thermos/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ python_thrift_library(
),
dependencies = [
'3rdparty/python:thrift',
'src/main/python/apache/aurora/thrift:protocol',
],
)
16 changes: 15 additions & 1 deletion pants.ini
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,21 @@ build_file_imports: allow


[thrift]
version: 0.10.0
version: 0.11.0


[gen.thrift-py]
deps: [
"src/main/python/apache/aurora/thrift:protocol",
]
gen_options_map: {
'coding': 'utf-8',
'new_style': None,
'slots': None,
'dynamic': None,
'dynbase': 'HashedTBase',
'dynimport': 'from apache.aurora.thrift.protocol import HashedTBase\n',
}


[python-setup]
Expand Down
28 changes: 28 additions & 0 deletions src/main/python/apache/aurora/thrift/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import os

python_library(
name = 'protocol',
sources = [
'protocol.py',
],
dependencies = [
'3rdparty/python:thrift',
],
provides = setup_py(
name = 'apache.aurora.thrift-protocol',
version = open(os.path.join(get_buildroot(), '.auroraversion')).read().strip().upper(),
)
)
22 changes: 22 additions & 0 deletions src/main/python/apache/aurora/thrift/protocol.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
from thrift.protocol.TBase import TBase


class HashedTBase(TBase):

def __hash__(self):
return hash(self.__class__) ^ hash(self.__slots__)

__all__ = ('HashedTBase',)

0 comments on commit 3757b72

Please sign in to comment.