diff --git a/README.md b/README.md index e2b0bc9..490db75 100644 --- a/README.md +++ b/README.md @@ -82,10 +82,10 @@ A script is called either by the configuration of the web server or a shebang an - Optional: set the `PYHPCONFIG` environ variable or copy *pyhp.toml* to one of the config file locations to use the CLI commands ### Debian package - 1. build the *pyhp-core* python package with `python3 setup.py bdist_wheel` - 2. go to the *debian* directory and execute `./build_deb.sh` - 3. enter a package version, the path of the *pyhp-core* wheel and the pip command you wish to use - 4. Done! You can now install the debian package with `sudo dpkg -i pyhp__all.deb` + 1. execute `debian/build_deb.sh` in the root directory of the project. + 2. Done! You can now install the debian package with `sudo dpkg -i python3-pyhp-core_{version}-1_all.deb` + + - Optional: check if the recommended packages `python3-toml` and `python3-werkzeug` are installed to use the CLI commands ### Manually 1. install the *pyhp-core* python package diff --git a/debian/build_deb.sh b/debian/build_deb.sh index 2155aab..dc5acc1 100755 --- a/debian/build_deb.sh +++ b/debian/build_deb.sh @@ -1,61 +1,62 @@ #!/bin/sh -e # script for building the pyhp debian package # it is recommended to run this script as root or to set the owner and group of the files to root -# you need to build the pyhp-core wheel first -if [ "$1" = "" ] -then read -p "Version: " version -else version=$1 -fi - -if [ "$2" = "" ] -then read -p "pyhp-core Wheel: " wheel -else wheel=$2 -fi - -if [ "$3" = "" ] -then read -p "pip executeable: " pip -else pip=$3 -fi - -package="pyhp_${version}_all" +version=$(python3 setup.py --version) +maintainer=$(python3 setup.py --maintainer) +email=$(python3 setup.py --maintainer-email) +homepage=$(python3 setup.py --url) +description=$(python3 setup.py --description) +licence=$(python3 setup.py --licence) +package="python3-pyhp-core_${version}-1_all" mkdir "$package" # place pyhp-core files -mkdir -p "${package}/usr/lib/python3/dist-packages" -$pip install --target "${package}/usr/lib/python3/dist-packages" --ignore-installed --no-compile "$wheel" +python3 setup.py install --install-layout=deb --no-compile --single-version-externally-managed --root="$package" -# place config file and "executable" -mkdir "${package}/etc" -cp ../pyhp.toml "${package}/etc" +# strip python version from .egg-info directory +mv $package/usr/lib/python3/dist-packages/pyhp_core-${version}-*.egg-info "$package/usr/lib/python3/dist-packages/pyhp_core-${version}.egg-info" -mkdir -p "${package}/usr/bin" -mv "${package}/usr/lib/python3/dist-packages/bin/pyhp" "${package}/usr/bin" -rmdir "${package}/usr/lib/python3/dist-packages/bin" -chmod +x "${package}/usr/bin/pyhp" +# place config file +mkdir "${package}/etc" +cp pyhp.toml "${package}/etc" # place metadata files mkdir "$package/DEBIAN" -# calculate installed size -cat control | python3 format.py "${version}" $(du -sk --apparent-size --exclude "DEBIAN" "${package}" 2>/dev/null | cut -f1) > "${package}/DEBIAN/control" -cp conffiles "$package/DEBIAN" - -mkdir -p "${package}/usr/share/doc/pyhp" -cp copyright "${package}/usr/share/doc/pyhp" -cp changelog "${package}/usr/share/doc/pyhp/changelog.Debian" -gzip -n --best "${package}/usr/share/doc/pyhp/changelog.Debian" -# generate md5sums file -chdir "$package" -md5sum $(find . -type d -name "DEBIAN" -prune -o -type f -print) > DEBIAN/md5sums # ignore metadata files -sha256sum $(find . -type d -name "DEBIAN" -prune -o -type f -print) > DEBIAN/sha256sums -chdir ../ +# place control +cat debian/control | python3 debian/format.py \ + "$version" \ + "$maintainer" "$email" \ + $(du -sk --apparent-size --exclude "DEBIAN" "${package}" 2>/dev/null | cut -f1) \ + "$homepage" \ + "$description" \ + > "${package}/DEBIAN/control" + +# place conffiles +cp debian/conffiles "$package/DEBIAN" + +# place copyright and changelog +mkdir -p "${package}/usr/share/doc/python3-pyhp-core" +cat debian/copyright | python3 debian/format.py \ + "$maintainer" "$email" \ + "$homepage" \ + "$licence" \ + > "${package}/usr/share/doc/python3-pyhp-core/copyright" +cp debian/changelog "${package}/usr/share/doc/python3-pyhp-core/changelog.Debian" +gzip -n --best "${package}/usr/share/doc/python3-pyhp-core/changelog.Debian" + +# generate md5sums and sha256sums file +cd "$package" +md5sum $(find . -type d -name "DEBIAN" -prune -o -type f -print) > "DEBIAN/md5sums" # ignore metadata files +sha256sum $(find . -type d -name "DEBIAN" -prune -o -type f -print) > "DEBIAN/sha256sums" +cd .. # if root set file permissions, else warn if [ $(id -u) = 0 ] then chown root:root -R "$package" -else echo "not running as root, permissions in package may be wrong" +else echo "Warning: not running as root, permissions in package may be wrong" fi # build debian package diff --git a/debian/control b/debian/control index ce6d9a0..3763075 100644 --- a/debian/control +++ b/debian/control @@ -1,13 +1,14 @@ -Package: pyhp -Version: {0} +Package: python3-pyhp-core +Source: pyhp-core +Version: {0}-1 Architecture: all -Maintainer: Eric Wolf -Installed-Size: {1} +Maintainer: {1} <{2}> +Installed-Size: {3} Depends: python3:any (>= 3.7) -Suggests: apache2 -Section: web +Recommends: python3-toml (>= 0.10.0), python3-werkzeug (>= 0.14.0) +Section: python Priority: optional -Homepage: https://github.com/Deric-W/PyHP -Description: Application for embedding and using python code like php - PyHP is a application/python package for embedding python code in text files like HTML, +Homepage: {4} +Description: {5} + PyHP is a application/python package for embedding python code in text files like HTML, with several PHP functions available. diff --git a/debian/copyright b/debian/copyright index 47a6531..80b63c2 100644 --- a/debian/copyright +++ b/debian/copyright @@ -1,10 +1,10 @@ Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ -Upstream-Name: pyhp -Upstream-Contact: Eric Wolf -Source: https://github.com/Deric-W/PyHP +Upstream-Name: python3-pyhp-core +Upstream-Contact: {0} <{1}> +Source: {2} Copyright: 2021 Eric Wolf -License: GPLv3 +License: {3} Files: * Copyright: 2021 Eric Wolf -License: GPLv3 +License: {3} diff --git a/debian/format.py b/debian/format.py index 47f5fce..7b2835d 100755 --- a/debian/format.py +++ b/debian/format.py @@ -1,7 +1,10 @@ #!/usr/bin/python3 -# format stdin with cli arguments + +"""format stdin with cli arguments""" + import sys -data = sys.stdin.read() -data = data.format(*sys.argv[1:]) -sys.stdout.write(data) + +sys.stdout.write( + sys.stdin.read().format(*sys.argv[1:]) +) diff --git a/pyhp.toml b/pyhp.toml index 3fcb000..5eadaef 100644 --- a/pyhp.toml +++ b/pyhp.toml @@ -73,10 +73,3 @@ enable = true # how many files can be uploaded at once max_files = 20 - - - - - - - diff --git a/setup.cfg b/setup.cfg index 134d60b..4d5465d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,7 +1,7 @@ [metadata] name = pyhp-core version = attr: pyhp.__version__ -description = package for embedding and using python code like php +description = Package for embedding and using python code like php license = GPLv3 license_file = LICENSE long_description = file: README.md @@ -12,17 +12,18 @@ maintainer = Eric Wolf maintainer_email = robo-eric@gmx.de url = https://github.com/Deric-W/PyHP classifiers = - Programming Language :: Python :: 3 - Programming Language :: Python :: 3 :: Only + Programming Language :: Python :: 3 :: Only Programming Language :: Python :: 3.7 Programming Language :: Python :: 3.8 Programming Language :: Python :: 3.9 - Intended Audience :: Developers Operating System :: Microsoft :: Windows Operating System :: POSIX - Topic :: Internet :: WWW/HTTP - Topic :: Internet :: WWW/HTTP :: Dynamic Content + Intended Audience :: Developers Topic :: Internet :: WWW/HTTP :: Dynamic Content :: CGI Tools/Libraries + Topic :: Internet :: WWW/HTTP :: WSGI :: Application + Topic :: Software Development :: Interpreters + Topic :: Text Processing :: Markup :: HTML + Typing :: Typed License :: OSI Approved :: GNU General Public License v3 (GPLv3) [options] @@ -38,7 +39,7 @@ python_requires = >=3.7 [options.extras_require] CONFIG = toml >= 0.10.0 -PHP = werkzeug >= 2.0.0 +PHP = werkzeug >= 0.14.0 [options.package_data] pyhp = py.typed @@ -67,9 +68,6 @@ check_untyped_defs = True disallow_untyped_defs = True no_implicit_optional = True -[mypy-pyhp.libpyhp] -ignore_errors = True - [mypy-pyhp.wsgi.interfaces.php] # the type: ignore is needed because CI fails somehow (but not local tests?) warn_unused_ignores = False diff --git a/tests/request/methods.pyhp b/tests/request/methods.pyhp index 40b145b..9136df6 100644 --- a/tests/request/methods.pyhp +++ b/tests/request/methods.pyhp @@ -8,7 +8,7 @@ print("GET, POST, COOKIE and REQUEST are available.") print("Their values are:") for method in (PyHP.GET, PyHP.POST, PyHP.COOKIE, PyHP.REQUEST): - print(sorted(method.items(multi=True))) + print(sorted(filter(lambda i: i[0] != "", method.items(multi=True)))) # filter empty cookies present before werkzeug 0.15.0 ?>