Skip to content

Commit

Permalink
Merge branch 'update-to-cmake-3.7.1'
Browse files Browse the repository at this point in the history
* update-to-cmake-3.7.1:
  Fix flake8 errors
  requirements-dev: Update setup.py to support sdist build with scikit-build>=0.5.0
  skbuild: Fix build within virtualenv on windows
  Unpin development requirements
  Update to CMake v3.7.1
  cmake: Add python CLI to easily update version of CMake
  • Loading branch information
jcfr committed Dec 22, 2016
2 parents 8062ead + 5659554 commit 3e78241
Show file tree
Hide file tree
Showing 9 changed files with 256 additions and 37 deletions.
26 changes: 1 addition & 25 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?
Expand Down
26 changes: 26 additions & 0 deletions CMakeUrls.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

#-----------------------------------------------------------------------------
# CMake sources
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.1.zip")
set(windows_source_sha256 "17f34341cc63a892679085f2cad3e3d1f172e0518ee7dde43716175033494dfa")

#-----------------------------------------------------------------------------
# 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.1-Linux-x86_64.tar.gz")
set(linux64_binary_sha256 "7b4b7a1d9f314f45722899c0521c261e4bfab4a6b532609e37fef391da6bade2")

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.1-win32-x86.zip")
set(win32_binary_sha256 "d2ec53ba3e3a12f734ed7127704ff9a83361e7cc6f9a0f0b3e2b56d9868a76b9")

set(win64_binary_url "https://cmake.org/files/v3.7/cmake-3.7.1-win64-x64.zip")
set(win64_binary_sha256 "659ecb8207e1266786188c7eaf45308458ba5f719c985970f6f55ec0b5a96746")
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://cmake.org/cmake/help/v3.7/index.html>`_.
The CMake python wheels provide `CMake 3.7.1 <https://cmake.org/cmake/help/v3.7/index.html>`_.

This project is maintained by Jean-Christophe Fillion-Robin from Kitware Inc.
It is covered by the `Apache License, Version 2.0 <http://www.apache.org/licenses/LICENSE-2.0>`_.
Expand Down
3 changes: 2 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://cmake.org/cmake/help/v3.6/index.html>`_.
The CMake python wheels provide `CMake 3.7.1 <https://cmake.org/cmake/help/v3.7/index.html>`_.

.. toctree::
:maxdepth: 2
Expand All @@ -32,6 +32,7 @@ The CMake python wheels provide `CMake 3.7.0 <https://cmake.org/cmake/help/v3.6/
:maxdepth: 2
:caption: For maintainers

update_cmake_version
make_a_release


Expand Down
35 changes: 35 additions & 0 deletions docs/update_cmake_version.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
====================
Update CMake version
====================

A developer should use the following steps to update the version ``X.Y.Z``
of CMake associated with the current CMake python distributions.

Available CMake archives can be found at https://cmake.org/files.


1. Install `requests` and `beautifulsoup4`::

$ pip install requests beautifulsoup4

2. Execute `scripts/update_cmake_version.py` command line tool with the desired
``X.Y.Z`` CMake version available for download. For example::

$ python scripts/update_cmake_version.py 3.7.1
Collecting URLs and SHA256s from 'https://cmake.org/files/v3.7'
Collecting URLs and SHA256s from 'https://cmake.org/files/v3.7' - done
Updating 'CMakeUrls.cmake' with CMake version 3.7.1
Updating 'CMakeUrls.cmake' with CMake version 3.7.1 - done
Updating docs/index.rst
Updating docs/index.rst - done
Updating README.rst
Updating README.rst - done
Updating tests/test_wheel.py
Updating tests/test_wheel.py - done

3. Create a topic named `update-to-cmake-X.Y.Z` and commit the changes

4. Create a `Pull Request`.

5. If all CI tests are passing, merge the topic and consider :doc:`making a new
release </make_a_release>`.
18 changes: 9 additions & 9 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -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.5
scikit-build>=0.5.0
virtualenv>=15.0.3
179 changes: 179 additions & 0 deletions scripts/update_cmake_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
"""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 <https://cmake.org/cmake/help/v\d.\d/index.html>")
replacement = (
"CMake %s <https://cmake.org/cmake/help/v%s/index.html>" % (
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()
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -39,6 +40,7 @@ def _parse_requirements(filename):
packages=['cmake'],

cmake_install_dir='cmake/data',
cmake_with_sdist=True,

entry_points={
'console_scripts': [
Expand Down
2 changes: 1 addition & 1 deletion tests/test_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 3e78241

Please sign in to comment.