What is setuptools? #!/usr/bin/env python from setuptools import setup setup( description=README, author='Stephen Holsapple', firstname.lastname@example.org', packages=['foo'], install_requires=, )
What is setuptools? Everything. • To Python, setuptools is everything. – Is the core API that most tools nowadays use. – Is the brains behind: • Build • Packaging • Metadata discovery • Dependency management
Building w/ setuptools • Tools like virtualenv and pip make life preHy good.
Packaging w/ setuptools • Tools like setuptools, pip, pex make life preHy good. – Source distribuJons – Binary distribuJons – Deployable distribuJon
Metadata w/ setuptools • Doesn't provide great ways to: – Reason about builds before/aOer – Reason about arJfacts programaJcally • Does expose programming interfaces to integrate with exisJng metadata systems. • Requires us to evaluate Python to query about metadata.
[pip/issues/988] “Requirements ﬁles are used to force pip to properly resolve dependencies. As it is now, pip doesn't have true dependency resolu=on, but instead simply uses the ﬁrst speciﬁca=on it ﬁnds for a project.”
pkg_resources is greedy • Simply use the ﬁrst speciﬁcaJon found for a dependency. • Ask developers to pin all of their dependencies. – pip freeze > requirements.txt
Building BeHer Building Systems • We have a core set of great tools to work with: – virtualenv – setuptools – pip – pex
A polite tool • The pip tool is polite because: – Al ows for customizaJon or disabling of setuptools and pip features: • --index-url • --extra-index-url • --no-deps – Al ows us to use local repositories. – Al ows us to solve our problems our way.
Gradle Infrastructure • python-product – Your enterprise build logic, covering everything from your resoluJon strategies, your repositories, your metadata, and more. – You could write a simple plugin that simply defers to setuptools, if you want.
Gradle Plugins • python-venv – Builds a local environment • python-sdist – Build a source distribuJon using setuptools. • python-wheel – Build a wheel distribuJon using setuptools. • python-pex – Build a pex distribuJon using pex.
python-venv • Under the hood: – CreaJng a virtual environment. – Installing build requirements. – Installing your resolved dependencies. – Installing your project. – Running tests – Packaging arJfacts
python-sdist • Under the hood: – Applying python-venv – Invoking ./setup.py sdist
python-wheel • Under the hood: – Applying python-venv – Invoking pip wheel • Making Python's wheel ﬁle compaJble with Ivy is hard.
python-pex • Under the hood: – Applying python-venv – Invoking pex • Prepare to baHle with pex's dependency resolver.
python-??? • ExisJng plugins easy to add now. • AddiJonal plugins easy to add later. • Mix and match any way we like. – We might want a source and a wheel distribuJon.
Why Python? • Why was Python so easy to build with Gradle? – Can decouple dep. mgmt. from setuptools – Can decouple dep. mgmt. from PyPI – Can represent dependencies with Ivy • Other languages like Python can also easily use Gradle