Skip to main content

a tiny package example w/setuptools

Project description

📦 py-tiny-pkg

test publish PyPI version

🦾 motivation

  • we can find lots of packaging examples with poetry, pdm, etc., but hard to find examples with the standard setuptools based on the latest PEP supports.

✔️ confirmed versions

  • Ubuntu 20.04 Mac OS X 11.6.4
  • python 3.7.*, 3.8.*, 3.9.*
  • pip 22.0.4+

⬇️ install locally

  • clone this repo
  • $ pip install . or $ pip install .[dev] (for testing)
  • $ pip show tinypkg
Name: tinypkg
Version: 0.0.0
Summary: a tiny package example w/setuptools
Home-page: github.com/denkiwakame/tiny-pkg
Author: denkiwakame
Author-email: denkivvakame@gmail.com
License: MIT License
        Copyright (c) 2022 denkiwakame
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
Location: ...
Requires: requests

👩‍🔧 testing

  • $ pip install .[dev]
  • $ python -m pytest --cov

:octocat: install from GitHub.com

  • pip install git+https://github.com/denkiwakame/py-tiny-pkg

📝 editable install (-e)

ERROR: Project file:///../tiny-py-pkg has a 'pyproject.toml' and its build backend is missing the 'build_editable' hook. Since it does not have a 'setup.py' nor a 'setup.cfg', it cannot be installed in editable mode. Consider using a build backend that supports PEP 660.
  • workaround: locate setup.py that contains the following lines: and then $ pip install -e .
from setuptools import setup
setup()

❓ How can I manage ext_modules ?

  • pyproject.toml does not strictly intend to replace setup.py .
  • If you need to build C/C++ extension modules w/pybind11 or something, write the following setup.py (dynamic config) alongside with the pyproject.toml (metadata file).
import subprocess
import os
import sys

from setuptools import Extension, setup
from setuptools.command.build_ext import build_ext

class CMakeExtension(Extension):
    def __init__(self, name, sourcedir=""):
        Extension.__init__(self, name, sources=[])
        self.sourcedir = os.path.abspath(sourcedir)

class CMakeBuild(build_ext):
    def build_extension(self, ext):
        cfg = "Debug" if self.debug else "Release"  # TODO
        extdir = os.path.abspath(os.path.dirname(
            self.get_ext_fullpath(ext.name)))
        cmake_args = [
            f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extdir}",
            f"-DPYTHON_EXECUTABLE={sys.executable}",
            f"-DCMAKE_BUILD_TYPE={cfg}",
        ]
        build_args = []
        if not os.path.exists(self.build_temp):
            os.makedirs(self.build_temp)
        subprocess.check_call(
            ["cmake", ext.sourcedir] + cmake_args, cwd=self.build_temp
        )
        subprocess.check_call(
            ["cmake", "--build", "."] + build_args, cwd=self.build_temp
        )
setup(
    ext_modules=[CMakeExtension("bindings")],
    cmdclass={"build_ext": CMakeBuild},
)

📦 publish to PyPI

📚 Refernces

pyproject.toml

build-system

metadata

linter support for pyproject.toml

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tinypkg-0.0.4.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tinypkg-0.0.4-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file tinypkg-0.0.4.tar.gz.

File metadata

  • Download URL: tinypkg-0.0.4.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for tinypkg-0.0.4.tar.gz
Algorithm Hash digest
SHA256 1c38ab2ef0ebd6777282a671addd6f200c8adfae82423361e60c463a4600875e
MD5 98f80c9c7278ebd82e75a7ae027ad337
BLAKE2b-256 57ecc1f368e176f9bd9b9e6a6e0f1a7d50f6bb3e10a0975132bff016d5f80807

See more details on using hashes here.

File details

Details for the file tinypkg-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: tinypkg-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for tinypkg-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 90e0a46e12946a223cd4fa28946409a022d131a3328a351e16d4337ff13f036a
MD5 dc43ebef490caea87696df1587fa2d69
BLAKE2b-256 1536cc88d26117a40dad8582394bb04f0ec5b7664e009dc112f86e071c661877

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page