DavidMuller / aws-requests-auth

AWS signature version 4 signing process for the python requests module
Other
504 stars 92 forks source link

Request: release aws-requests-auth as a wheel #54

Closed kgaughan closed 4 years ago

kgaughan commented 4 years ago

Currently, the version of aws-requests-auth published on PyPI is a source tarball, but this poses issues if you're building a lambda that has binary dependencies, such as, say PyYAML or the cryptography library.

To give you an example, say you do your development of a Mac or Windows box: you might install all your libraries into a directory to be zipped up like so:

pip3 install \
    --ignore-installed \
    --compile \
    --platform linux_x86_64 \
    --only-binary :all: \
    --implementation cp \
    --requirement "$requirements" \
    --target .

The use of --only-binary :all: is unfortunately required if you're also using --platform to guarantee that any binary dependencies downloaded are for the correct target platform. Unfortunately, this means that pip won't bother downloading source tarballs if that's all that's available. Instead, you get an error like the following:

ERROR: Could not find a version that satisfies the requirement aws-requests-auth (from -r ../requirements.txt (line 1)) (from versions: none)
ERROR: No matching distribution found for aws-requests-auth (from -r ../requirements.txt (line 1))

The likes of requests, boto3, &c., don't have this particular issue because they're packaged as wheels.

The additional flags are unavoidable, unfortunately, and there seems to be no way to tell pip that source distributions are OK as a fallback.

The fix is simple enough. Add this to setup.cfg:

[bdist_wheel]
universal = 1

That will mean the wheel will work with both Python 2 and Python 3 and indicates that the wheel will also work on any platform. Also, in setup.py, replace from distutils.core import setup with from setuptools import setup. This also fixes a bug as distutils doesn't actually support the install_requires distribution option, so it means the dependency on requests will now work properly.

Finally, rather than just doing python3 setup.py sdist bdist_wheel, ensure the wheel package is installed and do python3 setup.py sdist bdist_wheel instead.

You should end up with something like this:

$ ls dist
aws-requests-auth-0.4.2.tar.gz
aws_requests_auth-0.4.2-py2.py3-none-any.whl
DavidMuller commented 4 years ago

Thanks for the detailed writeup @kgaughan .

aws-requests-auth version 0.4.3 is now published and includes a wheel