Skip to content

Commit

Permalink
Bugfix for p2p_addr_explode() on non-posix platforms
Browse files Browse the repository at this point in the history
[test-312-latest]
[pypi]
  • Loading branch information
cipres committed Apr 17, 2024
1 parent f7ac38e commit da8f3a3
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 29 deletions.
25 changes: 0 additions & 25 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,28 +58,3 @@ jobs:
- name: Build wheel
run: |
python -m build
deploy:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'

- name: Build wheel
run: |
python -m pip install --upgrade pip
pip install build '.[car,dev]'
python -m build
- name: Upload to PyPI
if: contains(toJson(github.event.commits), '[pypi-deploy]') == true
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
pip install twine
twine check dist/*.whl
9 changes: 8 additions & 1 deletion aioipfs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
__version__ = '0.6.9'
__version__ = '0.7.0'

from yarl import URL
from distutils.version import StrictVersion # type: ignore
from typing import Union

import async_timeout
import asyncio
import aiohttp
import ipaddress
Expand Down Expand Up @@ -352,6 +353,12 @@ def allocate_tcp_maddr(self) -> Multiaddr:
# Shouldn't assume dns4 here
return Multiaddr(f'/dns4/{self.host}/tcp/{port}')

def timeout(self, time: float) -> async_timeout.Timeout:
return async_timeout.timeout(time)

def timeout_at(self, time: float) -> async_timeout.Timeout:
return async_timeout.timeout_at(time)

async def __aenter__(self):
return self

Expand Down
6 changes: 3 additions & 3 deletions aioipfs/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from contextlib import closing
from typing import Union
import socket
import os.path
import posixpath

from urllib.parse import quote

Expand Down Expand Up @@ -130,7 +130,7 @@ def p2p_addr_explode(addr: str) -> tuple:

peer_id_re = re.compile(r'([\w]){46,59}$')

parts = addr.lstrip(os.path.sep).split(os.path.sep)
parts = addr.lstrip('/').split('/')
try:
assert parts.pop(0) == 'p2p'
peer_id = parts.pop(0)
Expand Down Expand Up @@ -162,7 +162,7 @@ def p2p_addr_explode(addr: str) -> tuple:
assert len(parts) == 0
break

return peer_id, os.path.sep + os.path.join(*proto_a), p_version
return peer_id, '/' + posixpath.join(*proto_a), p_version
except Exception as err:
raise ValueError(f'Invalid p2p endpoint addr: {err}')

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ urls = {Homepage = "https://gitlab.com/cipres/aioipfs"}
dependencies = [
"aiohttp>=3.7.4",
"aiofiles>=0.7.0",
"async-timeout>=4.0.3",
"base58>=1.0.2",
"gitignore-parser==0.1.9",
"multiaddr>=0.0.9",
Expand Down
10 changes: 10 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,16 @@ async def test_basic(self, event_loop, ipfsdaemon, iclient):
await iclient.core.version()
await iclient.commands()

@pytest.mark.asyncio
async def test_timeout(self, event_loop, iclient):
with pytest.raises(asyncio.TimeoutError):
async with iclient.timeout(1):
await asyncio.sleep(3)

with pytest.raises(asyncio.TimeoutError):
async with iclient.timeout_at(event_loop.time() + 2):
await asyncio.sleep(4)

@pytest.mark.asyncio
async def test_bootstrap(self, event_loop, ipfsdaemon, iclient):
await iclient.bootstrap.list()
Expand Down

0 comments on commit da8f3a3

Please sign in to comment.