swc-installation-test-2.py: Targeted links to workshop setup instructions target-swc-setup-links
authorW. Trevor King <wking@tremily.us>
Thu, 5 Mar 2015 19:29:06 +0000 (11:29 -0800)
committerW. Trevor King <wking@tremily.us>
Thu, 5 Mar 2015 19:29:06 +0000 (11:29 -0800)
With [1], we can mostly point folks to the right place if we can't
find a particular package.

There's some funkiness around editors, since most of our editor
instructions are just links to the upstream projects, and we have
different suggestions for each operating system.

We're also pointing most users at Anaconda, instead of listing the
packages we need explicitly [2,3,4], it's hard to know which specific
PythonPackageDependencies should also link to #python-{system}.  I've
left them off entirely for now, but instructors who want to link to
their setup instructions when we can get a Python version but not, for
example, a NumPy version should add a ('numpy', 'python') entry to the
check/check_id loop.

[1]: https://github.com/swcarpentry/workshop-template/pull/171
[2]: https://github.com/swcarpentry/bc/issues/724#issuecomment-56095114
[3]: https://github.com/swcarpentry/bc/issues/724#issuecomment-56095877
[4]: https://github.com/swcarpentry/bc/issues/724#issuecomment-56096123

swc-installation-test-2.py

index 129bf96878ed0a821daf495a368b75eec908f429..89adce449779798212b0c14bdc9c6d482a400b40 100755 (executable)
@@ -102,6 +102,35 @@ CHECKS = [
     'mayavi.mlab',
     ]
 
+# setup page.  Leave this alone to use the stock workshop template's
+# setup instructions, point at your workshop page to use your
+# workshop's setup instructions, or set to None to only link to the
+# upstream project's setup instructions.
+SETUP_URL = 'https://swcarpentry.github.io/workshop-template/'
+
+# setup ID scheme (e.g. map nano issue to "editor")
+SETUP_IDS = {  # list unpredictable IDs in this dict literal
+    ('Windows', '*', 'notepad++'): 'editor-windows',
+    ('Darwin', '*', 'textwrangler'): 'editor-macosx',
+    ('Darwin', '*', 'sublime-text'): 'editor-macosx',
+    ('Linux', '*', 'kate'): 'editor-linux',
+    }
+
+# add predictable {system}-{check} IDs to SETUP_IDS
+for check, check_id in [
+        ('nano', 'editor'),
+        ('bash', 'shell'),
+        ('git', 'git'),
+        ('python', 'python'),
+        ('sqlite3', 'sql'),
+        ]:
+    for system, system_id in [
+            ('Linux', 'linux'),
+            ('Darwin', 'macosx'),
+            ('Windows', 'windows'),
+            ]:
+        SETUP_IDS[(system, '*', check)] = '{0}-{1}'.format(check_id, system_id)
+
 CHECKER = {}
 
 _ROOT_PATH = _os.sep
@@ -119,7 +148,7 @@ class InvalidCheck (KeyError):
 
 
 class DependencyError (Exception):
-    _default_url = 'http://software-carpentry.org/setup/'
+    _default_url = SETUP_URL
     _setup_urls = {  # (system, version, package) glob pairs
         ('*', '*', 'Cython'): 'http://docs.cython.org/src/quickstart/install.html',
         ('Linux', '*', 'EasyMercurial'): 'http://easyhg.org/download.html#download-linux',
@@ -206,11 +235,19 @@ class DependencyError (Exception):
                 version = value[0]
                 break
         package = self.checker.name
+        urls = []
+        for (s,v,p),id in SETUP_IDS.items():
+            if (_fnmatch.fnmatch(system, s) and
+                    _fnmatch.fnmatch(version, v) and
+                    _fnmatch.fnmatch(package, p)):
+                urls.append('{0}#{1}'.format(SETUP_URL, id))
         for (s,v,p),url in self._setup_urls.items():
             if (_fnmatch.fnmatch(system, s) and
                     _fnmatch.fnmatch(version, v) and
                     _fnmatch.fnmatch(package, p)):
-                return [url]
+                urls.append(url)
+        if urls:
+            return urls
         return [self._default_url]
 
     def __str__(self):