mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-02 03:46:53 +00:00
Find filenames for mercurial hook
Extract the files changed in a particular commit or set of commits for the commit and qrefresh mercurial hooks.
This commit is contained in:
parent
eff77e2bc2
commit
023de21fe2
1 changed files with 19 additions and 1 deletions
|
|
@ -32,8 +32,10 @@ def hook(ui, repo, **kwargs):
|
|||
hgconfig = configparser_for(hgrc)
|
||||
strict = hgconfig.get('flake8', 'strict', fallback=True)
|
||||
|
||||
filenames = list(get_filenames_from(repo, kwargs))
|
||||
|
||||
app = application.Application()
|
||||
app.run()
|
||||
app.run(filenames)
|
||||
|
||||
if strict:
|
||||
return app.result_count
|
||||
|
|
@ -78,6 +80,22 @@ def install():
|
|||
return True
|
||||
|
||||
|
||||
def get_filenames_from(repository, kwargs):
|
||||
seen_filenames = set()
|
||||
node = kwargs['node']
|
||||
for revision in range(repository[node], len(repository)):
|
||||
for filename in repository[revision].files():
|
||||
full_filename = os.path.join(repository.root, filename)
|
||||
have_seen_filename = full_filename in seen_filenames
|
||||
filename_does_not_exist = not os.path.exists(full_filename)
|
||||
if have_seen_filename or filename_does_not_exist:
|
||||
continue
|
||||
|
||||
seen_filenames.add(full_filename)
|
||||
if full_filename.endswith('.py'):
|
||||
yield full_filename
|
||||
|
||||
|
||||
def find_hgrc(create_if_missing=False):
|
||||
root = subprocess.Popen(
|
||||
['hg', 'root'],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue