From a8d1a4a669745ef60023f857c1b0b57666d5f3aa Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Thu, 1 Dec 2016 01:27:19 -0500 Subject: [PATCH 1/6] cmake: Add python CLI to easily update version of CMake The command line tool will automatically: * Update CMakeUrls.cmake parsing "https://cmake.org/files/vX.Y" and downloading list of SHA256s associated with each archives. * Update README.rst and docs/index.rst * Update tests/test_wheel.py --- CMakeLists.txt | 26 +---- CMakeUrls.cmake | 26 +++++ docs/index.rst | 1 + docs/update_cmake_version.rst | 35 +++++++ scripts/update_cmake_version.py | 178 ++++++++++++++++++++++++++++++++ 5 files changed, 241 insertions(+), 25 deletions(-) create mode 100644 CMakeUrls.cmake create mode 100644 docs/update_cmake_version.rst create mode 100644 scripts/update_cmake_version.py diff --git a/CMakeLists.txt b/CMakeLists.txt index cfdb6f057..75a288f4b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,31 +32,7 @@ if(CMakePythonDistributions_SUPERBUILD) message(STATUS "Build CMake from source: ${BUILD_CMAKE_FROM_SOURCE}") message(STATUS "***************************************************") - #----------------------------------------------------------------------------- - # CMake sources - set(unix_source_url "https://cmake.org/files/v3.7/cmake-3.7.0.tar.gz") - set(unix_source_sha256 "ed63e05c41aeb6c036e503114ab15847f29c312f9f21f5f1a7060a4b4ec2fb31") - - set(windows_source_url "https://cmake.org/files/v3.7/cmake-3.7.0.zip") - set(windows_source_sha256 "e147c8f95b31b8cb0ef903b39ac21c9f07faf1c2131f7ec54a55e664d70224e7") - - #----------------------------------------------------------------------------- - # CMake binaries - - set(linux32_binary_url "NA") # Linux 32-bit binaries not available - set(linux32_binary_sha256 "NA") - - set(linux64_binary_url "https://cmake.org/files/v3.7/cmake-3.7.0-Linux-x86_64.tar.gz") - set(linux64_binary_sha256 "e075f63e6a9104b1c3d11666ae9546bc8812f7e791a49c4ce11effc063141b2a") - - set(macosx_binary_url "https://cmake.org/files/v3.7/cmake-3.7.0-Darwin-x86_64.tar.gz") - set(macosx_binary_sha256 "38ea6955fb8c120eada1ff7985389b61ad5ca60a90a51025024638d92bfb43cf") - - set(win32_binary_url "https://cmake.org/files/v3.7/cmake-3.7.0-win32-x86.zip") - set(win32_binary_sha256 "26dc1e0c4e9ba6021ed171463f7c99b241c1c8f8ada4ea652f031ff835c6b928") - - set(win64_binary_url "https://cmake.org/files/v3.7/cmake-3.7.0-win64-x64.zip") - set(win64_binary_sha256 "11a2f8c4d52c5dbb6708a80f54d782fdfb2f5cd96c091ac51500c5607534e660") + include(${CMAKE_CURRENT_SOURCE_DIR}/CMakeUrls.cmake) #----------------------------------------------------------------------------- # Which archives ? diff --git a/CMakeUrls.cmake b/CMakeUrls.cmake new file mode 100644 index 000000000..702cec7c3 --- /dev/null +++ b/CMakeUrls.cmake @@ -0,0 +1,26 @@ + +#----------------------------------------------------------------------------- +# CMake sources +set(unix_source_url "https://cmake.org/files/v3.7/cmake-3.7.0.tar.gz") +set(unix_source_sha256 "ed63e05c41aeb6c036e503114ab15847f29c312f9f21f5f1a7060a4b4ec2fb31") + +set(windows_source_url "https://cmake.org/files/v3.7/cmake-3.7.0.zip") +set(windows_source_sha256 "e147c8f95b31b8cb0ef903b39ac21c9f07faf1c2131f7ec54a55e664d70224e7") + +#----------------------------------------------------------------------------- +# CMake binaries + +set(linux32_binary_url "NA") # Linux 32-bit binaries not available +set(linux32_binary_sha256 "NA") + +set(linux64_binary_url "https://cmake.org/files/v3.7/cmake-3.7.0-Linux-x86_64.tar.gz") +set(linux64_binary_sha256 "e075f63e6a9104b1c3d11666ae9546bc8812f7e791a49c4ce11effc063141b2a") + +set(macosx_binary_url "https://cmake.org/files/v3.7/cmake-3.7.0-Darwin-x86_64.tar.gz") +set(macosx_binary_sha256 "38ea6955fb8c120eada1ff7985389b61ad5ca60a90a51025024638d92bfb43cf") + +set(win32_binary_url "https://cmake.org/files/v3.7/cmake-3.7.0-win32-x86.zip") +set(win32_binary_sha256 "26dc1e0c4e9ba6021ed171463f7c99b241c1c8f8ada4ea652f031ff835c6b928") + +set(win64_binary_url "https://cmake.org/files/v3.7/cmake-3.7.0-win64-x64.zip") +set(win64_binary_sha256 "11a2f8c4d52c5dbb6708a80f54d782fdfb2f5cd96c091ac51500c5607534e660") diff --git a/docs/index.rst b/docs/index.rst index 281f91187..9ed58d4d1 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -32,6 +32,7 @@ The CMake python wheels provide `CMake 3.7.0 `. diff --git a/scripts/update_cmake_version.py b/scripts/update_cmake_version.py new file mode 100644 index 000000000..d920eb186 --- /dev/null +++ b/scripts/update_cmake_version.py @@ -0,0 +1,178 @@ +"""Command line executable allowing to update CMakeUrls.cmake + given a CMake version. +""" + +import argparse +import contextlib +import os +import re +import textwrap + +try: + import requests +except ImportError: + raise SystemExit( + "requests not available: " + "consider installing it running 'pip install requests'" + ) + +try: + from bs4 import BeautifulSoup +except ImportError: + raise SystemExit( + "BeautifulSoup not available: " + "consider installing it running 'pip install beautifulsoup4'" + ) + +ROOT_DIR = os.path.join(os.path.dirname(__file__), "..") + + +@contextlib.contextmanager +def _log(txt, verbose=True): + if verbose: + print(txt) + yield + if verbose: + print("%s - done" % txt) + + +def _major_minor(version): + """Given a string of the form ``X.Y.Z``, returns ``X.Y``.""" + return ".".join(version.split(".")[:2]) + + +def get_cmake_archive_urls_and_sha256s(version): + files_base_url = "https://cmake.org/files/v%s" % _major_minor(version) + + with _log("Collecting URLs and SHA256s from '%s'" % files_base_url): + + soup = BeautifulSoup(requests.get(files_base_url).text, 'html.parser') + + sha_256_file = "cmake-%s-SHA-256.txt" % version + + expected = { + "cmake-%s.tar.gz" % version: "unix_source", + "cmake-%s.zip" % version: "win_source", + "cmake-%s-Linux-x86_64.tar.gz" % version: "linux64_binary", + "cmake-%s-Darwin-x86_64.tar.gz" % version: "macosx_binary", + "cmake-%s-win32-x86.zip" % version: "win32_binary", + "cmake-%s-win64-x64.zip" % version: "win64_binary", + } + + # Check that (1) "a" text matches "href" value and (2) that all expected + # files are listed on the page. + found = 0 + for a in soup.find_all('a'): + if a.text in expected or a.text == sha_256_file: + found += 1 + assert a.text == a.get("href") + assert len(expected) + 1 == found + + # Get SHA256s and URLs + urls = {} + sha_256_url = files_base_url + "/" + sha_256_file + for line in requests.get(sha_256_url).text.splitlines(): + file = line.split()[1].strip() + if file in expected: + sha256 = line.split()[0].strip() + identifier = expected[file] + urls[identifier] = (files_base_url + "/" + file, sha256) + assert len(urls) == len(expected) + + return urls + + +def generate_cmake_variables(urls_and_sha256s): + template_inputs = {} + + # Get SHA256s and URLs + for var_prefix, urls_and_sha256s in urls_and_sha256s.items(): + template_inputs["%s_url" % var_prefix] = urls_and_sha256s[0] + template_inputs["%s_sha256" % var_prefix] = urls_and_sha256s[1] + + cmake_variables = textwrap.dedent(""" + #----------------------------------------------------------------------------- + # CMake sources + set(unix_source_url "{unix_source_url}") + set(unix_source_sha256 "{unix_source_sha256}") + + set(windows_source_url "{win_source_url}") + set(windows_source_sha256 "{win_source_sha256}") + + #----------------------------------------------------------------------------- + # CMake binaries + + set(linux32_binary_url "NA") # Linux 32-bit binaries not available + set(linux32_binary_sha256 "NA") + + set(linux64_binary_url "{linux64_binary_url}") + set(linux64_binary_sha256 "{linux64_binary_sha256}") + + set(macosx_binary_url "{macosx_binary_url}") + set(macosx_binary_sha256 "{macosx_binary_sha256}") + + set(win32_binary_url "{win32_binary_url}") + set(win32_binary_sha256 "{win32_binary_sha256}") + + set(win64_binary_url "{win64_binary_url}") + set(win64_binary_sha256 "{win64_binary_sha256}") + """).format(**template_inputs) + + return cmake_variables + + +def update_cmake_urls_script(version): + content = generate_cmake_variables( + get_cmake_archive_urls_and_sha256s(version)) + cmake_urls_filename = "CMakeUrls.cmake" + cmake_urls_filepath = os.path.join(ROOT_DIR, cmake_urls_filename) + + msg = "Updating '%s' with CMake version %s" % (cmake_urls_filename, version) + with _log(msg), open(cmake_urls_filepath, "w") as cmake_file: + cmake_file.write(content) + + +def _update_file(filepath, regex, replacement): + msg = "Updating %s" % os.path.relpath(filepath, ROOT_DIR) + with _log(msg): + pattern = re.compile(regex) + with open(filepath, 'r') as doc_file: + lines = doc_file.readlines() + updated_content = [] + for line in lines: + updated_content.append( + re.sub(pattern, replacement, line)) + with open(filepath, "w") as doc_file: + doc_file.writelines(updated_content) + + +def update_docs(version): + pattern = re.compile( + r"CMake \d.\d.\d ") + replacement = ( + "CMake %s " % ( + version, _major_minor(version))) + for filename in ["docs/index.rst", "README.rst"]: + _update_file(os.path.join(ROOT_DIR, filename), pattern, replacement) + + +def update_tests(version): + pattern = re.compile(r'expected_version = "\d.\d.\d"') + replacement = 'expected_version = "%s"' % version + _update_file(os.path.join( + ROOT_DIR, "tests/test_wheel.py"), pattern, replacement) + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument( + 'cmake_version', metavar='CMAKE_VERSION', type=str, + help='CMake version of the form X.Y.Z' + ) + args = parser.parse_args() + update_cmake_urls_script(args.cmake_version) + update_docs(args.cmake_version) + update_tests(args.cmake_version) + +if __name__ == "__main__": + main() From cee2739ee1b095b9483526ab13655db6517c8a29 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Thu, 1 Dec 2016 01:27:48 -0500 Subject: [PATCH 2/6] Update to CMake v3.7.1 --- CMakeUrls.cmake | 24 ++++++++++++------------ README.rst | 2 +- docs/index.rst | 2 +- tests/test_wheel.py | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/CMakeUrls.cmake b/CMakeUrls.cmake index 702cec7c3..15fdacc62 100644 --- a/CMakeUrls.cmake +++ b/CMakeUrls.cmake @@ -1,11 +1,11 @@ #----------------------------------------------------------------------------- # CMake sources -set(unix_source_url "https://cmake.org/files/v3.7/cmake-3.7.0.tar.gz") -set(unix_source_sha256 "ed63e05c41aeb6c036e503114ab15847f29c312f9f21f5f1a7060a4b4ec2fb31") +set(unix_source_url "https://cmake.org/files/v3.7/cmake-3.7.1.tar.gz") +set(unix_source_sha256 "449a5bce64dbd4d5b9517ebd1a1248ed197add6ad27934478976fd5f1f9330e1") -set(windows_source_url "https://cmake.org/files/v3.7/cmake-3.7.0.zip") -set(windows_source_sha256 "e147c8f95b31b8cb0ef903b39ac21c9f07faf1c2131f7ec54a55e664d70224e7") +set(windows_source_url "https://cmake.org/files/v3.7/cmake-3.7.1.zip") +set(windows_source_sha256 "17f34341cc63a892679085f2cad3e3d1f172e0518ee7dde43716175033494dfa") #----------------------------------------------------------------------------- # CMake binaries @@ -13,14 +13,14 @@ set(windows_source_sha256 "e147c8f95b31b8cb0ef903b39ac21c9f07faf1c2131f7ec54a55e set(linux32_binary_url "NA") # Linux 32-bit binaries not available set(linux32_binary_sha256 "NA") -set(linux64_binary_url "https://cmake.org/files/v3.7/cmake-3.7.0-Linux-x86_64.tar.gz") -set(linux64_binary_sha256 "e075f63e6a9104b1c3d11666ae9546bc8812f7e791a49c4ce11effc063141b2a") +set(linux64_binary_url "https://cmake.org/files/v3.7/cmake-3.7.1-Linux-x86_64.tar.gz") +set(linux64_binary_sha256 "7b4b7a1d9f314f45722899c0521c261e4bfab4a6b532609e37fef391da6bade2") -set(macosx_binary_url "https://cmake.org/files/v3.7/cmake-3.7.0-Darwin-x86_64.tar.gz") -set(macosx_binary_sha256 "38ea6955fb8c120eada1ff7985389b61ad5ca60a90a51025024638d92bfb43cf") +set(macosx_binary_url "https://cmake.org/files/v3.7/cmake-3.7.1-Darwin-x86_64.tar.gz") +set(macosx_binary_sha256 "1851d1448964893fdc5a8c05863326119f397a3790e0c84c40b83499c7960267") -set(win32_binary_url "https://cmake.org/files/v3.7/cmake-3.7.0-win32-x86.zip") -set(win32_binary_sha256 "26dc1e0c4e9ba6021ed171463f7c99b241c1c8f8ada4ea652f031ff835c6b928") +set(win32_binary_url "https://cmake.org/files/v3.7/cmake-3.7.1-win32-x86.zip") +set(win32_binary_sha256 "d2ec53ba3e3a12f734ed7127704ff9a83361e7cc6f9a0f0b3e2b56d9868a76b9") -set(win64_binary_url "https://cmake.org/files/v3.7/cmake-3.7.0-win64-x64.zip") -set(win64_binary_sha256 "11a2f8c4d52c5dbb6708a80f54d782fdfb2f5cd96c091ac51500c5607534e660") +set(win64_binary_url "https://cmake.org/files/v3.7/cmake-3.7.1-win64-x64.zip") +set(win64_binary_sha256 "659ecb8207e1266786188c7eaf45308458ba5f719c985970f6f55ec0b5a96746") diff --git a/README.rst b/README.rst index 51062c573..51a6f56c5 100644 --- a/README.rst +++ b/README.rst @@ -20,7 +20,7 @@ The suite of CMake tools were created by Kitware in response to the need for a powerful, cross-platform build environment for open-source projects such as ITK and VTK. -The CMake python wheels provide `CMake 3.7.0 `_. +The CMake python wheels provide `CMake 3.7.1 `_. This project is maintained by Jean-Christophe Fillion-Robin from Kitware Inc. It is covered by the `Apache License, Version 2.0 `_. diff --git a/docs/index.rst b/docs/index.rst index 9ed58d4d1..dad9ef960 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -15,7 +15,7 @@ The suite of CMake tools were created by Kitware in response to the need for a powerful, cross-platform build environment for open-source projects such as ITK and VTK. -The CMake python wheels provide `CMake 3.7.0 `_. +The CMake python wheels provide `CMake 3.7.1 `_. .. toctree:: :maxdepth: 2 diff --git a/tests/test_wheel.py b/tests/test_wheel.py index 3290376d7..68a0e4d00 100644 --- a/tests/test_wheel.py +++ b/tests/test_wheel.py @@ -13,7 +13,7 @@ def test_command_line(virtualenv, tmpdir): virtualenv.run("pip install %s" % wheels[0]) - expected_version = "3.7.0" + expected_version = "3.7.1" for executable_name in ["cmake", "cpack", "ctest"]: output = virtualenv.run( From 52938e11c651076301bae2a8d1ced415cc39e616 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Wed, 21 Dec 2016 18:37:53 -0500 Subject: [PATCH 3/6] Unpin development requirements Minimum required version will be updated if a specific feature or a bug fix from a newer version is required. --- requirements-dev.txt | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 6d908ed5a..5b7fb8e26 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,9 +1,9 @@ -codecov==2.0.5 -coverage==4.2 -flake8==3.0.4 -pytest==3.0.3 -pytest-cov==2.4.0 -pytest-runner==2.9 -pytest-virtualenv==1.2.4 -scikit-build==0.4.0 -virtualenv==15.0.3 +codecov>=2.0.5 +coverage>=4.2 +flake8>=3.0.4 +pytest>=3.0.3 +pytest-cov>=2.4.0 +pytest-runner>=2.9 +pytest-virtualenv>=1.2.4 +scikit-build>=0.4.0 +virtualenv>=15.0.3 From d5f49040483f1bb7569b05860b6518e796a5450c Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Wed, 21 Dec 2016 18:40:46 -0500 Subject: [PATCH 4/6] skbuild: Fix build within virtualenv on windows Updates "pytest-virtualenv" minimum required version to 1.2.5 to include manahl/pytest-plugins#37 --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 5b7fb8e26..f9776fc31 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -4,6 +4,6 @@ flake8>=3.0.4 pytest>=3.0.3 pytest-cov>=2.4.0 pytest-runner>=2.9 -pytest-virtualenv>=1.2.4 +pytest-virtualenv>=1.2.5 scikit-build>=0.4.0 virtualenv>=15.0.3 From 73c8570748d0073b6e3a2357a103c9c5a7ac8080 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Wed, 21 Dec 2016 18:47:25 -0500 Subject: [PATCH 5/6] requirements-dev: Update setup.py to support sdist build with scikit-build>=0.5.0 This is needed because following scikit-build/scikit-build@a371ed2, scikit-build whilelists commands expecting CMake to be run. See http://scikit-build.readthedocs.io/en/latest/usage.html#setup-options --- requirements-dev.txt | 2 +- setup.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index f9776fc31..77e964c9d 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -5,5 +5,5 @@ pytest>=3.0.3 pytest-cov>=2.4.0 pytest-runner>=2.9 pytest-virtualenv>=1.2.5 -scikit-build>=0.4.0 +scikit-build>=0.5.0 virtualenv>=15.0.3 diff --git a/setup.py b/setup.py index 0f9524d60..eb831db81 100755 --- a/setup.py +++ b/setup.py @@ -39,6 +39,7 @@ def _parse_requirements(filename): packages=['cmake'], cmake_install_dir='cmake/data', + cmake_with_sdist=True, entry_points={ 'console_scripts': [ From 56595546b6557e3586692c2508d65494023795cd Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Wed, 21 Dec 2016 19:35:22 -0500 Subject: [PATCH 6/6] Fix flake8 errors ./setup.py:20: [E305] expected 2 blank lines after class or function definition, found 1 requirements = [] ^ ./scripts/update_cmake_version.py:177: [E305] expected 2 blank lines after class or function definition, found 1 if __name__ == "__main__": ^ --- scripts/update_cmake_version.py | 1 + setup.py | 1 + 2 files changed, 2 insertions(+) diff --git a/scripts/update_cmake_version.py b/scripts/update_cmake_version.py index d920eb186..3dc42622e 100644 --- a/scripts/update_cmake_version.py +++ b/scripts/update_cmake_version.py @@ -174,5 +174,6 @@ def main(): update_docs(args.cmake_version) update_tests(args.cmake_version) + if __name__ == "__main__": main() diff --git a/setup.py b/setup.py index eb831db81..921e5c40f 100755 --- a/setup.py +++ b/setup.py @@ -17,6 +17,7 @@ def _parse_requirements(filename): return [str(ir.req) for ir in parse_requirements(filename, session=False)] + requirements = [] dev_requirements = _parse_requirements('requirements-dev.txt')