Skip to content

Commit edc9622

Browse files
committed
Merge main branch to get latest updates
2 parents 71927ad + c8d09c4 commit edc9622

File tree

11 files changed

+170
-15
lines changed

11 files changed

+170
-15
lines changed

.github/workflows/build.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ jobs:
1515
strategy:
1616
matrix:
1717
os: [ubuntu-latest, macos-latest, windows-latest]
18-
python: ['3.9', '3.10', '3.11']
18+
python: ['3.10', '3.11']
1919

2020
steps:
21-
- uses: compas-dev/compas-actions.build@v3
21+
- uses: compas-dev/compas-actions.build@v4
2222
with:
2323
python: ${{ matrix.python }}
2424
invoke_lint: true
@@ -33,16 +33,20 @@ jobs:
3333
steps:
3434
- uses: actions/checkout@v2
3535
- name: Install dependencies
36+
shell: cmd
3637
run: |
3738
curl -o compas.tar.gz -LJO https://pypi.debian.net/compas/latest
3839
curl -o ironpython-pytest.tar.gz -LJO https://pypi.debian.net/ironpython-pytest/latest
3940
choco install ironpython --version=2.7.8.1
4041
ipy -X:Frames -m ensurepip
41-
ipy -X:Frames -m pip install --no-deps compas.tar.gz
4242
ipy -X:Frames -m pip install --no-deps ironpython-pytest.tar.gz
43+
44+
rem untar and rename, these cannot be installed using ironpip because they not longer have a setup.py
45+
tar -xf compas.tar.gz && for /d %%i in (compas-*) do ren "%%i" compas
46+
4347
- name: Run tests
4448
env:
45-
IRONPYTHONPATH: ./src
49+
IRONPYTHONPATH: ./src;./compas/src
4650
run: |
4751
ipy -m pytest tests/unit
4852
@@ -54,7 +58,7 @@ jobs:
5458
run: |
5559
docker run -d --name nanomq -p 1883:1883 -p 8083:8083 -p 8883:8883 emqx/nanomq:latest
5660
docker ps -a
57-
- uses: compas-dev/compas-actions.build@v3
61+
- uses: compas-dev/compas-actions.build@v4
5862
with:
5963
python: '3.11'
6064
invoke_lint: false

.github/workflows/release.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ jobs:
1111
strategy:
1212
matrix:
1313
os: [ubuntu-latest, macos-latest, windows-latest]
14-
python: ['3.9', '3.10', '3.11']
14+
python: ['3.10', '3.11']
1515

1616
steps:
17-
- uses: compas-dev/compas-actions.build@v3
17+
- uses: compas-dev/compas-actions.build@v4
1818
with:
1919
python: ${{ matrix.python }}
2020
invoke_lint: true
@@ -31,7 +31,7 @@ jobs:
3131
run: |
3232
docker run -d --name nanomq -p 1883:1883 -p 8083:8083 -p 8883:8883 emqx/nanomq:latest
3333
docker ps -a
34-
- uses: compas-dev/compas-actions.build@v3
34+
- uses: compas-dev/compas-actions.build@v4
3535
with:
3636
python: '3.11'
3737
invoke_lint: false
@@ -100,7 +100,6 @@ jobs:
100100
run: |
101101
python -m pip install --upgrade pip
102102
python -m pip install wheel
103-
python -m pip install --no-cache-dir -r requirements-dev.txt
104103
105104
- uses: NuGet/[email protected]
106105
- name: Install dependencies

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12+
* Added support for MQTT-PAHO 2.0 versioned callbacks.
13+
1214
### Changed
1315

16+
* Updated dependency on `paho-mqtt` to support `>=1, <3` to include version `2.x` with backward compatibility.
17+
1418
### Removed
1519

1620

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ In short, this is how that works.
1212
3. Install development dependencies:
1313

1414
```bash
15-
pip install -r requirements-dev.txt
15+
pip install -e .[dev]
1616
```
1717

1818
4. Make sure all tests pass:

MANIFEST.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ include AUTHORS.md
1313
include CHANGELOG.md
1414
include requirements.txt
1515

