Update the package build system to support wheels.

This commit is contained in:
Andrew Leech
2022-11-04 21:44:28 +11:00
parent ad0bcd6409
commit 1544d35213
4 changed files with 44 additions and 10 deletions

View File

@@ -12,9 +12,8 @@ deploy:
image: python:3
stage: deploy
script:
- pip install -U twine setuptools
# We don't want to build wheel here as it doesn't support post-install script
- python setup.py sdist
- pip install -U twine setuptools wheel build
- python -m build
- twine upload -u $PYPI_USER -p $PYPI_PASS dist/*
only:
- tags

0
run_test.sh Normal file → Executable file
View File

View File

@@ -4,6 +4,7 @@ import distutils.sysconfig
from setuptools import setup
from setuptools.command.install import install
from setuptools.command.develop import develop
from setuptools.command.build_py import build_py
with open(os.path.join(os.path.dirname(__file__), 'README.rst')) as readme:
@@ -32,8 +33,21 @@ class DevelopCheck(develop):
check_pth(self.install_dir)
class BuildIncludePth(build_py):
"""Include the .pth file for this project in the generated wheel."""
def run(self):
super().run()
pth_file = "pip_system_certs.pth"
outfile = os.path.join(self.build_lib, pth_file)
self.copy_file(pth_file, outfile, preserve_mode=0)
site_packages = distutils.sysconfig.get_python_lib()
setup(
name='pip_system_certs',
use_git_versioner="gitlab:desc:snapshot",
@@ -45,9 +59,12 @@ setup(
license='BSD',
url='https://gitlab.com/alelec/pip-system-certs',
packages=['pip_system_certs'],
data_files=[(site_packages, ['pip_system_certs.pth'])],
install_requires=['wrapt>=1.10.4'],
zip_safe=False,
cmdclass={"install": InstallCheck, "develop": DevelopCheck},
cmdclass={
"build_py": BuildIncludePth,
"install": InstallCheck,
"develop": DevelopCheck,
},
python_requires='>=2.7.9, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*',
)

View File

@@ -1,25 +1,43 @@
#!/bin/bash
RED='\033[0;31m'
LRED='\033[1;31m'
GREEN='\033[0;32m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
pip install requests
pip uninstall pip-system-certs &> /dev/null
echo -e "${CYAN}start webserver with self-signed cert${NC}"
python3 test/simple-https-server.py &
curl -s https://localhost:4443 || (echo -e "\n${RED}curl failed as expected${NC}"; true)
python3 test/request.py 2> /dev/null || (echo -e "${RED}python failed as expected${NC}\n"; true)
echo -e "${CYAN}Should fail to verify self-signed cert${NC}"
curl -s https://localhost:4443 || (echo -e "\n${LRED}curl failed as expected${NC}"; true)
python3 test/request.py 2> /dev/null || (echo -e "${LRED}python failed as expected${NC}\n"; true)
echo -e "${CYAN}Install self-signed cert in system, curl should pass${NC}"
cp test/pki/ca.crt /usr/local/share/ca-certificates/
update-ca-certificates
curl -s https://localhost:4443 > /dev/null && echo -e "\n${GREEN}curl passed as expected${NC}"
python3 test/request.py 2> /dev/null || (echo -e "${RED}python failed as expected${NC}\n"; true)
python3 test/request.py 2> /dev/null || (echo -e "${LRED}python failed as expected${NC}\n"; true)
echo -e "${CYAN}Install pip-system-certs, curl & python should pass${NC}"
pip install .
curl -s https://localhost:4443 > /dev/null && echo -e "\n${GREEN}curl passed as expected${NC}"
python3 test/request.py > /dev/null && echo -e "${GREEN}python passed as expected${NC}\n"
echo -e "${CYAN}Uninstall pip-system-certs, python should fail again${NC}"
pip uninstall pip-system-certs &> /dev/null
curl -s https://localhost:4443 > /dev/null && echo -e "\n${GREEN}curl passed as expected${NC}"
python3 test/request.py 2> /dev/null || (echo -e "${LRED}python failed as expected${NC}\n"; true)
echo -e "${CYAN}Install pip-system-certs from wheel, curl & python should pass${NC}"
python setup.py bdist_wheel
pip install dist/*.whl
curl -s https://localhost:4443 > /dev/null && echo -e "\n${GREEN}curl passed as expected${NC}"
python3 test/request.py > /dev/null && echo -e "${GREEN}python passed as expected${NC}\n"