Skip to content

Commit

Permalink
Merge branch 'feature-pro-serial'
Browse files Browse the repository at this point in the history
  • Loading branch information
pjkundert committed Jan 17, 2025
2 parents 00e38df + 3a59aac commit aaf3347
Show file tree
Hide file tree
Showing 84 changed files with 7,804 additions and 1,984 deletions.
15 changes: 5 additions & 10 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,18 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12']
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@master
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@master
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install wheel
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
pip install flake8 pytest pytz tzlocal pymodbus pylogix
pip install 'argparse; python_version < "2.7"'
pip install 'configparser; python_version < "3.0"'
pip install 'ipaddress; python_version < "3.0"'
python3 -m pip install --upgrade pip
python3 -m pip install .[all,tests]
- name: Lint with flake8
run: |
make analyze || true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Build
run: |
python -m pip install --upgrade pip
python -m pip install setuptools build wheel
python -m pip install -r requirements-dev.txt
python -m build .
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

# System generated files
.DS_Store
*.png

*.tex
auto/
Expand All @@ -24,3 +23,8 @@ dist/
*.svg
.vagrant
.pytest_cache/
.cache/
*.aux
*.toc
/ttyS[0-9]
/ttyV[0-9]
183 changes: 105 additions & 78 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,26 @@
#

# PY[3] is the target Python interpreter. It must have pytest installed.
SHELL = /bin/bash

PY ?= python
PY2 ?= python2
PY2_V = $(shell $(PY2) -c "import sys; print('-'.join((next(iter(filter(None,sys.executable.split('/')))),sys.platform,sys.subversion[0].lower(),''.join(map(str,sys.version_info[:2])))))" )
PY3 ?= python3
PY3_V = $(shell $(PY3) -c "import sys; print('-'.join((next(iter(filter(None,sys.executable.split('/')))),sys.platform,sys.implementation.cache_tag)))" 2>/dev/null )


VERSION = $(shell $(PY3) -c 'exec(open("version.py").read()); print( __version__ )')
WHEEL = dist/cpppo-$(VERSION)-py3-none-any.whl

# TARGET=... nix-shell # CPython version targets: py27, py3{10,11,12,13}
# (py27 requires reverting to an older nixpkgs.nix)
#TARGET ?= py312
export TARGET

NIX_OPTS ?= # --pure


PY=python
PY2=python2
PY3=python3

# PY[23]TEST is the desired method of invoking py.test; either as a command, or
# loading it as module, by directly invoking the target Python interpreter.
Expand Down Expand Up @@ -35,14 +51,31 @@ PY3=python3
# LC_ALL=en_CA.UTF-8
#

# Some tests assume the local time-zone is:
TZ=Canada/Mountain


GIT_SSH_COMMAND = ssh -o StrictHostKeyChecking=no
export GIT_SSH_COMMAND

GHUB_NAME = cpppo
GHUB_REPO = git@github.com:pjkundert/$(GHUB_NAME).git
GHUB_BRCH = $(shell git rev-parse --abbrev-ref HEAD )

# We'll agonizingly find the directory above this makefile's path
VENV_DIR = $(abspath $(dir $(abspath $(lastword $(MAKEFILE_LIST))))/.. )
VENV_NAME = $(GHUB_NAME)-$(VERSION)-$(PY3_V)
VENV = $(VENV_DIR)/$(VENV_NAME)
VENV_OPTS =

# To see all pytest output, uncomment --capture=no
PYTESTOPTS=-v # --capture=no
PYTESTOPTS=-v --capture=no --log-cli-level=WARNING # INFO 25 == NORMAL 23 == DETAIL

PY_TEST=TZ=$(TZ) $(PY) -m pytest $(PYTESTOPTS)
PY2TEST=TZ=$(TZ) $(PY2) -m pytest $(PYTESTOPTS)
PY3TEST=TZ=$(TZ) $(PY3) -m pytest $(PYTESTOPTS)

.PHONY: all test clean upload
.PHONY: all test clean FORCE
all: help

help:
Expand All @@ -51,7 +84,6 @@ help:
@echo " test Run unit tests under Python2/3 (no serial_test w/o 'make SERIAL_TEST=1 test')"
@echo " install Install in /usr/local for Python2/3"
@echo " clean Remove build artifacts"
@echo " upload Upload new version to pypi (package maintainer only)"
@echo
@echo " virtualbox-* Manage VirtualBox virtual machine"
@echo " vmware-* Manage VMWare Fusion virtual machine (recommended; requires license)"
Expand All @@ -67,106 +99,101 @@ help:
@echo " vmware-debian-up Brings up Jessie VM w/ Docker capability"
@echo " vmware-debian-ssh Log in to the VM"

analyze:
$(PY3) -m flake8 --color never -j 1 --max-line-length=250 \
--exclude lib,bin,dist,build,signals,.git \
--ignore=W503,E201,E202,E203,E127,E211,E221,E222,E223,E225,E226,E231,E241,E242,E251,E265,E272,E274,E291 \

pylint:
pylint . --disable=W,C,R

#
# nix-...:
#
# Use a NixOS environment to execute the make target, eg.
#
# nix-venv-activate
#
# The default is the Python 3 crypto_licensing target in default.nix; choose
# TARGET=py27 to test under Python 2 (more difficult as time goes on). See default.nix for
# other Python version targets.
#
nix-%:
nix-shell $(NIX_OPTS) --run "make $*"