16+
recursive-include examples *.py
17+
1618
exclude compas_eve.jpg
1719
exclude requirements-dev.txt
1820
exclude pytest.ini .bumpversion.cfg .editorconfig
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Demonstration script to show MQTT-PAHO 2.0 compatibility.
4+
5+
This script demonstrates that the MqttTransport can work with both
6+
paho-mqtt 1.x and 2.x versions automatically.
7+
"""
8+
9+
import sys
10+
import os
11+
12+
# Add the src directory to the path to import compas_eve
13+
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'src'))
14+
15+
def main():
16+
print("COMPAS Eve MQTT-PAHO 2.0 Compatibility Demonstration")
17+
print("=" * 55)
18+
19+
try:
20+
# Import and check version compatibility
21+
from compas_eve.mqtt.mqtt_paho import PAHO_MQTT_V2_AVAILABLE
22+
import paho.mqtt
23+
24+
print(f"paho-mqtt version: {paho.mqtt.__version__}")
25+
print(f"MQTT-PAHO 2.0 support available: {PAHO_MQTT_V2_AVAILABLE}")
26+
print()
27+
28+
# Try to create transport (will fail due to network but shows client creation works)
29+
try:
30+
from compas_eve.mqtt.mqtt_paho import MqttTransport
31+
print("Attempting to create MqttTransport (will fail due to no broker)...")
32+
transport = MqttTransport('nonexistent-broker.local')
33+
print("✓ Transport created successfully")
34+
except Exception as e:
35+
if "No address associated with hostname" in str(e) or "gaierror" in str(e):
36+
print("✓ Client creation successful (expected network error)")
37+
else:
38+
print(f"❌ Unexpected error: {e}")
39+
raise
40+
41+
print()
42+
print("Compatibility verification:")
43+
if PAHO_MQTT_V2_AVAILABLE:
44+
from paho.mqtt.enums import CallbackAPIVersion
45+
print(f"✓ Using MQTT-PAHO 2.0 with CallbackAPIVersion.VERSION1")
46+
print(f"✓ CallbackAPIVersion available: {hasattr(CallbackAPIVersion, 'VERSION1')}")
47+
else:
48+
print("✓ Using MQTT-PAHO 1.x legacy mode")
49+
print("✓ No CallbackAPIVersion required")
50+
51+
print()
52+
print("🎉 All compatibility checks passed!")
53+
54+
except ImportError as e:
55+
print(f"❌ Import error: {e}")
56+
return 1
57+
except Exception as e:
58+
print(f"❌ Unexpected error: {e}")
59+
return 1
60+
61+
return 0
62+
63+
if __name__ == "__main__":
64+
sys.exit(main())

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
compas>=1.17.6
2-
paho-mqtt >=1, <2
2+
paho-mqtt >=1, <3

setup.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,17 @@ def read(*names, **kwargs):
2121

2222
long_description = read("README.md")
2323
requirements = read("requirements.txt").split("\n")
24-
optional_requirements = {}
24+
25+
# Read dev requirements for optional dependencies
26+
dev_requirements = [
27+
line.strip()
28+
for line in read("requirements-dev.txt").split("\n")
29+
if line.strip() and not line.strip().startswith("#") and line.strip() != "-e ."
30+
]
31+
32+
optional_requirements = {
33+
"dev": dev_requirements,
34+
}
2535

2636
setup(
2737
name="compas_eve",

src/compas_eve/mqtt/mqtt_paho.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
from ..event_emitter import EventEmitterMixin
33

44
import paho.mqtt.client as mqtt
5+
import uuid
6+
7+
try:
8+
from paho.mqtt.enums import CallbackAPIVersion
9+
10+
PAHO_MQTT_V2_AVAILABLE = True
11+
except ImportError:
12+
PAHO_MQTT_V2_AVAILABLE = False
513

614

715
class MqttTransport(Transport, EventEmitterMixin):
@@ -14,15 +22,23 @@ class MqttTransport(Transport, EventEmitterMixin):
1422
you are running a local broker on your machine.
1523
port : int
1624
MQTT broker port, defaults to ``1883``.
25+
client_id : str, optional
26+
Client ID for the MQTT connection. If not provided, a unique ID will be generated.
1727
"""
1828

19-
def __init__(self, host, port=1883, *args, **kwargs):
29+
def __init__(self, host, port=1883, client_id=None, *args, **kwargs):
2030
super(MqttTransport, self).__init__(*args, **kwargs)
2131
self.host = host
2232
self.port = port
2333
self._is_connected = False
2434
self._local_callbacks = {}
25-
self.client = mqtt.Client() # todo: generate client_id
35+
# Generate client ID if not provided
36+
if client_id is None:
37+
client_id = "compas_eve_{}".format(uuid.uuid4().hex[:8])
38+
if PAHO_MQTT_V2_AVAILABLE:
39+
self.client = mqtt.Client(client_id=client_id, callback_api_version=CallbackAPIVersion.VERSION1)
40+
else:
41+
self.client = mqtt.Client(client_id=client_id)
2642
self.client.on_connect = self._on_connect
2743
self.client.connect(self.host, self.port)
2844
self.client.loop_start()

tests/integration/test_mqtt.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,16 @@
99
from compas_eve import set_default_transport
1010
from compas_eve.mqtt import MqttTransport
1111

12-
HOST = "broker.hivemq.com"
12+
HOST = "localhost"
13+
14+
15+
def test_client_id():
16+
custom_client_id = "my_custom_client_id"
17+
transport = MqttTransport(HOST, client_id=custom_client_id)
18+
assert transport.client._client_id == custom_client_id.encode("utf-8")
19+
20+
transport = MqttTransport(HOST, client_id=None)
21+
assert transport.client._client_id.startswith("compas_eve_".encode("utf-8"))
1322

1423

1524
def test_default_transport_publishing():

0 commit comments

Comments
 (0)