summaryrefslogtreecommitdiff
path: root/src/flake8/main/vcs.py
diff options
context:
space:
mode:
authorIan Cordasco <graffatcolmingov@gmail.com>2016-06-25 12:01:02 -0500
committerIan Cordasco <graffatcolmingov@gmail.com>2016-06-25 12:01:02 -0500
commitcee691059f0a2805c644a1c3541f70e306225b48 (patch)
tree63ae4c14f3968d8d88c398bb4cbb15d691618202 /src/flake8/main/vcs.py
parent93089108932a5382630243a5691d4cf796b60ec4 (diff)
parent6eb2e3a70147baad1cc2ad3d51c269974da2320f (diff)
downloadflake8-3.0.0b1.tar.gz
Merge branch 'origin/proposed/3.0' into master3.0.0b1
Diffstat (limited to 'src/flake8/main/vcs.py')
-rw-r--r--src/flake8/main/vcs.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/flake8/main/vcs.py b/src/flake8/main/vcs.py
new file mode 100644
index 0000000..6f7499e
--- /dev/null
+++ b/src/flake8/main/vcs.py
@@ -0,0 +1,39 @@
+"""Module containing some of the logic for our VCS installation logic."""
+from flake8 import exceptions as exc
+from flake8.main import git
+from flake8.main import mercurial
+
+
+# NOTE(sigmavirus24): In the future, we may allow for VCS hooks to be defined
+# as plugins, e.g., adding a flake8.vcs entry-point. In that case, this
+# dictionary should disappear, and this module might contain more code for
+# managing those bits (in conjuntion with flake8.plugins.manager).
+_INSTALLERS = {
+ 'git': git.install,
+ 'mercurial': mercurial.install,
+}
+
+
+def install(option, option_string, value, parser):
+ """Determine which version control hook to install.
+
+ For more information about the callback signature, see:
+ https://docs.python.org/2/library/optparse.html#optparse-option-callbacks
+ """
+ installer = _INSTALLERS.get(value)
+ errored = False
+ successful = False
+ try:
+ successful = installer()
+ except exc.HookInstallationError as hook_error:
+ print(str(hook_error))
+ errored = True
+
+ if not successful:
+ print('Could not find the {0} directory'.format(value))
+ raise SystemExit(not successful and errored)
+
+
+def choices():
+ """Return the list of VCS choices."""
+ return list(_INSTALLERS.keys())