Skip to content

Commit

Permalink
fix pypa#352: add a envvar to ignore scm roots
Browse files Browse the repository at this point in the history
  • Loading branch information
RonnyPfannschmidt committed Nov 29, 2020
1 parent ef36e47 commit 9078b36
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
v4.2.0
======

* fix #352: add support for generally ignoring specific vcs roots
* fix #471: better error for version bump failing on complex but accepted tag
* fix #479: raise indicative error when tags carry non-parsable information
* Add `no-guess-dev` which does no next version guessing, just adds `.post1.devN` in
Expand Down
5 changes: 5 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,11 @@ Environment variables
derived, otherwise the current time is used
(https://reproducible-builds.org/docs/source-date-epoch/)


:SETUPTOOLS_SCM_IGNORE_VCS_ROOTS:
when defined, a ``os.pathsep`` separated list
of directory names to ignore for root finding

Extending setuptools_scm
------------------------

Expand Down
9 changes: 9 additions & 0 deletions src/setuptools_scm/file_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,12 @@ def _link_not_in_scm(n):
res.append(os.path.join(path, os.path.relpath(fullfilename, realpath)))
seen.add(realdirpath)
return res


def is_toplevel_acceptable(toplevel):
if toplevel is None:
return False

return toplevel not in os.environ.get("SETUPTOOLS_SCM_IGNORE_VCS_ROOTS", "").split(
os.pathsep
)
3 changes: 2 additions & 1 deletion src/setuptools_scm/file_finder_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import tarfile
import logging
from .file_finder import scm_find_files
from .file_finder import is_toplevel_acceptable
from .utils import trace

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -60,7 +61,7 @@ def _git_ls_files_and_dirs(toplevel):

def git_find_files(path=""):
toplevel = _git_toplevel(path)
if not toplevel:
if not is_toplevel_acceptable(toplevel):
return []
fullpath = os.path.abspath(os.path.normpath(path))
if not fullpath.startswith(toplevel):
Expand Down
3 changes: 2 additions & 1 deletion src/setuptools_scm/file_finder_hg.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import subprocess

from .file_finder import scm_find_files
from .file_finder import is_toplevel_acceptable


def _hg_toplevel(path):
Expand Down Expand Up @@ -41,7 +42,7 @@ def _hg_ls_files_and_dirs(toplevel):

def hg_find_files(path=""):
toplevel = _hg_toplevel(path)
if not toplevel:
if not is_toplevel_acceptable(toplevel):
return []
hg_files, hg_dirs = _hg_ls_files_and_dirs(toplevel)
return scm_find_files(path, hg_files, hg_dirs)
6 changes: 6 additions & 0 deletions testing/test_file_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ def test_symlink_file_out_of_git(inwd):
assert set(find_files("adir")) == _sep({"adir/filea"})


@pytest.mark.parametrize("path_add", ["{cwd}", "{cwd}:broken"])
def test_ignore_root(inwd, monkeypatch, path_add):
monkeypatch.setenv("SETUPTOOLS_SCM_IGNORE_VCS_ROOTS", path_add.format(cwd=inwd.cwd))
assert find_files() == []


def test_empty_root(inwd):
subdir = inwd.cwd / "cdir" / "subdir"
subdir.mkdir(parents=True)
Expand Down

0 comments on commit 9078b36

Please sign in to comment.