diff --git a/Changelog.rst b/Changelog.rst index 8348eb865..3fc8b8530 100644 --- a/Changelog.rst +++ b/Changelog.rst @@ -1,6 +1,16 @@ Changelog ========= +3.4.2 (8 March 2016) ++++++++++++++++++++ + + +Resolved issues +--------------- + +* Fix renaming of package for ``install`` command. + + 3.4.1 (21 February 2016) +++++++++++++++++++ diff --git a/README.rst b/README.rst index 256f1e711..283ac524b 100644 --- a/README.rst +++ b/README.rst @@ -73,7 +73,8 @@ All the code can be downloaded from `GitHub`_. News ---- -* **21 Feb 2016 (NEW)**. Release 3.4.1. +* **8 Mar 2016 (NEW)**. Bugfix release 3.4.2. +* 21 Feb 2016. Release 3.4.1. * 7 Feb 2016. Release 3.4. * Nov 2015. Release 3.3.1. * 29 Oct 2015. Release 3.3. diff --git a/lib/Crypto/__init__.py b/lib/Crypto/__init__.py index c3d5ff6fd..78a5956fe 100644 --- a/lib/Crypto/__init__.py +++ b/lib/Crypto/__init__.py @@ -44,4 +44,4 @@ __all__ = ['Cipher', 'Hash', 'Protocol', 'PublicKey', 'Util', 'Signature', 'IO', 'Math'] -version_info = (3, 4, 1) +version_info = (3, 4, 2) diff --git a/setup.py b/setup.py index 89bf212ab..a0077a381 100644 --- a/setup.py +++ b/setup.py @@ -26,9 +26,10 @@ from distutils.core import Extension, Command, setup from distutils.command.build_ext import build_ext from distutils.command.build import build +from distutils.command.install_lib import install_lib from distutils.errors import CCompilerError import distutils -import os, sys, shutil +import re, os, sys, shutil use_separate_namespace = os.path.isfile(".separate_namespace") @@ -134,6 +135,7 @@ def PrintErr(*args, **kwd): w(str(a)) w(kwd.get("end", "\n")) + def test_compilation(program, extra_cc_options=None, extra_libraries=None): """Test if a certain C program can be compiled.""" @@ -189,11 +191,75 @@ def test_compilation(program, extra_cc_options=None, extra_libraries=None): return result +def change_module_name(file_name): + """Change any occurrance of 'Crypto' to 'Cryptodome'.""" + + fd = open(file_name, "rt") + content = (fd.read(). + replace("Crypto.", "Cryptodome."). + replace("Crypto ", "Cryptodome "). + replace("'Crypto'", "'Cryptodome'"). + replace('"Crypto"', '"Cryptodome"')) + fd.close() + + os.remove(file_name) + + fd = open(file_name, "wt") + fd.write(content) + fd.close() + + +def rename_crypto_dir(build_lib): + """Move all files from the 'Crypto' package to the + 'Cryptodome' package in the given build directory""" + + source = os.path.join(build_lib, "Crypto") + target = os.path.join(build_lib, "Cryptodome") + + if not os.path.exists(target): + PrintErr("Creating directory %s" % target) + os.makedirs(target) + else: + PrintErr("Directory %s already exists" % target) + + # Crypto package becomes Cryptodome + for root_src, dirs, files in os.walk(source): + + root_dst, nr_repl = re.subn('Crypto', 'Cryptodome', root_src) + assert nr_repl == 1 + + for dir_name in dirs: + full_dir_name_dst = os.path.join(root_dst, dir_name) + if not os.path.exists(full_dir_name_dst): + os.makedirs(full_dir_name_dst) + + for file_name in files: + full_file_name_src = os.path.join(root_src, file_name) + full_file_name_dst = os.path.join(root_dst, file_name) + + PrintErr("Copying file %s to %s" % (full_file_name_src, full_file_name_dst)) + shutil.copy2(full_file_name_src, full_file_name_dst) + + if file_name.endswith(".py"): + change_module_name(full_file_name_dst) + + class PCTBuildExt (build_ext): aesni_mod_names = "Crypto.Cipher._raw_aesni", + def run(self): + build_ext.run(self) + + if use_separate_namespace: + rename_crypto_dir(self.build_lib) + + # Clean-up (extensions are built last) + crypto_dir = os.path.join(self.build_lib, "Crypto") + PrintErr("Deleting directory %s" % crypto_dir) + shutil.rmtree(crypto_dir) + def build_extensions(self): # Disable any assembly in libtomcrypt files self.compiler.define_macro("LTC_NO_ASM") @@ -274,6 +340,7 @@ def remove_extensions(self, names): self.extensions = [ x for x in self.extensions if x.name not in names ] + class PCTBuildPy(build_py): def find_package_modules(self, package, package_dir, *args, **kwargs): modules = build_py.find_package_modules(self, package, package_dir, @@ -286,43 +353,11 @@ def find_package_modules(self, package, package_dir, *args, **kwargs): retval.append(item) return retval -class PCTBuild(build): - def run(self): - build.run(self) - - if not use_separate_namespace: - return - - PrintErr("Renaming Crypto to Cryptodome...\n") - - # Rename root package - source = os.path.join(self.build_lib, "Crypto") - target = os.path.join(self.build_lib, "Cryptodome") - try: - shutil.rmtree(target) - except OSError: - pass - os.rename(source, target) - - # Crypto becomes Cryptodome - for roots, dirs, files in os.walk(target): - files = [os.path.join(roots, f) for f in files if f.endswith(".py")] - for filepy in files: - - fd = open(filepy, "rt") - content = (fd.read(). - replace("Crypto.", "Cryptodome."). - replace("Crypto ", "Cryptodome "). - replace("'Crypto'", "'Cryptodome'"). - replace('"Crypto"', '"Cryptodome"')) - fd.close() - - os.remove(filepy) + build_py.run(self) + if use_separate_namespace: + rename_crypto_dir(self.build_lib) - fd = open(filepy, "wt") - fd.write(content) - fd.close() class TestCommand(Command): @@ -462,7 +497,6 @@ def run(self): "Crypto.Math" : [ "mpir.dll" ], }, cmdclass = { - 'build':PCTBuild, 'build_ext':PCTBuildExt, 'build_py': PCTBuildPy, 'test': TestCommand