Skip to content

About

Minimal package to demonstrate good Python development habits

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

python-dev-tips, Slides

Creating virtual environment and install

With Anaconda (recommended). After installing Anaconda or Miniconda (light version), create a new environment:

# create new environment, press enter to accept
conda create -n project_env python=3.9

# view available environments
conda info --envs

# activate environment
conda activate project_env

# instal package locally
(project_env) pip install -e .

# deactivate environment
(project_env) conda deactivate

For machines really light on memory (e.g. Raspberry Pi) use Virtualenv:

# install library if not already
pip install virtualenv

# create virtual environment (creates folder called project_env)
python3 -m venv project_env

# activate virtual environment
source project_env/bin/activate

# instal package locally
(project_env) pip install -e .

# deactivate virtual environment
(project_env) deactivate

Code formatting

Through pre-commit hooks:

# inside virtual environment
(project_env) pip install pre-commit
(project_env) pip install black

# Install git hooks
(project_env) pre-commit install
# pre-commit installed at .git/hooks/pre-commit

Testing

Write tests in the tests folder as function that begin with test_.

To run tests (install pytest first if not already done):

# inside virtual environment
(project_env) pip install pytest

# run tests
(project_env) pytest

To run a specific test:

# inside virtual environment
(project_env) pytest tests/test_fftconvolve.py::test_fft

Releasing package to PyPi

This is done through twine:

# inside virtual environment
(project_env) pip install twine

# build package
(project_env) python setup.py sdist bdist_wheel
# -- create in dist folder

# upload to test pypi
(project_env) python -m twine upload  dist/pydevtips-X.X.X.tar.gz
# -- X.X.X is the version number in setup.py
# -- enter username and password
# -- check https://pypi.org/project/pydevtips/X.X.X/

TODO

  • matplotlib, pytest, black in dev install
  • example file with hydra
  • manifest file to not include file in package
  • GitHub actions for formating and unit tests
  • GitHub actions for releasing to PyPi
  • documentation if time

About

Minimal package to demonstrate good Python development habits

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages