housekeeping around poetry stuff #10

Merged
ben merged 11 commits from poetry-fixes into main 2022-10-03 15:25:04 +00:00
9 changed files with 257 additions and 877 deletions

1
.gitignore vendored
View File

@ -1,7 +1,6 @@
*~
*.pyc
dist/
build/
logs/
MANIFEST
sudoisbot.egg-info/

View File

@ -31,7 +31,6 @@ _NOTE: this project will be renamed, most likely to `roomie`._
* sensor
* apis
# license
GPL

121
docs/poetry-bumpversion.md Normal file
View File

@ -0,0 +1,121 @@
# `poetry-bumpversion` and working around PEP 440 errors
install the `poetry-bumpversion` plugin as [per the poetry
docs](https://python-poetry.org/docs/plugins/#the-self-add-command),
since it isnt part of the poetry repo, but the poetry setup on the
system:
```shell
poetry self add poetry-bumpversion
```
poetry 1.2.0 is a lot more careful/specific about version numbers, if
you get an error like
```
Invalid PEP 440 version: '1.1build1'
```
that means that poetry found a package installed on your system that
doesnt follow PEP 440 versioning.
use `python3 -m pip freeze` to find which package it is. on Debian and
Ubuntu it is likely to be a package installed by apt (intalled in
`/usr/lib/python3/dist-packages`), and in this case the package is
`distro-info`.
```shell
$ python3 -m pip freeze | grep "build1"
distro-info===1.1build1
$ apt-cache policy python3-distro-info
python3-distro-info:
Installed: 1.1build1
```
so the ubuntu package `python3-distro-info` is installed into
`dist-packages` with an uncompliant version string.
## install poetry with `pipx`
following [the docs](https://python-poetry.org/docs/#installing-with-pipx),
first install `pipx`:
```shell
python3 -m pip install --user pipx
python3 -m pipx ensurepath
# on ubuntu, to get `ensurepip`:
sudo apt-get install python3.10-venv
```
and then install `poetry` into a `pipx` managed venv:
```shell
pipx install poetry
```
this will create a virtual environment at `~/.local/pipx/venvs` and
install `poetry` there. it also creates a symlink at `~/.local/bin/poetry`:
```shell
# which poetry
~/.local/bin/poetry
```
and then just add the `poetry-bumpversion` plugin:
```shell
poetry add poetry-bumpversion
```
now it works, the `poetry-bumpversion` plugin updates files according to our settings in `pyproject.toml`:
```shell
$ poetry version patch
Bumping version from 0.4.10 to 0.4.11
$ git status --short
M pyproject.toml
M sudoisbot/__init__.py
```
since `pipx` doesnt care about `dist-packages`, the ubuntu-maintened
`dist-packages` was ignored, since `pipx` doesnt look at it (being in
a venv).
## workaround for poetry installed with pip
you can run `poetry` inside its own managed venv, because that [wont
have access to the `site-packages` by
default](https://python-poetry.org/docs/plugins/#the-self-add-command).
check the value of `virtualenvs.options.system-site-packages`
```shell
$ poetry config virtualenvs.options.system-site-packages
false
```
if you need to change it:
```shell
poetry config virtualenvs.options.system-site-packages false
```
now you can use it like this:
```shell
$ poetry run python3 -m poetry self add poetry-bumpversion
$ poetry run python3 -m poetry version patch
Bumping version from 0.4.10 to 0.4.11
```
and it will have updated the files you configured it to update in
`pyproject.toml` (usually `$package/__init__.py`).
unfortuately it doesnt help to add it to your projects dependencies,
your local `site-packages` with `--user` or install into the venv that
poetry manages, since `poetry self` doesnt use that (unless we pull a
fast one poetry and run it from within its own venv).

987
poetry.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
[tool.poetry]
name = "sudoisbot"
version = "0.4.10"
version = "0.4.11"
description = "a home automation and monitoring system written to learn zmq"
authors = ["Ben Kristinsson <ben@lokun.is>"]
homepage = "https://www.sudo.is"
@ -12,9 +12,9 @@ readme = "README.md"
python = "^3.9"
loguru = "^0.6.0"
PyYAML = "^6.0"
pyzmq = "^23.2.1"
pyzmq = "^24.0.1"
sudoistemper = "^0.1.0"
peewee = "^3.15.2"
peewee = "^3.15.3"
requests = "^2.28.1"
python-dateutil = "^2.8.2"
python-telegram-bot = { version = "^13.1", optional = true }
@ -24,7 +24,6 @@ PyMySQL = "^1.0.2"
autopep8 = "^1.7.0"
isort = "^5.10.1"
poethepoet = "^0.16.2"
poetry-bumpversion = "^0.2.0"
flake8 = "^5.0.4"
pytest = "^7.1.3"
@ -35,13 +34,11 @@ telegram = ["python-telegram-bot"]
sudoisbot = "sudoisbot:main"
ruok_sudoisbot = "sudoisbot:ruok"
[tool.poetry_bumpversion.file."sudoisbot/__init__.py"]
# install with either:
# $POETRY_HOME/bin/pip install --user poetry-bumpversion
# poetry add -D poetry-bumpversion
# poetry self add poetry-bumpversion
[tool.poetry_bumpversion.file."sudoisbot/__init__.py"]
[build-system]
requires = ["poetry_core>=1.0.0"]
requires = ["poetry-core>=1.2.1"]
build-backend = "poetry.core.masonry.api"

View File

@ -2,7 +2,7 @@
set -e
source ./scripts/docker.env
source ./scripts/build/docker.env
if [[ "$1" == "builder" ]] || [[ "$1" == "" ]]; then
docker build --pull --target builder -t ${repo_name}_builder:${docker_tag} .

View File

@ -2,6 +2,6 @@
set -e
source ./scripts/docker.env
source ./scripts/build/docker.env
docker run --rm -it ${repo_name}:${docker_tag} $*

5
scripts/bump-version.sh Executable file
View File

@ -0,0 +1,5 @@
#!/bin/bash
set -e
poetry run python3 -m poetry version $*

View File

@ -1,4 +1,4 @@
__version__ = '0.4.10'
__version__ = '0.4.11'
import argparse
import os