Skip to content

Commit

Permalink
from master
Browse files Browse the repository at this point in the history
  • Loading branch information
Robpol86 committed Aug 13, 2016
1 parent 576785d commit d45046a
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 39 deletions.
10 changes: 7 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,13 @@ This project adheres to `Semantic Versioning <http://semver.org/>`_.
Unreleased
----------

* Environment variables for CLI.
* --git-root
* Multi level verbose.
Changed
* Renamed command line option ``--prioritize`` to ``--priority``.

TODO
* Environment variables for CLI.
* --git-root
* Multi level verbose.

1.1.0 - 2016-08-07
------------------
Expand Down
4 changes: 2 additions & 2 deletions docs/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ These arguments/options apply to both :ref:`build <build-arguments>` and :ref:`p
Invert the order of branches/tags displayed in the sidebars in generated HTML documents. The default order is
whatever git prints when running "**git ls-remote --heads --tags**".

.. option:: -p <kind>, --prioritize <kind>
.. option:: -p <kind>, --priority <kind>

``kind`` may be either **branches** or **tags**. This argument is for themes that don't split up branches and tags
in the generated HTML (e.g. sphinx_rtd_theme). This argument groups branches and tags together and whichever is
Expand Down Expand Up @@ -81,7 +81,7 @@ These arguments/options apply to both :ref:`build <build-arguments>` and :ref:`p
Overflow/Pass Options
---------------------

It is possible to give the underlying ``sphinx-build`` program comand line options. SCVersioning passes everything after
It is possible to give the underlying ``sphinx-build`` program command line options. SCVersioning passes everything after
``--`` to it. For example if you changed the theme for your docs between versions and want docs for all versions to have
the same theme, you can run:

Expand Down
6 changes: 3 additions & 3 deletions sphinxcontrib/versioning/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
REL_DEST in DST_BRANCH.
-h --help Show this screen.
-i --invert Invert/reverse order of versions.
-p K --prioritize=KIND Set to "branches" or "tags" to group those kinds
-p K --priority=KIND Set to "branches" or "tags" to group those kinds
of versions at the top (for themes that don't
separate them).
-r REF --root-ref=REF The branch/tag at the root of DESTINATION. All
Expand Down Expand Up @@ -104,14 +104,14 @@ def main_build(config, root, destination):
# Gather git data.
log.info('Gathering info about the remote git repository...')
conf_rel_paths = [os.path.join(s, 'conf.py') for s in config.rel_source]
root, remotes = gather_git_info(root, conf_rel_paths)
remotes = gather_git_info(root, conf_rel_paths)
if not remotes:
log.error('No docs found in any remote branch/tag. Nothing to do.')
raise HandledError
versions = Versions(
remotes,
sort=(config.sort or '').split(','),
prioritize=config.prioritize,
priority=config.priority,
invert=config.invert,
)

Expand Down
6 changes: 3 additions & 3 deletions sphinxcontrib/versioning/__main___.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,14 @@ def build(config, rel_source, destination, **options):
# Gather git data.
log.info('Gathering info about the remote git repository...')
conf_rel_paths = [os.path.join(s, 'conf.py') for s in rel_source]
root, remotes = gather_git_info(config.git_root, conf_rel_paths)
remotes = gather_git_info(config.git_root, conf_rel_paths)
if not remotes:
log.error('No docs found in any remote branch/tag. Nothing to do.')
raise HandledError
versions = Versions(
remotes,
sort=(config.sort or '').split(','),
prioritize=config.priority,
priority=config.priority,
invert=config.invert,
)

Expand All @@ -234,7 +234,7 @@ def build(config, rel_source, destination, **options):

# Pre-build.
log.info('Pre-running Sphinx to determine URLs.')
exported_root = pre_build(root, versions, config.overflow)
exported_root = pre_build(config.git_root, versions, config.overflow)

# Build.
build_all(exported_root, destination, versions, config.overflow)
Expand Down
1 change: 0 additions & 1 deletion sphinxcontrib/versioning/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def __init__(self):
self.dst_branch = None
self.git_root = None
self.priority = None
self.prioritize = None
self.rel_dst = None
self.rel_source = None
self.root_ref = None
Expand Down
6 changes: 3 additions & 3 deletions sphinxcontrib/versioning/routines.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def gather_git_info(root, conf_rel_paths):
:param str root: Root directory of repository.
:param iter conf_rel_paths: List of possible relative paths (to git root) of Sphinx conf.py (e.g. docs/conf.py).
:return: Local git root and commits with docs. Latter is a list of tuples: (sha, name, kind, date, conf_rel_path).
:rtype: tuple
:return: Commits with docs. A list of tuples: (sha, name, kind, date, conf_rel_path).
:rtype: list
"""
log = logging.getLogger(__name__)

Expand Down Expand Up @@ -56,7 +56,7 @@ def gather_git_info(root, conf_rel_paths):
filtered_remotes = [[i[0], i[1], i[2], ] + dates_paths[i[0]] for i in remotes if i[0] in dates_paths]
log.info('With docs: %s', ' '.join(i[1] for i in filtered_remotes))

return root, filtered_remotes
return filtered_remotes


def pre_build(local_root, versions, overflow):
Expand Down
10 changes: 5 additions & 5 deletions sphinxcontrib/versioning/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ class Versions(object):
:ivar dict root_remote: Branch/tag at the root of all HTML docs.
"""

