Skip to content

Instantly share code, notes, and snippets.

@wd15
Last active May 26, 2016 12:00
Show Gist options
  • Select an option

  • Save wd15/30bc62e0aec7bdedcc05e104c960f155 to your computer and use it in GitHub Desktop.

Select an option

Save wd15/30bc62e0aec7bdedcc05e104c960f155 to your computer and use it in GitHub Desktop.
Repository for SWC python lesson at NIST on 05/23/2016

Software development with Python

Where

West Square, Building 101

Schedule

  • 13:00 start
  • 14:30 coffee
  • 14:45 restart
  • 16:00 finish

Workshop Website

Go to https://pages.nist.gov/2016-05-23-nist/

Register

Go to https://doc.csod.com/

  • Type “Carpentry” in the search field in the upper right hand corner
  • A global search page will appear. Then click on “Training” in the left hand column
  • Scroll down through the Training results and locate and click on the event name: “NIST FY2016 – Software Carpentry”
  • Scroll down under “Sessions” and click the “Request” button to the right of the “Advanced - 05/23-24/2016, 9-5” or the “Novice - 05/26-27/2016, 9-5” session name and you will be enrolled

Survey

Pre-survey

Post-survey

Pair Programming

Team up in pairs

Check that Python is working

https://pages.nist.gov/2016-05-23-nist/setup/index.html

Jupyter Notebook

Does everyone have access to a notebook?

Syllabus

Programming in Python

  • Using libraries, working with numpy arrays and plotting data
  • Creating and using functions
  • Exceptions
  • Defensive programming
  • Debugging
  • Using Python from the command line -- command line programs

Links

Data

Link is at http://swcarpentry.github.io/python-novice-inflammation/index.html.

$ wget http://swcarpentry.github.io/python-novice-inflammation/python-novice-inflammation-data.zip

This Gist

https://gist.github.com/wd15/30bc62e0aec7bdedcc05e104c960f155

Fix Notebook for demo

