Skip to content

Commit 632b02b

Browse files
Merge pull request #186 from anntzer/gitarchive-exportignore
Respect git's export-ignore for building the sdist.
2 parents fc824aa + 8da360a commit 632b02b

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
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: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
from .utils import do_ex, trace, has_command
22
from .version import meta
3+
34
from os.path import isfile, join
5+
import subprocess
6+
import sys
7+
import tarfile
48
import warnings
59

10+
611
try:
712
from os.path import samefile
813
except ImportError:
914
from .win_py31_compat import samefile
1015

1116

12-
FILES_COMMAND = 'git ls-files'
17+
FILES_COMMAND = sys.executable + ' -m setuptools_scm.git'
1318
DEFAULT_DESCRIBE = 'git describe --dirty --tags --long --match *.*'
1419

1520

@@ -116,3 +121,17 @@ def parse(root, describe_command=DEFAULT_DESCRIBE, pre_parse=warn_on_shallow):
116121
return meta(tag, distance=number, node=node, dirty=dirty)
117122
else:
118123
return meta(tag, node=node, dirty=dirty)
124+
125+
126+
def _list_files_in_archive():
127+
"""List the files that 'git archive' generates.
128+
"""
129+
cmd = ['git', 'archive', 'HEAD']
130+
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
131+
tf = tarfile.open(fileobj=proc.stdout, mode='r|*')
132+
for name in tf.getnames():
133+
print(name)
134+
135+
136+
if __name__ == "__main__":
137+
_list_files_in_archive()

setuptools_scm/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def _popen_pipes(cmd, cwd):
6161

6262
def do_ex(cmd, cwd='.'):
6363
trace('cmd', repr(cmd))
64-
if not isinstance(cmd, (list, tuple)):
64+
if os.name == "posix" and not isinstance(cmd, (list, tuple)):
6565
cmd = shlex.split(cmd)
6666

6767
p = _popen_pipes(cmd, cwd)

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)