From 78f3e01854d82c696578fbeb733902997864f81d Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Fri, 30 Mar 2018 00:23:02 -0700 Subject: [PATCH 1/4] Fix version bump script --- script/version_bump.py | 157 ++++++++++++++++++++++++----------------- 1 file changed, 91 insertions(+), 66 deletions(-) diff --git a/script/version_bump.py b/script/version_bump.py index 0500fc45957..59060a7075b 100755 --- a/script/version_bump.py +++ b/script/version_bump.py @@ -3,82 +3,97 @@ import argparse import re +from packaging.version import Version + from homeassistant import const -PARSE_PATCH = r'(?P\d+)(\.(?P\D+)(?P\d+))?' +def _bump_release(release, bump_type): + """Bump a release tuple consisting of 3 numbers.""" + major, minor, patch = release + + if bump_type == 'patch': + patch += 1 + elif bump_type == 'minor': + minor += 1 + patch = 0 + + return major, minor, patch -def format_patch(patch_parts): - """Format the patch parts back into a patch string.""" - return '{patch}.{prerel}{prerelversion}'.format(**patch_parts) - - -def bump_version(cur_major, cur_minor, cur_patch, bump_type): +def bump_version(version, bump_type): """Return a new version given a current version and action.""" - patch_parts = re.match(PARSE_PATCH, cur_patch).groupdict() - patch_parts['patch'] = int(patch_parts['patch']) - if patch_parts['prerelversion'] is not None: - patch_parts['prerelversion'] = int(patch_parts['prerelversion']) + to_change = {} - if bump_type == 'release_patch': + if bump_type == 'minor': + # Convert 0.67.3 to 0.68.0 + # Convert 0.67.3.b5 to 0.68.0 + # Convert 0.67.3.dev0 to 0.68.0 + # Convert 0.67.0.b5 to 0.67.0 + # Convert 0.67.0.dev0 to 0.67.0 + to_change['dev'] = None + to_change['pre'] = None + + if not version.is_prerelease or version.release[2] != 0: + to_change['release'] = _bump_release(version.release, 'minor') + + elif bump_type == 'patch': # Convert 0.67.3 to 0.67.4 # Convert 0.67.3.b5 to 0.67.3 # Convert 0.67.3.dev0 to 0.67.3 - new_major = cur_major - new_minor = cur_minor + to_change['dev'] = None + to_change['pre'] = None - if patch_parts['prerel'] is None: - new_patch = str(patch_parts['patch'] + 1) - else: - new_patch = str(patch_parts['patch']) + if not version.is_prerelease: + to_change['release'] = _bump_release(version.release, 'patch') elif bump_type == 'dev': # Convert 0.67.3 to 0.67.4.dev0 # Convert 0.67.3.b5 to 0.67.4.dev0 # Convert 0.67.3.dev0 to 0.67.3.dev1 - new_major = cur_major - - if patch_parts['prerel'] == 'dev': - new_minor = cur_minor - patch_parts['prerelversion'] += 1 - new_patch = format_patch(patch_parts) + if version.is_devrelease: + to_change['dev'] = ('dev', version.dev + 1) else: - new_minor = cur_minor + 1 - new_patch = '0.dev0' + to_change['pre'] = ('dev', 0) + to_change['release'] = _bump_release(version.release, 'minor') elif bump_type == 'beta': - # Convert 0.67.5 to 0.67.8.b0 - # Convert 0.67.0.dev0 to 0.67.0.b0 - # Convert 0.67.5.b4 to 0.67.5.b5 - new_major = cur_major - new_minor = cur_minor + # Convert 0.67.5 to 0.67.6b0 + # Convert 0.67.0.dev0 to 0.67.0b0 + # Convert 0.67.5.b4 to 0.67.5b5 - if patch_parts['prerel'] is None: - patch_parts['patch'] += 1 - patch_parts['prerel'] = 'b' - patch_parts['prerelversion'] = 0 + if version.is_devrelease: + to_change['dev'] = None + to_change['pre'] = ('b', 0) - elif patch_parts['prerel'] == 'b': - patch_parts['prerelversion'] += 1 - - elif patch_parts['prerel'] == 'dev': - patch_parts['prerel'] = 'b' - patch_parts['prerelversion'] = 0 + elif version.is_prerelease: + if version.pre[0] == 'a': + to_change['pre'] = ('b', 0) + if version.pre[0] == 'b': + to_change['pre'] = ('b', version.pre[1] + 1) + else: + to_change['pre'] = ('b', 0) + to_change['release'] = _bump_release(version.release, 'patch') else: - raise Exception('Can only bump from beta or no prerel version') + to_change['release'] = _bump_release(version.release, 'patch') + to_change['pre'] = ('b', 0) - new_patch = format_patch(patch_parts) + else: + assert False, 'Unsupported type: {}'.format(bump_type) - return new_major, new_minor, new_patch + temp = Version('0') + temp._version = version._version._replace(**to_change) + return Version(str(temp)) -def write_version(major, minor, patch): +def write_version(version): """Update Home Assistant constant file with new version.""" with open('homeassistant/const.py') as fil: content = fil.read() + major, minor, patch = str(version).split('.', 2) + content = re.sub('MAJOR_VERSION = .*\n', 'MAJOR_VERSION = {}\n'.format(major), content) @@ -100,35 +115,45 @@ def main(): parser.add_argument( 'type', help="The type of the bump the version to.", - choices=['beta', 'dev', 'release_patch'], + choices=['beta', 'dev', 'patch', 'minor'], ) arguments = parser.parse_args() - write_version(*bump_version(const.MAJOR_VERSION, const.MINOR_VERSION, - const.PATCH_VERSION, arguments.type)) + current = Version(const.__version__) + bumped = bump_version(current, arguments.type) + assert bumped > current, 'BUG! New version is not newer than old version' + write_version(bumped) def test_bump_version(): """Make sure it all works.""" - assert bump_version(0, 56, '0', 'beta') == \ - (0, 56, '1.b0') - assert bump_version(0, 56, '0.b3', 'beta') == \ - (0, 56, '0.b4') - assert bump_version(0, 56, '0.dev0', 'beta') == \ - (0, 56, '0.b0') + assert bump_version(Version('0.56.0'), 'beta') == Version('0.56.1b0') + assert bump_version(Version('0.56.0b3'), 'beta') == Version('0.56.0b4') + assert bump_version(Version('0.56.0.dev0'), 'beta') == Version('0.56.0b0') - assert bump_version(0, 56, '3', 'dev') == \ - (0, 57, '0.dev0') - assert bump_version(0, 56, '0.b3', 'dev') == \ - (0, 57, '0.dev0') - assert bump_version(0, 56, '0.dev0', 'dev') == \ - (0, 56, '0.dev1') + assert bump_version(Version('0.56.3'), 'dev') == Version('0.57.0.dev0') + assert bump_version(Version('0.56.0b3'), 'dev') == Version('0.57.0.dev0') + assert bump_version(Version('0.56.0.dev0'), 'dev') == \ + Version('0.56.0.dev1') - assert bump_version(0, 56, '3', 'release_patch') == \ - (0, 56, '4') - assert bump_version(0, 56, '3.b3', 'release_patch') == \ - (0, 56, '3') - assert bump_version(0, 56, '0.dev0', 'release_patch') == \ - (0, 56, '0') + assert bump_version(Version('0.56.3'), 'patch') == \ + Version('0.56.4') + assert bump_version(Version('0.56.3.b3'), 'patch') == \ + Version('0.56.3') + assert bump_version(Version('0.56.0.dev0'), 'patch') == \ + Version('0.56.0') + + assert bump_version(Version('0.56.0'), 'minor') == \ + Version('0.57.0') + assert bump_version(Version('0.56.3'), 'minor') == \ + Version('0.57.0') + assert bump_version(Version('0.56.0.b3'), 'minor') == \ + Version('0.56.0') + assert bump_version(Version('0.56.3.b3'), 'minor') == \ + Version('0.57.0') + assert bump_version(Version('0.56.0.dev0'), 'minor') == \ + Version('0.56.0') + assert bump_version(Version('0.56.2.dev0'), 'minor') == \ + Version('0.57.0') if __name__ == '__main__': From 9fc8a8f67900a3db5be22e9d5a589a37db46b823 Mon Sep 17 00:00:00 2001 From: Johann Kellerman Date: Fri, 30 Mar 2018 04:57:19 +0200 Subject: [PATCH 2/4] Check whitelisted paths #13107 (#13154) --- homeassistant/core.py | 10 +++++++--- tests/test_core.py | 3 ++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/homeassistant/core.py b/homeassistant/core.py index 65db82a1fbe..feb8d331ae8 100644 --- a/homeassistant/core.py +++ b/homeassistant/core.py @@ -1060,15 +1060,19 @@ class Config(object): """Check if the path is valid for access from outside.""" assert path is not None - parent = pathlib.Path(path) + thepath = pathlib.Path(path) try: - parent = parent.resolve() # pylint: disable=no-member + # The file path does not have to exist (it's parent should) + if thepath.exists(): + thepath = thepath.resolve() + else: + thepath = thepath.parent.resolve() except (FileNotFoundError, RuntimeError, PermissionError): return False for whitelisted_path in self.whitelist_external_dirs: try: - parent.relative_to(whitelisted_path) + thepath.relative_to(whitelisted_path) return True except ValueError: pass diff --git a/tests/test_core.py b/tests/test_core.py index 7a1610c0966..1fcd9416f36 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -809,7 +809,8 @@ class TestConfig(unittest.TestCase): valid = [ test_file, - tmp_dir + tmp_dir, + os.path.join(tmp_dir, 'notfound321') ] for path in valid: assert self.config.is_allowed_path(path) From 0f2cfe7f2760a32ed287e1de0d9fe30f2e3e6b7e Mon Sep 17 00:00:00 2001 From: dramamoose Date: Fri, 30 Mar 2018 15:10:25 -0600 Subject: [PATCH 3/4] Fix FLUX_LED error when no color is set (#13527) * Handle turn_on situation when no color is set As is, an error gets thrown when turn_on is called without an HS value. By adding an if statement, we only try to set RGB if an HS value is applied. * Fix Whitespace Issues * Made Requested Changes --- homeassistant/components/light/flux_led.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/light/flux_led.py b/homeassistant/components/light/flux_led.py index ed0836f1449..6ffdcc0bb4a 100644 --- a/homeassistant/components/light/flux_led.py +++ b/homeassistant/components/light/flux_led.py @@ -204,7 +204,12 @@ class FluxLight(Light): self._bulb.turnOn() hs_color = kwargs.get(ATTR_HS_COLOR) - rgb = color_util.color_hs_to_RGB(*hs_color) + + if hs_color: + rgb = color_util.color_hs_to_RGB(*hs_color) + else: + rgb = None + brightness = kwargs.get(ATTR_BRIGHTNESS) effect = kwargs.get(ATTR_EFFECT) From 4dea55b29c665955d27d4d1913589d51fae62ca9 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Fri, 30 Mar 2018 14:11:32 -0700 Subject: [PATCH 4/4] Version bump to 0.66.0 --- homeassistant/const.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/const.py b/homeassistant/const.py index ccb75634601..3dce8882015 100644 --- a/homeassistant/const.py +++ b/homeassistant/const.py @@ -2,7 +2,7 @@ """Constants used by Home Assistant components.""" MAJOR_VERSION = 0 MINOR_VERSION = 66 -PATCH_VERSION = '0b3' +PATCH_VERSION = '0' __short_version__ = '{}.{}'.format(MAJOR_VERSION, MINOR_VERSION) __version__ = '{}.{}'.format(__short_version__, PATCH_VERSION) REQUIRED_PYTHON_VER = (3, 5, 3)