diff --git a/pbr/packaging.py b/pbr/packaging.py index 8d411044..c42600e9 100644 --- a/pbr/packaging.py +++ b/pbr/packaging.py @@ -25,7 +25,6 @@ from distutils import log import email import functools import itertools -import json import os import platform import re @@ -41,6 +40,7 @@ from setuptools.command import sdist from pbr import extra_files from pbr import git from pbr import options +import pbr.pbr_json from pbr import version REQUIREMENTS_FILES = ('requirements.txt', 'tools/pip-requires') @@ -505,19 +505,6 @@ def _get_increment_kwargs(git_dir, tag): return result -def write_pbr_json(cmd, basename, filename): - git_dir = git._run_git_functions() - if not git_dir: - return - values = dict() - git_version = git.get_git_short_sha(git_dir) - is_release = git.get_is_release(git_dir) - if git_version is not None: - values['git_version'] = git_version - values['is_release'] = is_release - cmd.write_file('pbr', filename, json.dumps(values)) - - def _get_revno_and_last_tag(git_dir): """Return the commit data about the most recent tag. @@ -671,3 +658,10 @@ def get_version(package_name, pre_version=None): raise Exception("Versioning for this project requires either an sdist" " tarball, or access to an upstream git repository." " Are you sure that git is installed?") + + +# This is added because pbr uses pbr to install itself. That means that +# any changes to the egg info writer entrypoints must be forward and +# backward compatible. This maintains the pbr.packaging.write_pbr_json +# path. +write_pbr_json = pbr.pbr_json.write_pbr_json diff --git a/pbr/pbr_json.py b/pbr/pbr_json.py new file mode 100644 index 00000000..22901036 --- /dev/null +++ b/pbr/pbr_json.py @@ -0,0 +1,32 @@ +# Copyright 2011 OpenStack LLC. +# Copyright 2012-2013 Hewlett-Packard Development Company, L.P. +# All Rights Reserved. +# +# 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 json + +from pbr import git + + +def write_pbr_json(cmd, basename, filename): + git_dir = git._run_git_functions() + if not git_dir: + return + values = dict() + git_version = git.get_git_short_sha(git_dir) + is_release = git.get_is_release(git_dir) + if git_version is not None: + values['git_version'] = git_version + values['is_release'] = is_release + cmd.write_file('pbr', filename, json.dumps(values)) diff --git a/setup.cfg b/setup.cfg index b217fd31..c2d06e7f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -39,7 +39,7 @@ distutils.setup_keywords = distutils.commands = testr = pbr.testr_command:Testr egg_info.writers = - pbr.json = pbr.packaging:write_pbr_json + pbr.json = pbr.pbr_json:write_pbr_json console_scripts = pbr = pbr.cmd.main:main