forked from platformio/platformio-core
Move package "version" related things to "platformio.package.version" module
This commit is contained in:
@ -23,6 +23,7 @@ from SCons.Script import COMMAND_LINE_TARGETS # pylint: disable=import-error
|
||||
from platformio import fs, util
|
||||
from platformio.compat import WINDOWS
|
||||
from platformio.package.meta import PackageItem
|
||||
from platformio.package.version import get_original_version
|
||||
from platformio.platform.exception import UnknownBoard
|
||||
from platformio.platform.factory import PlatformFactory
|
||||
from platformio.project.config import ProjectOptions
|
||||
@ -210,7 +211,7 @@ def PrintConfiguration(env): # pylint: disable=too-many-statements
|
||||
def _get_packages_data():
|
||||
data = []
|
||||
for item in platform.dump_used_packages():
|
||||
original_version = util.get_original_version(item["version"])
|
||||
original_version = get_original_version(item["version"])
|
||||
info = "%s %s" % (item["name"], item["version"])
|
||||
extra = []
|
||||
if original_version:
|
||||
|
@ -26,9 +26,9 @@ from SCons.Script import DefaultEnvironment # pylint: disable=import-error
|
||||
from SCons.Script import Export # pylint: disable=import-error
|
||||
from SCons.Script import SConscript # pylint: disable=import-error
|
||||
|
||||
from platformio import fs
|
||||
from platformio import __version__, fs
|
||||
from platformio.compat import string_types
|
||||
from platformio.util import pioversion_to_intstr
|
||||
from platformio.package.version import pepver_to_semver
|
||||
|
||||
SRC_HEADER_EXT = ["h", "hpp"]
|
||||
SRC_ASM_EXT = ["S", "spp", "SPP", "sx", "s", "asm", "ASM"]
|
||||
@ -94,11 +94,16 @@ def BuildProgram(env):
|
||||
|
||||
def ProcessProgramDeps(env):
|
||||
def _append_pio_macros():
|
||||
core_version = pepver_to_semver(__version__)
|
||||
env.AppendUnique(
|
||||
CPPDEFINES=[
|
||||
(
|
||||
"PLATFORMIO",
|
||||
int("{0:02d}{1:02d}{2:02d}".format(*pioversion_to_intstr())),
|
||||
int(
|
||||
"{0:02d}{1:02d}{2:02d}".format(
|
||||
core_version.major, core_version.minor, core_version.patch
|
||||
)
|
||||
),
|
||||
)
|
||||
]
|
||||
)
|
||||
|
@ -16,12 +16,12 @@ import os
|
||||
|
||||
import click
|
||||
|
||||
from platformio import util
|
||||
from platformio.cache import cleanup_content_cache
|
||||
from platformio.commands.boards import print_boards
|
||||
from platformio.compat import dump_json_to_unicode
|
||||
from platformio.package.manager.platform import PlatformPackageManager
|
||||
from platformio.package.meta import PackageItem, PackageSpec
|
||||
from platformio.package.version import get_original_version
|
||||
from platformio.platform.exception import UnknownPlatform
|
||||
from platformio.platform.factory import PlatformFactory
|
||||
|
||||
@ -121,7 +121,7 @@ def _get_installed_platform_data(platform, with_boards=True, expose_packages=Tru
|
||||
continue
|
||||
item[key] = value
|
||||
if key == "version":
|
||||
item["originalVersion"] = util.get_original_version(value)
|
||||
item["originalVersion"] = get_original_version(value)
|
||||
data["packages"].append(item)
|
||||
|
||||
return data
|
||||
|
@ -19,7 +19,7 @@ from time import time
|
||||
import click
|
||||
import semantic_version
|
||||
|
||||
from platformio import __version__, app, exception, fs, telemetry, util
|
||||
from platformio import __version__, app, exception, fs, telemetry
|
||||
from platformio.cache import cleanup_content_cache
|
||||
from platformio.clients import http
|
||||
from platformio.commands import PlatformioCLI
|
||||
@ -32,6 +32,7 @@ from platformio.package.manager.library import LibraryPackageManager
|
||||
from platformio.package.manager.platform import PlatformPackageManager
|
||||
from platformio.package.manager.tool import ToolPackageManager
|
||||
from platformio.package.meta import PackageSpec
|
||||
from platformio.package.version import pepver_to_semver
|
||||
from platformio.platform.factory import PlatformFactory
|
||||
from platformio.proc import is_container
|
||||
|
||||
@ -87,12 +88,8 @@ def set_caller(caller=None):
|
||||
|
||||
class Upgrader(object):
|
||||
def __init__(self, from_version, to_version):
|
||||
self.from_version = semantic_version.Version.coerce(
|
||||
util.pepver_to_semver(from_version)
|
||||
)
|
||||
self.to_version = semantic_version.Version.coerce(
|
||||
util.pepver_to_semver(to_version)
|
||||
)
|
||||
self.from_version = pepver_to_semver(from_version)
|
||||
self.to_version = pepver_to_semver(to_version)
|
||||
|
||||
self._upgraders = [
|
||||
(semantic_version.Version("3.5.0-a.2"), self._update_dev_platforms),
|
||||
@ -141,9 +138,7 @@ def after_upgrade(ctx):
|
||||
|
||||
if last_version == "0.0.0":
|
||||
app.set_state_item("last_version", __version__)
|
||||
elif semantic_version.Version.coerce(
|
||||
util.pepver_to_semver(last_version)
|
||||
) > semantic_version.Version.coerce(util.pepver_to_semver(__version__)):
|
||||
elif pepver_to_semver(last_version) > pepver_to_semver(__version__):
|
||||
click.secho("*" * terminal_width, fg="yellow")
|
||||
click.secho(
|
||||
"Obsolete PIO Core v%s is used (previous was %s)"
|
||||
@ -229,9 +224,7 @@ def check_platformio_upgrade():
|
||||
update_core_packages(silent=True)
|
||||
|
||||
latest_version = get_latest_version()
|
||||
if semantic_version.Version.coerce(
|
||||
util.pepver_to_semver(latest_version)
|
||||
) <= semantic_version.Version.coerce(util.pepver_to_semver(__version__)):
|
||||
if pepver_to_semver(latest_version) <= pepver_to_semver(__version__):
|
||||
return
|
||||
|
||||
terminal_width, _ = click.get_terminal_size()
|
||||
|
@ -357,28 +357,9 @@ class PackageMetaData(object):
|
||||
self._version = (
|
||||
value
|
||||
if isinstance(value, semantic_version.Version)
|
||||
else self.to_semver(value)
|
||||
else cast_version_to_semver(value)
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def to_semver(value, force=True, raise_exception=False):
|
||||
assert value
|
||||
try:
|
||||
return semantic_version.Version(value)
|
||||
except ValueError:
|
||||
pass
|
||||
if force:
|
||||
try:
|
||||
return semantic_version.Version.coerce(value)
|
||||
except ValueError:
|
||||
pass
|
||||
if raise_exception:
|
||||
raise ValueError("Invalid SemVer version %s" % value)
|
||||
# parse commit hash
|
||||
if re.match(r"^[\da-f]+$", value, flags=re.I):
|
||||
return semantic_version.Version("0.0.0+sha." + value)
|
||||
return semantic_version.Version("0.0.0+" + value)
|
||||
|
||||
def as_dict(self):
|
||||
return dict(
|
||||
type=self.type,
|
||||
|
53
platformio/package/version.py
Normal file
53
platformio/package/version.py
Normal file
@ -0,0 +1,53 @@
|
||||
# Copyright (c) 2014-present PlatformIO <contact@platformio.org>
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import re
|
||||
|
||||
import semantic_version
|
||||
|
||||
|
||||
def cast_version_to_semver(value, force=True, raise_exception=False):
|
||||
assert value
|
||||
try:
|
||||
return semantic_version.Version(value)
|
||||
except ValueError:
|
||||
pass
|
||||
if force:
|
||||
try:
|
||||
return semantic_version.Version.coerce(value)
|
||||
except ValueError:
|
||||
pass
|
||||
if raise_exception:
|
||||
raise ValueError("Invalid SemVer version %s" % value)
|
||||
# parse commit hash
|
||||
if re.match(r"^[\da-f]+$", value, flags=re.I):
|
||||
return semantic_version.Version("0.0.0+sha." + value)
|
||||
return semantic_version.Version("0.0.0+" + value)
|
||||
|
||||
|
||||
def pepver_to_semver(pepver):
|
||||
return cast_version_to_semver(
|
||||
re.sub(r"(\.\d+)\.?(dev|a|b|rc|post)", r"\1-\2.", pepver, 1)
|
||||
)
|
||||
|
||||
|
||||
def get_original_version(version):
|
||||
if version.count(".") != 2:
|
||||
return None
|
||||
_, raw = version.split(".")[:2]
|
||||
if int(raw) <= 99:
|
||||
return None
|
||||
if int(raw) <= 9999:
|
||||
return "%s.%s" % (raw[:-2], int(raw[-2:]))
|
||||
return "%s.%s.%s" % (raw[:-4], int(raw[-4:-2]), int(raw[-2:]))
|
@ -18,8 +18,9 @@ import subprocess
|
||||
import click
|
||||
import semantic_version
|
||||
|
||||
from platformio import __version__, fs, proc, util
|
||||
from platformio import __version__, fs, proc
|
||||
from platformio.package.manager.tool import ToolPackageManager
|
||||
from platformio.package.version import pepver_to_semver
|
||||
from platformio.platform._packages import PlatformPackagesMixin
|
||||
from platformio.platform._run import PlatformRunMixin
|
||||
from platformio.platform.board import PlatformBoardConfig
|
||||
@ -31,7 +32,7 @@ class PlatformBase( # pylint: disable=too-many-instance-attributes,too-many-pub
|
||||
PlatformPackagesMixin, PlatformRunMixin
|
||||
):
|
||||
|
||||
PIO_VERSION = semantic_version.Version(util.pepver_to_semver(__version__))
|
||||
CORE_SEMVER = pepver_to_semver(__version__)
|
||||
_BOARDS_CACHE = {}
|
||||
|
||||
def __init__(self, manifest_path):
|
||||
@ -110,10 +111,10 @@ class PlatformBase( # pylint: disable=too-many-instance-attributes,too-many-pub
|
||||
def ensure_engine_compatible(self):
|
||||
if not self.engines or "platformio" not in self.engines:
|
||||
return True
|
||||
if self.PIO_VERSION in semantic_version.SimpleSpec(self.engines["platformio"]):
|
||||
if self.CORE_SEMVER in semantic_version.SimpleSpec(self.engines["platformio"]):
|
||||
return True
|
||||
raise IncompatiblePlatform(
|
||||
self.name, str(self.PIO_VERSION), self.engines["platformio"]
|
||||
self.name, str(self.CORE_SEMVER), self.engines["platformio"]
|
||||
)
|
||||
|
||||
def get_dir(self):
|
||||
|
@ -244,26 +244,12 @@ def get_mdns_services():
|
||||
|
||||
|
||||
def pioversion_to_intstr():
|
||||
""" Legacy for framework-zephyr/scripts/platformio/platformio-build-pre.py"""
|
||||
vermatch = re.match(r"^([\d\.]+)", __version__)
|
||||
assert vermatch
|
||||
return [int(i) for i in vermatch.group(1).split(".")[:3]]
|
||||
|
||||
|
||||
def pepver_to_semver(pepver):
|
||||
return re.sub(r"(\.\d+)\.?(dev|a|b|rc|post)", r"\1-\2.", pepver, 1)
|
||||
|
||||
|
||||
def get_original_version(version):
|
||||
if version.count(".") != 2:
|
||||
return None
|
||||
_, raw = version.split(".")[:2]
|
||||
if int(raw) <= 99:
|
||||
return None
|
||||
if int(raw) <= 9999:
|
||||
return "%s.%s" % (raw[:-2], int(raw[-2:]))
|
||||
return "%s.%s.%s" % (raw[:-4], int(raw[-4:-2]), int(raw[-2:]))
|
||||
|
||||
|
||||
def items_to_list(items):
|
||||
if isinstance(items, list):
|
||||
return items
|
||||
|
Reference in New Issue
Block a user