Skip to main content

Functions and scripts to demonstrate Python development tips.

Project description

Documentation Status Unit tests and formatting Recording Slides

Reproducibility is important for software: if it’s not reproducible, it’s not useful. Even if you don’t plan on sharing your code, imagine coming back to a project after a few weeks, or having to install it on a new machine. You’ll be all the more thankful to your past self if you have a clear way to install and run your code.

This repository is a collection of tips and tricks for developing stable and reproducible Python code. There is a slight focus on scientific computing, but the general principles can apply to most Python projects. If you’re reading this from GitHub, please check out the documentation for a more in-depth explanation of the topics covered.

The intended audience is myself (as I often find myself going to past projects to find how I did something!), but also for students and anyone who is interested in learning some new tricks or even sharing their own! I try to follow the principles laid out here on development and reproducibility, so feel free to point out any lapses or suggest improvements, either by opening an issue or pull request.

As is typical in open source, there are many ways to do the same thing. But hopefully this gives you a starting point. Feel free to pick and choose the features that you like. This flexibility is one of the best (and worst parts) of open source. Some of the things we cover:

  • Virtual environments.

  • Version control.

  • Reproducible examples.

  • Documentation.

  • Code formatting.

  • Unit tests and continuous integration.

  • Packaging and distribution.

  • Remove development.

The accompanying slides and video are from a tutorial given at LauzHack’s Deep Learning Bootcamp. Feel free to modify and use it for your own purposes.

Installation

This “dummy” package can be installed with pip:

pip install pydevtips

Or from source, e.g. with Anaconda / Miniconda:

# create new environment, press enter to accept
# -- important to set python version, otherwise `python` executable may not exist
# -- (would be `python3` instead)
conda create -n project_env python=3.11

# view available environments
conda info --envs

# activate environment
conda activate project_env

# install package locally
(project_env) poetry install --with dev

# run tests
(project_env) poetry run pytest

# deactivate environment
(project_env) conda deactivate

Examples

Examples can be found in the examples and notebooks folders. Scripts from the examples folder should be run from the root of the repository, e.g.:

python examples/real_convolve.py

Parameter setting is done with hydra. More on that in the Reproducible examples section of the documentation.

TODO

  • numba: https://numba.pydata.org/

  • picking a license

  • change documentation links to main branch

  • github page

  • point out features in scripts: object-oriented, asserts, tqdm, type hints

  • matplotlib, pytest, black in dev install

  • manifest file to not include file in package

  • GitHub actions for releasing to PyPi when changes to version

  • pytorch compatible

  • Cython / C++

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pydevtips-0.0.3.tar.gz (5.1 kB view hashes)

Uploaded Source

Built Distribution

pydevtips-0.0.3-py3-none-any.whl (5.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page