romelgomez / example-python-project-with-pantsbuild-and-poetry

example python project with pantsbuild and poetry

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pants with Poetry example

Project structure

├── README.md
├── external <folder name is defined by you>
│   └── python <folder name ref to python projects>
│       ├── BUILD
│       ├── poetry.lock <generate after install some dep e.g: poetry add requests>
│       └── pyproject.toml <generate by poetry init - in this folder>
├── pants.toml
├── src
│   └── python
│       └── my_package
│           ├── BUILD
│           ├── __init__.py
│           └── my_module.py
└── tests
    └── python
        └── my_package
            ├── BUILD
            ├── __init__.py
            └── test_my_module.py

Steps for reproduce & work with this project structure

We need have Poetry installed

brew install poetry

Let create a folder with the sub folder /python to have all deps

  • mkdir -r external/python
  • cd external/python & poetry init

Installs a project dependency

  • poetry add requests

We need to init pants at the root dir

pants

this commant will create a pants.toml file similiar to this:

[GLOBAL]
pants_version = "2.19.1"

Update it like this:

[GLOBAL]
pants_version = "2.19.1"
backend_packages = ["pants.backend.python"]

[python]
interpreter_constraints = ["==3.8.*", "==3.9.*"]

run a function e.g: main

pants run src/python/my_package:my_main

Test Command

pants test tests/python/my_package:test_my_module

About

example python project with pantsbuild and poetry


Languages

Language:Python 51.1%Language:Starlark 48.9%