Skip to content

blooop/python_template

Repository files navigation

python_template

A template repo for python projects that is set up using pixi.

This has basic setup for

  • pylint
  • ruff
  • black
  • pytest
  • git-lfs
  • basic github actions ci
  • pulling updates from this template
  • codecov
  • pypi upload
  • dependabot

Continuous Integration Status

Ci Codecov GitHub issues GitHub pull-requests merged GitHub release License Python Pixi Badge

Install

There are two methods of using this project.

  1. Use github to use this project as a template
  2. Clone the project and run, scripts/update_from_template.sh and then run the scripts/rename_project.sh to rename the project.

If you want to use docker you may want to run the scripts/setup_host.sh script. It will set up docker and nvidia-docker (assuming you are on ubuntu22.04).

If you are using pixi, look at the available tasks in pyproject.toml If you are new to pixi follow the instructions on the pixi website

Github setup

There are github workflows for CI, codecov and automated pypi publishing in ci.yml and publish.yml.

ci.yml uses pixi tasks to set up the environment matrix and run the various CI tasks. To set up codecov on github, you need to get a CODECOV_TOKEN and add it to your actions secrets.

publish.yml uses pypy-auto-publish to automatically publish to pypi if the package version number changes. You need to add a PYPI_API_TOKEN to your github secrets to enable this.

Usage

There are currently two ways of running code. The preferred way is to use pixi to manage your environment and dependencies.

cd project

$pixi run ci
pixi run arbitrary_task

If you have dependencies or configuration that cannot be managed by pixi, you can use alternative tools:

  • rockerc: A command-line tool for dynamically creating docker containers with access to host resources such as GPU and
  • rockervsc: A Visual Studio Code extension that integrates rockerc functionality into vscode remote containers.

These tools help you create isolated environments with specific dependencies, ensuring consistent setups across different machines.

cd project_name

rockerc # build and launch container with dependencies set up
# OR
rockervsc # build container, launch and attach vscode to that container.

#once you are inside the container you can use the pixi workflows.
pixi run ci

Legacy

If you don't want to install rocker on your system but want to use vscode, you can run the scripts/launch_vscode.sh script to build and connect to a docker container. It will install rocker in a venv. The docker container is dynamically generated using rocker and deps rocker. deps rocker looks at the python_template.deps.yaml file to install any required apt, pip or shell scripts and launches a container that vscode attaches to.

Troubleshooting

The main pixi tasks are related to CI. Github actions runs the pixi task "ci". The CI is mostly likey to fail from a lockfile mismatch. Use pixi run fix to fix any lockfile related problems.

vscode tasks

There are two core tasks.

  1. set <cfg> from active file

    This sets <cfg> to the currently opened file in the editor

  2. run <cfg>

    This runs python with the file set in <cfg>

About

A template repo for python projects

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published