Skip to content

Commit

Permalink
Use Poetry for dependency management and packaging
Browse files Browse the repository at this point in the history
Alters the package to use Poetry for dependency management and packaging.
Reasoning for this includes, but is not limited to, the fact that it is
not really advisable to develop in an environment where the `make develop`
incantation makes changes to system or user Python packages, which can
quickly lead to dependency conflicts. (I've been hit by this a few times.)

Resolves #63.
  • Loading branch information
asullivan-blze committed Mar 20, 2024
1 parent 640343c commit 8471543
Show file tree
Hide file tree
Showing 8 changed files with 1,458 additions and 50 deletions.
5 changes: 3 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ plenty of detail and context.
In addition to the python version specified in the `pyproject.toml`, you will
need:

- [Poetry](https://python-poetry.org/docs/)
- `make`
- `pip3`
- `podman`
Expand All @@ -44,8 +45,8 @@ need:
The [Makefile](./Makefile) has some useful targets for typical development
operations, like formatting, building, and locally installing the module.

To install the module in editable mode run `make develop`. This will also
install extra development dependencies.
To install the module into a Poetry virtual environment in editable mode run
`make develop`. This will also install extra development dependencies.
To run the server in development mode, run `make develop-server`.

See the content of the Makefile for other useful targets.
Expand Down
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
FROM python:3.10 AS build
WORKDIR /build
COPY . .
RUN make build
RUN python3 -m pip install --user pipx \
&& PATH=PATH:/root/.local/bin pipx install poetry \
&& PATH=PATH:/root/.local/bin poetry build

FROM python:3.10-slim
COPY --from=build /build/dist ./dist
Expand Down
2 changes: 0 additions & 2 deletions MANIFEST.in

This file was deleted.

17 changes: 8 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ build: dist

.PHONY: container
container:
podman build . --tag boardwalk:$(shell cat VERSION | tr -d '\n')
podman build . --tag boardwalk:$$(poetry version --short)

# Cleans up temporary data that might get created during normal development
.PHONY: clean
clean:
rm -r \
build \
dist \
src/*.egg-info \
src/boardwalk/__pycache__ \
Expand All @@ -23,7 +22,7 @@ clean:
# Installs modules in editable mode
.PHONY: develop
develop:
python3 -m pip install --upgrade --editable .[develop]
poetry install

.PHONY: develop-server
develop-server: develop
Expand All @@ -43,8 +42,7 @@ else
endif

dist: clean
python3 -m pip install --upgrade build pip
python3 -m build
poetry build

# Applys project's required code style
.PHONY: format
Expand All @@ -53,11 +51,12 @@ format:
@# This is a workaround for https://github.com/facebook/usort/issues/216
LIBCST_PARSER_TYPE=native usort format .

# Installs modules to the local system
# Installs modules to the local system (via pipx; will need Ansible injected)
.PHONY: install
install:
python3 -m pip install --upgrade .

install: build
pipx install --pip-args=--upgrade ./dist/boardwalk-$(poetry version --short)-py3-none-any.whl
echo "Boardwalk $(poetry version --short) installed via pipx; execute the following to inject Ansible"
echo " pipx inject boardwalk ansible"

# Installs/updates JS/CSS dependencies in boardwalkd
BOOTSTRAP_VERSION := 5.2.2
Expand Down
1 change: 0 additions & 1 deletion VERSION

This file was deleted.

1,408 changes: 1,408 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

65 changes: 36 additions & 29 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,49 +1,56 @@
[build-system]
build-backend = "setuptools.build_meta"
requires = ["setuptools >=62"]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[project]
[tool.poetry]
name = "boardwalk"
version = "0.8.15"
description = "Boardwalk is a linear Ansible workflow engine"
dynamic = ["dependencies", "version"]
readme = "README.md"
authors = [
{name = "Mat Hornbeek (Backblaze, Inc.)", email = "[email protected]"}
"Mat Hornbeek <[email protected]>",
]
maintainers = [
"Alex Sullivan (Backblaze, Inc.) <[email protected]>",
]
classifiers = [
"Programming Language :: Python :: 3",
"Operating System :: POSIX :: Linux",
"Operating System :: MacOS"
]
requires-python = ">=3.10"

[project.optional-dependencies]
develop = [
"black",
"build",
"pyright",
"semgrep",
"usort"
repository = "https://github.com/Backblaze/boardwalk"
packages = [
{ include = "boardwalk", from = "src" },
{ include = "boardwalkd", from = "src" }
]
include = [
{ path = "py.typed" },
{ path = "static/*.css" },
{ path = "static/*.js"},
{ path = "templates/*.html"}
]

[project.urls]
source = "https://github.com/Backblaze/boardwalk"
issues = "https://github.com/Backblaze/boardwalk/issues"
[tool.poetry.urls]
"Issues" = "https://github.com/Backblaze/boardwalk/issues"

[project.scripts]
boardwalk = "boardwalk.cli:cli"
boardwalkd = "boardwalkd.cli:cli"
[tool.poetry.dependencies]
python = ">=3.10,<4"
ansible-runner = ">=2.3.0"
click = ">=8.1.3"
cryptography = ">=38.0.3"
email-validator = ">=1.3.0" # Required by pydantic to validate emails using EmailStr
pydantic = ">=2.4.2"
tornado = ">=6.2"

[tool.setuptools.package-data]
boardwalk = ["py.typed"]
boardwalkd = ["static/*.css", "static/*.js", "templates/*.html", "py.typed"]
[tool.poetry.group.dev.dependencies]
black = "==24.3.0"
pyright = "==1.1.350"
semgrep = ">=1.66.0"
usort = "==1.0.8"

[tool.setuptools.dynamic]
# We still use a requirements.txt because GitHub's depependency scanner doesn't
# currently support reading dependencies directly from a pyproject.toml, at
# least not without also using poetry
dependencies = {file = "requirements.txt"}
version = {file = "VERSION"}
[tool.poetry.scripts]
boardwalk = "boardwalk.cli:cli"
boardwalkd = "boardwalkd.cli:cli"

[tool.pyright]
exclude = [
Expand Down
6 changes: 0 additions & 6 deletions requirements.txt

This file was deleted.

0 comments on commit 8471543

Please sign in to comment.