A simple pyproject.toml initiator
Project description
tomifier
pyproject.toml
is a modern configuration file to package and publish Python packages. tomifier
is a command-line tool to help you initialize a simple Python project. This is similar to the way you can initialize a package in npm with npm init
. The starter code itsef is a command-line interface (CLI) that can launch a FastAPI application and it comes with all the settings and tools to package and publish the generated code as a package.
If you have Ollama installed, tomifier
now also offers code generation capabilities. You can use it to create new files in your project and/or generate code based on a prompt (see the add
command usage details below).
References:
Installation
pip install tomifier
Usage
Initialize a package in current Folder:
tomifier init
Initialize a package at a target folder:
tomifier init -o target_folder/
Initialize a package with a given package name and at a target folder:
tomifier init --name my-package1 --output target_folder/
Add a file:
tomifier add -f myproject1/services/service1.py
Add a file and generate Ollama code:
tomifier add -f myproject1/services/service1.py -p "write a function to add two integers"
Sample output of creating a file and generating code:
File: myproject1/service1.py added
code generated
Sample run
This is what a sample tomifier
run looks like:
tomifier CLI
Description [My package]: Description for myproject1
Author [Name]:
Author email [name@email.com]:
Homepage [https://github.com/<usernane>/<repo>]:
The following packages will be added by default: click, fastapi, and uvicorn[standard]
Command separated list of additional packages [ ]:
Ready to inialize project. Proceed [Y/n]:
Creating package: my-project1
Creating folder test1
New project iniatialized at: test1
Type: cd test1
- Review the generated code
- Check the package requirements in pyproject.toml and requirements.txt
- To build the project type: sh.build
Note: if you intend to deploy the package to pypi.org, make sure that the name is available. Even if it is available, the name could be too close to another name preventing posting. If you end up having to choose a different name, you will need to rename the package directory and the package name references in the
README.md
,pyproject.toml
andMANIFIST.in
files
Scaffolded files
The CLI will scaffold the following files and folder structure at the current folder or at the given target folder:
.
├── .devcontainer
│ └── devcontainer.json
├── .github
│ └── dependabot.yml
├── .gitignore
├── LICENSE
├── MANIFEST.in
├── README.md
├── build.sh
├── myproject1
│ ├── __init__.py
│ ├── cmd
│ │ ├── __init__.py
│ │ ├── root.py
│ │ └── static
│ │ └── index.html
│ └── version.py
├── pyproject.toml
├── requirements.txt
└── setup.py
The scaffolded files include:
- The project files
- The project publishing files including:
pyproject.toml, setup.py, MANIFEST.in, LICENSE, build.sh, and README.md
- The
devcontainer
anddependabot
folders and files for VS Code - A
.gitignore
file
Sample generated pyproject.toml
file
[build-system]
requires = ["setuptools", "setuptools-scm"]
build-backend = "setuptools.build_meta"
[project]
name = "my-package1"
authors = [
{ name="Name", email="name@email.com" },
]
description = "Description my-package1"
readme = "README.md"
license = { file="LICENSE" }
requires-python = ">=3.9"
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
]
dependencies = [
"click",
"fastapi",
"uvicorn[standard]"
]
dynamic = ["version"]
[tool.setuptools]
include-package-data = true
[tool.setuptools.dynamic]
version = {attr = "mypackage1.version.VERSION"}
readme = {file = ["README.md"]}
[tool.setuptools.packages.find]
include = ["mypackage1*"]
exclude = ["*.tests*"]
namespaces = false
[tool.setuptools.package-data]
"mypackage1" = ["*.*"]
[project.urls]
"Homepage" = "https://github.com/<usernane>/<repo>"
[project.scripts]
mypackage1 = "mypackage1.cmd.root:main"
Note: the
pyproject.toml
contents of this file can be and most likely will need to be modified further to meet your needs.
Building the package
build.sh
is a useful bash script included as part of the scaffolded code to build and deploy the package locally in editable mode.
To run it from a bash terminal type:
sh build.sh
The bash script includes the following commands:
rm -rf dist
pip uninstall mypackage1 -y
python -m build
pip install -e .
mypackage1 ui
Pushing the package to pypi.org
After building the package, to push the build to pypi.org using twine. Type:
# Verfify that the package name does not exist
# Install twine
pip install twine
# Make sure to get and install pypi.org token
# Publish the package
twine upload dis/*
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file tomifier-0.0.7.tar.gz
.
File metadata
- Download URL: tomifier-0.0.7.tar.gz
- Upload date:
- Size: 12.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 69553e8f0c0cb4add01339b0164201fd473be7a5f5192b08bd96a40a2c1d2b09 |
|
MD5 | 57157f46a403721ea94485d2b888576e |
|
BLAKE2b-256 | 239837630e9b3e9cca362913d662735a56b5f27cb838582e1f6f7a025d360d24 |
File details
Details for the file tomifier-0.0.7-py3-none-any.whl
.
File metadata
- Download URL: tomifier-0.0.7-py3-none-any.whl
- Upload date:
- Size: 12.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b5b59dd33f64a02a4a29218d11c7d99113225ee8a9b0260bd61499b1c245a300 |
|
MD5 | 3c9e11deca43166dad3af35bab01bf48 |
|
BLAKE2b-256 | 874eb0cfa1294ece3e6b6e42aa580e9813c58505010f50ea0a43db76613167c7 |