From f0d502164a9ba666bf5f300002e298dae1df8c8a Mon Sep 17 00:00:00 2001 From: Maurits van Rees Date: Sat, 17 Aug 2019 00:26:05 +0200 Subject: [PATCH] Ran black. Black sees a SyntaxError in changelog.py, so that one is not changed. --- bootstrap.py | 112 ++++++++++++++++++-------------- plone/__init__.py | 2 +- plone/releaser/__init__.py | 54 +++++++--------- plone/releaser/buildout.py | 68 ++++++++------------ plone/releaser/db.py | 11 ++-- plone/releaser/manage.py | 92 +++++++++++++------------- plone/releaser/package.py | 120 ++++++++++++++++------------------ plone/releaser/pypi.py | 5 +- plone/releaser/release.py | 128 ++++++++++++++++++------------------- setup.py | 94 +++++++++++++-------------- 10 files changed, 335 insertions(+), 351 deletions(-) diff --git a/bootstrap.py b/bootstrap.py index a629566..bdda4e8 100644 --- a/bootstrap.py +++ b/bootstrap.py @@ -27,7 +27,7 @@ tmpeggs = tempfile.mkdtemp() -usage = '''\ +usage = """\ [DESIRED PYTHON FOR BUILDOUT] bootstrap.py [options] Bootstraps a buildout-based project. @@ -37,30 +37,41 @@ Note that by using --find-links to point to local resources, you can keep this script from going over the network. -''' +""" parser = OptionParser(usage=usage) parser.add_option("-v", "--version", help="use a specific zc.buildout version") -parser.add_option("-t", "--accept-buildout-test-releases", - dest='accept_buildout_test_releases', - action="store_true", default=False, - help=("Normally, if you do not specify a --version, the " - "bootstrap script and buildout gets the newest " - "*final* versions of zc.buildout and its recipes and " - "extensions for you. If you use this flag, " - "bootstrap and buildout will get the newest releases " - "even if they are alphas or betas.")) -parser.add_option("-c", "--config-file", - help=("Specify the path to the buildout configuration " - "file to be used.")) -parser.add_option("-f", "--find-links", - help=("Specify a URL to search for buildout releases")) -parser.add_option("--allow-site-packages", - action="store_true", default=False, - help=("Let bootstrap.py use existing site packages")) -parser.add_option("--setuptools-version", - help="use a specific setuptools version") +parser.add_option( + "-t", + "--accept-buildout-test-releases", + dest="accept_buildout_test_releases", + action="store_true", + default=False, + help=( + "Normally, if you do not specify a --version, the " + "bootstrap script and buildout gets the newest " + "*final* versions of zc.buildout and its recipes and " + "extensions for you. If you use this flag, " + "bootstrap and buildout will get the newest releases " + "even if they are alphas or betas." + ), +) +parser.add_option( + "-c", + "--config-file", + help=("Specify the path to the buildout configuration " "file to be used."), +) +parser.add_option( + "-f", "--find-links", help=("Specify a URL to search for buildout releases") +) +parser.add_option( + "--allow-site-packages", + action="store_true", + default=False, + help=("Let bootstrap.py use existing site packages"), +) +parser.add_option("--setuptools-version", help="use a specific setuptools version") options, args = parser.parse_args() @@ -77,25 +88,26 @@ from urllib2 import urlopen ez = {} -exec(urlopen('https://bootstrap.pypa.io/ez_setup.py').read(), ez) +exec(urlopen("https://bootstrap.pypa.io/ez_setup.py").read(), ez) if not options.allow_site_packages: # ez_setup imports site, which adds site packages # this will remove them from the path to ensure that incompatible versions # of setuptools are not in the path import site + # inside a virtualenv, there is no 'getsitepackages'. # We can't remove these reliably - if hasattr(site, 'getsitepackages'): + if hasattr(site, "getsitepackages"): for sitepackage_path in site.getsitepackages(): sys.path[:] = [x for x in sys.path if sitepackage_path not in x] setup_args = dict(to_dir=tmpeggs, download_delay=0) if options.setuptools_version is not None: - setup_args['version'] = options.setuptools_version + setup_args["version"] = options.setuptools_version -ez['use_setuptools'](**setup_args) +ez["use_setuptools"](**setup_args) import setuptools import pkg_resources @@ -110,28 +122,35 @@ ws = pkg_resources.working_set -cmd = [sys.executable, '-c', - 'from setuptools.command.easy_install import main; main()', - '-mZqNxd', tmpeggs] +cmd = [ + sys.executable, + "-c", + "from setuptools.command.easy_install import main; main()", + "-mZqNxd", + tmpeggs, +] find_links = os.environ.get( - 'bootstrap-testing-find-links', - options.find_links or - ('http://downloads.buildout.org/' - if options.accept_buildout_test_releases else None) - ) + "bootstrap-testing-find-links", + options.find_links + or ( + "http://downloads.buildout.org/" + if options.accept_buildout_test_releases + else None + ), +) if find_links: - cmd.extend(['-f', find_links]) + cmd.extend(["-f", find_links]) -setuptools_path = ws.find( - pkg_resources.Requirement.parse('setuptools')).location +setuptools_path = ws.find(pkg_resources.Requirement.parse("setuptools")).location -requirement = 'zc.buildout' +requirement = "zc.buildout" version = options.version if version is None and not options.accept_buildout_test_releases: # Figure out the most recent final version of zc.buildout. import setuptools.package_index - _final_parts = '*final-', '*final' + + _final_parts = "*final-", "*final" def _final_version(parsed_version): try: @@ -139,12 +158,11 @@ def _final_version(parsed_version): except AttributeError: # Older setuptools for part in parsed_version: - if (part[:1] == '*') and (part not in _final_parts): + if (part[:1] == "*") and (part not in _final_parts): return False return True - index = setuptools.package_index.PackageIndex( - search_path=[setuptools_path]) + index = setuptools.package_index.PackageIndex(search_path=[setuptools_path]) if find_links: index.add_find_links((find_links,)) req = pkg_resources.Requirement.parse(requirement) @@ -163,13 +181,13 @@ def _final_version(parsed_version): best.sort() version = best[-1].version if version: - requirement = '=='.join((requirement, version)) + requirement = "==".join((requirement, version)) cmd.append(requirement) import subprocess + if subprocess.call(cmd, env=dict(os.environ, PYTHONPATH=setuptools_path)) != 0: - raise Exception( - "Failed to execute command:\n%s" % repr(cmd)[1:-1]) + raise Exception("Failed to execute command:\n%s" % repr(cmd)[1:-1]) ###################################################################### # Import and run buildout @@ -178,12 +196,12 @@ def _final_version(parsed_version): ws.require(requirement) import zc.buildout.buildout -if not [a for a in args if '=' not in a]: - args.append('bootstrap') +if not [a for a in args if "=" not in a]: + args.append("bootstrap") # if -c was provided, we push it back into args for buildout' main function if options.config_file is not None: - args[0:0] = ['-c', options.config_file] + args[0:0] = ["-c", options.config_file] zc.buildout.buildout.main(args) shutil.rmtree(tmpeggs) diff --git a/plone/__init__.py b/plone/__init__.py index 68c04af..03d08ff 100644 --- a/plone/__init__.py +++ b/plone/__init__.py @@ -1,2 +1,2 @@ # -*- coding: utf-8 -*- -__import__('pkg_resources').declare_namespace(__name__) +__import__("pkg_resources").declare_namespace(__name__) diff --git a/plone/releaser/__init__.py b/plone/releaser/__init__.py index c39911e..bbebcd7 100644 --- a/plone/releaser/__init__.py +++ b/plone/releaser/__init__.py @@ -1,44 +1,38 @@ # -*- coding: utf-8 -*- THIRD_PARTY_PACKAGES = ( - 'Zope2', - 'ZODB3', - 'txtfilter', - 'Products.CMFActionIcons', - 'Products.CMFCalendar', - 'Products.CMFCore', - 'Products.CMFDefault', - 'Products.CMFTopic', - 'Products.CMFUid', - 'Products.DCWorkflow', - 'Products.GenericSetup', - 'Products.GroupUserFolder', - 'Products.PluggableAuthService', - 'Products.PluginRegistry', - 'Products.ZCatalog', + "Zope2", + "ZODB3", + "txtfilter", + "Products.CMFActionIcons", + "Products.CMFCalendar", + "Products.CMFCore", + "Products.CMFDefault", + "Products.CMFTopic", + "Products.CMFUid", + "Products.DCWorkflow", + "Products.GenericSetup", + "Products.GroupUserFolder", + "Products.PluggableAuthService", + "Products.PluginRegistry", + "Products.ZCatalog", ) -IGNORED_PACKAGES = ( - 'plone.releaser', -) +IGNORED_PACKAGES = ("plone.releaser",) ALWAYS_CHECKED_OUT = ( - 'Plone', - 'Products.CMFPlone', - 'plone.app.upgrade', - 'plone.app.locales', + "Plone", + "Products.CMFPlone", + "plone.app.upgrade", + "plone.app.locales", ) # Upon checking a package... # ... ask every time if an action should be performed -ACTION_INTERACTIVE = 'interactive' +ACTION_INTERACTIVE = "interactive" # ... don't ask anything and perform all actions -ACTION_BATCH = 'batch' +ACTION_BATCH = "batch" # ... don't ask anything *AND* don't make any action, just show the status # of the package -ACTION_REPORT = 'report' +ACTION_REPORT = "report" -PACKAGE_ACTIONS = ( - ACTION_BATCH, - ACTION_INTERACTIVE, - ACTION_REPORT, -) +PACKAGE_ACTIONS = (ACTION_BATCH, ACTION_INTERACTIVE, ACTION_REPORT) diff --git a/plone/releaser/buildout.py b/plone/releaser/buildout.py index 13476fe..5ae4e6e 100644 --- a/plone/releaser/buildout.py +++ b/plone/releaser/buildout.py @@ -12,12 +12,11 @@ from UserDict import UserDict PATH_RE = re.compile( - '(\w+://)(.+@)*([\w\d\.]+)(:[\d]+){0,1}/(?P.+(?=\.git))(\.git)' + "(\w+://)(.+@)*([\w\d\.]+)(:[\d]+){0,1}/(?P.+(?=\.git))(\.git)" ) class Source(object): - def __init__(self, protocol=None, url=None, push_url=None, branch=None): self.protocol = protocol self.url = url @@ -26,19 +25,20 @@ def __init__(self, protocol=None, url=None, push_url=None, branch=None): def create_from_string(self, source_string): protocol, url, extra_1, extra_2, extra_3 = ( - lambda a, b, c=None, d=None, e=None: (a, b, c, d, e))(*source_string.split()) + lambda a, b, c=None, d=None, e=None: (a, b, c, d, e) + )(*source_string.split()) for param in [extra_1, extra_2, extra_3]: if param is not None: - key, value = param.split('=') + key, value = param.split("=") setattr(self, key, value) self.protocol = protocol self.url = url if self.push_url is not None: - self.push_url = self.push_url.split('=')[-1] + self.push_url = self.push_url.split("=")[-1] if self.branch is None: - self.branch = 'master' + self.branch = "master" else: - self.branch = self.branch.split('=')[-1] + self.branch = self.branch.split("=")[-1] return self @property @@ -46,12 +46,11 @@ def path(self): if self.url: match = PATH_RE.match(self.url) if match: - return match.groupdict()['path'] + return match.groupdict()["path"] return None class VersionsFile(object): - def __init__(self, file_location): self.file_location = file_location @@ -62,13 +61,10 @@ def versions(self): We use strict=False to avoid a DuplicateOptionError. This happens in coredev 4.3 because we pin 'babel' and 'Babel'. """ - config = ConfigParser( - interpolation=ExtendedInterpolation(), - strict=False, - ) + config = ConfigParser(interpolation=ExtendedInterpolation(), strict=False) with open(self.file_location) as f: config.read_file(f) - return config['versions'] + return config["versions"] def __contains__(self, package_name): return package_name.lower() in self.versions.keys() @@ -81,7 +77,7 @@ def __getitem__(self, package_name): def __setitem__(self, package_name, new_version): path = os.path.join(os.getcwd(), self.file_location) - with open(path, 'r') as f: + with open(path, "r") as f: versionstxt = f.read() if package_name not in self: @@ -90,10 +86,10 @@ def __setitem__(self, package_name, new_version): reg = re.compile( "(^{0}[\s\=]+)[0-9\.abrc]+(.post\d+)?(.dev\d+)?".format(package_name), - re.MULTILINE + re.MULTILINE, ) newVersionsTxt = reg.sub(r"\g<1>{0}".format(new_version), versionstxt) - with open(path, 'w') as f: + with open(path, "w") as f: f.write(newVersionsTxt) def get(self, package_name): @@ -104,7 +100,6 @@ def set(self, package_name, new_version): class SourcesFile(UserDict): - def __init__(self, file_location): self.file_location = file_location @@ -115,7 +110,7 @@ def data(self): with open(self.file_location) as f: config.read_file(f) sources_dict = OrderedDict() - for name, value in config['sources'].items(): + for name, value in config["sources"].items(): source = Source().create_from_string(value) sources_dict[name] = source return sources_dict @@ -128,7 +123,6 @@ def __iter__(self): class CheckoutsFile(UserDict): - def __init__(self, file_location): self.file_location = file_location @@ -137,8 +131,8 @@ def data(self): config = ConfigParser(interpolation=ExtendedInterpolation()) with open(self.file_location) as f: config.read_file(f) - checkouts = config.get('buildout', 'auto-checkout') - checkout_list = checkouts.split('\n') + checkouts = config.get("buildout", "auto-checkout") + checkout_list = checkouts.split("\n") return checkout_list def __contains__(self, package_name): @@ -146,25 +140,18 @@ def __contains__(self, package_name): def __setitem__(self, package_name, enabled=True): path = os.path.join(os.getcwd(), self.file_location) - with open(path, 'r') as f: + with open(path, "r") as f: checkoutstxt = f.read() - with open(path, 'w') as f: + with open(path, "w") as f: if enabled: fixes_text = "# test-only fixes:" - reg = re.compile( - "^[\s]*{0}\n".format(fixes_text), - re.MULTILINE - ) + reg = re.compile("^[\s]*{0}\n".format(fixes_text), re.MULTILINE) newCheckoutsTxt = reg.sub( - ' {0}\n{1}\n'.format(package_name, fixes_text), - checkoutstxt + " {0}\n{1}\n".format(package_name, fixes_text), checkoutstxt ) else: - reg = re.compile( - "^[\s]*{0}\n".format(package_name), - re.MULTILINE - ) - newCheckoutsTxt = reg.sub('', checkoutstxt) + reg = re.compile("^[\s]*{0}\n".format(package_name), re.MULTILINE) + newCheckoutsTxt = reg.sub("", checkoutstxt) f.write(newCheckoutsTxt) def __delitem__(self, package_name): @@ -189,11 +176,12 @@ def remove(self, package_name): class Buildout(object): - - def __init__(self, - sources_file='sources.cfg', - checkouts_file='checkouts.cfg', - versions_file='versions.cfg'): + def __init__( + self, + sources_file="sources.cfg", + checkouts_file="checkouts.cfg", + versions_file="versions.cfg", + ): self.sources = SourcesFile(sources_file) self.versions = VersionsFile(versions_file) self.checkouts = CheckoutsFile(checkouts_file) diff --git a/plone/releaser/db.py b/plone/releaser/db.py index 5d53d15..5982865 100644 --- a/plone/releaser/db.py +++ b/plone/releaser/db.py @@ -4,21 +4,20 @@ class IgnoresDB(object): - def __init__(self): - self._filename = '.package_ignores' + self._filename = ".package_ignores" if not os.path.isfile(self._filename): - open(self._filename, 'w').close() + open(self._filename, "w").close() - with open(self._filename, 'r') as f: + with open(self._filename, "r") as f: content = f.read() - if content != '': + if content != "": self._db = json.loads(content) else: self._db = {} def save(self): - with open(self._filename, 'w+') as f: + with open(self._filename, "w+") as f: f.write(json.dumps(self._db)) def get(self, package_name): diff --git a/plone/releaser/manage.py b/plone/releaser/manage.py index 77c06d5..29575ef 100644 --- a/plone/releaser/manage.py +++ b/plone/releaser/manage.py @@ -30,13 +30,14 @@ def checkPypi(user): pass else: if not pypi.can_user_release_package_to_pypi(user, package): - print("{0}: {1}".format( - package, - ', '.join(pypi.get_users_with_release_rights(package)) - )) + print( + "{0}: {1}".format( + package, ", ".join(pypi.get_users_with_release_rights(package)) + ) + ) -@named('jenkins') +@named("jenkins") def jenkins_report(): """Read-only version of checkAllPackagesForUpdates.""" sources = buildout.sources @@ -45,72 +46,70 @@ def jenkins_report(): pkg(action=ACTION_REPORT) -@arg('--interactive', default=False) +@arg("--interactive", default=False) def checkPackageForUpdates(package_name, **kwargs): pkg = Package(buildout, package_name) - if kwargs['interactive']: + if kwargs["interactive"]: pkg(action=ACTION_INTERACTIVE) else: pkg(action=ACTION_BATCH) -@named('report') -@arg('--interactive', default=False) +@named("report") +@arg("--interactive", default=False) def checkAllPackagesForUpdates(**kwargs): sources = buildout.sources - for package_name, source in Bar('Scanning').iter(sources.iteritems()): + for package_name, source in Bar("Scanning").iter(sources.iteritems()): pkg = Package(buildout, package_name) - if kwargs['interactive']: + if kwargs["interactive"]: pkg(action=ACTION_INTERACTIVE) else: pkg(action=ACTION_REPORT) def pulls(): - client_id = 'b9f6639835b8c9cf462a' - client_secret = keyring.get_password('plone.releaser', client_id) + client_id = "b9f6639835b8c9cf462a" + client_secret = keyring.get_password("plone.releaser", client_id) g = Github(client_id=client_id, client_secret=client_secret) for package_name, source in buildout.sources.iteritems(): if source.path: repo = g.get_repo(source.path) - pulls = [a for a in repo.get_pulls( - 'open') if a.head.ref == source.branch] + pulls = [a for a in repo.get_pulls("open") if a.head.ref == source.branch] if pulls: print(package_name) for pull in pulls: - print(" {0}: {1} ({2})".format( - pull.user.login, - pull.title, - pull.url - )) + print( + " {0}: {1} ({2})".format( + pull.user.login, pull.title, pull.url + ) + ) -@named('changelog') -@arg('--start') -@arg('--end', default='here') +@named("changelog") +@arg("--start") +@arg("--end", default="here") def changelog(**kwargs): from plone.releaser.changelog import build_unified_changelog - build_unified_changelog(kwargs['start'], kwargs['end']) + build_unified_changelog(kwargs["start"], kwargs["end"]) -@named('launchpad') + +@named("launchpad") def create_launchpad_release(version): - launchpad = Launchpad.login_with('plone.releaser', 'production') - plone = launchpad.projects['plone'] + launchpad = Launchpad.login_with("plone.releaser", "production") + plone = launchpad.projects["plone"] parsed_version = StrictVersion(version) # Blech. This feels flimsy - series_name = '.'.join([str(a) for a in parsed_version.version[0:2]]) + series_name = ".".join([str(a) for a in parsed_version.version[0:2]]) series = plone.getSeries(name=series_name) if series is None: return "No series named {0}.".format(series_name) now = datetime.datetime.now().isoformat() - milestone = series.newMilestone(name=version, - date_targeted=now) + milestone = series.newMilestone(name=version, date_targeted=now) # TODO: Get release notes - release = milestone.createProductRelease(date_released=now, - release_notes='') + release = milestone.createProductRelease(date_released=now, release_notes="") release_url = release.web_link @@ -119,16 +118,17 @@ def create_launchpad_release(version): def check_checkout(package_name, path): if package_name not in CheckoutsFile(path): - msg = 'Your package {0} is not on auto-checkout section' + msg = "Your package {0} is not on auto-checkout section" raise KeyError(msg.format(package_name)) def append_jenkins_build_number_to_package_version(jenkins_build_number): from zest.releaser.vcs import BaseVersionControl from zest.releaser.utils import cleanup_version + vcs = BaseVersionControl() old_version = cleanup_version(vcs.version) - new_version = '{0}.{1}'.format(old_version, jenkins_build_number) + new_version = "{0}.{1}".format(old_version, jenkins_build_number) vcs.version = new_version return new_version @@ -139,20 +139,22 @@ def set_package_version(version_file_path, package_name, new_version): class Manage(object): - def __call__(self, **kwargs): parser = ArghParser() parser.add_commands( - [checkPypi, - checkPackageForUpdates, - checkAllPackagesForUpdates, - pulls, - changelog, - create_launchpad_release, - check_checkout, - append_jenkins_build_number_to_package_version, - set_package_version, - jenkins_report]) + [ + checkPypi, + checkPackageForUpdates, + checkAllPackagesForUpdates, + pulls, + changelog, + create_launchpad_release, + check_checkout, + append_jenkins_build_number_to_package_version, + set_package_version, + jenkins_report, + ] + ) parser.dispatch() diff --git a/plone/releaser/package.py b/plone/releaser/package.py index 92ebfed..f4f3b46 100644 --- a/plone/releaser/package.py +++ b/plone/releaser/package.py @@ -28,12 +28,7 @@ def git_repo(source): http://preshing.com/20110920/the-python-with-statement-by-example/ """ tmp_dir = mkdtemp() - repo = git.Repo.clone_from( - source.url, - tmp_dir, - branch=source.branch, - depth=100 - ) + repo = git.Repo.clone_from(source.url, tmp_dir, branch=source.branch, depth=100) # give the control back yield repo @@ -88,7 +83,7 @@ def __init__(self, buildout, package): def __call__(self, action=ACTION_INTERACTIVE): if action not in PACKAGE_ACTIONS: - print('This package action does not exist: {0}'.format(action)) + print("This package action does not exist: {0}".format(action)) return self.set_interaction_and_report(action) @@ -96,9 +91,11 @@ def __call__(self, action=ACTION_INTERACTIVE): # - is on the ignored list # - there is no version available # - is not hosted on a git VCS - if self.name in IGNORED_PACKAGES or \ - self.version is None or \ - not self.is_git_hosted(): + if ( + self.name in IGNORED_PACKAGES + or self.version is None + or not self.is_git_hosted() + ): return # clone the package and gather data about it @@ -118,43 +115,44 @@ def __call__(self, action=ACTION_INTERACTIVE): if latest_ignored_commit is not None: try: commits_since_ignore = self._commits_between( - repo, - latest_ignored_commit, - self.source.branch + repo, latest_ignored_commit, self.source.branch ) except git.exc.GitCommandError: - print('\nCould not read commits for package {0}'.format(self.name)) + print("\nCould not read commits for package {0}".format(self.name)) return # if there are no changes since the last release (i.e. last tag) - if not commits_since_release \ - or 'Back to development' in commits_since_release[0].message \ - or commits_since_release[0].message.startswith('vb'): + if ( + not commits_since_release + or "Back to development" in commits_since_release[0].message + or commits_since_release[0].message.startswith("vb") + ): self.remove() elif commits_since_ignore is None: # Check for checkout if self.name not in self.buildout.checkouts: - msg = '\nWARNING: No auto-checkout exists for {0}\n Changes in {0}:' # noqa + msg = ( + "\nWARNING: No auto-checkout exists for {0}\n Changes in {0}:" + ) # noqa self.print_commits( - commits_since_release, - message=msg.format(self.name) + commits_since_release, message=msg.format(self.name) ) if self.name in THIRD_PARTY_PACKAGES: - msg = 'NOTE: {0} is a third-party package.' + msg = "NOTE: {0} is a third-party package." print(msg.format(self.name)) self.add(commits_since_release) else: if not self.interactive: - msg = '\nChanges in {0}:'.format(self.name) + msg = "\nChanges in {0}:".format(self.name) self.print_commits(commits_since_release, message=msg) if self.name in THIRD_PARTY_PACKAGES: - msg = 'NOTE: {0} is a third-party package.' + msg = "NOTE: {0} is a third-party package." print(msg.format(self.name)) def set_interaction_and_report(self, action): @@ -169,9 +167,9 @@ def set_interaction_and_report(self, action): self.report_only = False def is_git_hosted(self): - if self.source.protocol != 'git': + if self.source.protocol != "git": if self.report_only: - msg = 'Skipped check of {0} as it\'s not a git repo.' + msg = "Skipped check of {0} as it's not a git repo." print(msg.format(self.name)) return False return True @@ -182,17 +180,17 @@ def get_version(self): version = self.buildout.get_version(self.name) except (NoOptionError, KeyError): if self.report_only: - print('No version available for {0}'.format(self.name)) + print("No version available for {0}".format(self.name)) return version def latest_tag(self, repo): tag = None try: - tag = repo.git.describe('--abbrev=0', '--tags') + tag = repo.git.describe("--abbrev=0", "--tags") except git.exc.GitCommandError: if self.report_only: - print('Unable to check tags for {0}'.format(self.name)) + print("Unable to check tags for {0}".format(self.name)) return tag @@ -200,63 +198,53 @@ def latest_commits(self, repo): commits = None try: - commits = self._commits_between( - repo, - self.version, - self.source.branch - ) + commits = self._commits_between(repo, self.version, self.source.branch) except git.exc.GitCommandError: - print('\nCould not read commits for package {0}'.format(self.name)) + print("\nCould not read commits for package {0}".format(self.name)) return commits @staticmethod def _commits_between(repo, start, end): - return list( - repo.iter_commits( - '{0}..{1}'.format(start, end) - ) - ) + return list(repo.iter_commits("{0}..{1}".format(start, end))) def remove(self): - if self.name in self.buildout.checkouts and \ - self.name not in ALWAYS_CHECKED_OUT: - msg = '\nNo new changes in {0}, but it is listed for auto-checkout.' # noqa + if self.name in self.buildout.checkouts and self.name not in ALWAYS_CHECKED_OUT: + msg = "\nNo new changes in {0}, but it is listed for auto-checkout." # noqa print(msg.format(self.name)) if self.report_only: return - msg = 'Remove {0} from checkouts.cfg'.format(self.name) + msg = "Remove {0} from checkouts.cfg".format(self.name) if confirm(msg, default=True, skip=not self.interactive): self.buildout.remove_from_checkouts(self.name) with buildout_coredev() as core_repo: - checkouts_path = os.path.join(os.getcwd(), 'checkouts.cfg') + checkouts_path = os.path.join(os.getcwd(), "checkouts.cfg") core_repo.git.add(checkouts_path) - msg = 'No new changes in {0}'.format(self.name) + msg = "No new changes in {0}".format(self.name) core_repo.git.commit(message=msg) def add(self, commits_since_release): if self.report_only: return - msg = 'Add {0} to checkouts.cfg'.format(self.name) + msg = "Add {0} to checkouts.cfg".format(self.name) if confirm(msg, default=True, skip=not self.interactive): self.buildout.add_to_checkouts(self.name) with buildout_coredev() as core_repo: - checkouts_path = os.path.join(os.getcwd(), 'checkouts.cfg') + checkouts_path = os.path.join(os.getcwd(), "checkouts.cfg") core_repo.index.add([checkouts_path]) - core_repo.index.commit('{0} has changes.'.format(self.name)) - - elif confirm('Ignore changes in {0}'.format(self.name), - default=False, - skip=not self.interactive): - self.commit_ignores.set( - self.name, - commits_since_release[0].hexsha - ) + core_repo.index.commit("{0} has changes.".format(self.name)) + + elif confirm( + "Ignore changes in {0}".format(self.name), + default=False, + skip=not self.interactive, + ): + self.commit_ignores.set(self.name, commits_since_release[0].hexsha) @staticmethod def print_commits(commits_list, message=None): @@ -264,28 +252,28 @@ def print_commits(commits_list, message=None): print(message) for commit in commits_list: - print(' {0}: {1}'.format( - commit.author.name.encode('ascii', 'replace'), - commit.summary.encode('ascii', 'replace') - )) + print( + " {0}: {1}".format( + commit.author.name.encode("ascii", "replace"), + commit.summary.encode("ascii", "replace"), + ) + ) def update_version(self, tag): if tag <= self.version: return - msg = '\nNewer version {0} is available for {1} (Currently {2})' + msg = "\nNewer version {0} is available for {1} (Currently {2})" print(msg.format(tag, self.name, self.version)) if self.report_only: return - if confirm('Update versions.cfg', - default=True, - skip=not self.interactive): + if confirm("Update versions.cfg", default=True, skip=not self.interactive): self.buildout.set_version(self.name, tag) with buildout_coredev() as core_repo: - versions_path = os.path.join(os.getcwd(), 'versions.cfg') + versions_path = os.path.join(os.getcwd(), "versions.cfg") core_repo.git.add(versions_path) - core_repo.git.commit(message='{0}={1}'.format(self.name, tag)) + core_repo.git.commit(message="{0}={1}".format(self.name, tag)) core_repo.git.push() diff --git a/plone/releaser/pypi.py b/plone/releaser/pypi.py index eb7600c..91db3dd 100644 --- a/plone/releaser/pypi.py +++ b/plone/releaser/pypi.py @@ -7,9 +7,8 @@ def get_users_with_release_rights(package_name): - client = ServerProxy('https://pypi.org/pypi') - existing_admins = set([ - user for role, user in client.package_roles(package_name)]) + client = ServerProxy("https://pypi.org/pypi") + existing_admins = set([user for role, user in client.package_roles(package_name)]) return existing_admins diff --git a/plone/releaser/release.py b/plone/releaser/release.py index 1e0dd35..e793e17 100644 --- a/plone/releaser/release.py +++ b/plone/releaser/release.py @@ -15,72 +15,73 @@ import textwrap # Define texts to check for during prereleaser or add during postrelease. -NOTHING_CHANGED_YET = '*add item here*' +NOTHING_CHANGED_YET = "*add item here*" BREAKING_TEXT = """ Breaking changes: - {} -""".format(NOTHING_CHANGED_YET) +""".format( + NOTHING_CHANGED_YET +) FEATURE_TEXT = """ New features: - {} -""".format(NOTHING_CHANGED_YET) +""".format( + NOTHING_CHANGED_YET +) BUGFIXES_TEXT = """ Bug fixes: - {} -""".format(NOTHING_CHANGED_YET) -HEADERS = [ - BREAKING_TEXT, - FEATURE_TEXT, - BUGFIXES_TEXT, -] +""".format( + NOTHING_CHANGED_YET +) +HEADERS = [BREAKING_TEXT, FEATURE_TEXT, BUGFIXES_TEXT] # Used by changelog.py: -HEADINGS = [ - 'Breaking changes:', - 'New features:', - 'Bug fixes:', -] +HEADINGS = ["Breaking changes:", "New features:", "Bug fixes:"] # For compatibility with previous names of the headers. INCOMPATIBILITIES_TEXT = """ Incompatibilities: - {} -""".format(NOTHING_CHANGED_YET) +""".format( + NOTHING_CHANGED_YET +) NEW_TEXT = """ New: - {} -""".format(NOTHING_CHANGED_YET) +""".format( + NOTHING_CHANGED_YET +) FIXES_TEXT = """ Fixes: - {} -""".format(NOTHING_CHANGED_YET) -OLD_HEADERS = [ - INCOMPATIBILITIES_TEXT, - NEW_TEXT, - FIXES_TEXT, -] +""".format( + NOTHING_CHANGED_YET +) +OLD_HEADERS = [INCOMPATIBILITIES_TEXT, NEW_TEXT, FIXES_TEXT] ALL_HEADERS = copy(HEADERS) ALL_HEADERS.extend(OLD_HEADERS) OLD_HEADING_MAPPING = { - 'Incompatibilities:': 'Breaking changes:', - 'New:': 'New features:', - 'Fixes:': 'Bug fixes:', + "Incompatibilities:": "Breaking changes:", + "New:": "New features:", + "Fixes:": "Bug fixes:", } KNOWN_HEADINGS = copy(HEADINGS) KNOWN_HEADINGS.extend(OLD_HEADING_MAPPING.keys()) ALWAYS_CHECKED_OUT_PACKAGES = ( - 'Plone', - 'Products.CMFPlone', - 'plone.app.upgrade', - 'plone.app.locales', + "Plone", + "Products.CMFPlone", + "plone.app.upgrade", + "plone.app.locales", ) + def set_nothing_changed_yet(data): """Set line that we look for in prerelease. @@ -90,7 +91,7 @@ def set_nothing_changed_yet(data): Note that currently this must be a single line, because zest.releaser looks for this text in each line. """ - data['nothing_changed_yet'] = NOTHING_CHANGED_YET + data["nothing_changed_yet"] = NOTHING_CHANGED_YET def set_required_changelog(data): @@ -98,7 +99,7 @@ def set_required_changelog(data): This is during the prerelease phase. """ - data['required_changelog_text'] = KNOWN_HEADINGS + data["required_changelog_text"] = KNOWN_HEADINGS def set_new_changelog(data): @@ -107,8 +108,8 @@ def set_new_changelog(data): Yes, this overrides what we have set in the prerelease, and that is fine. """ - text = ''.join(HEADERS) - data['nothing_changed_yet'] = textwrap.dedent(text).strip() + text = "".join(HEADERS) + data["nothing_changed_yet"] = textwrap.dedent(text).strip() def cleanup_changelog(data): @@ -129,42 +130,40 @@ def cleanup_changelog(data): # The history_file is probably not set yet, as we are called too early. # That might change subtly in future zest.releaser versions, so let's check # it anyway. - history_file = data.get('history_file') + history_file = data.get("history_file") if history_file: - contents = '\n'.join(data['history_lines']) - encoding = data['history_encoding'] + contents = "\n".join(data["history_lines"]) + encoding = data["history_encoding"] else: # We do not want to copy the logic from zest.releaser that tries to # find the history file, but we can check the most obvious spot. - history_file = 'CHANGES.rst' + history_file = "CHANGES.rst" if not os.path.exists(history_file): - print('Cannot cleanup history, will try again later.') + print("Cannot cleanup history, will try again later.") return contents, encoding = read_text_file(history_file) orig_contents = contents changed = False for header in ALL_HEADERS: if header in contents: - contents = contents.replace(header, '') + contents = contents.replace(header, "") changed = True if not changed: return - write_text_file( - history_file, contents, encoding=encoding) + write_text_file(history_file, contents, encoding=encoding) print("Cleaned up empty headers from history file {}".format(history_file)) # Update the data, otherwise our work may get overwritten. - data['history_lines'] = contents.split('\n') - if not os.path.isdir('.git'): - print('Not a git checkout, cannot commit.') + data["history_lines"] = contents.split("\n") + if not os.path.isdir(".git"): + print("Not a git checkout, cannot commit.") return - g = git.Git('.') + g = git.Git(".") message = "Cleaned up empty headers from changelog.\n\n[ci skip]" print(g.diff(history_file)) msg = "Commit changes?" if not ask(msg, default=True): # Restore original contents. - write_text_file( - history_file, orig_contents, encoding=encoding) + write_text_file(history_file, orig_contents, encoding=encoding) sys.exit() print("Committing changes.") print(g.add(history_file)) @@ -172,10 +171,10 @@ def cleanup_changelog(data): def check_pypi_access(data): - pypi_user = pypi.PypiConfig().config.get('pypi', 'username') - if not can_user_release_package_to_pypi(pypi_user, data['name']): + pypi_user = pypi.PypiConfig().config.get("pypi", "username") + if not can_user_release_package_to_pypi(pypi_user, data["name"]): msg = "User {0} does not have pypi release rights to {1}. Continue?" - if not ask(msg.format(pypi_user, data['name']), default=False): + if not ask(msg.format(pypi_user, data["name"]), default=False): sys.exit() @@ -184,18 +183,18 @@ def update_core(data, branch=None): if branch: msg = "Ok to update coredev {0} versions.cfg/checkouts.cfg?".format(branch) if ask(msg, default=True): - root_path = os.path.join(os.getcwd(), '../../') + root_path = os.path.join(os.getcwd(), "../../") g = git.Git(root_path) g.pull() # make sure buildout.coredev is up-to-date - package_name = data['name'] - new_version = data['version'] + package_name = data["name"] + new_version = data["version"] update_versions(package_name, new_version) if package_name not in ALWAYS_CHECKED_OUT_PACKAGES: remove_from_checkouts(package_name) # git commit message = "{0} {1}".format(package_name, new_version) - g.add('versions.cfg') - g.add('checkouts.cfg') + g.add("versions.cfg") + g.add("checkouts.cfg") print("Committing changes.") g.commit(message=message) msg = "Ok to push coredev?" @@ -207,21 +206,21 @@ def update_core(data, branch=None): def update_other_core_branches(data): - CORE_BRANCHES = ['4.3', '5.1', '5.2', ] - package_name = data['name'] - root_path = os.path.join(os.getcwd(), '../../') + CORE_BRANCHES = ["4.3", "5.1", "5.2"] + package_name = data["name"] + root_path = os.path.join(os.getcwd(), "../../") def _get_current_core_branch(): g = git.Repo(root_path) return g.head.reference.name def _get_package_branch(package_name): - path = os.path.join(root_path, 'sources.cfg') + path = os.path.join(root_path, "sources.cfg") sources = SourcesFile(path) try: return sources[package_name].branch except KeyError: # package is not on sources.cfg of the current core branch - return '' + return "" current_core_branch = _get_current_core_branch() CORE_BRANCHES.remove(current_core_branch) @@ -238,9 +237,8 @@ def _get_package_branch(package_name): update_core(data, branch=branch_name) except Exception: print( - 'There was an error trying to update {0} on {1}'.format( - package_name, - branch_name, + "There was an error trying to update {0} on {1}".format( + package_name, branch_name ) ) @@ -250,13 +248,13 @@ def _get_package_branch(package_name): def update_versions(package_name, new_version): # Update version print("Updating versions.cfg") - path = os.path.join(os.getcwd(), '../../versions.cfg') + path = os.path.join(os.getcwd(), "../../versions.cfg") versions = VersionsFile(path) versions.set(package_name, new_version) def remove_from_checkouts(package_name): print("Removing package from checkouts.cfg") - path = os.path.join(os.getcwd(), '../../checkouts.cfg') + path = os.path.join(os.getcwd(), "../../checkouts.cfg") checkouts = CheckoutsFile(path) checkouts.remove(package_name) diff --git a/setup.py b/setup.py index 56b046f..49baf7e 100644 --- a/setup.py +++ b/setup.py @@ -3,74 +3,72 @@ from setuptools import setup -version = '1.7.3.dev0' +version = "1.7.3.dev0" -long_description = '{0}\n{1}'.format( - open('README.rst').read(), - open('CHANGES.rst').read() +long_description = "{0}\n{1}".format( + open("README.rst").read(), open("CHANGES.rst").read() ) setup( - name='plone.releaser', + name="plone.releaser", version=version, - description='Plone release management utilities', + description="Plone release management utilities", long_description=long_description, # Get more strings from # https://pypi.python.org/pypi?:action=list_classifiers classifiers=[ - 'Framework :: Plone', - "License :: OSI Approved :: GNU General Public License (GPL)", - 'Programming Language :: Python', - 'Programming Language :: Python :: 2.7', + "Framework :: Plone", + "License :: OSI Approved :: GNU General Public License (GPL)", + "Programming Language :: Python", + "Programming Language :: Python :: 2.7", ], - keywords='plone release', - author='Eric Steele', - author_email='eric@esteele.net', - url='https://github.com/plone/plone.releaser', - license='GPL', + keywords="plone release", + author="Eric Steele", + author_email="eric@esteele.net", + url="https://github.com/plone/plone.releaser", + license="GPL", packages=find_packages(), - namespace_packages=['plone'], + namespace_packages=["plone"], include_package_data=True, zip_safe=False, install_requires=[ - 'setuptools', - 'argh', - 'gitpython>=0.3', - 'configparser', - 'argcomplete', - 'progress', - 'PyGithub', - 'keyring', - 'zest.releaser>=6.6.0', - 'zestreleaser.towncrier>=1.0.0b3', - 'docutils', - 'launchpadlib', + "setuptools", + "argh", + "gitpython>=0.3", + "configparser", + "argcomplete", + "progress", + "PyGithub", + "keyring", + "zest.releaser>=6.6.0", + "zestreleaser.towncrier>=1.0.0b3", + "docutils", + "launchpadlib", ], entry_points={ - 'console_scripts': [ - 'manage = plone.releaser.manage:manage', + "console_scripts": ["manage = plone.releaser.manage:manage"], + "zest.releaser.prereleaser.before": [ + ( + "set_nothing_changed_yet=" + "plone.releaser.release:set_nothing_changed_yet" + ), + ("set_required_changelog=" "plone.releaser.release:set_required_changelog"), + ("cleanup_changelog=" "plone.releaser.release:cleanup_changelog"), ], - 'zest.releaser.prereleaser.before': [ - ('set_nothing_changed_yet=' - 'plone.releaser.release:set_nothing_changed_yet'), - ('set_required_changelog=' - 'plone.releaser.release:set_required_changelog'), - ('cleanup_changelog=' - 'plone.releaser.release:cleanup_changelog'), - ], - 'zest.releaser.prereleaser.middle': [ + "zest.releaser.prereleaser.middle": [ # Note: we explicitly call cleanup_changelog twice. - ('cleanup_changelog=' - 'plone.releaser.release:cleanup_changelog'), - 'check_pypi=plone.releaser.release:check_pypi_access', + ("cleanup_changelog=" "plone.releaser.release:cleanup_changelog"), + "check_pypi=plone.releaser.release:check_pypi_access", ], - 'zest.releaser.releaser.after': [ - 'update_core=plone.releaser.release:update_core', - ('update_other_core_branches=' - 'plone.releaser.release:update_other_core_branches'), + "zest.releaser.releaser.after": [ + "update_core=plone.releaser.release:update_core", + ( + "update_other_core_branches=" + "plone.releaser.release:update_other_core_branches" + ), ], - 'zest.releaser.postreleaser.before': [ - 'set_new_changelog=plone.releaser.release:set_new_changelog', + "zest.releaser.postreleaser.before": [ + "set_new_changelog=plone.releaser.release:set_new_changelog" ], }, )