Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
In progress
===========

* fix #587: don't fail file finders when distribution is not given
* fix #524: new parameters ``normalize`` and ``version_cls`` to customize the version normalization class.
* fix #585: switch from toml to tomli

Expand Down
28 changes: 18 additions & 10 deletions src/setuptools_scm/file_finder_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from .file_finder import is_toplevel_acceptable
from .file_finder import scm_find_files
from .utils import do_ex
from .utils import trace

log = logging.getLogger(__name__)
Expand All @@ -13,13 +14,17 @@
def _git_toplevel(path):
try:
cwd = os.path.abspath(path or ".")
with open(os.devnull, "wb") as devnull:
out = subprocess.check_output(
["git", "rev-parse", "--show-prefix"],
cwd=cwd,
universal_newlines=True,
stderr=devnull,
)
out, err, ret = do_ex(["git", "rev-parse", "HEAD"], cwd=cwd)
if ret != 0:
# BAIL if there is no commit
log.error("listing git files failed - pretending there aren't any")
return None
out, err, ret = do_ex(
["git", "rev-parse", "--show-prefix"],
cwd=cwd,
)
if ret != 0:
return None
out = out.strip()[:-1] # remove the trailing pathsep
if not out:
out = cwd
Expand All @@ -28,7 +33,7 @@ def _git_toplevel(path):
# ``cwd`` is absolute path to current working directory.
# the below method removes the length of ``out`` from
# ``cwd``, which gives the git toplevel
assert cwd.replace("\\", "/").endswith(out)
assert cwd.replace("\\", "/").endswith(out), f"cwd={cwd!r}\nout={out!r}"
# In windows cwd contains ``\`` which should be replaced by ``/``
# for this assertion to work. Length of string isn't changed by replace
# ``\\`` is just and escape for `\`
Expand Down Expand Up @@ -59,8 +64,11 @@ def _git_interpret_archive(fd, toplevel):
def _git_ls_files_and_dirs(toplevel):
# use git archive instead of git ls-file to honor
# export-ignore git attribute

cmd = ["git", "archive", "--prefix", toplevel + os.path.sep, "HEAD"]
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, cwd=toplevel)
proc = subprocess.Popen(
cmd, stdout=subprocess.PIPE, cwd=toplevel, stderr=subprocess.DEVNULL
)
try:
try:
return _git_interpret_archive(proc.stdout, toplevel)
Expand All @@ -70,7 +78,7 @@ def _git_ls_files_and_dirs(toplevel):
proc.terminate()
except Exception:
if proc.wait() != 0:
log.exception("listing git files failed - pretending there aren't any")
log.error("listing git files failed - pretending there aren't any")
return (), ()


Expand Down
7 changes: 4 additions & 3 deletions src/setuptools_scm/file_finder_hg.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from .file_finder import is_toplevel_acceptable
from .file_finder import scm_find_files
from .utils import do_ex


def _hg_toplevel(path):
Expand All @@ -26,9 +27,9 @@ def _hg_toplevel(path):
def _hg_ls_files_and_dirs(toplevel):
hg_files = set()
hg_dirs = {toplevel}
out = subprocess.check_output(
["hg", "files"], cwd=toplevel, universal_newlines=True
)
out, err, ret = do_ex(["hg", "files"], cwd=toplevel)
if ret:
(), ()
for name in out.splitlines():
name = os.path.normcase(name).replace("/", os.path.sep)
fullname = os.path.join(toplevel, name)
Expand Down
9 changes: 8 additions & 1 deletion testing/test_file_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ def inwd(request, wd, monkeypatch):
bdir = wd.cwd / "bdir"
bdir.mkdir()
(bdir / "fileb").touch()
wd.add_and_commit()
if request.node.get_closest_marker("skip_commit") is None:
wd.add_and_commit()
monkeypatch.chdir(wd.cwd)
yield wd

Expand Down Expand Up @@ -184,3 +185,9 @@ def test_symlink_not_in_scm_while_target_is(inwd):
"data/datafile",
}
)


@pytest.mark.issue(587)
@pytest.mark.skip_commit
def test_not_commited(inwd):
assert find_files() == []
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ testpaths=testing
filterwarnings=error
markers=
issue(id): reference to github issue
skip_commit: allows to skip commiting in the helpers
# disable unraisable until investigated
addopts = -p no:unraisableexception

Expand Down