Skip to content

Commit

Permalink
Revert protobuf compilation changes (#19)
Browse files Browse the repository at this point in the history
Revert back to 4.24.3 compilations
  • Loading branch information
sdb9696 authored Sep 27, 2024
1 parent 2a643dc commit 07f826e
Show file tree
Hide file tree
Showing 11 changed files with 2,236 additions and 941 deletions.
81 changes: 41 additions & 40 deletions RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,6 @@
* [gitchub_changelog_generator](https://github.com/github-changelog-generator)
* [github access token](https://github.com/github-changelog-generator/github-changelog-generator#github-token)

## Updating protobuf version

Skip this part under normal circumstances.
Only required if protobuf minimum depencey is updated.

### Update protobuf version

```bash
export PROTOBUF_VERSION=x.x.0
uv add "protobuf>$PROTOBUF_VERSION"
uv add --dev "types-protobuf>$PROTOBUF_VERSION"
```

### Download and unzip latest protoc compiler

Replace download url with correct version/platform

```bash
cd /var/tmp
wget https://github.com/protocolbuffers/protobuf/releases/download/v28.0/protoc-28.0-linux-x86_64.zip
unzip protoc-28.0-linux-x86_64.zip
sudo cp bin/protoc /usr/local/bin/
cd <project-dir>
protoc --version # check version as expected
```

### Update generated python files

```bash
export PROTO_DIR="firebase_messaging/proto"
protoc --proto_path=$PROTO_DIR --python_out=$PROTO_DIR $PROTO_DIR/android_checkin.proto $PROTO_DIR/checkin.proto $PROTO_DIR/mcs.proto
protoc --proto_path=$PROTO_DIR --pyi_out=$PROTO_DIR $PROTO_DIR/android_checkin.proto $PROTO_DIR/checkin.proto $PROTO_DIR/mcs.proto
```

### Fix relative import

`protoc` doesn't do relative imports https://github.com/protocolbuffers/protobuf/issues/1491

In `checkin_pb2.py` and `checkin_pb2.pyi` put `from . ` in front of `import android_checkin_pb2 ...`

## Export changelog token

```bash
Expand Down Expand Up @@ -189,3 +149,44 @@ git push origin $NEW_RELEASE
### Approve the release workflow

This will automatically deploy to pypi


## Updating protobuf version

Skip this part under normal circumstances.
Only required if protobuf minimum dependency is updated.

### Update protobuf version

```bash
export PROTOBUF_VERSION=x.x.0
uv add "protobuf>$PROTOBUF_VERSION"
uv add --dev "types-protobuf>$PROTOBUF_VERSION"
```

### Download and unzip latest protoc compiler

Replace download url with correct version/platform

```bash
cd /var/tmp
wget https://github.com/protocolbuffers/protobuf/releases/download/v28.0/protoc-28.0-linux-x86_64.zip
unzip protoc-28.0-linux-x86_64.zip
sudo cp bin/protoc /usr/local/bin/
cd <project-dir>
protoc --version # check version as expected
```

### Update generated python files

```bash
export PROTO_DIR="firebase_messaging/proto"
protoc --proto_path=$PROTO_DIR --python_out=$PROTO_DIR $PROTO_DIR/android_checkin.proto $PROTO_DIR/checkin.proto $PROTO_DIR/mcs.proto
protoc --proto_path=$PROTO_DIR --pyi_out=$PROTO_DIR $PROTO_DIR/android_checkin.proto $PROTO_DIR/checkin.proto $PROTO_DIR/mcs.proto
```

### Fix relative import

`protoc` doesn't do relative imports https://github.com/protocolbuffers/protobuf/issues/1491

In `checkin_pb2.py` and `checkin_pb2.pyi` put `from . ` in front of `import android_checkin_pb2 ...`
26 changes: 12 additions & 14 deletions firebase_messaging/fcmpushclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,18 @@
MCS_SELECTIVE_ACK_ID,
MCS_VERSION,
)
from .fcmregister import FcmRegister, FcmRegisterConfig, catch_protobuf_warnings

with catch_protobuf_warnings():
from .proto.mcs_pb2 import ( # pylint: disable=no-name-in-module
Close,
DataMessageStanza,
HeartbeatAck,
HeartbeatPing,
IqStanza,
LoginRequest,
LoginResponse,
SelectiveAck,
StreamErrorStanza,
)
from .fcmregister import FcmRegister, FcmRegisterConfig
from .proto.mcs_pb2 import ( # pylint: disable=no-name-in-module
Close,
DataMessageStanza,
HeartbeatAck,
HeartbeatPing,
IqStanza,
LoginRequest,
LoginResponse,
SelectiveAck,
StreamErrorStanza,
)

_logger = logging.getLogger(__name__)

Expand Down
46 changes: 9 additions & 37 deletions firebase_messaging/fcmregister.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
import secrets
import time
import uuid
import warnings
from base64 import b64encode, urlsafe_b64encode
from collections.abc import Iterator
from contextlib import contextmanager
from dataclasses import dataclass
from typing import Any, Callable

Expand All @@ -29,40 +26,15 @@
GCM_SERVER_KEY_B64,
SDK_VERSION,
)


@contextmanager
def catch_protobuf_warnings() -> Iterator[None]:
"""Catch excessive protobuf warnings due to incorrect greater than check.
See https://github.com/protocolbuffers/protobuf/issues/18096
and https://protobuf.dev/support/cross-version-runtime-guarantee/#minor.
"""
match = (
r"^Protobuf gencode version \d+\.\d+\.\d+ is older than the runtime version"
r" \d+\.\d+\.\d+ at .*\.proto\. Please avoid checked-in Protobuf gencode "
r"that can be obsolete\.$"
)
with warnings.catch_warnings():
warnings.filterwarnings(
"ignore",
category=UserWarning,
module="google.protobuf.runtime_version",
message=match,
)
yield


with catch_protobuf_warnings():
from .proto.android_checkin_pb2 import (
DEVICE_CHROME_BROWSER,
AndroidCheckinProto,
ChromeBuildProto,
)
from .proto.checkin_pb2 import (
AndroidCheckinRequest,
AndroidCheckinResponse,
)
from .proto.android_checkin_pb2 import (
DEVICE_CHROME_BROWSER,
AndroidCheckinProto,
ChromeBuildProto,
)
from .proto.checkin_pb2 import (
AndroidCheckinRequest,
AndroidCheckinResponse,
)

_logger = logging.getLogger(__name__)

Expand Down
47 changes: 19 additions & 28 deletions firebase_messaging/proto/android_checkin_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 07f826e

Please sign in to comment.