summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pbr/packaging.py107
-rw-r--r--pbr/tests/test_core.py38
-rw-r--r--pbr/tests/test_setup.py13
-rw-r--r--pbr/tests/testpackage/pbr_testpackage/cmd.py7
-rw-r--r--pbr/tests/testpackage/setup.cfg1
5 files changed, 95 insertions, 71 deletions
diff --git a/pbr/packaging.py b/pbr/packaging.py
index 25d374d..8e6ab4a 100644
--- a/pbr/packaging.py
+++ b/pbr/packaging.py
@@ -86,41 +86,30 @@ def _make_links_args(links):
return ["-f '%s'" % link for link in links]
-def _missing_requires(requires):
- """Return the list of requirements that are not already installed.
-
- Do this check explicitly, because it's very easy to see if a package
- is in the current working set, to avoid shelling out to pip and attempting
- an install. pip will do the right thing, but we don't need to do the
- excess work on everyone's machines all the time (especially since tox
- likes re-installing things a lot)
- """
- return [r for r in requires
- if not pkg_resources.working_set.find(
- pkg_resources.Requirement.parse(r))]
-
-
-def _pip_install(links, requires, root=None):
- if str(os.getenv('SKIP_PIP_INSTALL', '')).lower() in TRUE_VALUES:
+def _pip_install(links, requires, root=None, option_dict=dict()):
+ if get_boolean_option(
+ option_dict, 'skip_pip_install', 'SKIP_PIP_INSTALL'):
return
root_cmd = ""
if root:
root_cmd = "--root=%s" % root
- missing_requires = _missing_requires(requires)
- if missing_requires:
- _run_shell_command(
- "%s -m pip.__init__ install %s %s %s" % (
- sys.executable,
- root_cmd,
- " ".join(links),
- " ".join(_wrap_in_quotes(missing_requires))),
- throw_on_error=True, buffer=False)
-
-
-def read_git_mailmap(git_dir, mailmap='.mailmap'):
- mailmap = os.path.join(git_dir, mailmap)
+ _run_shell_command(
+ "%s -m pip.__init__ install %s %s %s" % (
+ sys.executable,
+ root_cmd,
+ " ".join(links),
+ " ".join(_wrap_in_quotes(requires))),
+ throw_on_error=True, buffer=False)
+
+
+def read_git_mailmap(root_dir=None, mailmap='.mailmap'):
+ if not root_dir:
+ root_dir = _run_shell_command('git rev-parse --show-toplevel')
+
+ mailmap = os.path.join(root_dir, mailmap)
if os.path.exists(mailmap):
return _parse_mailmap(open(mailmap, 'r').readlines())
+
return dict()
@@ -262,7 +251,7 @@ def write_git_changelog(git_dir=None, dest_dir=os.path.curdir,
if git_dir:
git_log_cmd = 'git --git-dir=%s log' % git_dir
changelog = _run_shell_command(git_log_cmd)
- mailmap = read_git_mailmap(git_dir)
+ mailmap = read_git_mailmap()
with open(new_changelog, "wb") as changelog_file:
changelog_file.write(canonicalize_emails(
changelog, mailmap).encode('utf-8'))
@@ -298,7 +287,7 @@ def generate_authors(git_dir=None, dest_dir='.', option_dict=dict()):
for signed in signed_entries.split("\n") if signed])
changelog = "\n".join((changelog, new_entries))
- mailmap = read_git_mailmap(git_dir)
+ mailmap = read_git_mailmap()
with open(new_authors, 'wb') as new_authors_fh:
if os.path.exists(old_authors):
with open(old_authors, "rb") as old_authors_fh:
@@ -343,10 +332,13 @@ class LocalInstall(install.install):
command_name = 'install'
def run(self):
+ option_dict = self.distribution.get_option_dict('pbr')
if (not self.single_version_externally_managed
and self.distribution.install_requires):
links = _make_links_args(self.distribution.dependency_links)
- _pip_install(links, self.distribution.install_requires, self.root)
+ _pip_install(
+ links, self.distribution.install_requires, self.root,
+ option_dict=option_dict)
return du_install.install.run(self)
@@ -379,7 +371,10 @@ class _PipInstallTestRequires(object):
links = _make_links_args(
parse_dependency_links(TEST_REQUIREMENTS_FILES))
if self.distribution.tests_require:
- _pip_install(links, self.distribution.tests_require)
+ option_dict = self.distribution.get_option_dict('pbr')
+ _pip_install(
+ links, self.distribution.tests_require,
+ option_dict=option_dict)
def pre_run(self):
self.egg_name = pkg_resources.safe_name(self.distribution.get_name())
@@ -441,11 +436,11 @@ _script_text = """# PBR Generated from %(group)r
import sys
-from %(module_name)s import %(func)s
+from %(module_name)s import %(import_target)s
if __name__ == "__main__":
- sys.exit(%(func)s())
+ sys.exit(%(invoke_target)s())
"""
@@ -455,10 +450,15 @@ def override_get_script_args(
header = easy_install.get_script_header("", executable, is_wininst)
for group in 'console_scripts', 'gui_scripts':
for name, ep in dist.get_entry_map(group).items():
+ if not ep.attrs or len(ep.attrs) > 2:
+ raise ValueError("Script targets must be of the form "
+ "'func' or 'Class.class_method'.")
script_text = _script_text % dict(
group=group,
module_name=ep.module_name,
- func=ep.attrs[0])
+ import_target=ep.attrs[0],
+ invoke_target='.'.join(ep.attrs),
+ )
yield (name, header+script_text)
@@ -513,6 +513,7 @@ class LocalSDist(sdist.sdist):
sdist.sdist.run(self)
try:
+ from sphinx import apidoc
from sphinx import application
from sphinx import config
from sphinx import setup_command
@@ -522,17 +523,21 @@ try:
command_name = 'build_sphinx'
builders = ['html', 'man']
- def generate_autoindex(self):
+ def _get_source_dir(self):
option_dict = self.distribution.get_option_dict('build_sphinx')
- log.info("[pbr] Autodocumenting from %s"
- % os.path.abspath(os.curdir))
- modules = {}
if 'source_dir' in option_dict:
source_dir = os.path.join(option_dict['source_dir'][1], 'api')
else:
source_dir = 'doc/source/api'
if not os.path.exists(source_dir):
os.makedirs(source_dir)
+ return source_dir
+
+ def generate_autoindex(self):
+ log.info("[pbr] Autodocumenting from %s"
+ % os.path.abspath(os.curdir))
+ modules = {}
+ source_dir = self._get_source_dir()
for pkg in self.distribution.packages:
if '.' not in pkg:
for dirpath, dirnames, files in os.walk(pkg):
@@ -559,6 +564,10 @@ try:
output_file.write(_rst_template % values)
autoindex.write(" %s.rst\n" % module)
+ def _sphinx_tree(self):
+ source_dir = self._get_source_dir()
+ apidoc.main(['apidoc', '.', '-H', 'Modules', '-o', source_dir])
+
def _sphinx_run(self):
if not self.verbose:
status_stream = io.StringIO()
@@ -599,11 +608,19 @@ try:
def run(self):
option_dict = self.distribution.get_option_dict('pbr')
- if ('autodoc_index_modules' in option_dict and
- option_dict.get(
- 'autodoc_index_modules')[1].lower() in TRUE_VALUES and
- not os.getenv('SPHINX_DEBUG')):
- self.generate_autoindex()
+ tree_index = get_boolean_option(option_dict,
+ 'autodoc_tree_index_modules',
+ 'AUTODOC_TREE_INDEX_MODULES')
+ auto_index = get_boolean_option(option_dict,
+ 'autodoc_index_modules',
+ 'AUTODOC_INDEX_MODULES')
+ if not os.getenv('SPHINX_DEBUG'):
+ #NOTE(afazekas): These options can be used together,
+ # but they do a very similar thing in a difffernet way
+ if tree_index:
+ self._sphinx_tree()
+ if auto_index:
+ self.generate_autoindex()
for builder in self.builders:
self.builder = builder
diff --git a/pbr/tests/test_core.py b/pbr/tests/test_core.py
index f8e5989..a7376eb 100644
--- a/pbr/tests/test_core.py
+++ b/pbr/tests/test_core.py
@@ -49,6 +49,22 @@ from pbr import tests
class TestCore(tests.BaseTestCase):
+ cmd_names = ('pbr_test_cmd', 'pbr_test_cmd_with_class')
+
+ def check_script_install(self, install_stdout):
+ for cmd_name in self.cmd_names:
+ install_txt = 'Installing %s script to %s' % (cmd_name,
+ self.temp_dir)
+ self.assertIn(install_txt, install_stdout)
+
+ cmd_filename = os.path.join(self.temp_dir, cmd_name)
+
+ script_txt = open(cmd_filename, 'r').read()
+ self.assertNotIn('pkg_resources', script_txt)
+
+ stdout, _, return_code = self._run_cmd(cmd_filename)
+ self.assertIn("PBR", stdout)
+
def test_setup_py_keywords(self):
"""setup.py --keywords.
@@ -85,19 +101,10 @@ class TestCore(tests.BaseTestCase):
stdout, _, return_code = self.run_setup(
'install_scripts', '--install-dir=%s' % self.temp_dir)
- self.assertIn(
- 'Installing pbr_test_cmd script to %s' % self.temp_dir,
- stdout)
- self.assertNotIn(
- 'pkg_resources',
- open(os.path.join(self.temp_dir, 'pbr_test_cmd'), 'r').read())
-
self.useFixture(
fixtures.EnvironmentVariable('PYTHONPATH', '.'))
- stdout, _, return_code = self._run_cmd(
- os.path.join(self.temp_dir, 'pbr_test_cmd'))
- self.assertIn("PBR", stdout)
+ self.check_script_install(stdout)
def test_console_script_develop(self):
"""Test that we develop a non-pkg-resources console script."""
@@ -112,13 +119,4 @@ class TestCore(tests.BaseTestCase):
stdout, _, return_code = self.run_setup(
'develop', '--install-dir=%s' % self.temp_dir)
- self.assertIn(
- 'Installing pbr_test_cmd script to %s' % self.temp_dir,
- stdout)
- self.assertNotIn(
- 'pkg_resources',
- open(os.path.join(self.temp_dir, 'pbr_test_cmd'), 'r').read())
-
- stdout, _, return_code = self._run_cmd(
- os.path.join(self.temp_dir, 'pbr_test_cmd'))
- self.assertIn("PBR", stdout)
+ self.check_script_install(stdout)
diff --git a/pbr/tests/test_setup.py b/pbr/tests/test_setup.py
index 398c503..11f9a04 100644
--- a/pbr/tests/test_setup.py
+++ b/pbr/tests/test_setup.py
@@ -49,27 +49,26 @@ class MailmapTestCase(tests.BaseTestCase):
def setUp(self):
super(MailmapTestCase, self).setUp()
- self.git_dir = self.useFixture(fixtures.TempDir()).path
- self.mailmap = os.path.join(self.git_dir, '.mailmap')
+ self.root_dir = self.useFixture(fixtures.TempDir()).path
+ self.mailmap = os.path.join(self.root_dir, '.mailmap')
def test_mailmap_with_fullname(self):
- print(self.mailmap, self.git_dir)
with open(self.mailmap, 'w') as mm_fh:
mm_fh.write("Foo Bar <email@foo.com> Foo Bar <email@bar.com>\n")
self.assertEqual({'<email@bar.com>': '<email@foo.com>'},
- packaging.read_git_mailmap(self.git_dir))
+ packaging.read_git_mailmap(self.root_dir))
def test_mailmap_with_firstname(self):
with open(self.mailmap, 'w') as mm_fh:
mm_fh.write("Foo <email@foo.com> Foo <email@bar.com>\n")
self.assertEqual({'<email@bar.com>': '<email@foo.com>'},
- packaging.read_git_mailmap(self.git_dir))
+ packaging.read_git_mailmap(self.root_dir))
def test_mailmap_with_noname(self):
with open(self.mailmap, 'w') as mm_fh:
mm_fh.write("<email@foo.com> <email@bar.com>\n")
self.assertEqual({'<email@bar.com>': '<email@foo.com>'},
- packaging.read_git_mailmap(self.git_dir))
+ packaging.read_git_mailmap(self.root_dir))
class SkipFileWrites(tests.BaseTestCase):
@@ -185,9 +184,11 @@ class GitLogsTest(tests.BaseTestCase):
git_log_cmd = ("git --git-dir=%s log --format" % self.git_dir)
git_co_log_cmd = ("git log --git-dir=%s" % self.git_dir)
+ git_top_level = "git rev-parse --show-toplevel"
cmd_map = {
git_log_cmd: author_new,
git_co_log_cmd: co_author_by,
+ git_top_level: self.root_dir,
}
exist_files = [self.git_dir,
diff --git a/pbr/tests/testpackage/pbr_testpackage/cmd.py b/pbr/tests/testpackage/pbr_testpackage/cmd.py
index 1b03915..4cc4522 100644
--- a/pbr/tests/testpackage/pbr_testpackage/cmd.py
+++ b/pbr/tests/testpackage/pbr_testpackage/cmd.py
@@ -17,3 +17,10 @@ from __future__ import print_function
def main():
print("PBR Test Command")
+
+
+class Foo(object):
+
+ @classmethod
+ def bar(self):
+ print("PBR Test Command - with class!")
diff --git a/pbr/tests/testpackage/setup.cfg b/pbr/tests/testpackage/setup.cfg
index 9bcc0ee..a410e3c 100644
--- a/pbr/tests/testpackage/setup.cfg
+++ b/pbr/tests/testpackage/setup.cfg
@@ -34,6 +34,7 @@ extra-files = extra-file.txt
[entry_points]
console_scripts =
pbr_test_cmd = pbr_testpackage.cmd:main
+ pbr_test_cmd_with_class = pbr_testpackage.cmd:Foo.bar
[extension=pbr_testpackage.testext]
sources = src/testext.c