#
# test...: Perform Unit Tests
#
# Assumes that the requirements.txt has been installed in the target Python environment. This
# is probably best accomplished by first creating/activating a venv, and then running the test:
#
# $ make nix-venv-activate
# (crypto-licensing-4.0.0) [perry@Perrys-MBP crypto-licensing (feature-py-3.12)]$ make test
# make[1]: Entering directory '/Users/perry/src/crypto-licensing'
# ...
#
test:
$(PY_TEST)
test2:
$(PY2TEST)
test3:
$(PY3TEST)
test23:
$(PY2TEST)
$(PY3TEST)

install:
$(PY) setup.py install
install2:
$(PY2) setup.py install
install3:
$(PY3) setup.py install
install23:
$(PY2) setup.py install
$(PY3) setup.py install
doctest:
cd crypto/licensing && $(PY3TEST) --doctest-modules

analyze:
flake8 -j 1 --max-line-length=110 \
--ignore=F401,E221,E201,E202,E203,E223,E225,E226,E231,E241,E242,E261,E272,E302,W503,E701,E702,E,W \
flake8 -j 1 --max-line-length=110 \
--ignore=F401,E201,E202,E221,E223,E226,E231,E242,E272,E701,E702,W191,W291,W503,W293,W391,E \
--exclude="__init__.py" \
.

pylint:
cd .. && pylint cpppo --disable=W,C,R

# Support uploading a new version of cpppo to pypi. Must:
# o advance __version__ number in cpppo/version.py
# o log in to your pypi account (ie. for package maintainer only)
upload:
python setup.py sdist upload

clean:
@rm -rf MANIFEST *.png build dist auto *.egg-info $(shell find . -name '*.pyc' -o -name '__pycache__' )
build-check:
@$(PY3) -m build --version \
|| ( echo "\n*** Missing Python modules; run:\n\n $(PY3) -m pip install --upgrade -r requirements-dev.txt\n" \
&& false )

# Virtualization management, eg:
# make {vmware,vagrant}-up/halt/ssh/destroy
#
# To use a different Vagrant box than precise64 (eg. raring), Vagrantfile must be altered
.PHONY: vagrant vagrant_boxes \
precise64_virtualbox precise64_vmware_fusion \
raring_virtualbox

# The vagrant/ubuntu/Vagrantfile doesn't contain a config.vm.box_url; we must
# supply. The precise64 VMware image presently supports only VMware Fusion 5;
# if you see an error regarding hgfs kernel modules, you may be running a
# version of VMware Fusion incompatible with the VMware Tools in the image.
# TODO: remove; no longer supported.
vmware-ubuntu-%: precise64-vmware_fusion
cd vagrant/ubuntu; vagrant $* $(if $(filter up, $*), --provider=vmware_fusion,)

virtualbox-ubuntu-%: precise64-virtualbox
cd vagrant/ubuntu; vagrant $* $(if $(filter up, $*), --provider=virtualbox,)
build: build-check clean wheel

# The jessie64 VMware image is compatible with VMware Fusion 6, and the VirtualBox image is
# compatible with VirtualBox 4.3. Obtains the box, if necessary. The packer.io generated VMware
# boxes identify themselves as being for vmware_desktop; these are compatible with vmware_fusion
vmware-debian-%: jessie64-vmware_desktop
cd vagrant/debian; vagrant $* $(if $(filter up, $*), --provider=vmware_fusion,)
wheel: $(WHEEL)

virtualbox-debian-%: jessie64-virtualbox
cd vagrant/debian; vagrant $* $(if $(filter up, $*), --provider=virtualbox,)
$(WHEEL): FORCE
$(PY3) -m pip install -r requirements-dev.txt
$(PY3) -m build .
@ls -last dist

vagrant:
@vagrant --help >/dev/null || ( echo "Install vagrant: http://vagrantup.com"; exit 1 )
install: $(WHEEL) FORCE
$(PY3) -m pip install --force-reinstall $<[all]

install-%: # ...-dev, -tests
$(PY3) -m pip install --upgrade -r requirements-$*.txt

# Check if jessie64-{virtualbox,vmware_desktop} exists in the vagrant box list.
# If not, install it.
jessie64-%:
@if ! vagrant box list | grep -q '^jessie64.*($*'; then \
vagrant box add jessie64 http://box.hardconsulting.com/jessie64-$*.box --provider $*; \
fi

clean:
@rm -rf MANIFEST *.png build dist auto *.egg-info $(shell find . -name '*.pyc' -o -name '__pycache__' )


# Run only tests with a prefix containing the target string, eg test-blah
test-%:
$(PY_TEST) *$*_test.py
test2-%:
$(PY2TEST) *$*_test.py
test3-%:
$(PY3TEST) *$*_test.py
test23-%:
$(PY2TEST) *$*_test.py
$(PY3TEST) *$*_test.py

unit-%:
$(PY_TEST) -k $*
unit2-%:
$(PY2TEST) -k $*
unit3-%:
$(PY3TEST) -k $*
unit23-%:
$(PY2TEST) -k $*
$(PY3TEST) -k $*

#
# venv: Create a Virtual Env containing the installed repo
#
.PHONY: venv
venv: $(VENV)
@echo; echo "*** Activating $< VirtualEnv for Interactive $(SHELL)"
@bash --init-file $</bin/activate -i

$(VENV):
@echo; echo "*** Building $@ VirtualEnv..."
@rm -rf $@ && $(PY3) -m venv $(VENV_OPTS) $@ \
&& source $@/bin/activate \
&& make install install-tests

#
# Target to allow the printing of 'make' variables, eg:
Expand Down
6 changes: 5 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Both sdist and bdist include these files
include LICENSE
include README.org
include requirements.txt
include requirements-optional.txt
include requirements-*.txt
include cpppo.cfg
include crypto/licensing/licensing.sql*
recursive-include crypto/licensing/static *
global-exclude *~
Loading

0 comments on commit aaf3347

Please sign in to comment.