from IPython.core.display import display, HTML
display(HTML("<style>.container { width:70% !important; }</style>"))
def favorite_ice_cream():
ice_creams = [
"chocolate",
"vanilla",
"strawberry"
]
print(ice_creams[3])
<!DOCTYPE html>
<html lang="en" class="">
<head prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# object: http://ogp.me/ns/object# article: http://ogp.me/ns/article# profile: http://ogp.me/ns/profile#">
<meta charset='utf-8'>
<link crossorigin="anonymous" href="https://assets-cdn.github.com/assets/frameworks-536bcdee57776d99649d118d29a291c9d7b41d101696162d6456c87b07314253.css" media="all" rel="stylesheet" />
<link crossorigin="anonymous" href="https://assets-cdn.github.com/assets/github-62cdd177894e003285e5b8b6fa72b4a92fb79f11a1ec44c2f2ae0f6f4ad2e724.css" media="all" rel="stylesheet" />
<link crossorigin="anonymous" href="https://assets-cdn.github.com/assets/site-c4b4365da282e51c06e107368db8502a2ecf82e64094d29d791b797372212de2.css" media="all" rel="stylesheet" />
<link as="script" href="https://assets-cdn.github.com/assets/frameworks-45f69297ece210de81f8efda93619ce7cff2475dbe66e57b0f01f0aa1341915c.js" rel="preload" />
<link as="script" href="https://assets-cdn.github.com/assets/github-207236d9c34ff5ba0c5941f877df52c9b53c4ddad9a125c5d2094fed3300ea17.js" rel="preload" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="Content-Language" content="en">
<meta name="viewport" content="width=device-width">
<title>python-novice-inflammation/errors_02.py at gh-pages · swcarpentry/python-novice-inflammation · GitHub</title>
<link rel="search" type="application/opensearchdescription+xml" href="/opensearch.xml" title="GitHub">
<link rel="fluid-icon" href="https://github.com/fluidicon.png" title="GitHub">
<link rel="apple-touch-icon" href="/apple-touch-icon.png">
<link rel="apple-touch-icon" sizes="57x57" href="/apple-touch-icon-57x57.png">
<link rel="apple-touch-icon" sizes="60x60" href="/apple-touch-icon-60x60.png">
<link rel="apple-touch-icon" sizes="72x72" href="/apple-touch-icon-72x72.png">
<link rel="apple-touch-icon" sizes="76x76" href="/apple-touch-icon-76x76.png">
<link rel="apple-touch-icon" sizes="114x114" href="/apple-touch-icon-114x114.png">
<link rel="apple-touch-icon" sizes="120x120" href="/apple-touch-icon-120x120.png">
<link rel="apple-touch-icon" sizes="144x144" href="/apple-touch-icon-144x144.png">
<link rel="apple-touch-icon" sizes="152x152" href="/apple-touch-icon-152x152.png">
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon-180x180.png">
<meta property="fb:app_id" content="1401488693436528">
<meta content="https://avatars3.githubusercontent.com/u/2238358?v=3&amp;s=400" name="twitter:image:src" /><meta content="@github" name="twitter:site" /><meta content="summary" name="twitter:card" /><meta content="swcarpentry/python-novice-inflammation" name="twitter:title" /><meta content="python-novice-inflammation - Software Carpentry introduction to Python for novices using inflammation data." name="twitter:description" />
<meta content="https://avatars3.githubusercontent.com/u/2238358?v=3&amp;s=400" property="og:image" /><meta content="GitHub" property="og:site_name" /><meta content="object" property="og:type" /><meta content="swcarpentry/python-novice-inflammation" property="og:title" /><meta content="https://github.com/swcarpentry/python-novice-inflammation" property="og:url" /><meta content="python-novice-inflammation - Software Carpentry introduction to Python for novices using inflammation data." property="og:description" />
<meta name="browser-stats-url" content="https://api.github.com/_private/browser/stats">
<meta name="browser-errors-url" content="https://api.github.com/_private/browser/errors">
<link rel="assets" href="https://assets-cdn.github.com/">
<meta name="pjax-timeout" content="1000">
<meta name="msapplication-TileImage" content="/windows-tile.png">
<meta name="msapplication-TileColor" content="#ffffff">
<meta name="selected-link" value="repo_source" data-pjax-transient>
<meta name="google-site-verification" content="KT5gs8h0wvaagLKAVWq8bbeNwnZZK1r1XQysX3xurLU">
<meta name="google-site-verification" content="ZzhVyEFwb7w3e0-uOTltm8Jsck2F5StVihD0exw2fsA">
<meta name="google-analytics" content="UA-3769691-2">
<meta content="collector.githubapp.com" name="octolytics-host" /><meta content="github" name="octolytics-app-id" /><meta content="6C1CA974:18C1:6502F05:573F7BC7" name="octolytics-dimension-request_id" />
<meta content="/&lt;user-name&gt;/&lt;repo-name&gt;/blob/show" data-pjax-transient="true" name="analytics-location" />
<meta class="js-ga-set" name="dimension1" content="Logged Out">
<meta name="hostname" content="github.com">
<meta name="user-login" content="">
<meta name="expected-hostname" content="github.com">
<meta name="js-proxy-site-detection-payload" content="ZTQ3MzAwNzQzOGUxZmQ2M2I3ZWJjMDA2MjQ0NDk1ODM3ZDFjMzk4ODQ5NmU0ZmNiMmJkNGY0NGJlYmNlNDU2N3x7InJlbW90ZV9hZGRyZXNzIjoiMTA4LjI4LjE2OS4xMTYiLCJyZXF1ZXN0X2lkIjoiNkMxQ0E5NzQ6MThDMTo2NTAyRjA1OjU3M0Y3QkM3IiwidGltZXN0YW1wIjoxNDYzNzc4MjQ3fQ==">
<link rel="mask-icon" href="https://assets-cdn.github.com/pinned-octocat.svg" color="#4078c0">
<link rel="icon" type="image/x-icon" href="https://assets-cdn.github.com/favicon.ico">
<meta name="html-safe-nonce" content="53d3d4cecaf73be9cddbbe7101a69380bc66bdd7">
<meta content="4a3440c2a6c0c29f952391bccbe2a3e3565dfef0" name="form-nonce" />
<meta http-equiv="x-pjax-version" content="384f6b58a193c5ab53409b7f0be00034">
<meta name="description" content="python-novice-inflammation - Software Carpentry introduction to Python for novices using inflammation data.">
<meta name="go-import" content="github.com/swcarpentry/python-novice-inflammation git https://github.com/swcarpentry/python-novice-inflammation.git">
<meta content="2238358" name="octolytics-dimension-user_id" /><meta content="swcarpentry" name="octolytics-dimension-user_login" /><meta content="27150322" name="octolytics-dimension-repository_id" /><meta content="swcarpentry/python-novice-inflammation" name="octolytics-dimension-repository_nwo" /><meta content="true" name="octolytics-dimension-repository_public" /><meta content="false" name="octolytics-dimension-repository_is_fork" /><meta content="27150322" name="octolytics-dimension-repository_network_root_id" /><meta content="swcarpentry/python-novice-inflammation" name="octolytics-dimension-repository_network_root_nwo" />
<link href="https://github.com/swcarpentry/python-novice-inflammation/commits/gh-pages.atom" rel="alternate" title="Recent Commits to python-novice-inflammation:gh-pages" type="application/atom+xml">
<link rel="canonical" href="https://github.com/swcarpentry/python-novice-inflammation/blob/gh-pages/code/errors_02.py" data-pjax-transient>
</head>
<body class="logged-out env-production vis-public page-blob">
<div id="js-pjax-loader-bar" class="pjax-loader-bar"></div>
<a href="#start-of-content" tabindex="1" class="accessibility-aid js-skip-to-content">Skip to content</a>
<header class="site-header js-details-container" role="banner">
<div class="container-responsive">
<a class="header-logo-invertocat" href="https://github.com/" aria-label="Homepage" data-ga-click="(Logged out) Header, go to homepage, icon:logo-wordmark">
<svg aria-hidden="true" class="octicon octicon-mark-github" height="32" version="1.1" viewBox="0 0 16 16" width="32"><path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59 0.4 0.07 0.55-0.17 0.55-0.38 0-0.19-0.01-0.82-0.01-1.49-2.01 0.37-2.53-0.49-2.69-0.94-0.09-0.23-0.48-0.94-0.82-1.13-0.28-0.15-0.68-0.52-0.01-0.53 0.63-0.01 1.08 0.58 1.23 0.82 0.72 1.21 1.87 0.87 2.33 0.66 0.07-0.52 0.28-0.87 0.51-1.07-1.78-0.2-3.64-0.89-3.64-3.95 0-0.87 0.31-1.59 0.82-2.15-0.08-0.2-0.36-1.02 0.08-2.12 0 0 0.67-0.21 2.2 0.82 0.64-0.18 1.32-0.27 2-0.27 0.68 0 1.36 0.09 2 0.27 1.53-1.04 2.2-0.82 2.2-0.82 0.44 1.1 0.16 1.92 0.08 2.12 0.51 0.56 0.82 1.27 0.82 2.15 0 3.07-1.87 3.75-3.65 3.95 0.29 0.25 0.54 0.73 0.54 1.48 0 1.07-0.01 1.93-0.01 2.2 0 0.21 0.15 0.46 0.55 0.38C13.71 14.53 16 11.53 16 8 16 3.58 12.42 0 8 0z"></path></svg>
</a>
<button class="btn-link right site-header-toggle js-details-target" type="button" aria-label="Toggle navigation">
<svg aria-hidden="true" class="octicon octicon-three-bars" height="24" version="1.1" viewBox="0 0 12 16" width="18"><path d="M11.41 9H0.59c-0.59 0-0.59-0.41-0.59-1s0-1 0.59-1h10.81c0.59 0 0.59 0.41 0.59 1s0 1-0.59 1z m0-4H0.59c-0.59 0-0.59-0.41-0.59-1s0-1 0.59-1h10.81c0.59 0 0.59 0.41 0.59 1s0 1-0.59 1zM0.59 11h10.81c0.59 0 0.59 0.41 0.59 1s0 1-0.59 1H0.59c-0.59 0-0.59-0.41-0.59-1s0-1 0.59-1z"></path></svg>
</button>
<div class="site-header-menu">
<nav class="site-header-nav site-header-nav-main">
<a href="/personal" class="js-selected-navigation-item nav-item nav-item-personal" data-ga-click="Header, click, Nav menu - item:personal" data-selected-links="/personal /personal">
Personal
</a> <a href="/open-source" class="js-selected-navigation-item nav-item nav-item-opensource" data-ga-click="Header, click, Nav menu - item:opensource" data-selected-links="/open-source /open-source">
Open source
</a> <a href="/business" class="js-selected-navigation-item nav-item nav-item-business" data-ga-click="Header, click, Nav menu - item:business" data-selected-links="/business /business/features /business/customers /business">
Business
</a> <a href="/explore" class="js-selected-navigation-item nav-item nav-item-explore" data-ga-click="Header, click, Nav menu - item:explore" data-selected-links="/explore /trending /trending/developers /integrations /integrations/feature/code /integrations/feature/collaborate /integrations/feature/ship /explore">
Explore
</a> </nav>
<div class="site-header-actions">
<a class="btn btn-primary site-header-actions-btn" href="/join?source=header-repo" data-ga-click="(Logged out) Header, clicked Sign up, text:sign-up">Sign up</a>
<a class="btn site-header-actions-btn mr-2" href="/login?return_to=%2Fswcarpentry%2Fpython-novice-inflammation%2Fblob%2Fgh-pages%2Fcode%2Ferrors_02.py" data-ga-click="(Logged out) Header, clicked Sign in, text:sign-in">Sign in</a>
</div>
<nav class="site-header-nav site-header-nav-secondary">
<a class="nav-item" href="/pricing">Pricing</a>
<a class="nav-item" href="/blog">Blog</a>
<a class="nav-item" href="https://help.github.com">Support</a>
<a class="nav-item header-search-link" href="https://github.com/search">Search GitHub</a>
<div class="header-search scoped-search site-scoped-search js-site-search" role="search">
<!-- </textarea> --><!-- '"` --><form accept-charset="UTF-8" action="/swcarpentry/python-novice-inflammation/search" class="js-site-search-form" data-scoped-search-url="/swcarpentry/python-novice-inflammation/search" data-unscoped-search-url="/search" method="get"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div>
<label class="form-control header-search-wrapper js-chromeless-input-container">
<div class="header-search-scope">This repository</div>
<input type="text"
class="form-control header-search-input js-site-search-focus js-site-search-field is-clearable"
data-hotkey="s"
name="q"
placeholder="Search"
aria-label="Search this repository"
data-unscoped-placeholder="Search GitHub"
data-scoped-placeholder="Search"
tabindex="1"
autocapitalize="off">
</label>
</form></div>
</nav>
</div>
</div>
</header>
<div id="start-of-content" class="accessibility-aid"></div>
<div id="js-flash-container">
</div>
<div role="main" class="main-content">
<div itemscope itemtype="http://schema.org/SoftwareSourceCode">
<div id="js-repo-pjax-container" data-pjax-container>
<div class="pagehead repohead instapaper_ignore readability-menu experiment-repo-nav">
<div class="container repohead-details-container">
<ul class="pagehead-actions">
<li>
<a href="/login?return_to=%2Fswcarpentry%2Fpython-novice-inflammation"
class="btn btn-sm btn-with-count tooltipped tooltipped-n"
aria-label="You must be signed in to watch a repository" rel="nofollow">
<svg aria-hidden="true" class="octicon octicon-eye" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path d="M8.06 2C3 2 0 8 0 8s3 6 8.06 6c4.94 0 7.94-6 7.94-6S13 2 8.06 2z m-0.06 10c-2.2 0-4-1.78-4-4 0-2.2 1.8-4 4-4 2.22 0 4 1.8 4 4 0 2.22-1.78 4-4 4z m2-4c0 1.11-0.89 2-2 2s-2-0.89-2-2 0.89-2 2-2 2 0.89 2 2z"></path></svg>
Watch
</a>
<a class="social-count" href="/swcarpentry/python-novice-inflammation/watchers">
110
</a>
</li>
<li>
<a href="/login?return_to=%2Fswcarpentry%2Fpython-novice-inflammation"
class="btn btn-sm btn-with-count tooltipped tooltipped-n"
aria-label="You must be signed in to star a repository" rel="nofollow">
<svg aria-hidden="true" class="octicon octicon-star" height="16" version="1.1" viewBox="0 0 14 16" width="14"><path d="M14 6l-4.9-0.64L7 1 4.9 5.36 0 6l3.6 3.26L2.67 14l4.33-2.33 4.33 2.33L10.4 9.26 14 6z"></path></svg>
Star
</a>
<a class="social-count js-social-count" href="/swcarpentry/python-novice-inflammation/stargazers">
34
</a>
</li>
<li>
<a href="/login?return_to=%2Fswcarpentry%2Fpython-novice-inflammation"
class="btn btn-sm btn-with-count tooltipped tooltipped-n"
aria-label="You must be signed in to fork a repository" rel="nofollow">
<svg aria-hidden="true" class="octicon octicon-repo-forked" height="16" version="1.1" viewBox="0 0 10 16" width="10"><path d="M8 1c-1.11 0-2 0.89-2 2 0 0.73 0.41 1.38 1 1.72v1.28L5 8 3 6v-1.28c0.59-0.34 1-0.98 1-1.72 0-1.11-0.89-2-2-2S0 1.89 0 3c0 0.73 0.41 1.38 1 1.72v1.78l3 3v1.78c-0.59 0.34-1 0.98-1 1.72 0 1.11 0.89 2 2 2s2-0.89 2-2c0-0.73-0.41-1.38-1-1.72V9.5l3-3V4.72c0.59-0.34 1-0.98 1-1.72 0-1.11-0.89-2-2-2zM2 4.2c-0.66 0-1.2-0.55-1.2-1.2s0.55-1.2 1.2-1.2 1.2 0.55 1.2 1.2-0.55 1.2-1.2 1.2z m3 10c-0.66 0-1.2-0.55-1.2-1.2s0.55-1.2 1.2-1.2 1.2 0.55 1.2 1.2-0.55 1.2-1.2 1.2z m3-10c-0.66 0-1.2-0.55-1.2-1.2s0.55-1.2 1.2-1.2 1.2 0.55 1.2 1.2-0.55 1.2-1.2 1.2z"></path></svg>
Fork
</a>
<a href="/swcarpentry/python-novice-inflammation/network" class="social-count">
200
</a>
</li>
</ul>
<h1 class="entry-title public ">
<svg aria-hidden="true" class="octicon octicon-repo" height="16" version="1.1" viewBox="0 0 12 16" width="12"><path d="M4 9h-1v-1h1v1z m0-3h-1v1h1v-1z m0-2h-1v1h1v-1z m0-2h-1v1h1v-1z m8-1v12c0 0.55-0.45 1-1 1H6v2l-1.5-1.5-1.5 1.5V14H1c-0.55 0-1-0.45-1-1V1C0 0.45 0.45 0 1 0h10c0.55 0 1 0.45 1 1z m-1 10H1v2h2v-1h3v1h5V11z m0-10H2v9h9V1z"></path></svg>
<span class="author" itemprop="author"><a href="/swcarpentry" class="url fn" rel="author">swcarpentry</a></span><!--
--><span class="path-divider">/</span><!--
--><strong itemprop="name"><a href="/swcarpentry/python-novice-inflammation" data-pjax="#js-repo-pjax-container">python-novice-inflammation</a></strong>
</h1>
</div>
<div class="container">
<nav class="reponav js-repo-nav js-sidenav-container-pjax"
itemscope
itemtype="http://schema.org/BreadcrumbList"
role="navigation"
data-pjax="#js-repo-pjax-container">
<span itemscope itemtype="http://schema.org/ListItem" itemprop="itemListElement">
<a href="/swcarpentry/python-novice-inflammation" aria-selected="true" class="js-selected-navigation-item selected reponav-item" data-hotkey="g c" data-selected-links="repo_source repo_downloads repo_commits repo_releases repo_tags repo_branches /swcarpentry/python-novice-inflammation" itemprop="url">
<svg aria-hidden="true" class="octicon octicon-code" height="16" version="1.1" viewBox="0 0 14 16" width="14"><path d="M9.5 3l-1.5 1.5 3.5 3.5L8 11.5l1.5 1.5 4.5-5L9.5 3zM4.5 3L0 8l4.5 5 1.5-1.5L2.5 8l3.5-3.5L4.5 3z"></path></svg>
<span itemprop="name">Code</span>
<meta itemprop="position" content="1">
</a> </span>
<span itemscope itemtype="http://schema.org/ListItem" itemprop="itemListElement">
<a href="/swcarpentry/python-novice-inflammation/issues" class="js-selected-navigation-item reponav-item" data-hotkey="g i" data-selected-links="repo_issues repo_labels repo_milestones /swcarpentry/python-novice-inflammation/issues" itemprop="url">
<svg aria-hidden="true" class="octicon octicon-issue-opened" height="16" version="1.1" viewBox="0 0 14 16" width="14"><path d="M7 2.3c3.14 0 5.7 2.56 5.7 5.7S10.14 13.7 7 13.7 1.3 11.14 1.3 8s2.56-5.7 5.7-5.7m0-1.3C3.14 1 0 4.14 0 8s3.14 7 7 7 7-3.14 7-7S10.86 1 7 1z m1 3H6v5h2V4z m0 6H6v2h2V10z"></path></svg>
<span itemprop="name">Issues</span>
<span class="counter">29</span>
<meta itemprop="position" content="2">
</a> </span>
<span itemscope itemtype="http://schema.org/ListItem" itemprop="itemListElement">
<a href="/swcarpentry/python-novice-inflammation/pulls" class="js-selected-navigation-item reponav-item" data-hotkey="g p" data-selected-links="repo_pulls /swcarpentry/python-novice-inflammation/pulls" itemprop="url">
<svg aria-hidden="true" class="octicon octicon-git-pull-request" height="16" version="1.1" viewBox="0 0 12 16" width="12"><path d="M11 11.28c0-1.73 0-6.28 0-6.28-0.03-0.78-0.34-1.47-0.94-2.06s-1.28-0.91-2.06-0.94c0 0-1.02 0-1 0V0L4 3l3 3V4h1c0.27 0.02 0.48 0.11 0.69 0.31s0.3 0.42 0.31 0.69v6.28c-0.59 0.34-1 0.98-1 1.72 0 1.11 0.89 2 2 2s2-0.89 2-2c0-0.73-0.41-1.38-1-1.72z m-1 2.92c-0.66 0-1.2-0.55-1.2-1.2s0.55-1.2 1.2-1.2 1.2 0.55 1.2 1.2-0.55 1.2-1.2 1.2zM4 3c0-1.11-0.89-2-2-2S0 1.89 0 3c0 0.73 0.41 1.38 1 1.72 0 1.55 0 5.56 0 6.56-0.59 0.34-1 0.98-1 1.72 0 1.11 0.89 2 2 2s2-0.89 2-2c0-0.73-0.41-1.38-1-1.72V4.72c0.59-0.34 1-0.98 1-1.72z m-0.8 10c0 0.66-0.55 1.2-1.2 1.2s-1.2-0.55-1.2-1.2 0.55-1.2 1.2-1.2 1.2 0.55 1.2 1.2z m-1.2-8.8c-0.66 0-1.2-0.55-1.2-1.2s0.55-1.2 1.2-1.2 1.2 0.55 1.2 1.2-0.55 1.2-1.2 1.2z"></path></svg>
<span itemprop="name">Pull requests</span>
<span class="counter">62</span>
<meta itemprop="position" content="3">
</a> </span>
<a href="/swcarpentry/python-novice-inflammation/pulse" class="js-selected-navigation-item reponav-item" data-selected-links="pulse /swcarpentry/python-novice-inflammation/pulse">
<svg aria-hidden="true" class="octicon octicon-pulse" height="16" version="1.1" viewBox="0 0 14 16" width="14"><path d="M11.5 8L8.8 5.4 6.6 8.5 5.5 1.6 2.38 8H0V10h3.6L4.5 8.2l0.9 5.4L9 8.5l1.6 1.5H14V8H11.5z"></path></svg>
Pulse
</a>
<a href="/swcarpentry/python-novice-inflammation/graphs" class="js-selected-navigation-item reponav-item" data-selected-links="repo_graphs repo_contributors /swcarpentry/python-novice-inflammation/graphs">
<svg aria-hidden="true" class="octicon octicon-graph" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path d="M16 14v1H0V0h1v14h15z m-11-1H3V8h2v5z m4 0H7V3h2v10z m4 0H11V6h2v7z"></path></svg>
Graphs
</a>
</nav>
</div>
</div>
<div class="container new-discussion-timeline experiment-repo-nav">
<div class="repository-content">
<a href="/swcarpentry/python-novice-inflammation/blob/7ae4e74810538ed5bd964124be8198e3d5009b7e/code/errors_02.py" class="hidden js-permalink-shortcut" data-hotkey="y">Permalink</a>
<!-- blob contrib key: blob_contributors:v21:10191f8032758f1b2e49dc96e1e1feda -->
<div class="file-navigation js-zeroclipboard-container">
<div class="select-menu branch-select-menu js-menu-container js-select-menu left">
<button class="btn btn-sm select-menu-button js-menu-target css-truncate" data-hotkey="w"
title="gh-pages"
type="button" aria-label="Switch branches or tags" tabindex="0" aria-haspopup="true">
<i>Branch:</i>
<span class="js-select-button css-truncate-target">gh-pages</span>
</button>
<div class="select-menu-modal-holder js-menu-content js-navigation-container" data-pjax aria-hidden="true">
<div class="select-menu-modal">
<div class="select-menu-header">
<svg aria-label="Close" class="octicon octicon-x js-menu-close" height="16" role="img" version="1.1" viewBox="0 0 12 16" width="12"><path d="M7.48 8l3.75 3.75-1.48 1.48-3.75-3.75-3.75 3.75-1.48-1.48 3.75-3.75L0.77 4.25l1.48-1.48 3.75 3.75 3.75-3.75 1.48 1.48-3.75 3.75z"></path></svg>
<span class="select-menu-title">Switch branches/tags</span>
</div>
<div class="select-menu-filters">
<div class="select-menu-text-filter">
<input type="text" aria-label="Filter branches/tags" id="context-commitish-filter-field" class="form-control js-filterable-field js-navigation-enable" placeholder="Filter branches/tags">
</div>
<div class="select-menu-tabs">
<ul>
<li class="select-menu-tab">
<a href="#" data-tab-filter="branches" data-filter-placeholder="Filter branches/tags" class="js-select-menu-tab" role="tab">Branches</a>
</li>
<li class="select-menu-tab">
<a href="#" data-tab-filter="tags" data-filter-placeholder="Find a tag…" class="js-select-menu-tab" role="tab">Tags</a>
</li>
</ul>
</div>
</div>
<div class="select-menu-list select-menu-tab-bucket js-select-menu-tab-bucket" data-tab-filter="branches" role="menu">
<div data-filterable-for="context-commitish-filter-field" data-filterable-type="substring">
<a class="select-menu-item js-navigation-item js-navigation-open "
href="/swcarpentry/python-novice-inflammation/blob/functions-over-methods/code/errors_02.py"
data-name="functions-over-methods"
data-skip-pjax="true"
rel="nofollow">
<svg aria-hidden="true" class="octicon octicon-check select-menu-item-icon" height="16" version="1.1" viewBox="0 0 12 16" width="12"><path d="M12 5L4 13 0 9l1.5-1.5 2.5 2.5 6.5-6.5 1.5 1.5z"></path></svg>
<span class="select-menu-item-text css-truncate-target js-select-menu-filter-text" title="functions-over-methods">
functions-over-methods
</span>
</a>
<a class="select-menu-item js-navigation-item js-navigation-open selected"
href="/swcarpentry/python-novice-inflammation/blob/gh-pages/code/errors_02.py"
data-name="gh-pages"
data-skip-pjax="true"
rel="nofollow">
<svg aria-hidden="true" class="octicon octicon-check select-menu-item-icon" height="16" version="1.1" viewBox="0 0 12 16" width="12"><path d="M12 5L4 13 0 9l1.5-1.5 2.5 2.5 6.5-6.5 1.5 1.5z"></path></svg>
<span class="select-menu-item-text css-truncate-target js-select-menu-filter-text" title="gh-pages">
gh-pages
</span>
</a>
</div>
<div class="select-menu-no-results">Nothing to show</div>
</div>
<div class="select-menu-list select-menu-tab-bucket js-select-menu-tab-bucket" data-tab-filter="tags">
<div data-filterable-for="context-commitish-filter-field" data-filterable-type="substring">
<a class="select-menu-item js-navigation-item js-navigation-open "
href="/swcarpentry/python-novice-inflammation/tree/v5.3/code/errors_02.py"
data-name="v5.3"
data-skip-pjax="true"
rel="nofollow">
<svg aria-hidden="true" class="octicon octicon-check select-menu-item-icon" height="16" version="1.1" viewBox="0 0 12 16" width="12"><path d="M12 5L4 13 0 9l1.5-1.5 2.5 2.5 6.5-6.5 1.5 1.5z"></path></svg>
<span class="select-menu-item-text css-truncate-target" title="v5.3">
v5.3
</span>
</a>
</div>
<div class="select-menu-no-results">Nothing to show</div>
</div>
</div>
</div>
</div>
<div class="btn-group right">
<a href="/swcarpentry/python-novice-inflammation/find/gh-pages"
class="js-pjax-capture-input btn btn-sm"
data-pjax
data-hotkey="t">
Find file
</a>
<button aria-label="Copy file path to clipboard" class="js-zeroclipboard btn btn-sm zeroclipboard-button tooltipped tooltipped-s" data-copied-hint="Copied!" type="button">Copy path</button>
</div>
<div class="breadcrumb js-zeroclipboard-target">
<span class="repo-root js-repo-root"><span class="js-path-segment"><a href="/swcarpentry/python-novice-inflammation"><span>python-novice-inflammation</span></a></span></span><span class="separator">/</span><span class="js-path-segment"><a href="/swcarpentry/python-novice-inflammation/tree/gh-pages/code"><span>code</span></a></span><span class="separator">/</span><strong class="final-path">errors_02.py</strong>
</div>
</div>
<div class="commit-tease">
<span class="right">
<a class="commit-tease-sha" href="/swcarpentry/python-novice-inflammation/commit/f876f3b946ef1ddf10c46b50e2d7ccdf19f77542" data-pjax>
f876f3b
</a>
<relative-time datetime="2015-10-28T03:31:44Z">Oct 27, 2015</relative-time>
</span>
<div>
<img alt="@zonca" class="avatar" height="20" src="https://avatars0.githubusercontent.com/u/383090?v=3&amp;s=40" width="20" />
<a href="/zonca" class="user-mention" rel="contributor">zonca</a>
<a href="/swcarpentry/python-novice-inflammation/commit/f876f3b946ef1ddf10c46b50e2d7ccdf19f77542" class="message" data-pjax="true" title="Renamed module with dashes to underscores
Cannot import module with dashes.
The lesson text uses underscores.">Renamed module with dashes to underscores</a>
</div>
<div class="commit-tease-contributors">
<button type="button" class="btn-link muted-link contributors-toggle" data-facebox="#blob_contributors_box">
<strong>1</strong>
contributor
</button>
</div>
<div id="blob_contributors_box" style="display:none">
<h2 class="facebox-header" data-facebox-id="facebox-header">Users who have contributed to this file</h2>
<ul class="facebox-user-list" data-facebox-id="facebox-description">
<li class="facebox-user-list-item">
<img alt="@zonca" height="24" src="https://avatars2.githubusercontent.com/u/383090?v=3&amp;s=48" width="24" />
<a href="/zonca">zonca</a>
</li>
</ul>
</div>
</div>
<div class="file">
<div class="file-header">
<div class="file-actions">
<div class="btn-group">
<a href="/swcarpentry/python-novice-inflammation/raw/gh-pages/code/errors_02.py" class="btn btn-sm " id="raw-url">Raw</a>
<a href="/swcarpentry/python-novice-inflammation/blame/gh-pages/code/errors_02.py" class="btn btn-sm js-update-url-with-hash">Blame</a>
<a href="/swcarpentry/python-novice-inflammation/commits/gh-pages/code/errors_02.py" class="btn btn-sm " rel="nofollow">History</a>
</div>
<button type="button" class="btn-octicon disabled tooltipped tooltipped-nw"
aria-label="You must be signed in to make or propose changes">
<svg aria-hidden="true" class="octicon octicon-pencil" height="16" version="1.1" viewBox="0 0 14 16" width="14"><path d="M0 12v3h3l8-8-3-3L0 12z m3 2H1V12h1v1h1v1z m10.3-9.3l-1.3 1.3-3-3 1.3-1.3c0.39-0.39 1.02-0.39 1.41 0l1.59 1.59c0.39 0.39 0.39 1.02 0 1.41z"></path></svg>
</button>
<button type="button" class="btn-octicon btn-octicon-danger disabled tooltipped tooltipped-nw"
aria-label="You must be signed in to make or propose changes">
<svg aria-hidden="true" class="octicon octicon-trashcan" height="16" version="1.1" viewBox="0 0 12 16" width="12"><path d="M10 2H8c0-0.55-0.45-1-1-1H4c-0.55 0-1 0.45-1 1H1c-0.55 0-1 0.45-1 1v1c0 0.55 0.45 1 1 1v9c0 0.55 0.45 1 1 1h7c0.55 0 1-0.45 1-1V5c0.55 0 1-0.45 1-1v-1c0-0.55-0.45-1-1-1z m-1 12H2V5h1v8h1V5h1v8h1V5h1v8h1V5h1v9z m1-10H1v-1h9v1z"></path></svg>
</button>
</div>
<div class="file-info">
16 lines (13 sloc)
<span class="file-info-divider"></span>
455 Bytes
</div>
</div>
<div itemprop="text" class="blob-wrapper data type-python">
<table class="highlight tab-size js-file-line-container" data-tab-size="8">
<tr>
<td id="L1" class="blob-num js-line-number" data-line-number="1"></td>
<td id="LC1" class="blob-code blob-code-inner js-file-line"><span class="pl-k">def</span> <span class="pl-en">print_message</span>(<span class="pl-smi">day</span>):</td>
</tr>
<tr>
<td id="L2" class="blob-num js-line-number" data-line-number="2"></td>
<td id="LC2" class="blob-code blob-code-inner js-file-line"> messages <span class="pl-k">=</span> {</td>
</tr>
<tr>
<td id="L3" class="blob-num js-line-number" data-line-number="3"></td>
<td id="LC3" class="blob-code blob-code-inner js-file-line"> <span class="pl-s"><span class="pl-pds">&quot;</span>monday<span class="pl-pds">&quot;</span></span>: <span class="pl-s"><span class="pl-pds">&quot;</span>Hello, world!<span class="pl-pds">&quot;</span></span>,</td>
</tr>
<tr>
<td id="L4" class="blob-num js-line-number" data-line-number="4"></td>
<td id="LC4" class="blob-code blob-code-inner js-file-line"> <span class="pl-s"><span class="pl-pds">&quot;</span>tuesday<span class="pl-pds">&quot;</span></span>: <span class="pl-s"><span class="pl-pds">&quot;</span>Today is tuesday!<span class="pl-pds">&quot;</span></span>,</td>
</tr>
<tr>
<td id="L5" class="blob-num js-line-number" data-line-number="5"></td>
<td id="LC5" class="blob-code blob-code-inner js-file-line"> <span class="pl-s"><span class="pl-pds">&quot;</span>wednesday<span class="pl-pds">&quot;</span></span>: <span class="pl-s"><span class="pl-pds">&quot;</span>It is the middle of the week.<span class="pl-pds">&quot;</span></span>,</td>
</tr>
<tr>
<td id="L6" class="blob-num js-line-number" data-line-number="6"></td>
<td id="LC6" class="blob-code blob-code-inner js-file-line"> <span class="pl-s"><span class="pl-pds">&quot;</span>thursday<span class="pl-pds">&quot;</span></span>: <span class="pl-s"><span class="pl-pds">&quot;</span>Today is Donnerstag in German!<span class="pl-pds">&quot;</span></span>,</td>
</tr>
<tr>
<td id="L7" class="blob-num js-line-number" data-line-number="7"></td>
<td id="LC7" class="blob-code blob-code-inner js-file-line"> <span class="pl-s"><span class="pl-pds">&quot;</span>friday<span class="pl-pds">&quot;</span></span>: <span class="pl-s"><span class="pl-pds">&quot;</span>Last day of the week!<span class="pl-pds">&quot;</span></span>,</td>
</tr>
<tr>
<td id="L8" class="blob-num js-line-number" data-line-number="8"></td>
<td id="LC8" class="blob-code blob-code-inner js-file-line"> <span class="pl-s"><span class="pl-pds">&quot;</span>saturday<span class="pl-pds">&quot;</span></span>: <span class="pl-s"><span class="pl-pds">&quot;</span>Hooray for the weekend!<span class="pl-pds">&quot;</span></span>,</td>
</tr>
<tr>
<td id="L9" class="blob-num js-line-number" data-line-number="9"></td>
<td id="LC9" class="blob-code blob-code-inner js-file-line"> <span class="pl-s"><span class="pl-pds">&quot;</span>sunday<span class="pl-pds">&quot;</span></span>: <span class="pl-s"><span class="pl-pds">&quot;</span>Aw, the weekend is almost over.<span class="pl-pds">&quot;</span></span></td>
</tr>
<tr>
<td id="L10" class="blob-num js-line-number" data-line-number="10"></td>
<td id="LC10" class="blob-code blob-code-inner js-file-line"> }</td>
</tr>
<tr>
<td id="L11" class="blob-num js-line-number" data-line-number="11"></td>
<td id="LC11" class="blob-code blob-code-inner js-file-line"> <span class="pl-c1">print</span>(messages[day])</td>
</tr>
<tr>
<td id="L12" class="blob-num js-line-number" data-line-number="12"></td>
<td id="LC12" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="L13" class="blob-num js-line-number" data-line-number="13"></td>
<td id="LC13" class="blob-code blob-code-inner js-file-line">
</td>
</tr>
<tr>
<td id="L14" class="blob-num js-line-number" data-line-number="14"></td>
<td id="LC14" class="blob-code blob-code-inner js-file-line"><span class="pl-k">def</span> <span class="pl-en">print_friday_message</span>():</td>
</tr>
<tr>
<td id="L15" class="blob-num js-line-number" data-line-number="15"></td>
<td id="LC15" class="blob-code blob-code-inner js-file-line"> print_message(<span class="pl-s"><span class="pl-pds">&quot;</span>Friday<span class="pl-pds">&quot;</span></span>)</td>
</tr>
</table>
</div>
</div>
<button type="button" data-facebox="#jump-to-line" data-facebox-class="linejump" data-hotkey="l" class="hidden">Jump to Line</button>
<div id="jump-to-line" style="display:none">
<!-- </textarea> --><!-- '"` --><form accept-charset="UTF-8" action="" class="js-jump-to-line-form" method="get"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div>
<input class="form-control linejump-input js-jump-to-line-field" type="text" placeholder="Jump to line&hellip;" aria-label="Jump to line" autofocus>
<button type="submit" class="btn">Go</button>
</form></div>
</div>
<div class="modal-backdrop"></div>
</div>
</div>
</div>
</div>
<div class="container site-footer-container">
<div class="site-footer" role="contentinfo">
<ul class="site-footer-links right">
<li><a href="https://status.github.com/" data-ga-click="Footer, go to status, text:status">Status</a></li>
<li><a href="https://developer.github.com" data-ga-click="Footer, go to api, text:api">API</a></li>
<li><a href="https://training.github.com" data-ga-click="Footer, go to training, text:training">Training</a></li>
<li><a href="https://shop.github.com" data-ga-click="Footer, go to shop, text:shop">Shop</a></li>
<li><a href="https://github.com/blog" data-ga-click="Footer, go to blog, text:blog">Blog</a></li>
<li><a href="https://github.com/about" data-ga-click="Footer, go to about, text:about">About</a></li>
</ul>
<a href="https://github.com" aria-label="Homepage" class="site-footer-mark" title="GitHub">
<svg aria-hidden="true" class="octicon octicon-mark-github" height="24" version="1.1" viewBox="0 0 16 16" width="24"><path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59 0.4 0.07 0.55-0.17 0.55-0.38 0-0.19-0.01-0.82-0.01-1.49-2.01 0.37-2.53-0.49-2.69-0.94-0.09-0.23-0.48-0.94-0.82-1.13-0.28-0.15-0.68-0.52-0.01-0.53 0.63-0.01 1.08 0.58 1.23 0.82 0.72 1.21 1.87 0.87 2.33 0.66 0.07-0.52 0.28-0.87 0.51-1.07-1.78-0.2-3.64-0.89-3.64-3.95 0-0.87 0.31-1.59 0.82-2.15-0.08-0.2-0.36-1.02 0.08-2.12 0 0 0.67-0.21 2.2 0.82 0.64-0.18 1.32-0.27 2-0.27 0.68 0 1.36 0.09 2 0.27 1.53-1.04 2.2-0.82 2.2-0.82 0.44 1.1 0.16 1.92 0.08 2.12 0.51 0.56 0.82 1.27 0.82 2.15 0 3.07-1.87 3.75-3.65 3.95 0.29 0.25 0.54 0.73 0.54 1.48 0 1.07-0.01 1.93-0.01 2.2 0 0.21 0.15 0.46 0.55 0.38C13.71 14.53 16 11.53 16 8 16 3.58 12.42 0 8 0z"></path></svg>
</a>
<ul class="site-footer-links">
<li>&copy; 2016 <span title="0.05447s from github-fe121-cp1-prd.iad.github.net">GitHub</span>, Inc.</li>
<li><a href="https://github.com/site/terms" data-ga-click="Footer, go to terms, text:terms">Terms</a></li>
<li><a href="https://github.com/site/privacy" data-ga-click="Footer, go to privacy, text:privacy">Privacy</a></li>
<li><a href="https://github.com/security" data-ga-click="Footer, go to security, text:security">Security</a></li>
<li><a href="https://github.com/contact" data-ga-click="Footer, go to contact, text:contact">Contact</a></li>
<li><a href="https://help.github.com" data-ga-click="Footer, go to help, text:help">Help</a></li>
</ul>
</div>
</div>
<div id="ajax-error-message" class="ajax-error-message flash flash-error">
<svg aria-hidden="true" class="octicon octicon-alert" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path d="M15.72 12.5l-6.85-11.98C8.69 0.21 8.36 0.02 8 0.02s-0.69 0.19-0.87 0.5l-6.85 11.98c-0.18 0.31-0.18 0.69 0 1C0.47 13.81 0.8 14 1.15 14h13.7c0.36 0 0.69-0.19 0.86-0.5S15.89 12.81 15.72 12.5zM9 12H7V10h2V12zM9 9H7V5h2V9z"></path></svg>
<button type="button" class="flash-close js-flash-close js-ajax-error-dismiss" aria-label="Dismiss error">
<svg aria-hidden="true" class="octicon octicon-x" height="16" version="1.1" viewBox="0 0 12 16" width="12"><path d="M7.48 8l3.75 3.75-1.48 1.48-3.75-3.75-3.75 3.75-1.48-1.48 3.75-3.75L0.77 4.25l1.48-1.48 3.75 3.75 3.75-3.75 1.48 1.48-3.75 3.75z"></path></svg>
</button>
Something went wrong with that request. Please try again.
</div>
<script crossorigin="anonymous" src="https://assets-cdn.github.com/assets/compat-7db58f8b7b91111107fac755dd8b178fe7db0f209ced51fc339c446ad3f8da2b.js"></script>
<script crossorigin="anonymous" src="https://assets-cdn.github.com/assets/frameworks-45f69297ece210de81f8efda93619ce7cff2475dbe66e57b0f01f0aa1341915c.js"></script>
<script async="async" crossorigin="anonymous" src="https://assets-cdn.github.com/assets/github-207236d9c34ff5ba0c5941f877df52c9b53c4ddad9a125c5d2094fed3300ea17.js"></script>
<div class="js-stale-session-flash stale-session-flash flash flash-warn flash-banner hidden">
<svg aria-hidden="true" class="octicon octicon-alert" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path d="M15.72 12.5l-6.85-11.98C8.69 0.21 8.36 0.02 8 0.02s-0.69 0.19-0.87 0.5l-6.85 11.98c-0.18 0.31-0.18 0.69 0 1C0.47 13.81 0.8 14 1.15 14h13.7c0.36 0 0.69-0.19 0.86-0.5S15.89 12.81 15.72 12.5zM9 12H7V10h2V12zM9 9H7V5h2V9z"></path></svg>
<span class="signed-in-tab-flash">You signed in with another tab or window. <a href="">Reload</a> to refresh your session.</span>
<span class="signed-out-tab-flash">You signed out in another tab or window. <a href="">Reload</a> to refresh your session.</span>
</div>
<div class="facebox" id="facebox" style="display:none;">
<div class="facebox-popup">
<div class="facebox-content" role="dialog" aria-labelledby="facebox-header" aria-describedby="facebox-description">
</div>
<button type="button" class="facebox-close js-facebox-close" aria-label="Close modal">
<svg aria-hidden="true" class="octicon octicon-x" height="16" version="1.1" viewBox="0 0 12 16" width="12"><path d="M7.48 8l3.75 3.75-1.48 1.48-3.75-3.75-3.75 3.75-1.48-1.48 3.75-3.75L0.77 4.25l1.48-1.48 3.75 3.75 3.75-3.75 1.48 1.48-3.75 3.75z"></path></svg>
</button>
</div>
</div>
</body>
</html>

