summaryrefslogtreecommitdiff
path: root/common/templates/python
diff options
context:
space:
mode:
Diffstat (limited to 'common/templates/python')
-rw-r--r--common/templates/python/.envrc1
-rw-r--r--common/templates/python/.gitignore219
-rw-r--r--common/templates/python/flake.nix98
-rw-r--r--common/templates/python/pyproject.toml19
-rw-r--r--common/templates/python/src/hello_world/__init__.py3
-rw-r--r--common/templates/python/src/hello_world/main.py6
-rw-r--r--common/templates/python/uv.lock8
7 files changed, 354 insertions, 0 deletions
diff --git a/common/templates/python/.envrc b/common/templates/python/.envrc
new file mode 100644
index 0000000..3550a30
--- /dev/null
+++ b/common/templates/python/.envrc
@@ -0,0 +1 @@
+use flake
diff --git a/common/templates/python/.gitignore b/common/templates/python/.gitignore
new file mode 100644
index 0000000..f51634e
--- /dev/null
+++ b/common/templates/python/.gitignore
@@ -0,0 +1,219 @@
+# Byte-compiled / optimized / DLL files
+__pycache__/
+*.py[codz]
+*$py.class
+
+# C extensions
+*.so
+
+# Distribution / packaging
+.Python
+build/
+develop-eggs/
+dist/
+downloads/
+eggs/
+.eggs/
+lib/
+lib64/
+parts/
+sdist/
+var/
+wheels/
+share/python-wheels/
+*.egg-info/
+.installed.cfg
+*.egg
+MANIFEST
+
+# PyInstaller
+# Usually these files are written by a python script from a template
+# before PyInstaller builds the exe, so as to inject date/other infos into it.
+*.manifest
+*.spec
+
+# Installer logs
+pip-log.txt
+pip-delete-this-directory.txt
+
+# Unit test / coverage reports
+htmlcov/
+.tox/
+.nox/
+.coverage
+.coverage.*
+.cache
+nosetests.xml
+coverage.xml
+*.cover
+*.py.cover
+.hypothesis/
+.pytest_cache/
+cover/
+
+# Translations
+*.mo
+*.pot
+
+# Django stuff:
+*.log
+local_settings.py
+db.sqlite3
+db.sqlite3-journal
+
+# Flask stuff:
+instance/
+.webassets-cache
+
+# Scrapy stuff:
+.scrapy
+
+# Sphinx documentation
+docs/_build/
+
+# PyBuilder
+.pybuilder/
+target/
+
+# Jupyter Notebook
+.ipynb_checkpoints
+
+# IPython
+profile_default/
+ipython_config.py
+
+# pyenv
+# For a library or package, you might want to ignore these files since the code is
+# intended to run in multiple environments; otherwise, check them in:
+# .python-version
+
+# pipenv
+# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
+# However, in case of collaboration, if having platform-specific dependencies or dependencies
+# having no cross-platform support, pipenv may install dependencies that don't work, or not
+# install all needed dependencies.
+# Pipfile.lock
+
+# UV
+# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
+# This is especially recommended for binary packages to ensure reproducibility, and is more
+# commonly ignored for libraries.
+# uv.lock
+
+# poetry
+# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
+# This is especially recommended for binary packages to ensure reproducibility, and is more
+# commonly ignored for libraries.
+# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
+# poetry.lock
+# poetry.toml
+
+# pdm
+# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
+# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
+# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
+# pdm.lock
+# pdm.toml
+.pdm-python
+.pdm-build/
+
+# pixi
+# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
+# pixi.lock
+# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
+# in the .venv directory. It is recommended not to include this directory in version control.
+.pixi
+
+# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
+__pypackages__/
+
+# Celery stuff
+celerybeat-schedule
+celerybeat.pid
+
+# Redis
+*.rdb
+*.aof
+*.pid
+
+# RabbitMQ
+mnesia/
+rabbitmq/
+rabbitmq-data/
+
+# ActiveMQ
+activemq-data/
+
+# SageMath parsed files
+*.sage.py
+
+# Environments
+.env
+.venv
+env/
+venv/
+ENV/
+env.bak/
+venv.bak/
+
+# Spyder project settings
+.spyderproject
+.spyproject
+
+# Rope project settings
+.ropeproject
+
+# mkdocs documentation
+/site
+
+# mypy
+.mypy_cache/
+.dmypy.json
+dmypy.json
+
+# Pyre type checker
+.pyre/
+
+# pytype static type analyzer
+.pytype/
+
+# Cython debug symbols
+cython_debug/
+
+# PyCharm
+# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
+# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
+# and can be added to the global gitignore or merged into this file. For a more nuclear
+# option (not recommended) you can uncomment the following to ignore the entire idea folder.
+# .idea/
+
+# Abstra
+# Abstra is an AI-powered process automation framework.
+# Ignore directories containing user credentials, local state, and settings.
+# Learn more at https://abstra.io/docs
+.abstra/
+
+# Visual Studio Code
+# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
+# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
+# and can be added to the global gitignore or merged into this file. However, if you prefer,
+# you could uncomment the following to ignore the entire vscode folder
+# .vscode/
+
+# Ruff stuff:
+.ruff_cache/
+
+# PyPI configuration file
+.pypirc
+
+# Marimo
+marimo/_static/
+marimo/_lsp/
+__marimo__/
+
+# Streamlit
+.streamlit/secrets.toml
+
+#nix
+.direnv
+result
diff --git a/common/templates/python/flake.nix b/common/templates/python/flake.nix
new file mode 100644
index 0000000..e773850
--- /dev/null
+++ b/common/templates/python/flake.nix
@@ -0,0 +1,98 @@
+{
+ inputs = {
+ nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
+
+ pyproject-nix = {
+ url = "github:pyproject-nix/pyproject.nix";
+ inputs.nixpkgs.follows = "nixpkgs";
+ };
+
+ uv2nix = {
+ url = "github:pyproject-nix/uv2nix";
+ inputs.pyproject-nix.follows = "pyproject-nix";
+ inputs.nixpkgs.follows = "nixpkgs";
+ };
+
+ pyproject-build-systems = {
+ url = "github:pyproject-nix/build-system-pkgs";
+ inputs.pyproject-nix.follows = "pyproject-nix";
+ inputs.uv2nix.follows = "uv2nix";
+ inputs.nixpkgs.follows = "nixpkgs";
+ };
+ };
+
+ outputs =
+ {
+ nixpkgs,
+ pyproject-nix,
+ uv2nix,
+ pyproject-build-systems,
+ ...
+ }:
+ let
+ inherit (nixpkgs) lib;
+ forAllSystems = lib.genAttrs lib.systems.flakeExposed;
+
+ workspace = uv2nix.lib.workspace.loadWorkspace { workspaceRoot = ./.; };
+
+ overlay = workspace.mkPyprojectOverlay {
+ sourcePreference = "wheel";
+ };
+
+ editableOverlay = workspace.mkEditablePyprojectOverlay {
+ root = "$REPO_ROOT";
+ };
+ packageName = "hello_world";
+
+ pythonSets = forAllSystems (
+ system:
+ let
+ pkgs = nixpkgs.legacyPackages.${system};
+ python = pkgs.python3;
+ in
+ (pkgs.callPackage pyproject-nix.build.packages {
+ inherit python;
+ }).overrideScope
+ (
+ lib.composeManyExtensions [
+ pyproject-build-systems.overlays.wheel
+ overlay
+ ]
+ )
+ );
+
+ in
+ {
+ devShells = forAllSystems (
+ system:
+ let
+ pkgs = nixpkgs.legacyPackages.${system};
+ pythonSet = pythonSets.${system}.overrideScope editableOverlay;
+ virtualenv = pythonSet.mkVirtualEnv "${packageName}-dev-env" workspace.deps.all;
+ in
+ {
+ default = pkgs.mkShellNoCC {
+ packages = [
+ virtualenv
+ pkgs.uv
+ pkgs.pyrefly
+ pkgs.ruff
+ ];
+ env = {
+ UV_NO_SYNC = "1";
+ UV_PYTHON = pythonSet.python.interpreter;
+ UV_PYTHON_DOWNLOADS = "never";
+ };
+ shellHook = ''
+ unset PYTHONPATH
+ export REPO_ROOT=$(git rev-parse --show-toplevel)
+ '';
+ };
+ }
+ );
+
+ packages = forAllSystems (system: {
+ default = pythonSets.${system}.mkVirtualEnv packageName workspace.deps.default;
+ });
+ };
+}
diff --git a/common/templates/python/pyproject.toml b/common/templates/python/pyproject.toml
new file mode 100644
index 0000000..5892765
--- /dev/null
+++ b/common/templates/python/pyproject.toml
@@ -0,0 +1,19 @@
+[project]
+name = "hello-world"
+version = "0.1.0"
+description = "Add your description here"
+requires-python = ">=3.12"
+dependencies = []
+
+[project.scripts]
+hello_world = "hello_world.main:main"
+
+[build-system]
+requires = ["uv_build>=0.10.0,<0.11.0"]
+build-backend = "uv_build"
+
+[tool.pyrefly]
+project-includes = [
+ "**/*.py*",
+ "**/*.ipynb",
+]
diff --git a/common/templates/python/src/hello_world/__init__.py b/common/templates/python/src/hello_world/__init__.py
new file mode 100644
index 0000000..402c976
--- /dev/null
+++ b/common/templates/python/src/hello_world/__init__.py
@@ -0,0 +1,3 @@
+def hello_world(action: str):
+ result = [*hello_world.__name__.split("_")]
+ eval(action)(" ".join(result).title() + "!\n")
diff --git a/common/templates/python/src/hello_world/main.py b/common/templates/python/src/hello_world/main.py
new file mode 100644
index 0000000..71ad102
--- /dev/null
+++ b/common/templates/python/src/hello_world/main.py
@@ -0,0 +1,6 @@
+from hello_world import hello_world
+
+
+def main():
+ hello_world("print")
+
diff --git a/common/templates/python/uv.lock b/common/templates/python/uv.lock
new file mode 100644
index 0000000..6fa00de
--- /dev/null
+++ b/common/templates/python/uv.lock
@@ -0,0 +1,8 @@
+version = 1
+revision = 3
+requires-python = ">=3.12"
+
+[[package]]
+name = "hello-world"
+version = "0.1.0"
+source = { editable = "." }