Skip to content

Commit fa08559

Browse files
authored
Merge pull request #45 from Deric-W/Issue#44
Issue#44
2 parents 92fd2c3 + 21b70f7 commit fa08559

File tree

8 files changed

+76
-80
lines changed

8 files changed

+76
-80
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ A script is called either by the configuration of the web server or a shebang an
8282
- Optional: set the `PYHPCONFIG` environ variable or copy *pyhp.toml* to one of the config file locations to use the CLI commands
8383

8484
### Debian package
85-
1. build the *pyhp-core* python package with `python3 setup.py bdist_wheel`
86-
2. go to the *debian* directory and execute `./build_deb.sh`
87-
3. enter a package version, the path of the *pyhp-core* wheel and the pip command you wish to use
88-
4. Done! You can now install the debian package with `sudo dpkg -i pyhp_<package version>_all.deb`
85+
1. execute `debian/build_deb.sh` in the root directory of the project.
86+
2. Done! You can now install the debian package with `sudo dpkg -i python3-pyhp-core_{version}-1_all.deb`
87+
88+
- Optional: check if the recommended packages `python3-toml` and `python3-werkzeug` are installed to use the CLI commands
8989

9090
### Manually
9191
1. install the *pyhp-core* python package

debian/build_deb.sh

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,62 @@
11
#!/bin/sh -e
22
# script for building the pyhp debian package
33
# it is recommended to run this script as root or to set the owner and group of the files to root
4-
# you need to build the pyhp-core wheel first
54

6-
if [ "$1" = "" ]
7-
then read -p "Version: " version
8-
else version=$1
9-
fi
10-
11-
if [ "$2" = "" ]
12-
then read -p "pyhp-core Wheel: " wheel
13-
else wheel=$2
14-
fi
15-
16-
if [ "$3" = "" ]
17-
then read -p "pip executeable: " pip
18-
else pip=$3
19-
fi
20-
21-
package="pyhp_${version}_all"
5+
version=$(python3 setup.py --version)
6+
maintainer=$(python3 setup.py --maintainer)
7+
email=$(python3 setup.py --maintainer-email)
8+
homepage=$(python3 setup.py --url)
9+
description=$(python3 setup.py --description)
10+
licence=$(python3 setup.py --licence)
2211

12+
package="python3-pyhp-core_${version}-1_all"
2313
mkdir "$package"
2414

2515
# place pyhp-core files
26-
mkdir -p "${package}/usr/lib/python3/dist-packages"
27-
$pip install --target "${package}/usr/lib/python3/dist-packages" --ignore-installed --no-compile "$wheel"
16+
python3 setup.py install --install-layout=deb --no-compile --single-version-externally-managed --root="$package"
2817

29-
# place config file and "executable"
30-
mkdir "${package}/etc"
31-
cp ../pyhp.toml "${package}/etc"
18+
# strip python version from .egg-info directory
19+
mv $package/usr/lib/python3/dist-packages/pyhp_core-${version}-*.egg-info "$package/usr/lib/python3/dist-packages/pyhp_core-${version}.egg-info"
3220

33-
mkdir -p "${package}/usr/bin"
34-
mv "${package}/usr/lib/python3/dist-packages/bin/pyhp" "${package}/usr/bin"
35-
rmdir "${package}/usr/lib/python3/dist-packages/bin"
36-
chmod +x "${package}/usr/bin/pyhp"
21+
# place config file
22+
mkdir "${package}/etc"
23+
cp pyhp.toml "${package}/etc"
3724

3825
# place metadata files
3926
mkdir "$package/DEBIAN"
40-
# calculate installed size
41-
cat control | python3 format.py "${version}" $(du -sk --apparent-size --exclude "DEBIAN" "${package}" 2>/dev/null | cut -f1) > "${package}/DEBIAN/control"
42-
cp conffiles "$package/DEBIAN"
43-
44-
mkdir -p "${package}/usr/share/doc/pyhp"
45-
cp copyright "${package}/usr/share/doc/pyhp"
46-
cp changelog "${package}/usr/share/doc/pyhp/changelog.Debian"
47-
gzip -n --best "${package}/usr/share/doc/pyhp/changelog.Debian"
4827

49-
# generate md5sums file
50-
chdir "$package"
51-
md5sum $(find . -type d -name "DEBIAN" -prune -o -type f -print) > DEBIAN/md5sums # ignore metadata files
52-
sha256sum $(find . -type d -name "DEBIAN" -prune -o -type f -print) > DEBIAN/sha256sums
53-
chdir ../
28+
# place control
29+
cat debian/control | python3 debian/format.py \
30+
"$version" \
31+
"$maintainer" "$email" \
32+
$(du -sk --apparent-size --exclude "DEBIAN" "${package}" 2>/dev/null | cut -f1) \
33+
"$homepage" \
34+
"$description" \
35+
> "${package}/DEBIAN/control"
36+
37+
# place conffiles
38+
cp debian/conffiles "$package/DEBIAN"
39+
40+
# place copyright and changelog
41+
mkdir -p "${package}/usr/share/doc/python3-pyhp-core"
42+
cat debian/copyright | python3 debian/format.py \
43+
"$maintainer" "$email" \
44+
"$homepage" \
45+
"$licence" \
46+
> "${package}/usr/share/doc/python3-pyhp-core/copyright"
47+
cp debian/changelog "${package}/usr/share/doc/python3-pyhp-core/changelog.Debian"
48+
gzip -n --best "${package}/usr/share/doc/python3-pyhp-core/changelog.Debian"
49+
50+
# generate md5sums and sha256sums file
51+
cd "$package"
52+
md5sum $(find . -type d -name "DEBIAN" -prune -o -type f -print) > "DEBIAN/md5sums" # ignore metadata files
53+
sha256sum $(find . -type d -name "DEBIAN" -prune -o -type f -print) > "DEBIAN/sha256sums"
54+
cd ..
5455

