3 from subprocess import Popen, PIPE
5 THISDIR_RE=re.compile("What's new in \"(.*)\"")
7 def exec_darcs(darcscmd):
8 cmd = ['darcs'] + darcscmd
10 p = Popen(cmd, stdout=PIPE, stderr=PIPE, universal_newlines=True)
11 except EnvironmentError:
12 cmd = ['realdarcs.exe'] + darcscmd
13 p = Popen(cmd, stdout=PIPE, stderr=PIPE, universal_newlines=True)
15 output = p.communicate()[0]
16 return (p.returncode, output)
18 def run_darcs_query_manifest():
19 return exec_darcs(['query', 'manifest'])
21 def run_darcs_whatsnew_dot():
22 return exec_darcs(['whatsnew', '.'])
24 def find_files_for_darcs(dirname):
26 unused, whatsnewoutput = run_darcs_whatsnew_dot()
27 queryretcode, queryoutput = run_darcs_query_manifest()
28 except EnvironmentError:
29 if not os.path.exists('PKG-INFO'):
30 from distutils import log
31 log.info("Unable to execute darcs -- if you are building a package with 'setup.py sdist', 'setup.py bdist_egg', or other package-building commands, then the resulting package might be missing some files. If you are not building a package then you can ignore this warning.")
32 # Oh well -- just return None.
36 if not os.path.exists('PKG-INFO'):
37 from distutils import log
38 log.warn("Failure to get the list of managed files from darcs -- if you are building a package with 'setup.py sdist', 'setup.py bdist_egg', or other package-building commands, then the resulting package might be missing some files. If you are not building a package then you can ignore this warning.")
39 # Oh well -- just return None.
43 mo = THISDIR_RE.search(whatsnewoutput)
45 curdirname = mo.group(1)
46 while curdirname.endswith('/'):
47 curdirname = curdirname[:-1]
52 # Prepend this directory.
53 rel_to_repo_dirname = curdirname + dirname
55 # Normalize rel_to_repo_dirname from local form to the form that setuptools uses to the form that "darcs query manifest" outputs (unix form).
56 rel_to_repo_dirname = rel_to_repo_dirname.replace('\\', '/')
57 while rel_to_repo_dirname.endswith('/'):
58 rel_to_repo_dirname = rel_to_repo_dirname[:-1]
60 # Append a '/' to make sure we don't match "foobar" when rel_to_repo_dirname is "foo".
61 if rel_to_repo_dirname:
62 rel_to_repo_dirname += '/'
65 for fn in queryoutput.split('\n'):
68 if fn.startswith('./'):
70 if fn.startswith(rel_to_repo_dirname):
71 fn = fn[len(rel_to_repo_dirname):]
73 # We need to replace "/" by "\\" because setuptools can't includes web/*.xhtml files on Windows, due of path separator
74 # This correct ticket #1033
75 yield fn.replace('/', os.sep)
77 if warn and not os.path.exists('PKG-INFO'):
78 from distutils import log
79 log.warn("Didn't find any files in directory \"%s\" (full path: \"%s\") that were managed by darcs revision control -- if you are building a package with 'setup.py sdist', 'setup.py bdist_egg', or other package-building commands, then the resulting package might be missing some files. If you are not building a package then you can ignore this warning." % (dirname, os.path.abspath(rel_to_repo_dirname),))