└── README.md /README.md: -------------------------------------------------------------------------------- 1 | * [Tools](#tools) 2 | * [Command-line interface](#command-line-interface) 3 | * [Coding style](#coding-style) 4 | * [Documentation](#documentation) 5 | * [Testing](#testing) 6 | * [Profiling](#profiling) 7 | * [Fast computing](#fast-computing) 8 | * [Build and Interpreter](#build-and-interpreter) 9 | * [Continuous integration](#continuous-integration) 10 | * [Cool libraries](#cool-libraries) 11 | * [Visualisation](#visualisation) 12 | * [Automatic differentiation](#automatic-differentiation) 13 | * [Resources](#resources) 14 | 15 | # Tools 16 | 17 | ## Command-line interface 18 | 19 | ### [argparse](https://docs.python.org/3/library/argparse.html) 20 | > The argparse module makes it easy to write user-friendly command-line interfaces. The program defines what arguments it requires, and argparse will figure out how to parse those out of sys.argv. The argparse module also automatically generates help and usage messages and issues errors when users give the program invalid arguments 21 | 22 | ### [docopt](https://github.com/docopt/docopt) 23 | > Isn't it awesome how argparse generate help messages based on your code?! 24 | > Hell no! You know what's awesome? It's when the option parser is generated based on the beautiful help message that you write yourself! This way you don't need to write this stupid repeatable parser-code, and instead can write only the help message--the way you want it. 25 | 26 | ## Coding style 27 | 28 | ### [pycodestyle](http://pycodestyle.pycqa.org/en/latest/intro.html) 29 | > Pycodestyle is a tool to check your Python code against some of the style conventions in PEP 8. 30 | 31 | ### [pylint](https://www.pylint.org/) 32 | > Code analysis for Python: standards, errors, refactoring, customizable 33 | 34 | ### [pyflakes](https://github.com/PyCQA/pyflakes) 35 | > A simple program which checks Python source files for errors 36 | > Pyflakes is also faster than Pylint or Pychecker. This is largely because Pyflakes only examines the syntax tree of each file individually. As a consequence, Pyflakes is more limited in the types of things it can check 37 | 38 | ### [flakes8](https://flake8.pycqa.org/en/latest/) 39 | > flake8 is a command-line utility for enforcing style consistency across Python projects. By default it includes lint checks provided by the PyFlakes project, PEP-0008 inspired style checks provided by the PyCodeStyle project 40 | 41 | ### [autopep8](https://github.com/hhatto/autopep8) 42 | > A tool that automatically formats Python code to conform to the PEP 8 style guide 43 | 44 | ## Documentation 45 | 46 | ### [sphinx](https://www.sphinx-doc.org/en/master/) 47 | > Sphinx is a tool that makes it easy to create intelligent and beautiful documentation, written by Georg Brandl and licensed under the BSD license. 48 | 49 | ### [Read The Docs](https://docs.readthedocs.io/en/stable/) with [sphinx](https://docs.readthedocs.io/en/stable/intro/getting-started-with-sphinx.html) 50 | > Read the Docs simplifies software documentation by automating building, versioning, and hosting of your docs for you. Think of it as Continuous Documentation. 51 | 52 | ## Testing 53 | 54 | ### [unittest](https://docs.python.org/3/library/unittest.html) 55 | > The unittest unit testing framework was originally inspired by JUnit and has a similar flavor as major unit testing frameworks in other languages. It supports test automation, sharing of setup and shutdown code for tests, aggregation of tests into collections, and independence of the tests from the reporting framework. 56 | 57 | ``` 58 | import unittest 59 | 60 | class TestBidule(unittest.TestCase): 61 | 62 | def test_machin(self): 63 | self.assertEqual(foo, bar) 64 | 65 | if __name__ == '__main__': 66 | unittest.main() 67 | ``` 68 | 69 | ### [pytest](https://docs.pytest.org/en/latest/) 70 | > The pytest framework makes it easy to write small tests, yet scales to support complex functional testing for applications and libraries. 71 | 72 | [Allegedly](http://sametmax.com/un-gros-guide-bien-gras-sur-les-tests-unitaires-en-python-partie-3/) better than _unittest_. 73 | ``` 74 | def test_machin(): 75 | assert foo == bar 76 | ``` 77 | 78 | ### [Coverage](https://coverage.readthedocs.io/en/coverage-5.0.3/) 79 | > Coverage.py is a tool for measuring code coverage of Python programs. It monitors your program, noting which parts of the code have been executed, then analyzes the source to identify code that could have been executed but was not. 80 | 81 | ## Profiling 82 | 83 | ### [cProfile](https://docs.python.org/2/library/profile.html) 84 | > cProfile and profile provide deterministic profiling of Python programs. A profile is a set of statistics that describes how often and for how long various parts of the program executed. These statistics can be formatted into reports via the pstats module. 85 | 86 | ### [With PyCharm](https://www.jetbrains.com/help/pycharm/profiler.html#) 87 | > If you have a yappi profiler installed on your interpreter, PyCharm starts the profiling session with it by default, otherwise it uses the standard cProfile profiler. 88 | 89 | 90 | ## Fast computing 91 | 92 | Beware of premature optimization! [Profile](#profiling) first. 93 | 94 | ### [pypy](https://www.pypy.org/) 95 | > "If you want your code to run faster, 96 | > you should probably just use PyPy." 97 | > -- Guido van Rossum (creator of Python) 98 | 99 | ### [cython](https://cython.org/) 100 | > Cython is an optimising static compiler for both the Python programming language and the extended Cython programming language (based on Pyrex). It makes writing C extensions for Python as easy as Python itself. 101 | > Cython gives you the combined power of Python and C to let you 102 | > - write Python code that calls back and forth from and to C or C++ code natively at any point. 103 | > - easily tune readable Python code into plain C performance by adding static type declarations, also in Python syntax. 104 | 105 | ### [numba](http://numba.pydata.org/numba-doc/latest/user/5minguide.html) 106 | > Numba translates Python functions to optimized machine code at runtime using the industry-standard LLVM compiler library. Numba-compiled numerical algorithms in Python can approach the speeds of C or FORTRAN. 107 | > You don't need to replace the Python interpreter, run a separate compilation step, or even have a C/C++ compiler installed. Just apply one of the Numba decorators to your Python function, and Numba does the rest. 108 | 109 | ```python 110 | from numba import jit 111 | import random 112 | 113 | @jit(nopython=True) 114 | def monte_carlo_pi(nsamples): 115 | acc = 0 116 | for i in range(nsamples): 117 | x = random.random() 118 | y = random.random() 119 | if (x ** 2 + y ** 2) < 1.0: 120 | acc += 1 121 | return 4.0 * acc / nsamples 122 | ``` 123 | 124 | See also [the differences between pypy, Cython and numba](https://www.quora.com/How-do-Cython-Numba-and-PyPy-compare-in-terms-of-performance-ease-of-use-and-restrictions) on Quora. 125 | 126 | ## Build and Interpreter 127 | 128 | ### [Remote interpreter with PyCharm](https://www.jetbrains.com/help/pycharm/configuring-remote-interpreters-via-ssh.html#) 129 | - Handles automatic ssh upload/download 130 | - Runs the remote python kernel locally (console, debugging, etc.) 131 | 132 | ### [make](https://en.wikipedia.org/wiki/Make_(software)) 133 | 134 | * [Makefiles in python projects](https://krzysztofzuraw.com/blog/2016/makefiles-in-python-projects.html) 135 | * [Automation and Make](https://swcarpentry.github.io/make-novice/02-makefiles/) 136 | 137 | 138 | ## Continuous integration 139 | 140 | ### [Travis](https://travis-ci.org/) 141 | > Test and Deploy with Confidence. Easily sync your projects with Travis CI and you’ll be testing your code in minutes! 142 | 143 | ### [Github Actions](https://github.com/features/actions) 144 | > Automate your workflow from idea to production. GitHub Actions makes it easy to automate all your software workflows, now with world-class CI/CD. Build, test, and deploy your code right from GitHub. Make code reviews, branch management, and issue triaging work the way you want. 145 | 146 | [Marketplace](https://github.com/marketplace?type=actions) 147 | 148 | Useful actions: 149 | * [Starter Python application](https://github.com/actions/starter-workflows/blob/master/ci/python-app.yml): install, lint with flake8, pytest 150 | * [LaTeX](https://github.com/marketplace/actions/github-action-for-latex) 151 | * [Sphinx](https://github.com/marketplace/actions/sphinx-build) documentation 152 | 153 | 154 | # Cool libraries 155 | 156 | ## Visualisation 157 | 158 | ### [tqdm](https://github.com/tqdm/tqdm) 159 | > A Fast, Extensible Progress Bar for Python and CLI 160 | 161 | ### [celluloid](https://github.com/jwkvam/celluloid/) 162 | > Matplotlib animations made easy 163 | 164 | ### [binder](https://mybinder.org/) 165 | > Turn a Git repo into a collection of interactive notebooks 166 | 167 | ## Automatic differentiation 168 | 169 | ### [autograd](https://github.com/HIPS/autograd) 170 | > Efficiently computes derivatives of numpy code 171 | 172 | ### [jax](https://github.com/google/jax) 173 | > JAX is Autograd and XLA, brought together for high-performance machine learning research. 174 | > What’s new is that JAX uses XLA to compile and run your NumPy programs on GPUs and TPUs 175 | 176 | # Resources 177 | - [Python Tricks: The Book](https://b-ok.cc/book/3525476/83453b), Dan Bader. 178 | 179 | --------------------------------------------------------------------------------