From 8ec1dfb56c4669b2295a6c097701e9aa3e4af96c Mon Sep 17 00:00:00 2001 From: Ray Date: Fri, 7 Apr 2017 13:53:48 -0700 Subject: [PATCH] Installation Fixes and Improvements Installation as well as distribution generation are now simplified. With the elimination of MinGW support there is now a unique set of platform binaries for 32-bit and 64-bit Windows. Pip will now automatically choose the proper binary wheel or the source distribution, depending under which platform and Python version it is being invoked. * README.md: add installation section * setup.py: rewrite to use bdist_wheel for Windows --- ChangeLog | 9 +++ README.md | 8 +++ setup.py | 179 ++++++++++++++++++++++++++---------------------------- 3 files changed, 104 insertions(+), 92 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2b3fa50..4417cd3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2017-04-06 Ray Brown + + Installation Fixes and Improvements + + Installation as well as distribution generation are now simplified. With the elimination of MinGW support there is now a unique set of platform binaries for 32-bit and 64-bit Windows. Pip will now automatically choose the proper binary wheel or the source distribution, depending under which platform and Python version it is being invoked. + + * README.md: add installation section + * setup.py: rewrite to use bdist_wheel for Windows + 2017-04-03 Ray Brown Release 1.2.0 diff --git a/README.md b/README.md index 0942bee..96e7747 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,14 @@ As of version 1.2.0, PyDTLS supports DTLS version 1.2 in addition to version 1.0. This version also introduces forward secrecy using elliptic curve cryptography and more fine-grained configuration options. +## Installation + +To install from PyPI, on any supported platform enter: + +``` +pip install Dtls +``` + ## Design Goals The primary design goal of PyDTLS is broad availability. It has therefore diff --git a/setup.py b/setup.py index a2fcc52..f1cdb04 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # PyDTLS setup script. -# Copyright 2012 Ray Brown +# Copyright 2017 Ray Brown # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -22,102 +22,97 @@ Install or create a distribution of the PyDTLS package. """ -from os import listdir, path, remove, rename -from sys import argv +from os import path, remove +from shutil import copy2, rmtree +from argparse import ArgumentParser from pickle import dump, load -from distutils.core import setup -from distutils.command.install import INSTALL_SCHEMES - -# Make the root for data file installations the same as Python code -for scheme in INSTALL_SCHEMES.values(): - scheme['data'] = scheme['purelib'] +from setuptools import setup NAME = "Dtls" VERSION = "1.2.0" -DIST_DIR = "dist" -FORMAT_TO_SUFFIX = { "zip": ".zip", - "gztar": ".tar.gz", - "bztar": ".tar.bz2", - "ztar": ".tar.Z", - "tar": ".tar" } - -def invoke_setup(data_files=None): - data_files_file = "data_files" - data_files_file_created = False - try: - if data_files: - # Save the value of data_files with the distribution archive - data_files_file_created = True - with open(data_files_file, "wb") as fl: - dump(data_files, fl) - data_files.append(('', [data_files_file]),) - else: - # Load data_files from the distribution archive, if present - try: - with open(data_files_file, "rb") as fl: - data_files = load(fl) - except IOError: - data_files = [] - data_files.append(('dtls', ["NOTICE", - "LICENSE", - "README.txt", - "ChangeLog"]),) - setup(name=NAME, - version=VERSION, - description="Python Datagram Transport Layer Security", - author="Ray Brown", - author_email="code@liquibits.com", - url="https://github.com/rbit/pydtls", - license="LICENSE", - long_description=open("README.txt").read(), - packages=["dtls", "dtls.demux", "dtls.test"], - package_data={"dtls.test": ["makecerts", - "openssl_ca.cnf", - "openssl_server.cnf", - "certs/*.pem"]}, - data_files=data_files, - ) - finally: - if data_files_file_created: - try: - remove(data_files_file) - except OSError: - pass - -def make_dists(): - prebuilt_platform_root = path.join("dtls", "prebuilt") - for platform in listdir(prebuilt_platform_root): - config = {"MANIFEST_DIR": path.join(prebuilt_platform_root, platform)} - execfile(path.join(prebuilt_platform_root, platform, "manifest.pycfg"), - config) - files = map(lambda x: "dtls/prebuilt/" + platform + "/" + x, - config["FILES"]) - argv.append("--formats=" + config["FORMATS"]) - invoke_setup([('dtls', files)]) - del argv[-1] - for dist_format in config["FORMATS"].split(','): - source_name = path.join(DIST_DIR, - NAME + "-" + VERSION + - FORMAT_TO_SUFFIX[dist_format]) - target_name = path.join(DIST_DIR, - NAME + "-" + VERSION + - ".sdist_with_openssl." + - config["ARCHITECTURE"] + - FORMAT_TO_SUFFIX[dist_format]) - try: - remove(target_name) - except OSError: - pass - rename(source_name, target_name) - if __name__ == "__main__": # Full upload sequence for new version: - # python setup.py sdist --formats=zip,gztar upload - # python setup.py sdist --prebuilts - # Manually add .sdist_with_openssl. archives to repository - if argv[-1] == "--prebuilts": - del argv[-1] - make_dists() + # 1. python setup.py sdist + # 2. python setup.py bdist_wheel -p win32 + # 3. python setup.py bdist_wheel -p win_amd64 + # 4. twine upload dist/* + + parser = ArgumentParser(add_help=False) + parser.add_argument("-h", "--help", action="store_true") + parser.add_argument("command", nargs="*") + parser.add_argument("-p", "--plat-name") + args = parser.parse_known_args()[0] + sdist = "sdist" in args.command and not args.help + bdist = "bdist_wheel" in args.command and not args.help + if sdist or bdist: + from pypandoc import convert + long_description = convert("README.md", "rst")\ + .translate({ord("\r"): None}) else: - invoke_setup() + long_description = open("README.md").read() + top_package_plat_files_file = "dtls_package_files" + if bdist: + prebuilt_platform_root = "dtls/prebuilt" + if args.plat_name == "win32": + platform = "win32-x86" + elif args.plat_name == "win_amd64": + platform = "win32-x86_64" + else: + raise ValueError("Unknown platform") + prebuilt_path = prebuilt_platform_root + "/" + platform + config = {"MANIFEST_DIR": prebuilt_path} + execfile(prebuilt_path + "/manifest.pycfg", config) + top_package_plat_files = map(lambda x: prebuilt_path + "/" + x, + config["FILES"]) + # Save top_package_plat_files with the distribution archive + with open(top_package_plat_files_file, "wb") as fl: + dump(top_package_plat_files, fl) + else: + # Load top_package_files from the distribution archive, if present + try: + with open(top_package_plat_files_file, "rb") as fl: + top_package_plat_files = load(fl) + except IOError: + top_package_plat_files = [] + top_package_extra_files = ["NOTICE", + "LICENSE", + "README.md", + "ChangeLog"] + top_package_plat_files + for extra_file in top_package_extra_files: + copy2(extra_file, "dtls") + top_package_extra_files = [path.basename(f) + for f in top_package_extra_files] + setup(name=NAME, + version=VERSION, + description="Python Datagram Transport Layer Security", + author="Ray Brown", + author_email="code@liquibits.com", + url="https://github.com/rbit/pydtls", + license="Apache-2.0", + classifiers=[ + 'Development Status :: 5 - Production/Stable', + 'Intended Audience :: Developers', + 'Topic :: Security :: Cryptography', + 'Topic :: Software Development :: Libraries :: Python Modules', + 'License :: OSI Approved :: Apache Software License', + 'Operating System :: POSIX :: Linux', + 'Operating System :: Microsoft :: Windows', + 'Programming Language :: Python :: 2.7', + ], + long_description=long_description, + packages=["dtls", "dtls.demux", "dtls.test"], + package_data={"dtls": top_package_extra_files, + "dtls.test": ["makecerts", + "makecerts_ec.bat", + "openssl_ca.cnf", + "openssl_server.cnf", + "certs/*.pem"]}, + data_files=[('', [top_package_plat_files_file])] + ) + for extra_file in top_package_extra_files: + remove("dtls/" + extra_file) + if bdist: + remove(top_package_plat_files_file) + rmtree("Dtls.egg-info", True) + rmtree("build", True)