Skip to content

Commit

Permalink
Build fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
JohNan committed Feb 24, 2023
1 parent f0568f8 commit 4bf9c1c
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 44 deletions.
19 changes: 12 additions & 7 deletions .github/workflows/pythonpublish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.pypi }}
pip install build wheel twine setuptools setuptools_scm
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Build package
run: |
python setup.py sdist bdist_wheel
twine upload dist/*
python -m build --outdir dist/
python -m twine check dist/*
python -m setuptools_scm --strip-dev
- name: Publish package to PyPI
if: startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{ secrets.PYPI }}
print_hash: true
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,5 @@ venv.bak/
dmypy.json

# Pyre type checker
.pyre/
.pyre/
/.tool-versions
19 changes: 11 additions & 8 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import asyncio
from asyncio import AbstractEventLoop

import async_timeout
import logging

Expand All @@ -9,9 +11,8 @@

logging.basicConfig(level=logging.DEBUG)

CLIENT_READY_TIMEOUT = 20.0
CLIENT_READY_TIMEOUT = 60.0
HOST = ('192.168.1.64', 8124)
LOOP = asyncio.get_event_loop()


def event_callback(button: FlicButton, event: Event):
Expand All @@ -38,10 +39,11 @@ def client_disconnected():
asyncio.create_task(client.async_connect())

try:
with async_timeout.timeout(CLIENT_READY_TIMEOUT):
async with async_timeout.timeout(CLIENT_READY_TIMEOUT):
await client_ready.wait()
except asyncio.TimeoutError:
print(f"Client not connected after {CLIENT_READY_TIMEOUT} secs so continuing with setup")
print(f"Client not connected after {CLIENT_READY_TIMEOUT} secs so terminating")
exit()

buttons = await client.get_buttons()
for button in buttons:
Expand All @@ -52,12 +54,13 @@ def client_disconnected():


if __name__ == '__main__':
client = FlicHubTcpClient(*HOST, loop=LOOP, event_callback=event_callback, command_callback=command_callback)
loop = asyncio.new_event_loop()
client = FlicHubTcpClient(*HOST, loop=loop, event_callback=event_callback, command_callback=command_callback)
try:
LOOP.run_until_complete(start())
LOOP.run_forever()
loop.run_until_complete(start())
loop.run_forever()
except KeyboardInterrupt:
client.disconnect()
LOOP.close()
loop.close()
except Exception as exc: # pylint: disable=broad-except
print(exc)
4 changes: 2 additions & 2 deletions pyflichub/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __init__(self, ip, port, loop, timeout=1.0, reconnect_timeout=10.0, event_ca
self._transport = None
self._command_callback = command_callback
self._event_callback = event_callback
self._loop = loop or asyncio.get_event_loop()
self._loop = loop
self._server_address = (ip, port)
self._tcp_check_timer = time.time()
self._tcp_disconnect_timer = time.time()
Expand All @@ -63,7 +63,7 @@ async def async_connect(self):
except asyncio.TimeoutError:
_LOGGER.error("Connecting to socket timed out for %s", self._server_address)
_LOGGER.info("Waiting %s secs before trying to connect again", self._reconnect_timeout)
await asyncio.sleep(self._reconnect_timeout, loop=self._loop)
await asyncio.sleep(self._reconnect_timeout)
except OSError:
_LOGGER.error("Failed to connect to socket at %s", self._server_address)
_LOGGER.info("Waiting %s secs before trying to connect again", self._reconnect_timeout)
Expand Down
24 changes: 24 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[build-system]
requires = [
"setuptools>=65",
"wheel>=0.37.0",
"setuptools_scm>=6.0",
]
build-backend = "setuptools.build_meta"

[tool.setuptools_scm]
fallback_version = "0.0.0"
write_to = "pyflichub/version.py"

[tool.black]
line-length = 120
target-version = ['py37', 'py38', 'py39', 'py310']
include = '\.pyi?$'
extend-exclude = '''
/(
# The following are specific to Black, you probably don't want those.
| blib2to3
| tests/data
| profiling
)/
'''
75 changes: 75 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
[metadata]
name = pyflichub-tcpclient
author = Johan Nenzén
author_email = [email protected]
description = Asynchronous Python TCP Client for FlicHub
long_description = file: README.md
long_description_content_type = text/markdown
url = https://github.com/JohNan/pyflichub-tcpclient
project_urls =
Bug Tracker = https://github.com/JohNan/pyflichub-tcpclient/issues
license = MIT
classifiers =
Framework :: AsyncIO
Programming Language :: Python :: 3
License :: OSI Approved :: MIT License
Operating System :: OS Independent
Topic :: Software Development :: Libraries :: Python Modules

[options]
install_requires =
pyhumps
async-timeout
package_dir =
= .
packages = find:
python_requires = >= 3.7

[options.packages.find]
where = .
exclude =
tests
tests.*

[flake8]
# To work with Black
# E501: line too long
# W503: Line break occurred before a binary operator
# E203: Whitespace before ':'
# D202 No blank lines allowed after function docstring
# W504 line break after binary operator
ignore =
E722,
I201,
W503,
CFQ001,
CFQ002,
E501,
W503,
E203,
D202,
W504

filename =
*.py

exclude =
.git,
__pycache__,
*.txt,
*.md,
*.cfg

max_line_length = 120
count = True
inline_quotes = double
show_source = True
statistics = True

[pycodestyle]
max_line_length=120
statistics = True
ignore = E722
count = True
verbose = True
show_source = True
26 changes: 0 additions & 26 deletions setup.py

This file was deleted.

0 comments on commit 4bf9c1c

Please sign in to comment.