Software Carpentry Workshop Notes

Webpages open

Installation

Intro

  • Teach practical skills that are difficult to gain elsewhere
  • only teach the basic core elements
  • save a lot of time by learning this material up front

Sign in sheet

In Browser

  • Main webpage
  • Code of conduct
  • Test suite

Main web page for SWC

https://pages.nist.gov/2016-05-26-nist/

Code of conduct

Be kind.

Stickers

  • red sticker on laptop to indicate that you are having problems

  • at the end of each session fill out one good and one bad thing about the session

Survey

Schedule

Interactive

Data

Introduce Instructors

  • Zach Trautt

  • Bill Krekelberg

  • Jon Guyer

  • Dilip Banerjee

import sys
import numpy
def main():
script = sys.argv[0]
action = sys.argv[1]
if action not in ['--min', '--mean', '--max']: # if no action given
action = '--mean' # set a default action, that being mean
filenames = sys.argv[1:] # start the filenames one place earlier in the argv list
else:
filenames = sys.argv[2:]
if len(filenames) == 0:
process(sys.stdin, action)
else:
for f in filenames:
process(f, action)
def process(filename, action):
data = numpy.loadtxt(filename, delimiter=',')
if action == '--min':
values = data.min(axis=1)
elif action == '--mean':
values = data.mean(axis=1)
elif action == '--max':
values = data.max(axis=1)
for m in values:
print m
main()
#!/usr/bin/env python
"""Test script to check required Python version.
Execute this code at the command line by typing:
python swc-installation-test-1.py
How to get a command line:
- On OSX run this with the Terminal application.
- On Windows, go to the Start menu, select 'Run' and type 'cmd'
(without the quotes) to run the 'cmd.exe' Windows Command Prompt.
- On Linux, either use your login shell directly, or run one of a
number of graphical terminals (e.g. 'xterm', 'gnome-terminal', ...).
For some screen shots, see:
http://software-carpentry.org/setup/terminal.html
Run the script and follow the instructions it prints at the end. If
you see an error saying that the 'python' command was not found, than
you may not have any version of Python installed. See:
http://www.python.org/download/releases/2.7.3/#download
for installation instructions.
This test is separate to avoid Python syntax errors parsing the more
elaborate `swc-installation-test-2.py`.
"""
import sys as _sys
__version__ = '0.2'
def check():
if _sys.version_info < (3, 3):
print('check for Python version (python):')
print('outdated version of Python: ' + _sys.version)
return False
return True
if __name__ == '__main__':
if check():
print('Passed')
else:
print('Failed')
print('Install a current version of Python 3!')
print('http://continuum.io/downloads')
_sys.exit(1)
#!/usr/bin/env python
"""Test script to check for required functionality.
Execute this code at the command line by typing:
python swc-installation-test-2.py
Run the script and follow the instructions it prints at the end.
This script requires at least Python 2.6. You can check the version
of Python that you have installed with 'swc-installation-test-1.py'.
By default, this script will test for all the dependencies your
instructor thinks you need. If you want to test for a different set
of packages, you can list them on the command line. For example:
python swc-installation-test-2.py git virtual-editor
This is useful if the original test told you to install a more recent
version of a particular dependency, and you just want to re-test that
dependency.
"""
# Some details about the implementation:
# The dependencies are divided into a hierarchy of classes rooted on
# Dependency class. You can refer to the code to see which package
# comes under which type of dependency.
# The CHECKER dictionary stores information about all the dependencies
# and CHECKS stores list of the dependencies which are to be checked in
# the current workshop.
# In the "__name__ == '__main__'" block, we launch all the checks with
# check() function, which prints information about the tests as they run
# and details about the failures after the tests complete. In case of
# failure, the functions print_system_info() and print_suggestions()
# are called after this, where the former prints information about the
# user's system for debugging purposes while the latter prints some
# suggestions to follow.
from __future__ import print_function # for Python 2.6 compatibility
import distutils.ccompiler as _distutils_ccompiler
import fnmatch as _fnmatch
try: # Python 2.7 and 3.x
import importlib as _importlib
except ImportError: # Python 2.6 and earlier
class _Importlib (object):
"""Minimal workarounds for functions we need
"""
@staticmethod
def import_module(name):
module = __import__(name)
for n in name.split('.')[1:]:
module = getattr(module, n)
return module
_importlib = _Importlib()
import logging as _logging
import os as _os
import platform as _platform
import re as _re
import shlex as _shlex
import subprocess as _subprocess
import sys as _sys
try: # Python 3.x
import urllib.parse as _urllib_parse
except ImportError: # Python 2.x
import urllib as _urllib_parse # for quote()
import xml.etree.ElementTree as _element_tree
if not hasattr(_shlex, 'quote'): # Python versions older than 3.3
# Use the undocumented pipes.quote()
import pipes as _pipes
_shlex.quote = _pipes.quote
__version__ = '0.1'
# Comment out any entries you don't need
CHECKS = [
# Shell
'virtual-shell',
# Editors
'virtual-editor',
# Browsers
'virtual-browser',
# Version control
'git',
# 'hg', # Command line tool
#'mercurial', # Python package
# 'EasyMercurial',
# Build tools and packaging
# 'make',
'virtual-pypi-installer',
'setuptools',
#'xcode',
# Testing
'nosetests', # Command line tool
'nose', # Python package
'py.test', # Command line tool
'pytest', # Python package
# SQL
'sqlite3', # Command line tool
'sqlite3-python', # Python package
# Python
'python',
'ipython', # Command line tool
'IPython', # Python package
'argparse', # Useful for utility scripts
'numpy',
'scipy',
'matplotlib',
'pandas',
#'sympy',
#'Cython',
#'networkx',
#'mayavi.mlab',
]
CHECKER = {}
_ROOT_PATH = _os.sep
if _platform.system() == 'win32':
_ROOT_PATH = 'c:\\'
class InvalidCheck (KeyError):
def __init__(self, check):
super(InvalidCheck, self).__init__(check)
self.check = check
def __str__(self):
return self.check
class DependencyError (Exception):
_default_url = 'http://software-carpentry.org/setup/'
_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',
('Darwin', '*', 'EasyMercurial'): 'http://easyhg.org/download.html#download-mac',
('Windows', '*', 'EasyMercurial'): 'http://easyhg.org/download.html#download-windows',
('*', '*', 'EasyMercurial'): 'http://easyhg.org/download.html',
('*', '*', 'argparse'): 'https://pypi.python.org/pypi/argparse#installation',
('*', '*', 'ash'): 'http://www.in-ulm.de/~mascheck/various/ash/',
('*', '*', 'bash'): 'http://www.gnu.org/software/bash/manual/html_node/Basic-Installation.html#Basic-Installation',
('Linux', '*', 'chromium'): 'http://code.google.com/p/chromium/wiki/LinuxBuildInstructions',
('Darwin', '*', 'chromium'): 'http://code.google.com/p/chromium/wiki/MacBuildInstructions',
('Windows', '*', 'chromium'): 'http://www.chromium.org/developers/how-tos/build-instructions-windows',
('*', '*', 'chromium'): 'http://www.chromium.org/developers/how-tos',
('Windows', '*', 'emacs'): 'http://www.gnu.org/software/emacs/windows/Installing-Emacs.html',
('*', '*', 'emacs'): 'http://www.gnu.org/software/emacs/#Obtaining',
('*', '*', 'firefox'): 'http://www.mozilla.org/en-US/firefox/new/',
('Linux', '*', 'gedit'): 'http://www.linuxfromscratch.org/blfs/view/svn/gnome/gedit.html',
('*', '*', 'git'): 'http://git-scm.com/downloads',
('*', '*', 'google-chrome'): 'https://www.google.com/intl/en/chrome/browser/',
('*', '*', 'hg'): 'http://mercurial.selenic.com/',
('*', '*', 'mercurial'): 'http://mercurial.selenic.com/',
('*', '*', 'IPython'): 'http://ipython.org/install.html',
('*', '*', 'ipython'): 'http://ipython.org/install.html',
('*', '*', 'jinja'): 'http://jinja.pocoo.org/docs/intro/#installation',
('*', '*', 'kate'): 'http://kate-editor.org/get-it/',
('*', '*', 'make'): 'http://www.gnu.org/software/make/',
('Darwin', '*', 'matplotlib'): 'http://matplotlib.org/users/installing.html#building-on-osx',
('Windows', '*', 'matplotlib'): 'http://matplotlib.org/users/installing.html#installing-on-windows',
('*', '*', 'matplotlib'): 'http://matplotlib.org/users/installing.html#installing',
('*', '*', 'mayavi.mlab'): 'http://docs.enthought.com/mayavi/mayavi/installation.html',
('*', '*', 'nano'): 'http://www.nano-editor.org/dist/latest/faq.html#3',
('*', '*', 'networkx'): 'http://networkx.github.com/documentation/latest/install.html#installing',
('*', '*', 'nose'): 'https://nose.readthedocs.org/en/latest/#installation-and-quick-start',
('*', '*', 'nosetests'): 'https://nose.readthedocs.org/en/latest/#installation-and-quick-start',
('*', '*', 'notepad++'): 'http://notepad-plus-plus.org/download/v6.3.html',
('*', '*', 'numpy'): 'http://docs.scipy.org/doc/numpy/user/install.html',
('*', '*', 'pandas'): 'http://pandas.pydata.org/pandas-docs/stable/install.html',
('*', '*', 'pip'): 'http://www.pip-installer.org/en/latest/installing.html',
('*', '*', 'pytest'): 'http://pytest.org/latest/getting-started.html',
('*', '*', 'python'): 'http://www.python.org/download/releases/2.7.3/#download',
('*', '*', 'pyzmq'): 'https://github.com/zeromq/pyzmq/wiki/Building-and-Installing-PyZMQ',
('*', '*', 'py.test'): 'http://pytest.org/latest/getting-started.html',
('Linux', '*', 'scipy'): 'http://www.scipy.org/Installing_SciPy/Linux',
('Darwin', '*', 'scipy'): 'http://www.scipy.org/Installing_SciPy/Mac_OS_X',
('Windows', '*', 'scipy'): 'http://www.scipy.org/Installing_SciPy/Windows',
('*', '*', 'scipy'): 'http://www.scipy.org/Installing_SciPy',
('*', '*', 'setuptools'): 'https://pypi.python.org/pypi/setuptools#installation-instructions',
('*', '*', 'sqlite3'): 'http://www.sqlite.org/download.html',
('*', '*', 'sublime-text'): 'http://www.sublimetext.com/2',
('*', '*', 'sympy'): 'http://docs.sympy.org/dev/install.html',
('Darwin', '*', 'textmate'): 'http://macromates.com/',
('Darwin', '*', 'textwrangler'): 'http://www.barebones.com/products/textwrangler/download.html',
('*', '*', 'tornado'): 'http://www.tornadoweb.org/',
('*', '*', 'vim'): 'http://www.vim.org/download.php',
('Darwin', '*', 'xcode'): 'https://developer.apple.com/xcode/',
('*', '*', 'xemacs'): 'http://www.us.xemacs.org/Install/',
('*', '*', 'zsh'): 'http://www.zsh.org/',
}
def _get_message(self):
return self._message
def _set_message(self, message):
self._message = message
message = property(_get_message, _set_message)
def __init__(self, checker, message, causes=None):
super(DependencyError, self).__init__(message)
self.checker = checker
self.message = message
if causes is None:
causes = []
self.causes = causes
def get_url(self):
system = _platform.system()
version = None
for pversion in (
'linux_distribution',
'mac_ver',
'win32_ver',
):
value = getattr(_platform, pversion)()
if value[0]:
version = value[0]
break
package = self.checker.name
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
return self._default_url
def __str__(self):
url = self.get_url()
lines = [
'check for {0} failed:'.format(self.checker.full_name()),
' ' + self.message,
' For instructions on installing an up-to-date version, see',
' ' + url,
]
if self.causes:
lines.append(' causes:')
for cause in self.causes:
lines.extend(' ' + line for line in str(cause).splitlines())
return '\n'.join(lines)
def check(checks=None):
successes = []
failures = []
if not checks:
checks = CHECKS
for check in checks:
try:
checker = CHECKER[check]
except KeyError as e:
raise InvalidCheck(check)# from e
_sys.stdout.write('check {0}...\t'.format(checker.full_name()))
try:
version = checker.check()
except DependencyError as e:
failures.append(e)
_sys.stdout.write('fail\n')
else:
_sys.stdout.write('pass\n')
successes.append((checker, version))
if successes:
print('\nSuccesses:\n')
for checker,version in successes:
print('{0} {1}'.format(
checker.full_name(),
version or 'unknown'))
if failures:
print('\nFailures:')
printed = []
for failure in failures:
if failure not in printed:
print()
print(failure)
printed.append(failure)
return False
return True
class Dependency (object):
def __init__(self, name, long_name=None, minimum_version=None,
version_delimiter='.', and_dependencies=None,
or_dependencies=None):
self.name = name
self.long_name = long_name or name
self.minimum_version = minimum_version
self.version_delimiter = version_delimiter
if not and_dependencies:
and_dependencies = []
self.and_dependencies = and_dependencies
if not or_dependencies:
or_dependencies = []
self.or_dependencies = or_dependencies
self._check_error = None
def __str__(self):
return '<{0} {1}>'.format(type(self).__name__, self.name)
def full_name(self):
if self.name == self.long_name:
return self.name
else:
return '{0} ({1})'.format(self.long_name, self.name)
def check(self):
if self._check_error:
raise self._check_error
try:
self._check_dependencies()
return self._check()
except DependencyError as e:
self._check_error = e # cache for future calls
raise
def _check_dependencies(self):
for dependency in self.and_dependencies:
if not hasattr(dependency, 'check'):
dependency = CHECKER[dependency]
try:
dependency.check()
except DependencyError as e:
raise DependencyError(
checker=self,
message=(
'some dependencies for {0} were not satisfied'
).format(self.full_name()),
causes=[e])
self.or_pass = None
or_errors = []
for dependency in self.or_dependencies:
if not hasattr(dependency, 'check'):
dependency = CHECKER[dependency]
try:
version = dependency.check()
except DependencyError as e:
or_errors.append(e)
else:
self.or_pass = {
'dependency': dependency,
'version': version,
}
break # no need to test other dependencies
if self.or_dependencies and not self.or_pass:
raise DependencyError(
checker=self,
message=(
'{0} requires at least one of the following dependencies'
).format(self.full_name()),
causes=or_errors)
def _check(self):
version = self._get_version()
parsed_version = None
if hasattr(self, '_get_parsed_version'):
parsed_version = self._get_parsed_version()
if self.minimum_version:
self._check_version(version=version, parsed_version=parsed_version)
return version
def _get_version(self):
raise NotImplementedError(self)
def _minimum_version_string(self):
return self.version_delimiter.join(
str(part) for part in self.minimum_version)
def _check_version(self, version, parsed_version=None):
if not parsed_version:
parsed_version = self._parse_version(version=version)
if not parsed_version or parsed_version < self.minimum_version:
raise DependencyError(
checker=self,
message='outdated version of {0}: {1} (need >= {2})'.format(
self.full_name(), version, self._minimum_version_string()))
def _parse_version(self, version):
if not version:
return None
parsed_version = []
for part in version.split(self.version_delimiter):
try:
parsed_version.append(int(part))
except ValueError as e:
raise DependencyError(
checker=self,
message=(
'unparsable {0!r} in version {1} of {2}, (need >= {3})'
).format(
part, version, self.full_name(),
self._minimum_version_string()))# from e
return tuple(parsed_version)
class VirtualDependency (Dependency):
def _check(self):
return '{0} {1}'.format(
self.or_pass['dependency'].full_name(),
self.or_pass['version'])
class CommandDependency (Dependency):
exe_extension = _distutils_ccompiler.new_compiler().exe_extension
def __init__(self, command, paths=None, version_options=('--version',),
stdin=None, version_regexp=None, version_stream='stdout',
**kwargs):
if 'name' not in kwargs:
kwargs['name'] = command
super(CommandDependency, self).__init__(**kwargs)
self.command = command
self.paths = paths
self.version_options = version_options
self.stdin = None
if not version_regexp:
regexp = r'([\d][\d{0}]*[\d])'.format(self.version_delimiter)
version_regexp = _re.compile(regexp)
self.version_regexp = version_regexp
self.version_stream = version_stream
def _get_command_version_stream(self, command=None, stdin=None,
expect=(0,)):
if command is None:
command = self.command + (self.exe_extension or '')
if not stdin:
stdin = self.stdin
if stdin:
popen_stdin = _subprocess.PIPE
else:
popen_stdin = None
try:
p = _subprocess.Popen(
[command] + list(self.version_options), stdin=popen_stdin,
stdout=_subprocess.PIPE, stderr=_subprocess.PIPE,
universal_newlines=True)
except OSError as e:
raise DependencyError(
checker=self,
message="could not find '{0}' executable".format(command),
)# from e
stdout,stderr = p.communicate(stdin)
status = p.wait()
if status not in expect:
lines = [
"failed to execute: {0} {1}".format(
command,
' '.join(_shlex.quote(arg)
for arg in self.version_options)),
'status: {0}'.format(status),
]
for name,string in [('stdout', stdout), ('stderr', stderr)]:
if string:
lines.extend([name + ':', string])
raise DependencyError(checker=self, message='\n'.join(lines))
for name,string in [('stdout', stdout), ('stderr', stderr)]:
if name == self.version_stream:
if not string:
raise DependencyError(
checker=self,
message='empty version stream on {0} for {1}'.format(
self.version_stream, command))
return string
raise NotImplementedError(self.version_stream)
def _get_version_stream(self, **kwargs):
paths = [self.command + (self.exe_extension or '')]
if self.exe_extension:
paths.append(self.command) # also look at the extension-less path
if self.paths:
paths.extend(self.paths)
or_errors = []
for path in paths:
try:
return self._get_command_version_stream(command=path, **kwargs)
except DependencyError as e:
or_errors.append(e)
raise DependencyError(
checker=self,
message='errors finding {0} version'.format(
self.full_name()),
causes=or_errors)
def _get_version(self):
version_stream = self._get_version_stream()
match = self.version_regexp.search(version_stream)
if not match:
raise DependencyError(
checker=self,
message='no version string in output:\n{0}'.format(
version_stream))
return match.group(1)
class VersionPlistCommandDependency (CommandDependency):
"""A command that doesn't support --version or equivalent options
On OS X, a command's executable may be hard to find, or not exist
in the PATH. Work around that by looking up the version
information in the package's version.plist file.
"""
def __init__(self, key='CFBundleShortVersionString', **kwargs):
super(VersionPlistCommandDependency, self).__init__(**kwargs)
self.key = key
def _get_command_version_stream(self, *args, **kwargs):
raise NotImplementedError()
def _get_version_stream(self, *args, **kwargs):
raise NotImplementedError()
@staticmethod
def _get_parent(root, element):
"""Returns the parent of this element or None for the root element
"""
for node in root.iter():
if element in node:
return node
raise ValueError((root, element))
@classmethod
def _get_next(cls, root, element):
"""Returns the following sibling of this element or None
"""
parent = cls._get_parent(root=root, element=element)
siblings = iter(parent)
for node in siblings:
if node == element:
try:
return next(siblings)
except StopIteration:
return None
return None
def _get_version_from_plist(self, path):
"""Parse the plist and return the value string for self.key
"""
tree = _element_tree.parse(source=path)
data = {}
for key in tree.findall('.//key'):
value = self._get_next(root=tree, element=key)
if value.tag != 'string':
raise ValueError((tree, key, value))
data[key.text] = value.text
return data[self.key]
def _get_version(self):
for path in self.paths:
if _os.path.exists(path):
return self._get_version_from_plist(path=path)
raise DependencyError(
checker=self,
message=(
'nothing exists at any of the expected paths for {0}:\n {1}'
).format(
self.full_name(),
'\n '.join(p for p in self.paths)))
class UserTaskDependency (Dependency):
"Prompt the user to complete a task and check for success"
def __init__(self, prompt, **kwargs):
super(UserTaskDependency, self).__init__(**kwargs)
self.prompt = prompt
def _check(self):
if _sys.version_info >= (3, ):
result = input(self.prompt)
else: # Python 2.x
result = raw_input(self.prompt)
return self._check_result(result)
def _check_result(self, result):
raise NotImplementedError()
class EditorTaskDependency (UserTaskDependency):
def __init__(self, **kwargs):
self.path = _os.path.expanduser(_os.path.join(
'~', 'swc-installation-test.txt'))
self.contents = 'Hello, world!'
super(EditorTaskDependency, self).__init__(
prompt=(
'Open your favorite text editor and create the file\n'
' {0}\n'
'containing the line:\n'
' {1}\n'
'Press enter here after you have done this.\n'
'You may remove the file after you have finished testing.'
).format(self.path, self.contents),
**kwargs)
def _check_result(self, result):
message = None
try:
with open(self.path, 'r') as f:
contents = f.read()
except IOError as e:
raise DependencyError(
checker=self,
message='could not open {0!r}: {1}'.format(self.path, e)
)# from e
if contents.strip() != self.contents:
raise DependencyError(
checker=self,
message=(
'file contents ({0!r}) did not match the expected {1!r}'
).format(contents, self.contents))
class MakeDependency (CommandDependency):
makefile = '\n'.join([
'all:',
'\t@echo "MAKE_VERSION=$(MAKE_VERSION)"',
'\t@echo "MAKE=$(MAKE)"',
'',
])
def _get_version(self):
try:
return super(MakeDependency, self)._get_version()
except DependencyError as e:
version_options = self.version_options
self.version_options = ['-f', '-']
try:
stream = self._get_version_stream(stdin=self.makefile)
info = {}
for line in stream.splitlines():
try:
key,value = line.split('=', 1)
except ValueError as ve:
raise e# from NotImplementedError(stream)
info[key] = value
if info.get('MAKE_VERSION', None):
return info['MAKE_VERSION']
elif info.get('MAKE', None):
return None
raise e
finally:
self.version_options = version_options
class EasyInstallDependency (CommandDependency):
def _get_version(self):
try:
return super(EasyInstallDependency, self)._get_version()
except DependencyError as e:
version_stream = self.version_stream
try:
self.version_stream = 'stderr'
stream = self._get_version_stream(expect=(1,))
if 'option --version not recognized' in stream:
return 'unknown (possibly Setuptools?)'
finally:
self.version_stream = version_stream
class PythonDependency (Dependency):
def __init__(self, name='python', long_name='Python version',
minimum_version=(2, 6), **kwargs):
super(PythonDependency, self).__init__(
name=name, long_name=long_name, minimum_version=minimum_version,
**kwargs)
def _get_version(self):
return _sys.version
def _get_parsed_version(self):
return _sys.version_info
class PythonPackageDependency (Dependency):
def __init__(self, package, **kwargs):
if 'name' not in kwargs:
kwargs['name'] = package
if 'and_dependencies' not in kwargs:
kwargs['and_dependencies'] = []
if 'python' not in kwargs['and_dependencies']:
kwargs['and_dependencies'].append('python')
super(PythonPackageDependency, self).__init__(**kwargs)
self.package = package
def _get_version(self):
package = self._get_package(self.package)
return self._get_version_from_package(package)
def _get_package(self, package):
try:
return _importlib.import_module(package)
except ImportError as e:
raise DependencyError(
checker=self,
message="could not import the '{0}' package for {1}".format(
package, self.full_name()),
)# from e
def _get_version_from_package(self, package):
try:
version = package.__version__
except AttributeError:
version = None
return version
class MercurialPythonPackage (PythonPackageDependency):
def _get_version(self):
try: # mercurial >= 1.2
package = _importlib.import_module('mercurial.util')
except ImportError as e: # mercurial <= 1.1.2
package = self._get_package('mercurial.version')
return package.get_version()
else:
return package.version()
class TornadoPythonPackage (PythonPackageDependency):
def _get_version_from_package(self, package):
return package.version
def _get_parsed_version(self):
package = self._get_package(self.package)
return package.version_info
class SQLitePythonPackage (PythonPackageDependency):
def _get_version_from_package(self, package):
return _sys.version
def _get_parsed_version(self):
return _sys.version_info
def _program_files_paths(*args):
"Utility for generating MS Windows search paths"
pf = _os.environ.get('ProgramFiles', '/usr/bin')
pfx86 = _os.environ.get('ProgramFiles(x86)', pf)
paths = [_os.path.join(pf, *args)]
if pfx86 != pf:
paths.append(_os.path.join(pfx86, *args))
return paths
CHECKER['python'] = PythonDependency()
for command,long_name,minimum_version,paths in [
('sh', 'Bourne Shell', None, None),
('ash', 'Almquist Shell', None, None),
('bash', 'Bourne Again Shell', None, None),
('csh', 'C Shell', None, None),
('ksh', 'KornShell', None, None),
('dash', 'Debian Almquist Shell', None, None),
('tcsh', 'TENEX C Shell', None, None),
('zsh', 'Z Shell', None, None),
('git', 'Git', (1, 7, 0), None),
('hg', 'Mercurial', (2, 0, 0), None),
('EasyMercurial', None, (1, 3), None),
('pip', None, None, None),
('sqlite3', 'SQLite 3', None, None),
('nosetests', 'Nose', (1, 0, 0), None),
('ipython', 'IPython script', (1, 0), None),
('emacs', 'Emacs', None, None),
('xemacs', 'XEmacs', None, None),
('vim', 'Vim', None, None),
('vi', None, None, None),
('nano', 'Nano', None, None),
('gedit', None, None, None),
('kate', 'Kate', None, None),
('notepad++', 'Notepad++', None,
_program_files_paths('Notepad++', 'notepad++.exe')),
('firefox', 'Firefox', None,
_program_files_paths('Mozilla Firefox', 'firefox.exe')),
('google-chrome', 'Google Chrome', None,
_program_files_paths('Google', 'Chrome', 'Application', 'chrome.exe')
),
('chromium', 'Chromium', None, None),
]:
if not long_name:
long_name = command
CHECKER[command] = CommandDependency(
command=command, paths=paths, long_name=long_name,
minimum_version=minimum_version)
del command, long_name, minimum_version, paths # cleanup namespace
CHECKER['make'] = MakeDependency(command='make', minimum_version=None)
CHECKER['easy_install'] = EasyInstallDependency(
command='easy_install', long_name='Setuptools easy_install',
minimum_version=None)
CHECKER['py.test'] = CommandDependency(
command='py.test', version_stream='stderr',
minimum_version=None)
for paths,name,long_name in [
([_os.path.join(_ROOT_PATH, 'Applications', 'Sublime Text 2.app',
'Contents', 'version.plist')],
'sublime-text', 'Sublime Text'),
([_os.path.join(_ROOT_PATH, 'Applications', 'TextMate.app',
'Contents', 'version.plist')],
'textmate', 'TextMate'),
([_os.path.join(_ROOT_PATH, 'Applications', 'TextWrangler.app',
'Contents', 'version.plist')],
'textwrangler', 'TextWrangler'),
([_os.path.join(_ROOT_PATH, 'Applications', 'Safari.app',
'Contents', 'version.plist')],
'safari', 'Safari'),
([_os.path.join(_ROOT_PATH, 'Applications', 'Xcode.app',
'Contents', 'version.plist'), # OS X >=1.7
_os.path.join(_ROOT_PATH, 'Developer', 'Applications', 'Xcode.app',
'Contents', 'version.plist'), # OS X 1.6,
],
'xcode', 'Xcode'),
]:
if not long_name:
long_name = name
CHECKER[name] = VersionPlistCommandDependency(
command=None, paths=paths, name=name, long_name=long_name)
del paths, name, long_name # cleanup namespace
for package,name,long_name,minimum_version,and_dependencies in [
('nose', None, 'Nose Python package',
CHECKER['nosetests'].minimum_version, None),
('pytest', None, 'pytest Python package',
CHECKER['py.test'].minimum_version, None),
('jinja2', 'jinja', 'Jinja', (2, 6), None),
('zmq', 'pyzmq', 'PyZMQ', (2, 1, 4), None),
('IPython', None, 'IPython Python package',
CHECKER['ipython'].minimum_version, [
'jinja',
'tornado',
'pyzmq',
VirtualDependency(
name='virtual-browser-ipython',
long_name='IPython-compatible web browser',
or_dependencies=[
CommandDependency(
command=CHECKER['firefox'].command,
paths=CHECKER['firefox'].paths,
name='{0}-for-ipython'.format(
CHECKER['firefox'].name),
long_name='{0} for IPython'.format(
CHECKER['firefox'].long_name),
minimum_version=(6, 0)),
CommandDependency(
command=CHECKER['google-chrome'].command,
paths=CHECKER['google-chrome'].paths,
name='{0}-for-ipython'.format(
CHECKER['google-chrome'].name),
long_name='{0} for IPython'.format(
CHECKER['google-chrome'].long_name),
minimum_version=(13, 0)),
CommandDependency(
command=CHECKER['chromium'].command,
paths=CHECKER['chromium'].paths,
name='{0}-for-ipython'.format(
CHECKER['chromium'].name),
long_name='{0} for IPython'.format(
CHECKER['chromium'].long_name),
minimum_version=(13, 0)),
VersionPlistCommandDependency(
command=CHECKER['safari'].command,
paths=CHECKER['safari'].paths,
key=CHECKER['safari'].key,
name='{0}-for-ipython'.format(
CHECKER['safari'].name),
long_name='{0} for IPython'.format(
CHECKER['safari'].long_name),
minimum_version=(5, 0)),
]),
]),
('argparse', None, 'Argparse', None, None),
('numpy', None, 'NumPy', None, None),
('scipy', None, 'SciPy', None, None),
('matplotlib', None, 'Matplotlib', None, None),
('pandas', None, 'Pandas', (0, 8), None),
('sympy', None, 'SymPy', None, None),
('Cython', None, None, None, None),
('networkx', None, 'NetworkX', None, None),
('mayavi.mlab', None, 'MayaVi', None, None),
('setuptools', None, 'Setuptools', None, None),
]:
if not name:
name = package
if not long_name:
long_name = name
kwargs = {}
if and_dependencies:
kwargs['and_dependencies'] = and_dependencies
CHECKER[name] = PythonPackageDependency(
package=package, name=name, long_name=long_name,
minimum_version=minimum_version, **kwargs)
# cleanup namespace
del package, name, long_name, minimum_version, and_dependencies, kwargs
CHECKER['mercurial'] = MercurialPythonPackage(
package='mercurial.util', name='mercurial',
long_name='Mercurial Python package',
minimum_version=CHECKER['hg'].minimum_version)
CHECKER['tornado'] = TornadoPythonPackage(
package='tornado', name='tornado', long_name='Tornado', minimum_version=(2, 0))
CHECKER['sqlite3-python'] = SQLitePythonPackage(
package='sqlite3', name='sqlite3-python',
long_name='SQLite Python package',
minimum_version=CHECKER['sqlite3'].minimum_version)
CHECKER['other-editor'] = EditorTaskDependency(
name='other-editor', long_name='')
for name,long_name,dependencies in [
('virtual-shell', 'command line shell', (
'bash',
'dash',
'ash',
'zsh',
'ksh',
'csh',
'tcsh',
'sh',
)),
('virtual-editor', 'text/code editor', (
'emacs',
'xemacs',
'vim',
'vi',
'nano',
'gedit',
'kate',
'notepad++',
'sublime-text',
'textmate',
'textwrangler',
'other-editor', # last because it requires user interaction
)),
('virtual-browser', 'web browser', (
'firefox',
'google-chrome',
'chromium',
'safari',
)),
('virtual-pypi-installer', 'PyPI installer', (
'pip',
'easy_install',
)),
]:
CHECKER[name] = VirtualDependency(
name=name, long_name=long_name, or_dependencies=dependencies)
del name, long_name, dependencies # cleanup namespace
def _print_info(key, value, indent=19):
print('{0}{1}: {2}'.format(key, ' '*(indent-len(key)), value))
def print_system_info():
print("If you do not understand why the above failures occurred,")
print("copy and send the *entire* output (all info above and summary")
print("below) to the instructor for help.")
print()
print('==================')
print('System information')
print('==================')
_print_info('os.name', _os.name)
_print_info('os.uname', _platform.uname())
_print_info('platform', _sys.platform)
_print_info('platform+', _platform.platform())
for pversion in (
'linux_distribution',
'mac_ver',
'win32_ver',
):
value = getattr(_platform, pversion)()
if value[0]:
_print_info(pversion, value)
_print_info('prefix', _sys.prefix)
_print_info('exec_prefix', _sys.exec_prefix)
_print_info('executable', _sys.executable)
_print_info('version_info', _sys.version_info)
_print_info('version', _sys.version)
_print_info('environment', '')
for key,value in sorted(_os.environ.items()):
print(' {0}={1}'.format(key, value))
print('==================')
def print_suggestions(instructor_fallback=True):
print()
print('For suggestions on installing missing packages, see')
print('http://software-carpentry.org/setup/')
print('')
print('For instructings on installing a particular package,')
print('see the failure message for that package printed above.')
if instructor_fallback:
print('')
print('For help, email the *entire* output of this script to')
print('your instructor.')
if __name__ == '__main__':
import optparse as _optparse
parser = _optparse.OptionParser(usage='%prog [options] [check...]')
epilog = __doc__
parser.format_epilog = lambda formatter: '\n' + epilog
parser.add_option(
'-v', '--verbose', action='store_true',
help=('print additional information to help troubleshoot '
'installation issues'))
options,args = parser.parse_args()
try:
passed = check(args)
except InvalidCheck as e:
print("I don't know how to check for {0!r}".format(e.check))
print('I do know how to check for:')
for key,checker in sorted(CHECKER.items()):
if checker.long_name != checker.name:
print(' {0} {1}({2})'.format(
key, ' '*(20-len(key)), checker.long_name))
else:
print(' {0}'.format(key))
_sys.exit(1)
if not passed:
if options.verbose:
print()
print_system_info()
print_suggestions(instructor_fallback=True)
_sys.exit(1)
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment