12
Build System for Large Codebases Angad Singh PyCon SG 2016 @angadsg

Python Pants Build System for Large Codebases

Embed Size (px)

Citation preview

Page 1: Python Pants Build System for Large Codebases

Build System for Large Codebases

Angad SinghPyCon SG 2016

@angadsg

Page 2: Python Pants Build System for Large Codebases

NUS Computer Engineering (2009-13)

SRE at Twitter (2013-14)

DevOps at Viki (2014-..)

Contact: t.co/as

Twitter: @angadsg

About me

Page 3: Python Pants Build System for Large Codebases

Agenda

Code Organization

Pain Points

Pants as a build tool

Python PEX format

Code Examples

Page 4: Python Pants Build System for Large Codebases

Service A Service B Service C

Project Repo A

Project Repo B

Project Repo C

Code Organization

Shared code

Does not scale well for a large number of microservices

Complex method of sharing libraries (publishing artifacts, versioning hell)

Page 5: Python Pants Build System for Large Codebases

Code Organization

Libraries repository

Service A

Service B

Service C

Libraries as Code Units

Single Lint, Build, Test and Release process

Easy to coordinate changes across modules

Easier to setup development environment

Tests run across modules are run together

Promote the idea of writing shareable code

Monorepo- A repository with a defined structure for organizing reusable components of code

Page 6: Python Pants Build System for Large Codebases

Pain Points

Virtualenv to manage dependencies for python projects is painful. Need something simpler.

Need easier code sharing amongst projects. Fixing a bug in a function should not require changing versions of other downstream projects.

Need standardization in testing and building process

Page 7: Python Pants Build System for Large Codebases

PantsBuild system for managing targets sharing

a single repository

Dependencies are managed in BUILD files that live alongside the code.

History - Used to be a python wrapper around Ant build tool which generated build.xml files and handed the build files to ant. (Python + Ant = Pants)

Later, rewritten to be an independent build tool with main support for JVM languages and Python.

Page 8: Python Pants Build System for Large Codebases

Pants

Define source tree - src/<lang> e.g. src/python/

BUILD files define targets at each leaf node in the source tree.

DSL, which invokes python constructors in the background

Targets can be either a binary (e.g PEX for python, JAR for Java) or a library which can be referenced by other targets.

Page 9: Python Pants Build System for Large Codebases

PEX

PEX files - Python Executables, similar in idea to a virtual environment.

Generate Immutable artifacts, that will run on any server

Run targets locally, without maintaining complex virtual environments

Easier debugging through standardized versioning of 3rdparty dependencies

Page 10: Python Pants Build System for Large Codebases

BUILD file

python_binary(name=’cli’, dependencies = [ “src/python/3rdparty/python:requests”, “:shared_lib” ] source=’cli.py’)

python_library(name=’shared_lib’, dependencies = [ “src/python/3rdparty/python:fabric” ] source=’lib.py’)

Page 11: Python Pants Build System for Large Codebases

Examples

A simple python flask application

https://github.com/angad/pants-flask

Twitter Commons

https://github.com/twitter/commons

Page 12: Python Pants Build System for Large Codebases

Thank you