Skip to content

Commit

Permalink
Add black code formatter (#32)
Browse files Browse the repository at this point in the history
* Add black code formatter

* Add requirements file for black for Python 3.6 on Travis.
* Run black check on Travis.
* Provide optional pre-commit config file for black.
* Add lint config to make lint compatible with black.
* Add black check and format to makefile.

* Run black

* De-duplicate tests

* Update readme
  • Loading branch information
MartinHjelmare authored Nov 9, 2019
1 parent e994ca6 commit ab9275b
Show file tree
Hide file tree
Showing 18 changed files with 308 additions and 242 deletions.
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# See https://pre-commit.com/
# See https://github.com/psf/black#version-control-integration
repos:
- repo: https://github.com/psf/black
rev: stable
hooks:
- id: black
language_version: python3.6
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
.PHONY: help clean clean-build clean-pyc lint test test-all coverage api-docs docs release test-release sdist

help:
@echo "black - run black code formatter check"
@echo "black-format - run black code formatter format"
@echo "clean - run both clean-build and clean-pyc"
@echo "clean-build - remove build artifacts"
@echo "clean-pyc - remove Python file artifacts"
Expand All @@ -15,6 +17,12 @@ help:
@echo "test-release - package and upload a release to test PyPI"
@echo "sdist - package"

black:
black --check ./

black-format:
black ./

clean: clean-build clean-pyc

clean-build:
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ Install dependencies and link development version of leicacam to pip:
pip install -r requirements_dev.txt
```

### Code formatting
We use black code formatter to automatically format the code.
This requires Python 3.6 for development.
```bash
black ./
```

### Testing
```bash
tox
Expand Down
16 changes: 8 additions & 8 deletions async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ async def run(loop):
cam = AsyncCAM(loop=loop)
await cam.connect()
print(cam.welcome_msg)
await cam.send(b'/cmd:deletelist')
await cam.send(b"/cmd:deletelist")
print(await cam.receive())
await cam.send(b'/cmd:deletelist')
print(await cam.wait_for(cmd='cmd', timeout=0.1))
await cam.send(b'/cmd:deletelist')
print(await cam.wait_for(cmd='cmd', timeout=0))
print(await cam.wait_for(cmd='cmd', timeout=0.1))
print(await cam.wait_for(cmd='test', timeout=0.1))
await cam.send(b"/cmd:deletelist")
print(await cam.wait_for(cmd="cmd", timeout=0.1))
await cam.send(b"/cmd:deletelist")
print(await cam.wait_for(cmd="cmd", timeout=0))
print(await cam.wait_for(cmd="cmd", timeout=0.1))
print(await cam.wait_for(cmd="test", timeout=0.1))
cam.close()


if __name__ == '__main__':
if __name__ == "__main__":
LOOP = asyncio.new_event_loop()
LOOP.run_until_complete(run(LOOP))
LOOP.close()
8 changes: 4 additions & 4 deletions client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ def run():
"""Run client."""
cam = CAM()
print(cam.welcome_msg)
print(cam.send(b'/cmd:deletelist'))
print(cam.send(b"/cmd:deletelist"))
sleep(0.1)
print(cam.receive())
print(cam.send(b'/cmd:deletelist'))
print(cam.send(b"/cmd:deletelist"))
sleep(0.1)
print(cam.wait_for(cmd='cmd', timeout=0.1))
print(cam.wait_for(cmd="cmd", timeout=0.1))
cam.close()


if __name__ == '__main__':
if __name__ == "__main__":
run()
Loading

0 comments on commit ab9275b

Please sign in to comment.