Pyproject.toml replacing setup.py as defacto

Pip no longer working in Ubuntu 23.04

Since I started my project I have just been struggling with building and packaging.
I used to be able to pip install and then that worked but then when I pip install on a friends computer it broke, and now as of recently ‘Ubuntu’ no longer wants to pip to install at all because it may conflict with apt packages so the only way to pip install is within a venv.

omg ubuntu article - “3 Ways to Solve Pip Install Error on Ubuntu 23.04”

Building for Windows | Mac | LInux

I then discovered that Panda3D actually has a way to neatly package and build our stuff for each platform:
Building Binaries
and at one point I did get this to work on a test package I made quickly, note how we can build for each platform: ‘platforms’: [‘manylinux1_x86_64’, ‘macosx_10_6_x86_64’, ‘win_amd64’],
But when I tried moving that example into my project I borked something, I borked it real good and I can no longer build anything I spend my evenings sobbing in the corner.

Future Android Build Ability (Panda3D version 1.11)

Goofing around I noticed that in the future build of Panda3D 1.11 coming one day we will have the ability to build for Android.

Building for Android

This got me fired up, I decided to just try and build for Android just for the fun of having a game on my phone. So I grab my favorite template building platform ‘cookie-cutter’ and just build a quick template and notice my familiar ‘setup.py’ file is no longer there???

As it turns out, python seems to be moving away from ‘setup.py’ and towards something called ‘pyproject.toml’ I spent a hour watching a Ytb video on the subject here:
Packaging Your Python Code With pyproject.toml | Complete Code Conversation


pyproject Documentation page

Now when I tried to build anything, it doesn’t seem to work with our existing project building platform. I would LOVE to contribute to the documentation and demonstrate maybe how I got it working but I never did.
Panda3d Distribution Documentation

If anybody has any pointers, I’d love to hear from you

Contents of my ‘pyproject.toml’ file

[build-system]
requires = ["setuptools>=61.0", "panda3d", "build", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "shenko"
version = "0.1.85"
description = "An open source game built using the Panda3D game engine, visit us at www.shenko.org"
readme = "README.rst"
authors = [
  {name = "Danny Dowshenko", email = "shenko.org@gmail.com"}
]
maintainers = [
  {name = "Danny Dowshenko", email = "shenko.org@gmail.com"}
]
classifiers = [
    "Development Status :: 4 - Beta",
    "Intended Audience :: Developers",
    "License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
    "Programming Language :: Python :: 3",
    "Programming Language :: Python :: 3.10",
    "Operating System :: OS Independent",
    "Topic :: Games/Entertainment"
]
license = {text = "GNU General Public License v3"}
dependencies = [
    "panda3d",
    "build",
    "wheel"
]
requires-python = ">=3.8"

[project.optional-dependencies]
dev = [
    "bump2version==0.5.11",
    "watchdog==0.9.0",
    "tox==3.14.0",
    "Sphinx==7.2.6",
    "twine==5.0.0",
    "coverage",
    "mypy",
    "pytest",
    "ruff"
]

[project.urls]
bugs = "https://github.com/shenko/shenko/issues"
changelog = "https://github.com/shenko/shenko/blob/master/changelog.md"
homepage = "https://github.com/shenko/shenko"

[tool.setuptools]
package-dir = {"" = "src"}

[tool.setuptools.package-data]
"*" = ["*.*"]

# Panda3D build_apps settings
[tool.panda3d.build_apps]
platforms = [
    "manylinux1_x86_64",  # Linux 64-bit
    "win_amd64",          # Windows 64-bit
    "macosx_10_9_x86_64"  # macOS 64-bit
]

name = "Shenko"
version = "0.1.85"
build_directory = "build"

include_patterns = [
    "src/**/*.py",
    "assets/**",
    "config/**"
]

exclude_patterns = [
    "**/__pycache__",
    "**/*.pyc",
    "**/*.pyo"
]

requirements = [
    "panda3d",
    "panda3d-tools"
]

plugins = [
    "pandagl",
    "p3openal_audio",
    "p3ffmpeg",
    "p3ptloader",
    "p3tinydisplay"
]

# MacOS specific options
[tool.panda3d.build_apps.macos]
bundle_identifier = "org.shenko.shenko"

# Windows specific options
[tool.panda3d.build_apps.windows]
product_name = "Shenko"
company_name = "Shenko Games"

# Linux specific options
[tool.panda3d.build_apps.linux]
installer = "manylinux1_x86_64"

# Mypy
[tool.mypy]
files = "."
strict = true
warn_unreachable = true
warn_no_return = true

[[tool.mypy.overrides]]
module = "tests.*"
allow_untyped_defs = true
disable_error_code = "attr-defined"

SHENKO project directory tree

Notice how It did build the .tar and the anywheel

/PROJECT_NAME
├── AUTHORS.rst
├── CODE_OF_CONDUCT.rst
├── CONTRIBUTING.rst
├── dist
│ ├── shenko-0.1.85-py3-none-any.whl
│ └── shenko-0.1.85.tar.gz
├── docs
│ ├── authors.rst
│ ├── conf.py
│ ├── contributing.rst
│ ├── history.rst
│ ├── index.rst
│ ├── installation.rst
│ ├── make.bat
│ ├── Makefile
│ ├── readme.rst
│ └── usage.rst
├── HISTORY.rst
├── LICENSE
├── Makefile
├── MANIFEST.in
├── pyproject (copy).toml
├── pyproject.toml
├── README.rst
├── requirements_dev.txt
├── ruff.toml
├── src
│ ├── shenko
│ │ ├── init.py
│ │ ├── main.py
│ │ └── pycache
│ │ └── init.cpython-310.pyc
│ └── shenko.egg-info
│ ├── dependency_links.txt
│ ├── PKG-INFO
│ ├── requires.txt
│ ├── SOURCES.txt
│ └── top_level.txt
├── tests
│ ├── init.py
│ └── test_shenko.py
└── tox.ini

Panda doesn’t (yet) read from pyproject.toml, so you’ll need to have setuptool pass the options along. In other words, instead of tool.panda3d, you’d need to set setuptools options. That said, I ran into issues getting this to work right, so I ended up added support to pman. An example of a project using this can be found here.

1 Like

This very helpful thank you so much.