From cb5598c47252d563e7b9744834a43bc1b3e813a0 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Sat, 28 Mar 2020 19:44:48 +0000 Subject: project.boost: factor out BoostVersion --- project/boost/build.py | 71 ++-------------------------------------- project/boost/version.py | 77 ++++++++++++++++++++++++++++++++++++++++++++ project/ci/appveyor/boost.py | 5 +-- project/ci/travis/boost.py | 5 +-- 4 files changed, 85 insertions(+), 73 deletions(-) create mode 100644 project/boost/version.py (limited to 'project') diff --git a/project/boost/build.py b/project/boost/build.py index 14c4b80..e9f2ffc 100644 --- a/project/boost/build.py +++ b/project/boost/build.py @@ -40,6 +40,7 @@ import sys import tempfile import urllib.request +from project.boost.version import Version from project.configuration import Configuration from project.linkage import Linkage from project.platform import Platform @@ -74,74 +75,6 @@ def _run_executable(cmd_line): return subprocess.run(cmd_line, check=True) -_Version = namedtuple('_Version', ['major', 'minor', 'patch']) - - -@total_ordering -class BoostVersion: - def __init__(self, major, minor, patch): - self._impl = _Version(major, minor, patch) - - @property - def major(self): - return self._impl.major - - @property - def minor(self): - return self._impl.minor - - @property - def patch(self): - return self._impl.patch - - def __lt__(self, other): - return self._impl < other._impl - - def __eq__(self, other): - return self._impl == other._impl - - @staticmethod - def from_string(s): - result = re.match(r'^(\d+)\.(\d+)\.(\d+)$', s) - if result is None: - raise ValueError(f'invalid Boost version: {s}') - major = int(result.group(1)) - minor = int(result.group(2)) - patch = int(result.group(3)) - return BoostVersion(major, minor, patch) - - def __str__(self): - return f'{self.major}.{self.minor}.{self.patch}' - - @property - def archive_ext(self): - return '.tar.gz' - - def dir_path(self, parent_dir): - return os.path.join(parent_dir, self.dir_name) - - @property - def dir_name(self): - return f'boost_{self.major}_{self.minor}_{self.patch}' - - @property - def archive_name(self): - return f'{self.dir_name}{self.archive_ext}' - - def _get_bintray_url(self): - return f'https://dl.bintray.com/boostorg/release/{self}/source/{self.archive_name}' - - def _get_sourceforge_url(self): - return f'https://sourceforge.net/projects/boost/files/boost/{self}/{self.archive_name}/download' - - def get_download_urls(self): - if self._impl < _Version(1, 63, 0): - # For versions older than 1.63.0, SourceForge is the only option: - return [self._get_sourceforge_url()] - # Otherwise, Bintray is preferred (the official website links to it). - return [self._get_bintray_url(), self._get_sourceforge_url()] - - class BoostArchive: def __init__(self, version, path): self.version = version @@ -407,7 +340,7 @@ def _parse_args(argv=None): type=_parse_dir, default='.', help='directory to unpack the archive to') download.add_argument('boost_version', metavar='VERSION', - type=BoostVersion.from_string, + type=Version.from_string, help='Boost version (in the MAJOR.MINOR.PATCH format)') build = subparsers.add_parser('build', help='build the libraries') diff --git a/project/boost/version.py b/project/boost/version.py new file mode 100644 index 0000000..3ba9901 --- /dev/null +++ b/project/boost/version.py @@ -0,0 +1,77 @@ +# Copyright (c) 2020 Egor Tensin +# This file is part of the "cmake-common" project. +# For details, see https://github.com/egor-tensin/cmake-common. +# Distributed under the MIT License. + +from collections import namedtuple +from functools import total_ordering +import os.path +import re + + +_Version = namedtuple('_Version', ['major', 'minor', 'patch']) + + +@total_ordering +class Version: + def __init__(self, major, minor, patch): + self._impl = _Version(major, minor, patch) + + @property + def major(self): + return self._impl.major + + @property + def minor(self): + return self._impl.minor + + @property + def patch(self): + return self._impl.patch + + def __lt__(self, other): + return self._impl < other._impl + + def __eq__(self, other): + return self._impl == other._impl + + @staticmethod + def from_string(s): + result = re.match(r'^(\d+)\.(\d+)\.(\d+)$', s) + if result is None: + raise ValueError(f'invalid Boost version: {s}') + major = int(result.group(1)) + minor = int(result.group(2)) + patch = int(result.group(3)) + return Version(major, minor, patch) + + def __str__(self): + return f'{self.major}.{self.minor}.{self.patch}' + + @property + def archive_ext(self): + return '.tar.gz' + + def dir_path(self, parent_dir): + return os.path.join(parent_dir, self.dir_name) + + @property + def dir_name(self): + return f'boost_{self.major}_{self.minor}_{self.patch}' + + @property + def archive_name(self): + return f'{self.dir_name}{self.archive_ext}' + + def _get_bintray_url(self): + return f'https://dl.bintray.com/boostorg/release/{self}/source/{self.archive_name}' + + def _get_sourceforge_url(self): + return f'https://sourceforge.net/projects/boost/files/boost/{self}/{self.archive_name}/download' + + def get_download_urls(self): + if self._impl < _Version(1, 63, 0): + # For versions older than 1.63.0, SourceForge is the only option: + return [self._get_sourceforge_url()] + # Otherwise, Bintray is preferred (the official website links to it). + return [self._get_bintray_url(), self._get_sourceforge_url()] diff --git a/project/ci/appveyor/boost.py b/project/ci/appveyor/boost.py index 4218dd6..aa2d77a 100644 --- a/project/ci/appveyor/boost.py +++ b/project/ci/appveyor/boost.py @@ -21,7 +21,8 @@ import os import os.path import sys -from project.boost.build import BoostVersion, main as build_main +from project.boost.version import Version +from project.boost.build import main as build_main def _env(name): @@ -82,7 +83,7 @@ def build_appveyor(argv=None): args = _parse_args(argv) _check_appveyor() - version = BoostVersion.from_string(_get_boost_version()) + version = Version.from_string(_get_boost_version()) appveyor_argv = [ 'download', '--unpack', _get_build_dir(), diff --git a/project/ci/travis/boost.py b/project/ci/travis/boost.py index 46ae96b..6d3e911 100644 --- a/project/ci/travis/boost.py +++ b/project/ci/travis/boost.py @@ -19,7 +19,8 @@ import os import os.path import sys -from project.boost.build import BoostVersion, main as build_main +from project.boost.version import Version +from project.boost.build import main as build_main def _env(name): @@ -80,7 +81,7 @@ def build_travis(argv=None): args = _parse_args(argv) _check_travis() - version = BoostVersion.from_string(_get_boost_version()) + version = Version.from_string(_get_boost_version()) travis_argv = [ 'download', '--unpack', _get_build_dir(), -- cgit v1.2.3