Skip to content

Commit

Permalink
Merge pull request #9 from Holzhaus/skip-refs-without-conf
Browse files Browse the repository at this point in the history
Skip git refs without sourcedir or conf.py
  • Loading branch information
Holzhaus authored May 1, 2020
2 parents e7dfaff + c19492b commit 04a81d9
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 13 deletions.
7 changes: 7 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ Changelog
Version 0.2
===========

Version 0.2.2
-------------

* Added additional checks to determine if a branch or tag contains both the Sphinx source directory and the :file:`conf.py` file. If that's not the case, that branch or tag is skipped automatically and not copied to the temporary directory. (`#9 <issue9_>`_)


Version 0.2.1
-------------

Expand Down Expand Up @@ -36,3 +42,4 @@ Version 0.1.0

.. _issue4: https://github.com/Holzhaus/sphinx-multiversion/issues/4
.. _issue7: https://github.com/Holzhaus/sphinx-multiversion/issues/7
.. _issue9: https://github.com/Holzhaus/sphinx-multiversion/issues/9
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

author = "Jan Holthuis"
project = "sphinx-multiversion"
release = "0.2.1"
release = "0.2.2"
version = "0.2"
copyright = "{}, {}".format(time.strftime("%Y"), author)

Expand Down
3 changes: 1 addition & 2 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ You can override all of these values inside your :file:`conf.py`.

.. note::

You can check which tags/branches are matched by running ``sphinx-multiversion`` with the ``--dump-metadata`` flag.

You can check which tags/branches are matched by running ``sphinx-multiversion`` with the ``--dump-metadata`` flag. Branches or tags that don't contain both the sphinx source directory and the :file:`conf.py` file will be skipped automatically.

Tag/Branch/Remote whitelists
============================
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
author="Jan Holthuis",
author_email="holthuis.jan@googlemail.com",
url="https://holzhaus.github.io/sphinx-multiversion/",
version="0.2.1",
version="0.2.2",
install_requires=["sphinx >= 2.1"],
license="BSD",
packages=["sphinx_multiversion"],
Expand Down
22 changes: 21 additions & 1 deletion sphinx_multiversion/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ def get_all_refs(gitroot):
yield GitRef(name, commit, source, is_remote, refname, creatordate)


def get_refs(gitroot, tag_whitelist, branch_whitelist, remote_whitelist):
def get_refs(
gitroot, tag_whitelist, branch_whitelist, remote_whitelist, files=()
):
for ref in get_all_refs(gitroot):
if ref.source == "tags":
if tag_whitelist is None or not re.match(tag_whitelist, ref.name):
Expand All @@ -69,9 +71,27 @@ def get_refs(gitroot, tag_whitelist, branch_whitelist, remote_whitelist):
else:
continue

if not all(
file_exists(gitroot, ref.name, filename) for filename in files
):
continue

yield ref


def file_exists(gitroot, refname, filename):
cmd = (
"git",
"cat-file",
"-e",
"{}:{}".format(refname, filename),
)
proc = subprocess.run(
cmd, cwd=gitroot, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL
)
return proc.returncode == 0


def copy_tree(src, dst, reference, sourcepath="."):
with tempfile.SpooledTemporaryFile() as fp:
cmd = (
Expand Down
18 changes: 10 additions & 8 deletions sphinx_multiversion/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,22 @@ def main(argv=None):
config.pre_init_values()
config.init_values()

# Get git references
# Get relative paths to root of git repository
gitroot = pathlib.Path(".").resolve()
sourcedir = os.path.relpath(args.sourcedir, str(gitroot))
if args.confdir:
confdir = os.path.relpath(args.confdir, str(gitroot))
else:
confdir = sourcedir
conffile = os.path.join(confdir, "conf.py")

# Get git references
gitrefs = git.get_refs(
str(gitroot),
config.smv_tag_whitelist,
config.smv_branch_whitelist,
config.smv_remote_whitelist,
files=(sourcedir, conffile),
)

# Order git refs
Expand All @@ -108,13 +117,6 @@ def main(argv=None):

logger = logging.getLogger(__name__)

# Get Sourcedir
sourcedir = os.path.relpath(args.sourcedir, str(gitroot))
if args.confdir:
confdir = os.path.relpath(args.confdir, str(gitroot))
else:
confdir = sourcedir

with tempfile.TemporaryDirectory() as tmp:
# Generate Metadata
metadata = {}
Expand Down

0 comments on commit 04a81d9

Please sign in to comment.