Skip to content

Commit 04a81d9

Browse files
authored
Merge pull request #9 from Holzhaus/skip-refs-without-conf
Skip git refs without sourcedir or conf.py
2 parents e7dfaff + c19492b commit 04a81d9

File tree

6 files changed

+41
-13
lines changed

6 files changed

+41
-13
lines changed

docs/changelog.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ Changelog
77
Version 0.2
88
===========
99

10+
Version 0.2.2
11+
-------------
12+
13+
* 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_>`_)
14+
15+
1016
Version 0.2.1
1117
-------------
1218

@@ -36,3 +42,4 @@ Version 0.1.0
3642

3743
.. _issue4: https://github.com/Holzhaus/sphinx-multiversion/issues/4
3844
.. _issue7: https://github.com/Holzhaus/sphinx-multiversion/issues/7
45+
.. _issue9: https://github.com/Holzhaus/sphinx-multiversion/issues/9

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
author = "Jan Holthuis"
66
project = "sphinx-multiversion"
7-
release = "0.2.1"
7+
release = "0.2.2"
88
version = "0.2"
99
copyright = "{}, {}".format(time.strftime("%Y"), author)
1010

docs/configuration.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ You can override all of these values inside your :file:`conf.py`.
3333

3434
.. note::
3535

36-
You can check which tags/branches are matched by running ``sphinx-multiversion`` with the ``--dump-metadata`` flag.
37-
36+
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.
3837

3938
Tag/Branch/Remote whitelists
4039
============================

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
author="Jan Holthuis",
2121
author_email="holthuis.jan@googlemail.com",
2222
url="https://holzhaus.github.io/sphinx-multiversion/",
23-
version="0.2.1",
23+
version="0.2.2",
2424
install_requires=["sphinx >= 2.1"],
2525
license="BSD",
2626
packages=["sphinx_multiversion"],

sphinx_multiversion/git.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ def get_all_refs(gitroot):
4848
yield GitRef(name, commit, source, is_remote, refname, creatordate)
4949

5050

51-
def get_refs(gitroot, tag_whitelist, branch_whitelist, remote_whitelist):
51+
def get_refs(
52+
gitroot, tag_whitelist, branch_whitelist, remote_whitelist, files=()
53+
):
5254
for ref in get_all_refs(gitroot):
5355
if ref.source == "tags":
5456
if tag_whitelist is None or not re.match(tag_whitelist, ref.name):
@@ -69,9 +71,27 @@ def get_refs(gitroot, tag_whitelist, branch_whitelist, remote_whitelist):
6971
else:
7072
continue
7173

74+
if not all(
75+
file_exists(gitroot, ref.name, filename) for filename in files
76+
):
77+
continue
78+
7279
yield ref
7380

7481

82+
def file_exists(gitroot, refname, filename):
83+
cmd = (
84+
"git",
85+
"cat-file",
86+
"-e",
87+
"{}:{}".format(refname, filename),
88+
)
89+
proc = subprocess.run(
90+
cmd, cwd=gitroot, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL
91+
)
92+
return proc.returncode == 0
93+
94+
7595
def copy_tree(src, dst, reference, sourcepath="."):
7696
with tempfile.SpooledTemporaryFile() as fp:
7797
cmd = (

sphinx_multiversion/main.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,22 @@ def main(argv=None):
9191
config.pre_init_values()
9292
config.init_values()
9393

94-
# Get git references
94+
# Get relative paths to root of git repository
9595
gitroot = pathlib.Path(".").resolve()
96+
sourcedir = os.path.relpath(args.sourcedir, str(gitroot))
97+
if args.confdir:
98+
confdir = os.path.relpath(args.confdir, str(gitroot))
99+
else:
100+
confdir = sourcedir
101+
conffile = os.path.join(confdir, "conf.py")
102+
103+
# Get git references
96104
gitrefs = git.get_refs(
97105
str(gitroot),
98106
config.smv_tag_whitelist,
99107
config.smv_branch_whitelist,
100108
config.smv_remote_whitelist,
109+
files=(sourcedir, conffile),
101110
)
102111

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

109118
logger = logging.getLogger(__name__)
110119

111-
# Get Sourcedir
112-
sourcedir = os.path.relpath(args.sourcedir, str(gitroot))
113-
if args.confdir:
114-
confdir = os.path.relpath(args.confdir, str(gitroot))
115-
else:
116-
confdir = sourcedir
117-
118120
with tempfile.TemporaryDirectory() as tmp:
119121
# Generate Metadata
120122
metadata = {}

0 commit comments

Comments
 (0)