5556
# if root set file permissions, else warn
5657
if [ $(id -u) = 0 ]
5758
then chown root:root -R "$package"
58-
else echo "not running as root, permissions in package may be wrong"
59+
else echo "Warning: not running as root, permissions in package may be wrong"
5960
fi
6061

6162
# build debian package

debian/control

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
Package: pyhp
2-
Version: {0}
1+
Package: python3-pyhp-core
2+
Source: pyhp-core
3+
Version: {0}-1
34
Architecture: all
4-
Maintainer: Eric Wolf <[email protected]>
5-
Installed-Size: {1}
5+
Maintainer: {1} <{2}>
6+
Installed-Size: {3}
67
Depends: python3:any (>= 3.7)
7-
Suggests: apache2
8-
Section: web
8+
Recommends: python3-toml (>= 0.10.0), python3-werkzeug (>= 0.14.0)
9+
Section: python
910
Priority: optional
10-
Homepage: https://github.com/Deric-W/PyHP
11-
Description: Application for embedding and using python code like php
12-
PyHP is a application/python package for embedding python code in text files like HTML,
11+
Homepage: {4}
12+
Description: {5}
13+
PyHP is a application/python package for embedding python code in text files like HTML,
1314
with several PHP functions available.

debian/copyright

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
2-
Upstream-Name: pyhp
3-
Upstream-Contact: Eric Wolf <[email protected]>
4-
Source: https://github.com/Deric-W/PyHP
2+
Upstream-Name: python3-pyhp-core
3+
Upstream-Contact: {0} <{1}>
4+
Source: {2}
55
Copyright: 2021 Eric Wolf
6-
License: GPLv3
6+
License: {3}
77

88
Files: *
99
Copyright: 2021 Eric Wolf
10-
License: GPLv3
10+
License: {3}

debian/format.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
#!/usr/bin/python3
2-
# format stdin with cli arguments
2+
3+
"""format stdin with cli arguments"""
4+
35
import sys
46

5-
data = sys.stdin.read()
6-
data = data.format(*sys.argv[1:])
7-
sys.stdout.write(data)
7+
8+
sys.stdout.write(
9+
sys.stdin.read().format(*sys.argv[1:])
10+
)

pyhp.toml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,3 @@ enable = true
7373

7474
# how many files can be uploaded at once
7575
max_files = 20
76-
77-
78-
79-
80-
81-
82-

setup.cfg

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[metadata]
22
name = pyhp-core
33
version = attr: pyhp.__version__
4-
description = package for embedding and using python code like php
4+
description = Package for embedding and using python code like php
55
license = GPLv3
66
license_file = LICENSE
77
long_description = file: README.md
@@ -12,17 +12,18 @@ maintainer = Eric Wolf
1212
maintainer_email = [email protected]
1313
url = https://github.com/Deric-W/PyHP
1414
classifiers =
15-
Programming Language :: Python :: 3
16-
Programming Language :: Python :: 3 :: Only
15+
Programming Language :: Python :: 3 :: Only
1716
Programming Language :: Python :: 3.7
1817
Programming Language :: Python :: 3.8
1918
Programming Language :: Python :: 3.9
20-
Intended Audience :: Developers
2119
Operating System :: Microsoft :: Windows
2220
Operating System :: POSIX
23-
Topic :: Internet :: WWW/HTTP
24-
Topic :: Internet :: WWW/HTTP :: Dynamic Content
21+
Intended Audience :: Developers
2522
Topic :: Internet :: WWW/HTTP :: Dynamic Content :: CGI Tools/Libraries
23+
Topic :: Internet :: WWW/HTTP :: WSGI :: Application
24+
Topic :: Software Development :: Interpreters
25+
Topic :: Text Processing :: Markup :: HTML
26+
Typing :: Typed
2627
License :: OSI Approved :: GNU General Public License v3 (GPLv3)
2728

2829
[options]
@@ -38,7 +39,7 @@ python_requires = >=3.7
3839

3940
[options.extras_require]
4041
CONFIG = toml >= 0.10.0
41-
PHP = werkzeug >= 2.0.0
42+
PHP = werkzeug >= 0.14.0
4243

4344
[options.package_data]
4445
pyhp = py.typed
@@ -67,9 +68,6 @@ check_untyped_defs = True
6768
disallow_untyped_defs = True
6869
no_implicit_optional = True
6970

70-
[mypy-pyhp.libpyhp]
71-
ignore_errors = True
72-
7371
[mypy-pyhp.wsgi.interfaces.php]
7472
# the type: ignore is needed because CI fails somehow (but not local tests?)
7573
warn_unused_ignores = False

tests/request/methods.pyhp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
print("GET, POST, COOKIE and REQUEST are available.")
99
print("Their values are:")
1010
for method in (PyHP.GET, PyHP.POST, PyHP.COOKIE, PyHP.REQUEST):
11-
print(sorted(method.items(multi=True)))
11+
print(sorted(filter(lambda i: i[0] != "", method.items(multi=True)))) # filter empty cookies present before werkzeug 0.15.0
1212
?>
1313
</body>
1414
</html>

0 commit comments

Comments
 (0)