Skip to content

Commit 5063443

Browse files
committed
Respect git's export-ignore for building the sdist.
Implemented by replacing the call to 'git ls-files' to '$sys.executable -msetuptools_scm.git' with the module parsing the output of 'git archive' as a tar file.
1 parent 46df188 commit 5063443

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
## Directory-based project format:
77
.idea/
88

9+
### Other editors
10+
.*.swp
11+
912

1013
### Python template
1114
# Byte-compiled / optimized

setuptools_scm/git.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
from .utils import do_ex, trace, has_command, _normalized
22
from .version import meta
3+
try:
4+
from io import BytesIO
5+
except ImportError:
6+
from cStringIO import StringIO as BytesIO
7+
38
from os.path import isfile, join
9+
import subprocess
10+
import sys
11+
from tarfile import TarFile
412
import warnings
513

6-
FILES_COMMAND = 'git ls-files'
14+
FILES_COMMAND = sys.executable + ' -msetuptools_scm.git'
715
DEFAULT_DESCRIBE = 'git describe --dirty --tags --long --match *.*'
816

917

@@ -110,3 +118,16 @@ def parse(root, describe_command=DEFAULT_DESCRIBE, pre_parse=warn_on_shallow):
110118
return meta(tag, distance=number, node=node, dirty=dirty)
111119
else:
112120
return meta(tag, node=node, dirty=dirty)
121+
122+
123+
def _main():
124+
"""List the files that 'git archive' wants.
125+
"""
126+
# TarFile wants a seekable stream.
127+
stream = BytesIO(subprocess.check_output(['git', 'archive', 'HEAD']))
128+
for name in TarFile(fileobj=stream).getnames():
129+
print(name)
130+
131+
132+
if __name__ == "__main__":
133+
_main()

testing/test_git.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,15 @@ def test_alphanumeric_tags_match(wd):
112112
wd.commit_testfile()
113113
wd('git tag newstyle-development-started')
114114
assert wd.version.startswith('0.1.dev1+g')
115+
116+
117+
def test_git_archive_export_ignore(wd):
118+
wd.write('test1.txt', 'test')
119+
wd.write('test2.txt', 'test')
120+
wd.write('.git/info/attributes',
121+
# Explicitly include test1.txt so that the test is not affected by
122+
# a potentially global gitattributes file on the test machine.
123+
'/test1.txt -export-ignore\n/test2.txt export-ignore')
124+
wd('git add test1.txt test2.txt')
125+
wd.commit()
126+
assert integration.find_files(str(wd.cwd)) == ['test1.txt']

0 commit comments

Comments
 (0)