Awesome python_projects created by fre171csiro
pip install python_projects
from python_projects import BaseClass
from python_projects import base_function
BaseClass().base_method()
base_function()
$ python -m python_projects
#or
$ python_projects
Dev setup
- Install
pyenv
if not already installed on your dev machine (see steps below), this is optional however it makes managing python easier - Install
poetry
(see steps below).poetry
is used to manage the python environment and is a alternative toconda
- Setup the project environment
- Using the
cmd
change directory to your code parent directory and: - Using
pyenv
install python 3.10.10, e.g.pyenv install 3.10.10
- Set the local version of python -
pyenv local 3.10.10
- Build the python environment -
poetry install
- Activate the environment -
poetry shell
- Open a
.ipynb
file and set the kernel to.venv/Scripts/python.exe
- Using the
- Run the unit tests (make sure the existing code is passing all tests prior to use)
- Set the workspace interpreter to
.venv/Scripts/python.exe
- ctrl+shift+p "Select Interpreter" and select '.venv':poetry
- Open the 'tests' directory or use the VS Code test extension to run all tests
- Set the workspace interpreter to
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
- 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.'
- pyenv overview
- pyenv linux installer
- pyenv windows installer Don't forget to put pyenv in you PATH
This is a useful page explaining the use of pyenv.
- 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 usepoetry init
. If the project already has apyproject.toml
file you can just usepoetry install
and all dependencies will be installed in a environment folder.venv
and a local lock file (poetry.lock
) generated. To add further dependencies runpoetry add [a package name]
or to remove an existing package/dependencypostry 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:
- A single name (requests): this will search for matches on PyPI
- A name and a constraint (requests@^2.23.0)
- A git url (git+https://github.com/python-poetry/poetry.git)
- A git url with a revision (git+https://github.com/python-poetry/poetry.git#develop)
- A file path (../my-package/my-package.whl)
- A directory (../my-package/)
- A url (https://example.com/packages/my-package-0.1.0.tar.gz)
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
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.
rockacbruno and his template https://github.com/rochacbruno/python-project-template