Skip to content

Commit

Permalink
Merge pull request #45 from Deric-W/Issue#44
Browse files Browse the repository at this point in the history
Issue#44
  • Loading branch information
Deric-W committed Jul 2, 2021
2 parents 92fd2c3 + 21b70f7 commit fa08559
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 80 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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_<package version>_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
Expand Down
81 changes: 41 additions & 40 deletions debian/build_deb.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
19 changes: 10 additions & 9 deletions debian/control
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
Package: pyhp
Version: {0}
Package: python3-pyhp-core
Source: pyhp-core
Version: {0}-1
Architecture: all
Maintainer: Eric Wolf <[email protected]>
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.
10 changes: 5 additions & 5 deletions debian/copyright
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: pyhp
Upstream-Contact: Eric Wolf <[email protected]>
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}
11 changes: 7 additions & 4 deletions debian/format.py
Original file line number Diff line number Diff line change
@@ -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:])
)
7 changes: 0 additions & 7 deletions pyhp.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,3 @@ enable = true

# how many files can be uploaded at once
max_files = 20







18 changes: 8 additions & 10 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -12,17 +12,18 @@ maintainer = Eric Wolf
maintainer_email = [email protected]
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]
Expand All @@ -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
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion tests/request/methods.pyhp
Original file line number Diff line number Diff line change
Expand Up @@ -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
?>
</body>
</html>

0 comments on commit fa08559

Please sign in to comment.