From 0f12d7b9d5b1ceeee3166b9fc7d1372da5893dd3 Mon Sep 17 00:00:00 2001 From: Jan Holthuis Date: Thu, 30 Apr 2020 22:09:46 +0200 Subject: [PATCH 1/6] Skip git refs without sourcedir or conf.py --- sphinx_multiversion/git.py | 17 ++++++++++++++++- sphinx_multiversion/main.py | 18 ++++++++++-------- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/sphinx_multiversion/git.py b/sphinx_multiversion/git.py index bdb6a1bc..166228c2 100644 --- a/sphinx_multiversion/git.py +++ b/sphinx_multiversion/git.py @@ -48,7 +48,7 @@ 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): @@ -69,9 +69,24 @@ 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, capture_output=True) + return proc.returncode == 0 + + def copy_tree(src, dst, reference, sourcepath="."): with tempfile.SpooledTemporaryFile() as fp: cmd = ( diff --git a/sphinx_multiversion/main.py b/sphinx_multiversion/main.py index 657c9188..f32a063e 100644 --- a/sphinx_multiversion/main.py +++ b/sphinx_multiversion/main.py @@ -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 @@ -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 = {} From 7fbdb902daad6ec5446c3597aa46a9bf5b0894cc Mon Sep 17 00:00:00 2001 From: Jan Holthuis Date: Fri, 1 May 2020 23:11:21 +0200 Subject: [PATCH 2/6] docs/configuration: Document automatic branch/tag skipping in note --- docs/configuration.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index af5fad99..6b7d6aa2 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -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 ============================ From f94f7e56b391c736a89243fcc82e03b7d25fa43e Mon Sep 17 00:00:00 2001 From: Jan Holthuis Date: Fri, 1 May 2020 23:12:27 +0200 Subject: [PATCH 3/6] Increase version to 0.2.2 and add changelog entry --- docs/changelog.rst | 7 +++++++ docs/conf.py | 2 +- setup.py | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 9eaedcee..4a3a7248 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -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 `_) + + Version 0.2.1 ------------- @@ -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 diff --git a/docs/conf.py b/docs/conf.py index 09284efb..b2119257 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -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) diff --git a/setup.py b/setup.py index 7ebd515c..491d25fd 100755 --- a/setup.py +++ b/setup.py @@ -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"], From 361621d1959d6d577a996ec5d159a786ad4f2aec Mon Sep 17 00:00:00 2001 From: Jan Holthuis Date: Fri, 1 May 2020 23:20:49 +0200 Subject: [PATCH 4/6] sphinx_multiversion/git: Break long line --- sphinx_multiversion/git.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sphinx_multiversion/git.py b/sphinx_multiversion/git.py index 166228c2..df8823b1 100644 --- a/sphinx_multiversion/git.py +++ b/sphinx_multiversion/git.py @@ -48,7 +48,8 @@ def get_all_refs(gitroot): yield GitRef(name, commit, source, is_remote, refname, creatordate) -def get_refs(gitroot, tag_whitelist, branch_whitelist, remote_whitelist, files=()): +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): From 37276b11345b6d2e3e3cc48426080c52f7589d19 Mon Sep 17 00:00:00 2001 From: Jan Holthuis Date: Fri, 1 May 2020 23:24:29 +0200 Subject: [PATCH 5/6] sphinx_multiversion/git: Apply black autoformatting --- sphinx_multiversion/git.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/sphinx_multiversion/git.py b/sphinx_multiversion/git.py index df8823b1..45186352 100644 --- a/sphinx_multiversion/git.py +++ b/sphinx_multiversion/git.py @@ -48,8 +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, - files=()): +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): @@ -70,8 +71,9 @@ 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): + if not all( + file_exists(gitroot, ref.name, filename) for filename in files + ): continue yield ref From c19492b97ade643ae5dfdeecd97fd2a41d3d399a Mon Sep 17 00:00:00 2001 From: Jan Holthuis Date: Fri, 1 May 2020 23:33:34 +0200 Subject: [PATCH 6/6] sphinx_multiversion/git: Restore Python 3.6 compatibility --- sphinx_multiversion/git.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sphinx_multiversion/git.py b/sphinx_multiversion/git.py index 45186352..37b3ea93 100644 --- a/sphinx_multiversion/git.py +++ b/sphinx_multiversion/git.py @@ -86,7 +86,9 @@ def file_exists(gitroot, refname, filename): "-e", "{}:{}".format(refname, filename), ) - proc = subprocess.run(cmd, cwd=gitroot, capture_output=True) + proc = subprocess.run( + cmd, cwd=gitroot, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL + ) return proc.returncode == 0