Skip to content

Commit

Permalink
Pybennu cleanup (#11)
Browse files Browse the repository at this point in the history
* pypmu: propagate exception to caller if connect fails

* setup.py: python 3.8+, re-add #!

* Exclude .venv from git

* Fix setup.py so "pip install" works with up to date setuptools

* add pyPMU to NOTICE

The license file was already included in the source tree.
However, it wasn't listed in NOTICE.

* Add RTDS provider to config.ini

* Improvements to RTDS provider

- Remove PMU sequence numbers.
They ended up being wildly inaccurate thanks to threading.
- Apply a field type mapping when creating Elasticsearch indices
- Handle Elastic bulk ingest error messages
- Add 'elastic-index-basename' option to configure
the Elasticsearch index name.
- Fix PMU connection rebuilding.
If RSCAD case is stopped, the provider no longer needs to be restarted and will properly restart the PMU connections.
This fixes a long-standing issue that's been around since HARMONIE.
- Improve PMU handling.
RTDS provider is now able to be started AFTER the RSCAD case is started.
- Change gtnet-skt to continually send data over UDP
- Add 'gtnet-skt-tcp-retry-delay' config option
- Add 'gtnet-skt-udp-write-rate' config option
- Move Elasticsearch processing and pushing into a thread.
This prevents it from blocking the core functionality of
sending data to SCEPTRE.
- Improve how boolean config options are handled
- Move RTDS data processing into a thread

* Add .editorconfig

* Remove references to tox

tox hasn't been used by pybennu for a very, very long time

* Remove version.py

Git hashes can't be used for the Version field in package metadata

* Remove pybennu-probe.spec

It isn't used anywhere. It's a pyinstaller spec but pyinstaller hasn't been used in a long time.

* fix "make bull"

* Cleanup Makefile

- Remove unused variables and stages
- Fix indentation
- Consolidate and update help messages
- Remove requirement for root from several commands

* fix errors and warnings during deb build

* update license in pybennu package metadata

* update license in deb package metadata

---------

Co-authored-by: Christopher Goes <[email protected]>
  • Loading branch information
GhostofGoes and GhostofGoes authored Nov 27, 2023
1 parent ba5a43c commit 991f1e5
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 316 deletions.
37 changes: 37 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# https://editorconfig.org/
root = true

[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8

[*.py]
max_line_length = 99
insert_final_newline = true
trim_trailing_whitespace = true

[*.rst]
indent_size = 3
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
insert_final_newline = true
trim_trailing_whitespace = true

[*.{yml,yaml}]
indent_size = 2

[*.json]
insert_final_newline = unset

[Makefile]
indent_style = tab

[*.{ps1,bat}]
end_of_line = crlf

[*.{xml,xslt}]
indent_size = 2
236 changes: 95 additions & 141 deletions src/pybennu/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,6 @@ endif
# Variables
##

define BROWSER_PYSCRIPT
import os, webbrowser, sys
try:
from urllib import pathname2url
except:
from urllib.request import pathname2url

webbrowser.open("file://" + pathname2url(os.path.abspath(sys.argv[1])))
endef
export BROWSER_PYSCRIPT
BROWSER := python -c "$$BROWSER_PYSCRIPT"
BUILD_DIR = $(CURDIR)/build
DIST_DIR = $(CURDIR)/dist
POST = $(CURDIR)/dist/postinst
Expand All @@ -56,7 +45,7 @@ PACKAGE_NAME = pybennu
PACKAGE_FILENAME = $(PACKAGE_NAME)_$(PACKAGE_FULL_VERSION)_amd64_$(TIMESTAMP).deb
PACKAGE_VENDOR = SNL
PACKAGE_MAINTAINER = Sandia National Laboratories <[email protected]>
PACKAGE_LICENSE = Proprietary
PACKAGE_LICENSE = GPLv3
PACKAGE_URL = https://github.com/sandialabs/sceptre-bennu.git
PACKAGE_ARCHITECTURE = amd64

Expand All @@ -77,126 +66,19 @@ endef
.PHONY: dist test docs

help:
@echo "clean - Remove python, build, and test file artifacts."
@echo "docs - Generate Sphinx HTML documentation and open index.html."
@echo "install - Install the project in the current python environment."
@echo "uninstall - Uninstall the project."

helpdev:
@echo "clean - Remove python, build, and test file artifacts."
@echo "coverage - Check code coverage with tox/pytest-cov."
@echo "deb - Create a Debian package."
@echo "dist - Create a src and whl distribution."
@echo "docs - Generate Sphinx HTML documentation and open index.html."
@echo "install - Install the project in the current python environment."
@echo "install-dev - Install the project in editable (-e) mode."
@echo "lint - Check style with tox/pytest-pylint."
@echo "test - Run tests on Python versions in tox.ini with tox/pytest."
@echo "uninstall - Uninstall the project."
@echo "wheelhouse - Create a wheelhouse (deps included) archive."

clean: root clean-pyc clean-build clean-tests

clean-build:
@rm -rfv "$(BUILD_DIR)"
@rm -rfv "$(DIST_DIR)"
@rm -rfv *.egg-info
@rm -rfv *.dist-info
@rm -rfv .eggs

clean-pyc:
# @find . -name "*.py[cod]" -exec rm -fv {} +
@find . -name "*~" -exec rm -fv {} +
@find . -name "__pycache__" -exec rm -rfv {} +
@find . -name ".cache" -exec rm -rfv {} +

clean-tests:
@rm -rf .tox
@rm -rf htmlcov

coverage: install-extras
@tox -e cov-report
@$(BROWSER) htmlcov/index.html

deb: packagetools
@mkdir -p dist/
@echo 'printf "\n--- RUNNING PYBENNU AFTER INSTALL SCRIPT ---\n\n"' > $(POST)
@echo 'mv /root/libzmq* /usr/lib/x86_64-linux-gnu' >> $(POST)
@echo 'printf "\n\tINSTALLING ZMQ WITH DRAFT SUPPORT...\n\n"' >> $(POST)
@echo 'wget --no-check-certificate https://raw.githubusercontent.com/zeromq/pyzmq/main/examples/draft/install.sh' >> $(POST)
@echo 'sed -i -e "s/wget/wget --no-check-certificate/g" install.sh' >> $(POST)
@echo 'sed -i -e "s/make -j/make -j $(nproc)/g" install.sh' >> $(POST)
@echo 'sed -i -e "s/pip install/pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org -I/g" install.sh' >> $(POST)
@echo 'chmod +x install.sh' >> $(POST)
@echo './install.sh' >> $(POST)
@echo 'printf "\n\tINSTALLING HELICS/PYHELICS...\n\n"' >> $(POST)
@echo 'wget --no-check-certificate -O pyhelics.tgz https://github.com/GMLC-TDC/pyhelics/releases/download/v2.7.1/helics-2.7.1.tar.gz' >> $(POST)
@echo 'mkdir -p /tmp/pyhelics && tar -C /tmp/pyhelics -xzf pyhelics.tgz && rm pyhelics.tgz' >> $(POST)
@echo 'cd /tmp/pyhelics/helics-2.7.1 && sed -i "s/helics-apps/helics-apps~=2.7.1/" /tmp/pyhelics/helics-2.7.1/setup.py' >> $(POST)
@echo 'pip3 install --trusted-host pypi.org --trusted-host files.pythonhosted.org /tmp/pyhelics/helics-2.7.1/' >> $(POST)
@ @echo 'printf "\n\tINSTALLING PYBENNU PIP DEPENDENCIES...\n\n"' >> $(POST)
@echo 'pip3 install --trusted-host pypi.org --trusted-host files.pythonhosted.org bitarray elasticsearch>=5.3.0 helics~=2.7.1 matplotlib>=1.5.3 networkx>=1.11 numpy>=1.11.2 opendssdirect.py~=0.6.1 py-expression-eval~=0.3.14 PYPOWER>=5.0.1 pyserial>=3.4 pyyaml>=3.12 requests>=2.20 scipy>=0.18.1 sysv_ipc' >> $(POST)
@echo 'printf "\nDONE!!\n\n"' >> $(POST)
@$(FPM) \
--verbose \
-f \
-s python \
-t deb \
-d cmake \
-d gcc \
-d g++ \
-d make \
-d python3-dev \
-d python3-pip \
-d python3-setuptools \
-d wget \
-p '$(subst __colon__,:,$(DIST_DIR)/$(PACKAGE_FILENAME))' \
--name '$(PACKAGE_NAME)' \
$(call iter,$(PACKAGE_VENDOR),--vendor) \
--maintainer '$(PACKAGE_MAINTAINER)' \
--license '$(PACKAGE_LICENSE)' \
--description '$(PACKAGE_DESCRIPTION)' \
--category '$(PACKAGE_SECTION)' \
$(call iter,$(PACKAGE_URL),--url) \
--deb-no-default-config-files \
--version '$(PACKAGE_FULL_VERSION)' \
--architecture '$(PACKAGE_ARCHITECTURE)' \
--python-bin python3 \
--python-pip pip3 \
--python-install-bin /usr/local/bin \
--python-install-lib /usr/lib/python3/dist-packages \
--no-python-dependencies \
--after-install $(POST) \
setup.py

dist: root pytools
@python3 setup.py sdist bdist_wheel

docs: install-extras
@tox -e docs
@$(BROWSER) docs/build/html/index.html

flake: install-extras
@tox -e flake8

install: install-extras
@pip3 install --trusted-host pypi.org --trusted-host files.pythonhosted.org .

install-dev: install-extras
@pip3 install --trusted-host pypi.org --trusted-host files.pythonhosted.org -e .

install-extras: root pytools
@pip3 install --trusted-host pypi.org --trusted-host files.pythonhosted.org .[extras] > /dev/null 2>&1

lint: install-extras
@tox -e pylint

livedocs: install-extras
@tox -e livedocs
@echo "clean - Remove python and build file artifacts."
@echo "deb - Create a Debian package."
@echo "dist - Create a src and whl distribution."
@echo "sdist - Create a src distribution (sdist)."
@echo "install - Install the project in the current python environment."
@echo "install-dev - Install the project in editable (-e) mode."
@echo "uninstall - Uninstall the project."
@echo "wheelhouse - Create a wheelhouse (deps included) archive."
@echo "bull - bull."

packagetools:
ifdef packagetools
$(error Cannot find packagetools: fpm. (Install with 'sudo gem install fpm'))
$(error Cannot find packagetools: fpm (Install with 'sudo gem install fpm'))
endif

pytools:
Expand All @@ -209,23 +91,95 @@ ifneq (root,$(shell whoami))
$(error Must run as root.)
endif

sdist: root pytools
@python3 setup.py sdist
clean: clean-pyc clean-build

clean-build:
@rm -rfv "$(BUILD_DIR)"
@rm -rfv "$(DIST_DIR)"
@rm -rfv *.egg-info
@rm -rfv *.dist-info
@rm -rfv .eggs

test: install-extras
@tox
clean-pyc:
# @find . -name "*.py[cod]" -exec rm -fv {} +
@find . -name "*~" -exec rm -fv {} +
@find . -name "__pycache__" -exec rm -rfv {} +
@find . -name ".cache" -exec rm -rfv {} +

deb: packagetools
@mkdir -p dist/
@echo 'printf "\n--- RUNNING PYBENNU AFTER INSTALL SCRIPT ---\n\n"' > $(POST)
@echo 'mv /root/libzmq* /usr/lib/x86_64-linux-gnu' >> $(POST)
@echo 'printf "\n\tINSTALLING ZMQ WITH DRAFT SUPPORT...\n\n"' >> $(POST)
@echo 'wget --no-check-certificate https://raw.githubusercontent.com/zeromq/pyzmq/main/examples/draft/install.sh' >> $(POST)
@echo 'sed -i -e "s/wget/wget --no-check-certificate/g" install.sh' >> $(POST)
@echo 'sed -i -e "s/make -j/make -j $(nproc)/g" install.sh' >> $(POST)
@echo 'sed -i -e "s/pip install/pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org -I/g" install.sh' >> $(POST)
@echo 'chmod +x install.sh' >> $(POST)
@echo './install.sh' >> $(POST)
@echo 'printf "\n\tINSTALLING HELICS/PYHELICS...\n\n"' >> $(POST)
@echo 'wget --no-check-certificate -O pyhelics.tgz https://github.com/GMLC-TDC/pyhelics/releases/download/v2.7.1/helics-2.7.1.tar.gz' >> $(POST)
@echo 'mkdir -p /tmp/pyhelics && tar -C /tmp/pyhelics -xzf pyhelics.tgz && rm pyhelics.tgz' >> $(POST)
@echo 'cd /tmp/pyhelics/helics-2.7.1 && sed -i "s/helics-apps/helics-apps~=2.7.1/" /tmp/pyhelics/helics-2.7.1/setup.py' >> $(POST)
@echo 'pip3 install --trusted-host pypi.org --trusted-host files.pythonhosted.org /tmp/pyhelics/helics-2.7.1/' >> $(POST)
@echo 'printf "\n\tINSTALLING PYBENNU PIP DEPENDENCIES...\n\n"' >> $(POST)
@echo 'pip3 install --trusted-host pypi.org --trusted-host files.pythonhosted.org bitarray elasticsearch>=5.3.0 helics~=2.7.1 matplotlib>=1.5.3 networkx>=1.11 numpy>=1.11.2 opendssdirect.py~=0.6.1 py-expression-eval~=0.3.14 PYPOWER>=5.0.1 pyserial>=3.4 pyyaml>=3.12 requests>=2.20 scipy>=0.18.1 sysv_ipc' >> $(POST)
@echo 'printf "\nDONE!!\n\n"' >> $(POST)
@$(FPM) \
--verbose \
-f \
-s python \
-t deb \
-d cmake \
-d gcc \
-d g++ \
-d make \
-d python3-dev \
-d python3-pip \
-d python3-setuptools \
-d wget \
-p '$(subst __colon__,:,$(DIST_DIR)/$(PACKAGE_FILENAME))' \
--name '$(PACKAGE_NAME)' \
$(call iter,$(PACKAGE_VENDOR),--vendor) \
--maintainer '$(PACKAGE_MAINTAINER)' \
--license '$(PACKAGE_LICENSE)' \
--description '$(PACKAGE_DESCRIPTION)' \
--category '$(PACKAGE_SECTION)' \
$(call iter,$(PACKAGE_URL),--url) \
--deb-no-default-config-files \
--version '$(PACKAGE_FULL_VERSION)' \
--architecture '$(PACKAGE_ARCHITECTURE)' \
--python-bin python3 \
--python-pip pip3 \
--python-install-bin /usr/local/bin \
--python-install-lib /usr/lib/python3/dist-packages \
--no-python-dependencies \
--after-install $(POST) \
setup.py

dist: pytools
@python3 setup.py sdist bdist_wheel

sdist: pytools
@python3 setup.py sdist

install: root pytools
@pip3 install --trusted-host pypi.org --trusted-host files.pythonhosted.org .

install-dev: pytools
@pip3 install --trusted-host pypi.org --trusted-host files.pythonhosted.org -e .

uninstall: root pytools
@pip3 uninstall $(PACKAGE_NAME)
@pip3 uninstall $(PACKAGE_NAME)

wheelhouse: root pytools
@pip3 wheel --wheel-dir=dist/$(PACKAGE_NAME)/ .
@tar -C dist/ -cvzf dist/$(PACKAGE_NAME)-$(PACKAGE_FULL_VERSION)-wheelhouse.tar.gz $(PACKAGE_NAME)/
@rm -rf dist/$(PACKAGE_NAME)/
wheelhouse: pytools
@pip3 wheel --wheel-dir=dist/$(PACKAGE_NAME)/ .
@tar -C dist/ -cvzf dist/$(PACKAGE_NAME)-$(PACKAGE_FULL_VERSION)-wheelhouse.tar.gz $(PACKAGE_NAME)/
@rm -rf dist/$(PACKAGE_NAME)/

bull: pytools
@pip3 install --trusted-host pypi.org --trusted-host files.pythonhosted.org colorama > /dev/null 2>&1
@$(BULL)
@pip3 install --trusted-host pypi.org --trusted-host files.pythonhosted.org colorama > /dev/null 2>&1
@$(BULL)
define BULL_PYSCRIPT
from colorama import init, Fore, Back, Style

Expand All @@ -241,7 +195,7 @@ bull = [r"""
init()

def colorize(chars, color):
for char in chars:
for char in chars:
bull[0] = bull[0].replace(char, color+char+Style.RESET_ALL)

colorize("o", Fore.RED)
Expand Down
32 changes: 0 additions & 32 deletions src/pybennu/pybennu-probe.spec

This file was deleted.

Loading

0 comments on commit 991f1e5

Please sign in to comment.