{ "cells": [ { "cell_type": "markdown", "id": "46e9114a", "metadata": {}, "source": [ "# Example\n", "\n", "[pyproject.toml](https://github.com/veit/items/blob/main/pyproject.toml)" ] }, { "cell_type": "markdown", "id": "6c2894f9", "metadata": {}, "source": [ "```toml\n", "[tool.black]\n", "line-length = 79\n", "\n", "[tool.isort]\n", "atomic=true\n", "force_grid_wrap=0\n", "include_trailing_comma=true\n", "lines_after_imports=2\n", "lines_between_types=1\n", "multi_line_output=3\n", "not_skip=\"__init__.py\"\n", "use_parentheses=true\n", "\n", "known_first_party=[\"MY_FIRST_MODULE\", \"MY_SECOND_MODULE\"]\n", "known_third_party=[\"mpi4py\", \"numpy\", \"requests\"]\n", "```" ] }, { "cell_type": "markdown", "id": "2fd54d53", "metadata": {}, "source": [ "For Python < 3.11 you need the Python package toml to convert TOML files into Python dictionaries. \n", "\n", "For Python ≥ 3.11 you can load TOML files, for example with:" ] }, { "cell_type": "code", "execution_count": 1, "id": "1cc6fb57", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'tool': {'black': {'line-length': 79},\n", " 'isort': {'atomic': True,\n", " 'force_grid_wrap': 0,\n", " 'include_trailing_comma': True,\n", " 'lines_after_imports': 2,\n", " 'lines_between_types': 1,\n", " 'multi_line_output': 3,\n", " 'not_skip': '__init__.py',\n", " 'use_parentheses': True,\n", " 'known_first_party': ['MY_FIRST_MODULE', 'MY_SECOND_MODULE'],\n", " 'known_third_party': ['mpi4py', 'numpy', 'requests']}}}" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import tomllib\n", "\n", "\n", "with open(\"pyproject.toml\", \"rb\") as f:\n", " data = tomllib.load(f)\n", "\n", "data" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.13 Kernel", "language": "python", "name": "python313" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.13.0" }, "widgets": { "application/vnd.jupyter.widget-state+json": { "state": {}, "version_major": 2, "version_minor": 0 } } }, "nbformat": 4, "nbformat_minor": 5 }