Skip to content

Commit

Permalink
Preparing BKSTools for publication on GitHub
Browse files Browse the repository at this point in the history
  • Loading branch information
DirkOsswald committed Dec 19, 2023
0 parents commit 4f03db9
Show file tree
Hide file tree
Showing 101 changed files with 11,537 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* text=auto
setenv text eol=lf
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# Distribution / packaging
build/
dist/
*.egg-info/
*.spec
MANIFEST
/venv/**
/.settings/org.eclipse.core.resources.derived.prefs
114 changes: 114 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
stages:
- build
- release

variables:
# Set the Python version
PYTHON_VERSION: "3.10"

before_script:
- python3 -V
- python3 -m venv venv
- source venv/bin/activate

#--------------------------------------------------------------------
build:
stage: build
script:
- pip install chardet wheel Markdown # Install building dependencies
- python3 setup.py sdist bdist_wheel # Build the source distribution and wheel

- |
release_notes_file=bkstools/release.py
latest_release_note_txt=$(python3 - << EOF
found_start=False
found_first=False
found_end=False
with open( r"${release_notes_file}", "r", encoding="latin-1" ) as inputfile:
for l in inputfile.readlines():
if ( not found_start and "From newest to oldest" in l ):
found_start = True
continue
if ( found_start and not found_end and not found_first and r"- \b" in l ):
found_first = True
start_column = l.find( "-" )
elif ( found_start and not found_end and found_first and r"- \b" in l ):
found_end = True
if ( not found_end and found_first ):
ll = l[start_column:-1].replace( '"', r'\&quot' )
if ( ll.startswith( "-" ) ):
print( ll )
else:
print( " " + ll)
EOF
)
latest_release_note=$(echo -e "${latest_release_note_txt}" \
| python3 -m markdown --output_format=xhtml \
| tr '\r' ' ' | tr '\n' ' ' )
#echo "latest_release_note_txt=${latest_release_note_txt}" # for debugging
#echo "latest_release_note=${latest_release_note}" # for debugging
#SaveVariables build.env latest_release_note
echo "latest_release_note=${latest_release_note}" >> "build.env"
#---
BKSTOOLS_PROJECT_RELEASE=$(cd bkstools ; python3 -c "import release; print(release.PROJECT_RELEASE)")
echo "${CI_JOB_NAME}_CI_JOB_ID=\"${CI_JOB_ID}\"" >> "build.env"
echo "BKSTOOLS_PROJECT_RELEASE=\"${BKSTOOLS_PROJECT_RELEASE}\"" >> "build.env"
echo "gitlab_host=\"gitlab-test.cloud.schunk.com\"" >> "build.env"
artifacts:
paths:
- dist/*.whl
- dist/*.tar.gz
reports:
dotenv: build.env

#--------------------------------------------------------------------
release_job:
stage: release
rules:
- if: $CI_COMMIT_TAG # Run this job when a tag is created only
script:
- |
#Log 'Running release_job to create release in GitLab->Project->Releases'
echo 'Running release_job to create release in GitLab->Project->Releases'
# (Remark: no variable defined here can be used in the release.description below!)
release:
name: 'Release $CI_COMMIT_TAG'
description: "<h3> Description </h3>
<p> Automatically generated release for git tag <b>${CI_COMMIT_TAG}</b>. </p>
<h3> Branches: </h3>
<ul>
<li>BKSTools: <b>${CI_COMMIT_REF_NAME}</b> (${CI_COMMIT_SHA})</li>
</ul>
<h3> Release note: </h3>
${latest_release_note}
<h3> Artifacts: </h3>
<ul>
<li> Created by
<a href='https://${gitlab_host}/python_stuff/BKSTools/-/pipelines/${CI_PIPELINE_ID}' >
pipeline ${CI_PIPELINE_ID}
</a>
</li>
<li> <a href='https://${gitlab_host}/python_stuff/BKSTools/-/jobs/${build_CI_JOB_ID}' title='view CI job results in GitLab'>
<img src='https://${gitlab_host}/uploads/-/system/project/avatar/73/BKSTools.png' width=32 height=32>
&nbsp;
BKSTools v${BKSTOOLS_PROJECT_RELEASE}
</a> &nbsp; - &nbsp;
<a href='https://${gitlab_host}/python_stuff/BKSTools/-/jobs/${build_CI_JOB_ID}/artifacts/raw/dist/bkstools-${BKSTOOLS_PROJECT_RELEASE}-py3-none-any.whl' title='download Python wheel for installation with pip, the Python paket manager'>
[ &#x21E9; ]
</a>
</li>
</ul>"
tag_name: '$CI_COMMIT_TAG'
ref: '$CI_COMMIT_TAG'
dependencies:
- build
18 changes: 18 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>BKSTools</name>
<comment></comment>
<projects>
<project>pyschunk</project>
</projects>
<buildSpec>
<buildCommand>
<name>org.python.pydev.PyDevBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.python.pydev.pythonNature</nature>
</natures>
</projectDescription>
14 changes: 14 additions & 0 deletions .pydevproject
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?eclipse-pydev version="1.0"?><pydev_project>

<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">python3.10 venv BKSTools</pydev_property>

<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python interpreter</pydev_property>

<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">

<path>/${PROJECT_DIR_NAME}</path>

</pydev_pathproperty>

</pydev_project>
2 changes: 2 additions & 0 deletions .settings/com.axivion.aclipse.plugin.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
com.axivion.aclipse.plugin/com.axivion.aclipse.plugin.properties.properties_version=2.1
eclipse.preferences.version=1
3 changes: 3 additions & 0 deletions .settings/org.eclipse.core.resources.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
separateDerivedEncodings=true
20 changes: 20 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
////////////////////////////////////////////////////////////////////////////////
//
// © Copyright 2023 SCHUNK SE & Co. KG, Lauffen/Neckar Germany
//
// This file is part of the Schunk BKSTools.
//
// The SCHUNK BKSTools is free software: you can redistribute it and/or
// modify it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or (at your
// option) any later version.
//
// The SCHUNK BKSTools is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
// Public License for more details.
//
// You should have received a copy of the GNU General Public License along with
// the SCHUNK BKSTools. If not, see <https://www.gnu.org/licenses/>.
//
////////////////////////////////////////////////////////////////////////////////
151 changes: 151 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
# Makefile to generate distribution packages.

.ONESHELL:
SHELL := bash

ifeq (${OSTYPE},cygwin)
# on cygwin still use the windows native python to create distributions
$(info Running on cygwin)
# The python interpreter to use. Can be overriden from the environment:
PYTHON?=python
else
$(info Running not on cygwin)
# The python interpreter to use. Can be overriden from the environment:
PYTHON?=python3
endif

# \remark
# 'cp -a' yields a "preserving permissions for /cygdrive/m/Software/Python/Schunk/python-msp430-tools-0.6.win-amd64.exe: Not supported" error
# but preseving the timestamps only works and is all we really want.
CP=cp -f --preserve=timestamps

RELEASE_DIR=bkstools
PROJECT_RELEASE=${shell cd ${RELEASE_DIR} ; ${PYTHON} -c "import release ; print( release.PROJECT_RELEASE )"}
PROJECT_NAME=${shell cd ${RELEASE_DIR} ; ${PYTHON} -c "import release ; print( release.PROJECT_NAME )"}
PROJECT_DATE=${shell cd ${RELEASE_DIR} ; ${PYTHON} -c "import release ; print( release.PROJECT_DATE )"}


.PHONY: all
all: dist

.PHONY: help
help:
@echo "Makefile for ${PROJECT_NAME}"
@echo "Targets:"
@echo " - all - dist (without copy or upload)"
@echo " - dist - generated all distribution packages + exe"
@echo " - bdist_wheel - generate a binary wheel package"
# bdist_wininst is deprecated! @echo " - bdist_wininst - generate a binary windows installer package"
# bdist_wininst is deprecated! @echo " - bdist_wininst64 - generate a binary windows installer package for 64-bit"
@echo " - sdist_bztar - generate a source distribution in tar.bz2 format"
@echo " - exe - generate standalone executable with py2exe"
@echo " - uncompressed in build/${PROJECT_NAME}-${PROJECT_RELEASE}-py2exe/"
@echo " - zipped in dist/${PROJECT_NAME}-${PROJECT_RELEASE}-py2exe.zip"
@echo " - clean - clean up current build in ./build/"
@echo " - mrproper - clean + clean up current distributions in ./dist/"
@echo " - show - show some variables used/derived by the makefile"
@echo " - venv - setup the python virtualenv environment required for building the frozen exes"
@echo " - venv-clean - remove the python virtualenv environment venv"
@echo " - venv-pip-list - do a pip list in the virtualenv environment venv"


.PHONY: show
show:
@echo "PYTHON=${PYTHON}"
@echo "PROJECT_RELEASE=${PROJECT_RELEASE}"
@echo "PROJECT_NAME=${PROJECT_NAME}"
@echo "PROJECT_DATE=${PROJECT_DATE}"

.PHONY: dist
dist: bdist_wheel sdist_bztar exe
# bdist_wininst bdist_wininst64 # bdist_wininst is deprecated!

.PHONY: clean
clean:
rm -rf build/*

.PHONY: mrproper
mrproper: clean venv-clean
rm -rf dist/${PROJECT_NAME}-${PROJECT_RELEASE}*

#---

.PHONY: bdist_wheel
bdist_wheel:
source ./venv/Scripts/activate
${PYTHON} setup.py $@

.PHONY: bdist_wininst
bdist_wininst:
source ./venv/Scripts/activate
${PYTHON} setup.py bdist_wininst
chmod a+x dist/*.exe

.PHONY: bdist_wininst64
bdist_wininst64:
source ./venv/Scripts/activate
${PYTHON} setup.py bdist_wininst --plat-name=win-amd64
chmod a+x dist/*.exe

.PHONY: sdist_bztar
sdist_bztar:
${PYTHON} setup.py sdist --formats bztar

#---



.PHONY: exe
exe:
mkdir -p dist ; \
source ./venv/Scripts/activate
${PYTHON} setup.py py2exe
pip freeze > build/${PROJECT_NAME}-${PROJECT_RELEASE}-py2exe/requirements.txt

cd build && zip -r -o ../dist/${PROJECT_NAME}-${PROJECT_RELEASE}-py2exe.zip ${PROJECT_NAME}-${PROJECT_RELEASE}-py2exe/

#---

.PHONY: venv
venv:
set -e
#virtualenv venv # does not work. (Generating exes with py2exe yields "ImportError: No module named pkg_resources._vendor.pyparsing"
${PYTHON} -m venv venv
if [ -e "./venv/Scripts/activate" ]; then
# running on cygwin/windows
activate="./venv/Scripts/activate"
dos2unix $${activate}
extra_packages="pypiwin32 py2exe pydevd"
else
# running on Linux
activate="./venv/bin/activate"
extra_msg="For the GUI tools 'bks_status' and 'bks_jog' you might have to install tkinter\nand idle3 packages. These are not available via pip, so use something like\n> sudo apt-get install python3-tk\nand\n> sudo apt-get install idle3"
fi
source "$${activate}"
pip install requests pyyaml minimalmodbus wrapt $${extra_packages} # for running
pip install chardet wheel # for building exes and wheels

# pip install --upgrade setuptools
pip list
@echo -e "\nTip: To activate the python virtual environment venv in your shell use \" source $${activate} \"\n$${extra_msg}"
######################################
# Command output starts below

.PHONY: venv-clean
venv-clean:
rm -rf venv/

.PHONY: venv-pip-list
venv-pip-list:
source ./venv/Scripts/activate
pip list

.PHONY: exes-run
exes-run:
for exe in build/${PROJECT_NAME}-${PROJECT_RELEASE}-int-py2exe/*.exe ; do
echo "==="
echo "$${exe} -h:"
$${exe} -h
echo
done

Loading

0 comments on commit 4f03db9

Please sign in to comment.