Skip to content

Python project setup and dev iteration documentation using poetry for virtual environment management

License

Notifications You must be signed in to change notification settings

fre171csiro/python-projects

Repository files navigation

python_projects

codecov CI

Awesome python_projects created by fre171csiro

Install it from PyPI

pip install python_projects

Usage

from python_projects import BaseClass
from python_projects import base_function

BaseClass().base_method()
base_function()
$ python -m python_projects
#or
$ python_projects

Development

Getting Started

Dev setup

  1. Install pyenv if not already installed on your dev machine (see steps below), this is optional however it makes managing python easier
  2. Install poetry (see steps below). poetry is used to manage the python environment and is a alternative to conda
  3. Setup the project environment
    1. Using the cmd change directory to your code parent directory and:
    2. Using pyenv install python 3.10.10, e.g. pyenv install 3.10.10
    3. Set the local version of python - pyenv local 3.10.10
    4. Build the python environment - poetry install
    5. Activate the environment - poetry shell
    6. Open a .ipynb file and set the kernel to .venv/Scripts/python.exe
  4. Run the unit tests (make sure the existing code is passing all tests prior to use)
    1. Set the workspace interpreter to .venv/Scripts/python.exe
      1. ctrl+shift+p "Select Interpreter" and select '.venv':poetry
    2. Open the 'tests' directory or use the VS Code test extension to run all tests

Installation process (Dev env)

Python Package Manager is a Python utility intended to simplify the tasks of locating, installing, upgrading and removing Python packages. It can determine if the most recent version of a software package is installed on a system, and can install or upgrade that package from a local or remote host. Wikipedia

  1. Install (optional, but helpful) pyenv to manage python version for different scenarios

'pyenv lets you easily switch between multiple versions of Python. It's simple, unobtrusive, and follows the UNIX tradition of single-purpose tools that do one thing well.'

This is a useful page explaining the use of pyenv.

  1. Install poetry to manage project/venv dependencies

We use poetry to manage the python environment and dependencies. If you don't have poetry installed please install it in your base environment and add poetry to your PATH.

Basic usage will help get you started using poetry. If pyproject.toml does not exist in the project directory you can use poetry init. If the project already has a pyproject.toml file you can just use poetry install and all dependencies will be installed in a environment folder .venv and a local lock file (poetry.lock) generated. To add further dependencies run poetry add [a package name] or to remove an existing package/dependency postry remove [package name to remove].

I like to keep the .venv in my project directory so I use poetry config --local virtualenvs.in-project true

You can specify a package to add in the following forms:

Note: Some systems will use a requirements.txt to build a python environment, therefore to easily generate a the requirements.txt run refresh_requirements.sh after any changes to the packages made with poetry

Notebooks/Lab books

These can be used within Visual Studio Code or run in your local browser

If running in a Web browser users will need to install the kernel with python -m ipykernel install --user --name .venv --display-name outlook-hydro, which needs to be executed from the command prompt prior to opening the notebook. Then when loading the notebook select the named outlook-hydro kernal.

To run in your browser open a terminal (make sure you have activated your environment) with the root folder and type jupyter notebook this will load a Jupyter Notebook in your browser. If you replace the url ending 'tree' with 'lab' the server should load a lab book which is more user friendly

Read the CONTRIBUTING.md file.

Acknowledgments

rockacbruno and his template https://github.com/rochacbruno/python-project-template

About

Python project setup and dev iteration documentation using poetry for virtual environment management

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published

Contributors 2

  •  
  •