summaryrefslogtreecommitdiff
path: root/setuptools_scm/file_finder.py
diff options
context:
space:
mode:
authorStéphane Bidoul (ACSONE) <stephane.bidoul@acsone.eu>2018-04-28 18:35:07 +0200
committerStéphane Bidoul (ACSONE) <stephane.bidoul@acsone.eu>2018-04-28 19:33:00 +0200
commit7253898ffff71c889d0a8ad2b5c0f4ca44146eee (patch)
treef527cacadc719ec958f02bfe7b7ec7a61a1daf23 /setuptools_scm/file_finder.py
parent9b36312cc0f08d052edee1b9567a83219960934f (diff)
downloadsetuptools-scm-7253898ffff71c889d0a8ad2b5c0f4ca44146eee.tar.gz
Refactor hg and git file finders to use the same algorithm
Also make the test parametric.
Diffstat (limited to 'setuptools_scm/file_finder.py')
-rw-r--r--setuptools_scm/file_finder.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/setuptools_scm/file_finder.py b/setuptools_scm/file_finder.py
new file mode 100644
index 0000000..fb7648a
--- /dev/null
+++ b/setuptools_scm/file_finder.py
@@ -0,0 +1,33 @@
+import os
+
+
+def scm_find_files(path, scm_files, scm_dirs):
+ """ setuptools compatible file finder that follows symlinks
+
+ - path: the root directory from which to search
+ - scm_files: set of scm controlled files
+ - scm_files: set of scm controlled directories
+
+ scm_files and scm_dirs must be absolute with symlinks resolved (realpath),
+ with normalized case (normcase)
+
+ Spec here: http://setuptools.readthedocs.io/en/latest/setuptools.html#\
+ adding-support-for-revision-control-systems
+ """
+ realpath = os.path.normcase(os.path.realpath(path))
+ seen = set()
+ res = []
+ for dirpath, dirnames, filenames in os.walk(realpath, followlinks=True):
+ # dirpath with symlinks resolved
+ realdirpath = os.path.normcase(os.path.realpath(dirpath))
+ if realdirpath not in scm_dirs or realdirpath in seen:
+ dirnames[:] = []
+ continue
+ for filename in filenames:
+ # dirpath + filename with symlinks preserved
+ fullfilename = os.path.join(dirpath, filename)
+ if os.path.normcase(os.path.realpath(fullfilename)) in scm_files:
+ res.append(
+ os.path.join(path, os.path.relpath(fullfilename, path)))
+ seen.add(realdirpath)
+ return res