def __init__(self, remotes, sort=None, prioritize=None, invert=False):
def __init__(self, remotes, sort=None, priority=None, invert=False):
"""Constructor.
:param iter remotes: Output of routines.gather_git_info(). Converted to list of dicts as instance variable.
:param iter sort: List of strings (order matters) to sort remotes by. Strings may be: alpha, chrono, semver
:param str prioritize: May be "branches" or "tags". Groups either before the other. Maintains order otherwise.
:param str priority: May be "branches" or "tags". Groups either before the other. Maintains order otherwise.
:param bool invert: Invert sorted/grouped remotes at the end of processing.
"""
self.remotes = [dict(
Expand All @@ -128,10 +128,10 @@ def __init__(self, remotes, sort=None, prioritize=None, invert=False):
if sort:
multi_sort(self.remotes, [s.strip().lower() for s in sort])

# Prioritize.
if prioritize == 'branches':
# Priority.
if priority == 'branches':
self.remotes.sort(key=lambda r: 1 if r['kind'] == 'tags' else 0)
elif prioritize == 'tags':
elif priority == 'tags':
self.remotes.sort(key=lambda r: 0 if r['kind'] == 'tags' else 1)

# Invert.
Expand Down
8 changes: 4 additions & 4 deletions tests/test_routines/test_build_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def test_single(tmpdir, local_docs):
:param tmpdir: pytest fixture.
:param local_docs: conftest fixture.
"""
versions = Versions(gather_git_info(str(local_docs), ['conf.py'])[1])
versions = Versions(gather_git_info(str(local_docs), ['conf.py']))
versions['master']['url'] = 'contents.html'
versions.set_root_remote('master')

Expand Down Expand Up @@ -53,7 +53,7 @@ def test_multiple(tmpdir, local_docs, run, triple):
run(local_docs, ['git', 'tag', 'v1.0.1'])
run(local_docs, ['git', 'push', 'origin', 'v1.0.1'])

versions = Versions(gather_git_info(str(local_docs), ['conf.py'])[1])
versions = Versions(gather_git_info(str(local_docs), ['conf.py']))
versions['master']['url'] = 'contents.html'
versions['v1.0.0']['url'] = 'v1.0.0/contents.html'
if triple:
Expand Down Expand Up @@ -124,7 +124,7 @@ def test_error(tmpdir, local_docs, run):
run(local_docs, ['git', 'checkout', '-b', 'd_broken', 'b_broken'])
run(local_docs, ['git', 'push', 'origin', 'a_good', 'b_broken', 'c_good', 'd_broken'])

versions = Versions(gather_git_info(str(local_docs), ['conf.py'])[1])
versions = Versions(gather_git_info(str(local_docs), ['conf.py']))
versions['master']['url'] = 'contents.html'
versions['a_good']['url'] = 'a_good/contents.html'
versions['c_good']['url'] = 'c_good/contents.html'
Expand Down Expand Up @@ -184,7 +184,7 @@ def test_all_errors(tmpdir, local_docs, run):
run(local_docs, ['git', 'checkout', '-b', 'b_broken', 'a_broken'])
run(local_docs, ['git', 'push', 'origin', 'a_broken', 'b_broken'])

versions = Versions(gather_git_info(str(local_docs), ['conf.py'])[1])
versions = Versions(gather_git_info(str(local_docs), ['conf.py']))
versions['master']['url'] = 'contents.html'
versions['a_broken']['url'] = 'a_broken/contents.html'
versions['b_broken']['url'] = 'b_broken/contents.html'
Expand Down
6 changes: 2 additions & 4 deletions tests/test_routines/test_gather_git_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ def test_working(local):
:param local: conftest fixture.
"""
root, filtered_remotes = gather_git_info(str(local), [os.path.join('.', 'README')])
assert root == str(local)
filtered_remotes = gather_git_info(str(local), [os.path.join('.', 'README')])
expected = [['feature', 'heads'], ['master', 'heads'], ['annotated_tag', 'tags'], ['light_tag', 'tags']]
assert [i[1:-2] for i in filtered_remotes] == expected

Expand All @@ -34,8 +33,7 @@ def test_fetch(monkeypatch, caplog, local, skip_fetch):
with pytest.raises(HandledError):
gather_git_info(str(local), ['README'])
else:
root, filtered_remotes = gather_git_info(str(local), ['README'])
assert root == str(local)
filtered_remotes = gather_git_info(str(local), ['README'])
expected = [
['feature', 'heads'],
['master', 'heads'],
Expand Down
10 changes: 5 additions & 5 deletions tests/test_routines/test_pre_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def test_single(local_docs):
:param local_docs: conftest fixture.
"""
versions = Versions(gather_git_info(str(local_docs), ['conf.py'])[1])
versions = Versions(gather_git_info(str(local_docs), ['conf.py']))
versions.set_root_remote('master')
assert len(versions) == 1

Expand Down Expand Up @@ -45,7 +45,7 @@ def test_dual(local_docs, run):
run(local_docs, ['git', 'commit', '-m', 'Adding docs with master_doc'])
run(local_docs, ['git', 'push', 'origin', 'feature'])

versions = Versions(gather_git_info(str(local_docs), ['conf.py'])[1])
versions = Versions(gather_git_info(str(local_docs), ['conf.py']))
versions.set_root_remote('master')
assert len(versions) == 2

Expand All @@ -69,7 +69,7 @@ def test_file_collision(local_docs, run):
run(local_docs, ['git', 'checkout', '-b', '_static'])
run(local_docs, ['git', 'push', 'origin', '_static'])

versions = Versions(gather_git_info(str(local_docs), ['conf.py'])[1])
versions = Versions(gather_git_info(str(local_docs), ['conf.py']))
versions.set_root_remote('master')
assert len(versions) == 2

Expand All @@ -88,7 +88,7 @@ def test_invalid_name(local_docs, run):
run(local_docs, ['git', 'checkout', '-b', 'robpol86/feature'])
run(local_docs, ['git', 'push', 'origin', 'robpol86/feature'])

versions = Versions(gather_git_info(str(local_docs), ['conf.py'])[1])
versions = Versions(gather_git_info(str(local_docs), ['conf.py']))
versions.set_root_remote('master')
assert len(versions) == 2

Expand All @@ -112,7 +112,7 @@ def test_error(local_docs, run):
run(local_docs, ['git', 'checkout', '-b', 'd_broken', 'b_broken'])
run(local_docs, ['git', 'push', 'origin', 'a_good', 'b_broken', 'c_good', 'd_broken'])

versions = Versions(gather_git_info(str(local_docs), ['conf.py'])[1], sort=['alpha'])
versions = Versions(gather_git_info(str(local_docs), ['conf.py']), sort=['alpha'])
assert [r[0] for r in versions] == ['a_good', 'b_broken', 'c_good', 'd_broken', 'master']

# Bad root ref.
Expand Down
12 changes: 6 additions & 6 deletions tests/test_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,20 +128,20 @@ def test_sort(remotes, sort):

@pytest.mark.parametrize('remotes', REMOTES_SHIFTED)
@pytest.mark.parametrize('sort', ['alpha', 'chrono'])
@pytest.mark.parametrize('prioritize', ['branches', 'tags'])
@pytest.mark.parametrize('priority', ['branches', 'tags'])
@pytest.mark.parametrize('invert', [False, True])
def test_priority(remotes, sort, prioritize, invert):
def test_priority(remotes, sort, priority, invert):
"""Test with branches/tags being prioritized.
:param iter remotes: Passed to class.
:param str sort: Passed to class after splitting by comma.
:param str prioritize: Passed to class.
:param str priority: Passed to class.
:param bool invert: Passed to class.
"""
versions = Versions(remotes, sort=sort.split(','), prioritize=prioritize, invert=invert)
versions = Versions(remotes, sort=sort.split(','), priority=priority, invert=invert)
actual = [i[0] for i in versions]

if sort == 'alpha' and prioritize == 'branches':
if sort == 'alpha' and priority == 'branches':
if invert:
expected = ['v3.0.0', 'v2.1.0', 'v2.0.0', 'v10.0.0', 'v1.2.0', 'zh-pages', 'master']
else:
Expand All @@ -151,7 +151,7 @@ def test_priority(remotes, sort, prioritize, invert):
expected = ['zh-pages', 'master', 'v3.0.0', 'v2.1.0', 'v2.0.0', 'v10.0.0', 'v1.2.0']
else:
expected = ['v1.2.0', 'v10.0.0', 'v2.0.0', 'v2.1.0', 'v3.0.0', 'master', 'zh-pages']
elif sort == 'chrono' and prioritize == 'branches':
elif sort == 'chrono' and priority == 'branches':
if invert:
expected = ['v1.2.0', 'v2.1.0', 'v3.0.0', 'v10.0.0', 'v2.0.0', 'master', 'zh-pages']
else:
Expand Down

0 comments on commit d45046a

Please sign in to comment.