Skip to content

Commit 89cb3fd

Browse files
resolve conficts, update to latest develop content
2 parents 87a764e + b2b042a commit 89cb3fd

File tree

14 files changed

+318
-25
lines changed

14 files changed

+318
-25
lines changed

.flake8

Lines changed: 105 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,113 @@
1+
# Configuration for flake8 analysis
12
[flake8]
2-
ignore =
3-
E501
4-
W504
3+
# Set the maximum length that any line (with some exceptions) may be.
4+
# max-line-length = 120
5+
6+
# Set the maximum length that a comment or docstring line may be.
7+
# max-doc-length = 120
8+
9+
# Set the maximum allowed McCabe complexity value for a block of code.
10+
# max-complexity = 15
11+
12+
# Specify a list of codes to ignore.
13+
# D107: Missing docstring in __init__
14+
# D400: First line should end with a period
15+
# E501: Line too long (82 > 79 characters)
16+
# W504: line break after binary operator -> Cannot break line with a long pathlib Path
17+
# D204: 1 blank line required after class docstring
18+
ignore = D107, D400, E501, W504, D204
19+
20+
# Specify a list of mappings of files and the codes that should be ignored for the entirety of the file.
21+
per-file-ignores =
22+
tests/*:D101,D102,D104
23+
24+
# Provide a comma-separated list of glob patterns to exclude from checks.
525
exclude =
26+
# No need to traverse our git directory
627
.git,
28+
# Python virtual environments
729
.venv,
30+
# tox virtual environments
31+
.tox,
32+
# There's no value in checking cache directories
833
__pycache__,
34+
# The conf file is mostly autogenerated, ignore it
935
docs/source/conf.py,
10-
old,
36+
# This contains our built documentation
1137
build,
38+
# This contains builds that we don't want to check
1239
dist,
13-
modules,
14-
setup,
15-
thinking
40+
# We don't use __init__.py for scripts
41+
__init__.py
42+
# example testing folder before going live
43+
thinking
44+
.idea
45+
# custom scripts, not being part of the distribution
46+
libs_external
47+
modules
48+
sdist_upip.py
49+
setup.py
50+
51+
# Provide a comma-separated list of glob patterns to add to the list of excluded ones.
52+
# extend-exclude =
53+
# legacy/,
54+
# vendor/
55+
56+
# Provide a comma-separate list of glob patterns to include for checks.
57+
# filename =
58+
# example.py,
59+
# another-example*.py
60+
61+
# Enable PyFlakes syntax checking of doctests in docstrings.
62+
doctests = False
63+
64+
# Specify which files are checked by PyFlakes for doctest syntax.
65+
# include-in-doctest =
66+
# dir/subdir/file.py,
67+
# dir/other/file.py
68+
69+
# Specify which files are not to be checked by PyFlakes for doctest syntax.
70+
# exclude-from-doctest =
71+
# tests/*
72+
73+
# Enable off-by-default extensions.
74+
# enable-extensions =
75+
# H111,
76+
# G123
77+
78+
# If True, report all errors, even if it is on the same line as a # NOQA comment.
79+
disable-noqa = False
80+
81+
# Specify the number of subprocesses that Flake8 will use to run checks in parallel.
82+
jobs = auto
83+
84+
# Also print output to stdout if output-file has been configured.
85+
tee = True
86+
87+
# Count the number of occurrences of each error/warning code and print a report.
88+
statistics = True
89+
90+
# Print the total number of errors.
91+
count = True
92+
93+
# Print the source code generating the error/warning in question.
94+
show-source = True
95+
96+
# Decrease the verbosity of Flake8's output. Each time you specify it, it will print less and less information.
97+
quiet = 0
98+
99+
# Select the formatter used to display errors to the user.
100+
format = pylint
101+
102+
[pydocstyle]
103+
# choose the basic list of checked errors by specifying an existing convention. Possible conventions: pep257, numpy, google.
104+
convention = pep257
105+
106+
# check only files that exactly match <pattern> regular expression
107+
# match = (?!test_).*\.py
108+
109+
# search only dirs that exactly match <pattern> regular expression
110+
# match_dir = [^\.].*
111+
112+
# ignore any functions or methods that are decorated by a function with a name fitting the <decorators> regular expression.
113+
# ignore_decorators =

.github/workflows/release.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# this file is *not* meant to cover or endorse the use of GitHub Actions, but rather to
2+
# help make automated releases for this project
3+
4+
name: Upload Python Package
5+
6+
on:
7+
push:
8+
branches:
9+
- develop
10+
11+
permissions:
12+
contents: read
13+
14+
jobs:
15+
deploy:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v2
20+
- name: Set up Python
21+
uses: actions/setup-python@v3
22+
with:
23+
python-version: '3.9'
24+
- name: Install build dependencies
25+
run: |
26+
if [ -f requirements-deploy.txt ]; then pip install -r requirements-deploy.txt; fi
27+
- name: Build package
28+
run: |
29+
changelog2version \
30+
--changelog_file changelog.md \
31+
--version_file umodbus/version.py \
32+
--version_file_type py \
33+
--debug
34+
python setup.py sdist
35+
rm dist/*.orig
36+
# sdist call create non conform twine files *.orig, remove them
37+
- name: Publish package
38+
uses: pypa/gh-action-pypi-publish@release/v1.5
39+
with:
40+
password: ${{ secrets.PYPI_API_TOKEN }}
41+
skip_existing: true
42+
verbose: true
43+
print_hash: true
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# this file is *not* meant to cover or endorse the use of GitHub Actions, but rather to
2+
# help make automated releases for this project
3+
4+
name: Upload Python Package to test.pypi.org
5+
6+
on: [pull_request]
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
test-deploy:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v2
17+
- name: Set up Python
18+
uses: actions/setup-python@v3
19+
with:
20+
python-version: '3.9'
21+
- name: Install build dependencies
22+
run: |
23+
if [ -f requirements-deploy.txt ]; then pip install -r requirements-deploy.txt; fi
24+
- name: Build package
25+
run: |
26+
changelog2version \
27+
--changelog_file changelog.md \
28+
--version_file umodbus/version.py \
29+
--version_file_type py \
30+
--additional_version_info="-rc${{ github.run_number }}.dev${{ github.event.number }}" \
31+
--debug
32+
python setup.py sdist
33+
- name: Test built package
34+
# sdist call creates non twine conform "*.orig" files, remove them
35+
run: |
36+
rm dist/*.orig
37+
twine check dist/*.tar.gz
38+
- name: Archive build package artifact
39+
uses: actions/upload-artifact@v3
40+
with:
41+
# https://docs.github.com/en/actions/learn-github-actions/contexts#github-context
42+
# ${{ github.repository }} and ${{ github.ref_name }} can't be used for artifact name due to unallowed '/'
43+
name: dist_repo.${{ github.event.repository.name }}_sha.${{ github.sha }}_build.${{ github.run_number }}
44+
path: dist/*.tar.gz
45+
retention-days: 14
46+
- name: Publish package
47+
uses: pypa/gh-action-pypi-publish@release/v1.5
48+
with:
49+
repository_url: https://test.pypi.org/legacy/
50+
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
51+
skip_existing: true
52+
verbose: true
53+
print_hash: true

.github/workflows/test.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
3+
4+
name: Test Python package
5+
6+
on:
7+
push:
8+
# branches: [ $default-branch ]
9+
branches-ignore:
10+
- 'main'
11+
- 'develop'
12+
13+
permissions:
14+
contents: read
15+
16+
jobs:
17+
build:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v3
22+
- name: Set up Python
23+
uses: actions/setup-python@v3
24+
with:
25+
python-version: '3.9'
26+
- name: Install test dependencies
27+
run: |
28+
pip install -r requirements-test.txt
29+
- name: Lint with flake8
30+
run: |
31+
flake8 .
32+
- name: Install deploy dependencies
33+
run: |
34+
python -m pip install --upgrade pip
35+
if [ -f requirements-deploy.txt ]; then pip install -r requirements-deploy.txt; fi
36+
- name: Build package
37+
run: |
38+
changelog2version \
39+
--changelog_file changelog.md \
40+
--version_file umodbus/version.py \
41+
--version_file_type py \
42+
--debug
43+
python setup.py sdist
44+
rm dist/*.orig
45+
- name: Test built package
46+
run: |
47+
twine check dist/*

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
![Release](https://img.shields.io/github/v/release/brainelectronics/micropython-modbus?include_prereleases&color=success)
55
![MicroPython](https://img.shields.io/badge/micropython-Ok-green.svg)
66
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7+
[![CI](https://github.com/brainelectronics/micropython-modbus/actions/workflows/release.yml/badge.svg)](https://github.com/brainelectronics/micropython-modbus/actions/workflows/release.yml)
78

89
MicroPython ModBus TCP and RTU library supporting client and host mode
910

changelog.md

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515
<!-- ## [Unreleased] -->
1616

1717
## Released
18-
## [1.0.1] - 2022-07-16
18+
## [1.1.1] - 2022-11-09
1919
### Fixed
2020
- Default value of `setup_registers` function parameter `use_default_vals`
2121
changed to `False` to avoid confusion behaviour if not explicitly defined,
@@ -24,13 +24,32 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2424
- `write_single_coil` allows `0`, `1`, `False`, `True`, `0x0` or `0xFF00`
2525
instead of `0x0` and `0xFF00` only as set value, see [issue 14][ref-issue-14]
2626

27+
## [1.1.0] - 2022-11-03
28+
### Added
29+
- `float_to_bin`, `bin_to_float`, `int_to_bin` functions added to
30+
[`umodbus/functions.py`](umodbus/functions.py)
31+
- Deploy to [Test Python Package Index](https://test.pypi.org/) on every PR
32+
build with a [PEP440][ref-pep440] compliant `-rc<BUILDNUMBER>.dev<PR_NUMBER>`
33+
meta data extension
34+
- [Test release workflow](.github/workflows/test-release.yaml) running only on
35+
PRs is archiving and uploading built artifacts to
36+
[Test Python Package Index](https://test.pypi.org/)
37+
38+
### Changed
39+
- Author is explicitly mentioned in [`setup.py`](setup.py) instead of used by
40+
`__author__` variable which has been previously defined in
41+
[`version.py`](umodbus/version.py) but no longer available with autodeploy.
42+
43+
### Fixed
44+
- All uncovered flake8 warnings of [`umodbus`](umodbus)
45+
2746
## [1.0.0] - 2022-02-26
2847
### Added
2948
- [`setup.py`](setup.py) and [`sdist_upip.py`](sdist_upip.py) taken from
3049
[pfalcon's picoweb repo][ref-pfalcon-picoweb-sdist-upip] and PEP8 improved
3150
- [`MIT License`](LICENSE)
32-
- [`version.py`](modbus/version.py) storing current library version
33-
- [`typing.py`](modbus/typing.py) enabling type hints
51+
- [`version.py`](umodbus/version.py) storing current library version
52+
- [`typing.py`](umodbus/typing.py) enabling type hints
3453

3554
### Changed
3655
- Moved all uModbus files from `lib/uModbus` into [`umodbus`](umodbus)
@@ -75,15 +94,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7594
- PEP8 style issues on all files of [`lib/uModbus`](lib/uModbus)
7695

7796
<!-- Links -->
78-
[Unreleased]: https://github.com/brainelectronics/micropython-modbus/compare/1.0.1...develop
97+
[Unreleased]: https://github.com/brainelectronics/micropython-modbus/compare/1.1.1...develop
7998

80-
[1.0.1]: https://github.com/brainelectronics/micropython-modbus/tree/1.0.1
99+
[1.1.1]: https://github.com/brainelectronics/micropython-modbus/tree/1.1.1
100+
[1.1.0]: https://github.com/brainelectronics/micropython-modbus/tree/1.1.0
81101
[1.0.0]: https://github.com/brainelectronics/micropython-modbus/tree/1.0.0
82102
[0.1.0]: https://github.com/brainelectronics/micropython-modbus/tree/0.1.0
83103

84104
[ref-issue-13]: https://github.com/brainelectronics/micropython-modbus/issues/13
85105
[ref-issue-14]: https://github.com/brainelectronics/micropython-modbus/issues/14
86-
106+
[ref-pep440]: https://peps.python.org/pep-0440/
87107
[ref-pypi]: https://pypi.org/
88108
[ref-pfalcon-picoweb-sdist-upip]: https://github.com/pfalcon/picoweb/blob/b74428ebdde97ed1795338c13a3bdf05d71366a0/sdist_upip.py
89109
[ref-be-micropython-module]: https://github.com/brainelectronics/micropython-modules/tree/1.1.0

requirements-deploy.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# List external packages here
2+
# Avoid fixed versions
3+
# # to upload package to PyPi or other package hosts
4+
twine>=4.0.1,<5
5+
changelog2version>=0.5.0,<1

requirements-test.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# List external packages here
2+
# Avoid fixed versions
3+
flake8>=5.0.0,<6
4+
coverage>=6.4.2,<7
5+
nose2>=0.12.0,<1

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
long_description=long_description,
2121
long_description_content_type='text/markdown',
2222
url='https://github.com/brainelectronics/micropython-modbus',
23-
author=__author__,
23+
author='brainelectronics',
2424
author_email='info@brainelectronics.de',
2525
classifiers=[
2626
'Development Status :: 4 - Beta',

umodbus/functions.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,15 @@ def response(function_code,
148148

149149
def exception_response(function_code, exception_code):
150150
return struct.pack('>BB', Const.ERROR_BIAS + function_code, exception_code)
151+
152+
153+
def float_to_bin(num):
154+
return bin(struct.unpack('!I', struct.pack('!f', num))[0])[2:].zfill(32)
155+
156+
157+
def bin_to_float(binary):
158+
return struct.unpack('!f', struct.pack('!I', int(binary, 2)))[0]
159+
160+
161+
def int_to_bin(num):
162+
return "{0:b}".format(num)

0 commit comments

Comments
 (0)