Skip to content

Instantly share code, notes, and snippets.

@SKalt
Last active May 29, 2019 02:55
Show Gist options
  • Save SKalt/d69f9f2c31dac4d3764f895f4a2b6cf8 to your computer and use it in GitHub Desktop.
Save SKalt/d69f9f2c31dac4d3764f895f4a2b6cf8 to your computer and use it in GitHub Desktop.
sci-stack

linux/windows scientific stack setup

It's dangerous to go alone! Take this.

step 0: use conda to create an isolated, reproducible environment

conda environment management docs

First, install anaconda with all the fixin's (Anaconda) or just the bare necessities (Miniconda). Either work.

On the command line:

conda create --name py37 python=3.7 -y

-y says "yes" to all "do you want to install" questions

conda activate py37

you've now working within a virtual environment (a.k.a. virtualenv):

  • python on the command line now points to a different, custom python executable
    • in this case the 3.7 you installed
    • you can have multiple versions going in different projects
  • conda, pip, and python now look first in a custom directory for installed packages and executables and installing packages within that directory.
    • This means you shouldn't have version conflicts with any other projects on your machine
  • you can look up your environments using conda env list
  • you can exit your virtualenv using conda deactivate

step 1: get a smart IDE

You'll want some basic functionality for any language you work with:

  • Code completion
  • type hints, docs on Hover
  • Jump to def
  • outline of symbols in a script/workspace
  • Find references
  • Diagnostics (style and logic checking)

Your editor shouldn't have to understand every language you might work with well enough to implement these. That's what the python language server is for: a separate service will parse the code in your project and communicate with your IDE, so the IDE only has to implement UI for completion, jumping, etc. See langserver.org/#implementations-client for IDEs that can do this. VSCode and Atom are fairly feature-rich.

Once you've installed an IDE, install the language server:

pip install 'python-language-server[all]' flake8 black pyls-black

If your language server client doesn't use the pyls-black plugin, uninstall the plugin and either use a linting plugin for black or use black directly. Black is named after Ford's comment on customizing the model T: you can get it in "any color you like" so long as it's black. It looks good and works FAST. black --test your/file.py your/directory will test the style therein, while black you/file.py your/directory will correct all style in the python files indicated. The .flake8 config included is a fallback in case your IDE well and truly doesn't support black; it configures flake8 to implement the same checks. Also, black and flake8 check for syntax and logic errors.

Personal advice: use the Atom IDE with the Hydrogen plugin.

Step 3: git gud

ALWAYS use version control. Commit early and often, 'cause nothing feels worse than losing untracked work. If you want your git log to work as a descriptive changelog, you can use

git config alias.checkpoint '!git stash --include-untracked && git stash apply'
# this alias will be local to this project unles you do git config --global ...
git checkpoint # takes a complete snapshot of your project
git stash show # shows what's in that snapshot

Now hit git checkpoint whenever something works or something doesn't work or you want to go get a coffee. Just do it (tm)

Step 4: automate everything

Keep a directory scripts; call them with python scripts/myscript.py

  • simplest
  • works cross-platform
  • pure python Alternately you could use make, or yarn run, but those rely on non-python software and will involve some cross-platform gotchas (i.e. '/' vs '\' in paths).
    • Note that if you're using git for windows, you've got access to git bash, which includes make.

Step 5: go forth and program

Here are some acronyms to help:

  • OOFP: Object-Oriented Functional Programming
    • A method is just a regular function with the instance passed as the first parameter
    • A function should do one thing
    • A function should have no side-effects outside of its local scope
  • KISS: Keep It Simple Stupid
    • There are many nice things that you might not need (testing, type annotations, etc). Reach for them when you need them: later.
    • Something that works but is ugly is ok. Anything that doesn't work is not.
    • A hack beats doing it right any day 'cause doing it right takes a week
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment