Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move catkin_prepare_release script as well as dependencies to catkin_pkg #941

Merged
merged 2 commits into from
May 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 0 additions & 43 deletions bin/catkin_package_version

This file was deleted.

404 changes: 0 additions & 404 deletions bin/catkin_prepare_release

This file was deleted.

2 changes: 1 addition & 1 deletion package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<buildtool_export_depend>cmake</buildtool_export_depend>

<depend>python-argparse</depend>
<depend version_gt="0.2.9">python-catkin-pkg</depend>
<depend version_gt="0.4.3">python-catkin-pkg</depend>

<build_depend>python-empy</build_depend>

Expand Down
148 changes: 2 additions & 146 deletions python/catkin/package_version.py
Original file line number Diff line number Diff line change
@@ -1,146 +1,2 @@
# Software License Agreement (BSD License)
#
# Copyright (c) 2012, Willow Garage, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of Willow Garage, Inc. nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

from __future__ import print_function
import datetime
import docutils.core
import os
import re

from catkin_pkg.changelog_generator import FORTHCOMING_LABEL


def _replace_version(package_str, new_version):
"""
replaces the version tag in contents if there is only one instance

:param package_str: str contents of package.xml
:param new_version: str version number
:returns: str new package.xml
:raises RuntimeError:
"""
# try to replace contens
new_package_str, number_of_subs = re.subn('<version([^<>]*)>[^<>]*</version>', '<version\g<1>>%s</version>' % new_version, package_str)
if number_of_subs != 1:
raise RuntimeError('Illegal number of version tags: %s' % (number_of_subs))
return new_package_str


def _check_for_version_comment(package_str, new_version):
"""
checks if a comment is present behind the version tag and return it

:param package_str: str contents of package.xml
:param version: str version number
:returns: str comment if available, else None
"""
version_tag = '>%s</version>' % new_version
pattern = '%s[ \t]*%s *(.+) *%s' % (re.escape(version_tag), re.escape('<!--'), re.escape('-->'))
comment = re.search(pattern, package_str)
if comment:
comment = comment.group(1)
return comment


def update_versions(paths, new_version):
"""
bulk replace of version: searches for package.xml files directly in given folders and replaces version tag within.

:param paths: list of string, folder names
:param new_version: version string "int.int.int"
:raises RuntimeError: if any one package.xml cannot be updated
"""
files = {}
for path in paths:
package_path = os.path.join(path, 'package.xml')
with open(package_path, 'r') as f:
package_str = f.read()
try:
new_package_str = _replace_version(package_str, new_version)
comment = _check_for_version_comment(new_package_str, new_version)
if comment:
print('NOTE: The package manifest "%s" contains a comment besides the version tag:\n %s' % (path, comment))
except RuntimeError as rue:
raise RuntimeError('Could not bump version number in file %s: %s' % (package_path, str(rue)))
files[package_path] = new_package_str
# if all replacements successful, write back modified package.xml
for package_path, new_package_str in files.items():
with open(package_path, 'w') as f:
f.write(new_package_str)


def get_forthcoming_label(rst):
document = docutils.core.publish_doctree(rst)
forthcoming_label = None
for child in document.children:
title = None
if isinstance(child, docutils.nodes.subtitle):
title = child
elif isinstance(child, docutils.nodes.section):
section = child
if len(section.children) > 0 and isinstance(section.children[0], docutils.nodes.title):
title = section.children[0]
if title and len(title.children) > 0 and isinstance(title.children[0], docutils.nodes.Text):
title_text = title.children[0].rawsource
if FORTHCOMING_LABEL.lower() in title_text.lower():
if forthcoming_label:
raise RuntimeError('Found multiple forthcoming sections')
forthcoming_label = title_text
return forthcoming_label


def update_changelog_sections(changelogs, new_version):
# rename forthcoming sections to new_version including current date
new_changelog_data = {}
new_label = '%s (%s)' % (new_version, datetime.date.today().isoformat())
for pkg_name, (changelog_path, changelog, forthcoming_label) in changelogs.items():
data = rename_section(changelog.rst, forthcoming_label, new_label)
new_changelog_data[changelog_path] = data

for changelog_path, data in new_changelog_data.items():
with open(changelog_path, 'wb') as f:
f.write(data.encode('utf-8'))


def rename_section(data, old_label, new_label):
valid_section_characters = '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'

def replace_section(match):
section_char = match.group(2)[0]
return new_label + '\n' + section_char * len(new_label)
pattern = '^(' + re.escape(old_label) + ')\n([' + re.escape(valid_section_characters) + ']+)$'
data, count = re.subn(pattern, replace_section, data, flags=re.MULTILINE)
if count == 0:
raise RuntimeError('Could not find section')
if count > 1:
raise RuntimeError('Found multiple matching sections')
return data
# for backward compatibility
from catkin_pkg.package_version import * # noqa
134 changes: 2 additions & 132 deletions python/catkin/terminal_color.py
Original file line number Diff line number Diff line change
@@ -1,132 +1,2 @@
# Software License Agreement (BSD License)
#
# Copyright (c) 2012, Willow Garage, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of Willow Garage, Inc. nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

"""
Module to enable color terminal output
"""

from __future__ import print_function

import string
import os

_ansi = {}


def ansi(key):
"""Returns the escape sequence for a given ansi color key"""
global _ansi
return _ansi[key]


def enable_ANSI_colors():
"""
Populates the global module dictionary `ansi` with ANSI escape sequences.
"""
global _ansi
color_order = [
'black', 'red', 'green', 'yellow', 'blue', 'purple', 'cyan', 'white'
]
short_colors = {
'black': 'k', 'red': 'r', 'green': 'g', 'yellow': 'y', 'blue': 'b',
'purple': 'p', 'cyan': 'c', 'white': 'w'
}
_ansi = {
'escape': '\033', 'reset': 0, '|': 0,
'boldon': 1, '!': 1, 'italicson': 3, '/': 3, 'ulon': 4, '_': 4,
'invon': 7, 'boldoff': 22, 'italicsoff': 23,
'uloff': 24, 'invoff': 27
}

# Convert plain numbers to escapes
for key in _ansi:
if key != 'escape':
_ansi[key] = '{0}[{1}m'.format(_ansi['escape'], _ansi[key])

# Foreground
for index, color in enumerate(color_order):
_ansi[color] = '{0}[{1}m'.format(_ansi['escape'], 30 + index)
_ansi[color + 'f'] = _ansi[color]
_ansi[short_colors[color] + 'f'] = _ansi[color + 'f']

# Background
for index, color in enumerate(color_order):
_ansi[color + 'b'] = '{0}[{1}m'.format(_ansi['escape'], 40 + index)
_ansi[short_colors[color] + 'b'] = _ansi[color + 'b']

# Fmt sanitizers
_ansi['atexclimation'] = '@!'
_ansi['atfwdslash'] = '@/'
_ansi['atunderscore'] = '@_'
_ansi['atbar'] = '@|'


def disable_ANSI_colors():
"""
Sets all the ANSI escape sequences to empty strings, effectively disabling
console colors.
"""
global _ansi
for key in _ansi:
_ansi[key] = ''

# Default to ansi colors on
enable_ANSI_colors()
if os.name in ['nt']:
disable_ANSI_colors()


class ColorTemplate(string.Template):
delimiter = '@'


def sanitize(msg):
"""Sanitizes the existing msg, use before adding color annotations"""
msg = msg.replace('@', '@@')
msg = msg.replace('{', '{{')
msg = msg.replace('}', '}}')
msg = msg.replace('@@!', '@{atexclimation}')
msg = msg.replace('@@/', '@{atfwdslash}')
msg = msg.replace('@@_', '@{atunderscore}')
msg = msg.replace('@@|', '@{atbar}')
return msg


def fmt(msg):
"""Replaces color annotations with ansi escape sequences"""
global _ansi
msg = msg.replace('@!', '@{boldon}')
msg = msg.replace('@/', '@{italicson}')
msg = msg.replace('@_', '@{ulon}')
msg = msg.replace('@|', '@{reset}')
t = ColorTemplate(msg)
return t.substitute(_ansi) + ansi('reset')
# for backward compatibility
from catkin_pkg.terminal_color import * # noqa
61 changes: 2 additions & 59 deletions python/catkin/workspace_vcs.py
Original file line number Diff line number Diff line change
@@ -1,59 +1,2 @@
# Software License Agreement (BSD License)
#
# Copyright (c) 2012, Willow Garage, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of Willow Garage, Inc. nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

from __future__ import print_function
import os
import subprocess


def get_repository_type(path):
for vcs_type in ['bzr', 'git', 'hg', 'svn']:
if os.path.isdir(os.path.join(path, '.%s' % vcs_type)):
return vcs_type
return None


def vcs_remotes(path, vcs_type=None):
if vcs_type is None:
vcs_type = get_repository_type(path)
if vcs_type == 'git':
return subprocess.check_output(['git', 'remote', '-v'], cwd=path)
elif vcs_type == 'hg':
return subprocess.check_output(['hg', 'paths'], cwd=path)
elif vcs_type == 'svn':
output = subprocess.check_output(['svn', 'info'], cwd=path)
for line in output.split(os.linesep):
if line.startswith('URL: '):
return line
raise RuntimeError('Could not determine URL of svn working copy')
else:
raise RuntimeError('"remotes" command not supported for vcs type "%s"' % vcs_type)
# for backward compatibility
from catkin_pkg.workspace_vcs import * # noqa
Loading