Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Poetry build system & normalise on Python 3.11 #2703

Closed
phillxnet opened this issue Oct 15, 2023 · 16 comments
Closed

Update Poetry build system & normalise on Python 3.11 #2703

phillxnet opened this issue Oct 15, 2023 · 16 comments
Assignees
Milestone

Comments

@phillxnet
Copy link
Member

We currently still depend upon a now outdated Poetry version of 1.1.15: employed to transition us from our prior Py2.7 to our current Py3.9. But now that we are well under-way with our Py3.9 dependency update we can move to updating our Poetry to re-enable our Tumbleweed install build capability: there exists an incompatibility with installing (but not using) Poetry that break new installer builds that should be addressed by this issue.

A significant element in addressing this issue is that there is no update path in Poetry from 1.1.15 to 1.2.x:
https://python-poetry.org/blog/announcing-poetry-1.1.15/#compatibility-between-poetry-11-and-12
https://python-poetry.org/docs/#installation
I.e. we will likely have to remove and re-install rather than just do a poetry self update.

Poetry 1.1 series releases are not able to update in-place to 1.2 or newer series releases. To migrate to newer releases, uninstall using your original install method, and then reinstall using the methods above.

@phillxnet
Copy link
Member Author

The relevant file in this case is our build.sh however we also need to address a similar install instantiated in our scriptlets of the rockstor-rpmbuild repository:

@phillxnet
Copy link
Member Author

To avoid excessively long package updates, where we already (necessarily) wipe and rebuild our .venv, it is proposed that we try to read the current version of Poetry installed; and if this is 1.1.15 (the only version employed to date) we do the uninstall re-install to presumably latest. Our current Python 3.9 should support this and we will likely be at 3.10 min by that time anyway give the associated/related Milestone: https://github.com/rockstor/rockstor-core/milestone/25

@phillxnet phillxnet added this to the Py3.10 milestone Nov 13, 2023
@phillxnet phillxnet self-assigned this Nov 22, 2023
@phillxnet
Copy link
Member Author

In both build.sh:

curl -sSL https://install.python-poetry.org | POETRY_VERSION=1.1.15 python3 -

and within our %build rpmbuild scriptlet:

https://github.com/rockstor/rockstor-rpmbuild/blob/1526dbfd102fdae94416a46c8fcb9f0eae4a201f/rockstor.spec#L222

We install poetry using the default Python3, which on Leap is 3.6.15:

lbuildvm:~ # python3 --version
Python 3.6.15

But on tumbleweed this varies, but has been at 3.11 for some time now:

twbuildvm:~ # python3 --version
Python 3.11.4

As a consequence of this, it is proposed that we standardise on the version used during the poerty install itself, as per our python version specification in pyproject.toml for all other dependencies. This way we can hopefully avoid breakages such as we have already observed here re TW's default Python updating breaking our Poetry install itself, and thus creating a blocker on our ability to build installers from then on.

@phillxnet
Copy link
Member Author

We need also to update the following within our pyproject.toml:

[build-system]
requires = ["poetry-core=1.1.15"]
build-backend = "poetry.core.masonry.api"

To whatever the equivalent is for our chosen Poetry version.

@phillxnet
Copy link
Member Author

phillxnet commented Nov 22, 2023

From: https://python-poetry.org/docs/#system-requirements

Poetry requires Python 3.8+

for the current 1.7.1 version.

@phillxnet
Copy link
Member Author

If we install poetry under Py3.11 we get the following when doing a poetry install after wiping an existing .venv to account for Python version update (as we do in scriptlets in rpm update):

lbuildvm:/opt/rockstor # poetry install
The currently activated Python version 3.11.5 is not supported by the project (~3.9).
Trying to find and use a compatible version. 
Using python3.9 (3.9.18)
Creating virtualenv rockstor in /opt/rockstor/.venv
Installing dependencies from lock file

Package operations: 42 installs, 0 updates, 0 removals

However if we try to also align our pyproject.toml with the venv python we installed under (3.11) Poetry fails re futures:

rm -rf .venv
poetry show --tree
Creating virtualenv rockstor in /opt/rockstor/.venv

failed to query /usr/bin/python3 with code 1 err: '  File "/root/.local/share/pypoetry/venv/lib64/python3.11/site-packages/virtualenv/discovery/py_info.py", line 7\n    from __future__ import annotations\n    ^\nSyntaxError: future feature annotations is not defined\n'

lbuildvm:/opt/rockstor # poetry install
Creating virtualenv rockstor in /opt/rockstor/.venv

failed to query /usr/bin/python3 with code 1 err: '  File "/root/.local/share/pypoetry/venv/lib64/python3.11/site-packages/virtualenv/discovery/py_info.py", line 7\n    from __future__ import annotations\n    ^\nSyntaxError: future feature annotations is not defined\n'

suggesting we have some mixed python version issue here when we use the same Python version within our .venv as Poetry was installed under !!

@phillxnet
Copy link
Member Author

Reverting pyproject to our existing Py3.9 and we have a successful .venv install again:

lbuildvm:/opt/rockstor # poetry install
The currently activated Python version 3.11.5 is not supported by the project (~3.9).
Trying to find and use a compatible version. 
Using python3.9 (3.9.18)
Creating virtualenv rockstor in /opt/rockstor/.venv
Installing dependencies from lock file

@phillxnet
Copy link
Member Author

If alternatively we install Poetry latest using the OS default Python 3.6.15 we get:

lbuildvm:/opt/rockstor # curl -sSL https://install.python-poetry.org | python3 -
Retrieving Poetry metadata

# Welcome to Poetry!

This will download and install the latest version of Poetry,
a dependency and package manager for Python.

It will add the `poetry` command to Poetry's bin directory, located at:

/root/.local/bin

You can uninstall at any time by executing this script with the --uninstall option,
and these changes will be reverted.

Installing Poetry (1.7.1): An error occurred. Removing partial environment.
Poetry installation failed.
See /opt/rockstor/poetry-installer-error-dd04ctzv.log for error logs.

where:

ERROR: Could not find a version that satisfies the requirement poetry==1.7.1 (from versions: 0.1.0, 0.2.0, 0.3.0, 0.4.0, 0.4.0.post1, 0.4.1, 0.4.2, 0.5.0b1, 0.5.0b2, 0.5.0, 0.6.0, 0.6.1, 0.6.2, 0.6.3b1, 0.6.3b2, 0.6.3b3, 0.6.3b4, 0.6.3b5, 0.6.3b6, 0.6.3b7, 0.6.3, 0.6.4b1, 0.6.4, 0.6.5, 0.7.0b1, 0.7.0b2, 0.7.0b3, 0.7.0b4, 0.7.0, 0.7.1, 0.8.0a0, 0.8.0a1, 0.8.0a2, 0.8.0a3, 0.8.0a4, 0.8.0, 0.8.1a0, 0.8.1, 0.8.2, 0.8.3, 0.8.4, 0.8.5a0, 0.8.5, 0.8.6, 0.9.0a0, 0.9.0a1, 0.9.0a2, 0.9.0a3, 0.9.0, 0.9.1, 0.10.0a0, 0.10.0a1, 0.10.0a2, 0.10.0a3, 0.10.0, 0.10.1, 0.10.2, 0.10.3, 0.11.0a0, 0.11.0a1, 0.11.0a2, 0.11.0a3, 0.11.0a4, 0.11.0, 0.11.1, 0.11.2, 0.11.3, 0.11.4, 0.11.5, 0.12.0a0, 0.12.0a1, 0.12.0a2, 0.12.0a3, 0.12.0a4, 0.12.0a5, 0.12.0, 0.12.1, 0.12.2, 0.12.3, 0.12.4, 0.12.5, 0.12.6, 0.12.7, 0.12.8, 0.12.9, 0.12.10, 0.12.11, 0.12.12, 0.12.13, 0.12.14, 0.12.15, 0.12.16, 0.12.17, 1.0.0a0, 1.0.0a1, 1.0.0a2, 1.0.0a3, 1.0.0a4, 1.0.0a5, 1.0.0b1, 1.0.0b2, 1.0.0b3, 1.0.0b4, 1.0.0b5, 1.0.0b6, 1.0.0b7, 1.0.0b8, 1.0.0b9, 1.0.0, 1.0.1, 1.0.2, 1.0.3, 1.0.4, 1.0.5, 1.0.6, 1.0.7, 1.0.8, 1.0.9, 1.0.10, 1.1.0a1, 1.1.0a2, 1.1.0a3, 1.1.0b1, 1.1.0b2, 1.1.0b3, 1.1.0b4, 1.1.0rc1, 1.1.0, 1.1.1, 1.1.2, 1.1.3, 1.1.4, 1.1.5, 1.1.6, 1.1.7, 1.1.8, 1.1.9, 1.1.10, 1.1.11, 1.1.12, 1.1.13, 1.1.14, 1.1.15, 1.2.0a1, 1.2.0a2)
ERROR: No matching distribution found for poetry==1.7.1

As latest Poetry requires at least Py3.8, we have Py3.6 (OS default) and Py3.10 from prior install, and trying to use Py3.11 for both Poetry and rockstor-core.

@phillxnet
Copy link
Member Author

phillxnet commented Nov 22, 2023

The above failure re moving to Py3.11 along with Poetry looks to be realated to our likely Py3.6 compatible venv:

failed to query /usr/bin/python3 with code 1 err: ' File "/root/.local/share/pypoetry/venv/lib64/python3.11/site-packages/virtualenv/discovery/py_info.py", line 7\n from future import annotations\n ^\nSyntaxError: future feature annotations is not defined\n'

I.e.:

lbuildvm:~ # zypper se -s virtualenv
Loading repository data...
Reading installed packages...

S | Name                      | Type       | Version              | Arch   | Repository
--+---------------------------+------------+----------------------+--------+-------------------------------------------------------------
  | python-virtualenv         | srcpackage | 20.22.0-150400.9.3.9 | noarch | Update repository with updates from SUSE Linux Enterprise 15
  | python3-pytest-virtualenv | package    | 1.7.0-150400.5.68    | noarch | Update repository with updates from SUSE Linux Enterprise 15
  | python3-pytest-virtualenv | package    | 1.7.0-150400.1.5     | noarch | Main Repository
  | python3-pytest-virtualenv | srcpackage | 1.7.0-150400.5.68    | noarch | Update repository with updates from SUSE Linux Enterprise 15
  | python3-virtualenv        | package    | 16.1.0-1.13          | noarch | Main Repository
  | python3-virtualenv-clone  | package    | 0.5.4-bp155.2.13     | noarch | Main Repository
  | python3-virtualenvwrapper | package    | 4.8.4-bp155.2.11     | noarch | Main Repository
  | python311-virtualenv      | package    | 20.22.0-150400.9.3.9 | noarch | Update repository with updates from SUSE Linux Enterprise 15

Experimenting with:

lbuildvm:~ # zypper in --no-recommends python311-virtualenv
Loading repository data...
Reading installed packages...
Resolving package dependencies...

The following 6 NEW packages are going to be installed:
  python311-backports.entry_points_selectable python311-distlib python311-filelock python311-platformdirs python311-setuptools python311-virtualenv

6 new packages to install.
Overall download size: 4.9 MiB. Already cached: 0 B. After the operation, additional 12.1 MiB will be used.
Continue? [y/n/v/...? shows all options] (y):

The OS python311-virtualenv is a red-herring as Poetry builds it's own venv containing, with Python3.11 as installer:

ls -lad /root/.local/share/pypoetry/venv/lib64/python3.11/site-packages/virtual*
drwxr-xr-x 1 root root 218 Nov 22 18:06 /root/.local/share/pypoetry/venv/lib64/python3.11/site-packages/virtualenv
drwxr-xr-x 1 root root 104 Nov 22 18:06 /root/.local/share/pypoetry/venv/lib64/python3.11/site-packages/virtualenv-20.24.7.dist-info

@phillxnet
Copy link
Member Author

Installing the last major Poetry version update of 1.6.1 under Py3.11:

curl -sSL https://install.python-poetry.org | POETRY_VERSION=1.6.1 python3.11 -

with our pyproject.toml set also to py3.11 and we get the same issue:

lbuildvm:/opt/rockstor # poetry install
Creating virtualenv rockstor in /opt/rockstor/.venv

failed to query /usr/bin/python3 with code 1 err: '  File "/root/.local/share/pypoetry/venv/lib64/python3.11/site-packages/virtualenv/discovery/py_info.py", line 7\n    from __future__ import annotations\n    ^\nSyntaxError: future feature annotations is not defined\n'

with:

lbuildvm:/opt/rockstor # ls -lad /root/.local/share/pypoetry/venv/lib64/python3.11/site-packages/virtual*
drwxr-xr-x 1 root root 218 Nov 22 18:34 /root/.local/share/pypoetry/venv/lib64/python3.11/site-packages/virtualenv
drwxr-xr-x 1 root root 104 Nov 22 18:34 /root/.local/share/pypoetry/venv/lib64/python3.11/site-packages/virtualenv-20.24.7.dist-info

@phillxnet
Copy link
Member Author

phillxnet commented Nov 22, 2023

Installing under our current Py3.9 via:

curl -sSL https://install.python-poetry.org | POETRY_VERSION=1.7.1 python3.9 -

and we have the same virtualenv

lbuildvm:/opt/rockstor # ls -lad /root/.local/share/pypoetry/venv/lib64/python3.9/site-packages/virtual*
drwxr-xr-x 1 root root 218 Nov 22 19:13 /root/.local/share/pypoetry/venv/lib64/python3.9/site-packages/virtualenv
drwxr-xr-x 1 root root 104 Nov 22 19:13 /root/.local/share/pypoetry/venv/lib64/python3.9/site-packages/virtualenv-20.24.7.dist-info

But we now have functioning poetry install when pyproject.toml is moved to Py3.11:

lbuildvm:/opt/rockstor # poetry install
The currently activated Python version 3.9.18 is not supported by the project (~3.11).
Trying to find and use a compatible version. 
Using python3.11 (3.11.5)
Creating virtualenv rockstor in /opt/rockstor/.venv
Installing dependencies from lock file
Warning: poetry.lock is not consistent with pyproject.toml. You may be getting improper dependencies. Run `poetry lock [--no-update]` to fix it.

Package operations: 41 installs, 0 updates, 0 removals
...
Installing the current project: rockstor (5.0.5)

and:

lbuildvm:/opt/rockstor # poetry env info

Virtualenv
Python:         3.11.5
Implementation: CPython
Path:           /opt/rockstor/.venv
Executable:     /opt/rockstor/.venv/bin/python
Valid:          True

System
Platform:   linux
OS:         posix
Python:     3.11.5
Path:       /usr
Executable: /usr/bin/python3.11

But not ideal to have to hand-on to Py3.9 just for Poetry official installer.

@FroggyFlox has had more promising success with using alternative Poetry install methods: more to follow.

@phillxnet
Copy link
Member Author

Given the difficulties above and @FroggyFlox more promising approach re pip installed Poetry (under Py3.11 venv) I'm now looking to use python3.11 pipx to install Poetry (globally) via the distro provided python311-pipx as we are then more in line with the recommendations re:
https://peps.python.org/pep-0668/#guide-users-towards-virtual-environments

And Poetry's own: https://python-poetry.org/docs/#installing-with-pipx Instructions
and
the following note here: https://python-poetry.org/docs/#ci-recommendations

The official installer script (install.python-poetry.org) offers a streamlined and simplified installation of Poetry, sufficient for developer use or for simple pipelines. However, in a CI environment the other two supported installation methods (pipx and manual) should be seriously considered.

@phillxnet
Copy link
Member Author

OS native python 3.11 pipx package Leap 15.5:

lbuildvm:~ # zypper in --no-recommends python311-pipx
Retrieving repository 'Update repository with updates from SUSE Linux Enterprise 15' metadata ...............................................................................[done]
Building repository 'Update repository with updates from SUSE Linux Enterprise 15' cache ....................................................................................[done]
Loading repository data...
Reading installed packages...
Resolving package dependencies...

The following 5 NEW packages are going to be installed:
  python311-argcomplete python311-click python311-packaging python311-pipx python311-userpath

5 new packages to install.
Overall download size: 555.0 KiB. Already cached: 0 B. After the operation, additional 1.7 MiB will be used.
Continue? [y/n/v/...? shows all options] (y): 

@phillxnet
Copy link
Member Author

phillxnet commented Nov 23, 2023

PIPX, os package supplied, is managed by alternatives:

lbuildvm:~ # which pipx
/usr/bin/pipx
lbuildvm:~ # ls -la /usr/bin/pipx
lrwxrwxrwx 1 root root 22 Oct 25 10:26 /usr/bin/pipx -> /etc/alternatives/pipx
...
lbuildvm:~ # alternatives --display pipx
pipx - auto mode
  link best version is /usr/bin/pipx-3.11
  link currently points to /usr/bin/pipx-3.11
  link pipx is /usr/bin/pipx
/usr/bin/pipx-3.11 - priority 311

And we can then install via:

export PIPX_HOME=/opt/pipx
export PIPX_BIN_DIR=/usr/local/bin
python3.11 -m pipx install poetry==1.7.1
  installed package poetry 1.7.1, installed using Python 3.11.5
  These apps are now globally available
    - poetry
done! ✨ 🌟 ✨

In the above under-test scenario we are looking to avoid the home defaults with a view to issue:
"Adopt dedicated 'rockstor' user for systemd services" #2700
in the interests of disabling /home access requirements entirely via systemd.

The above install results in:

which poetry
/usr/local/bin/poetry

Where this script entry point for Poetry is as follows:

cat /usr/local/bin/poetry
#!/opt/pipx/venvs/poetry/bin/python
# -*- coding: utf-8 -*-
import re
import sys
from poetry.console.application import main
if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(main())

And the python binary in that case is:

lbuildvm:~ # ls -la /opt/pipx/venvs/poetry/bin/python
lrwxrwxrwx 1 root root 10 Nov 23 15:21 /opt/pipx/venvs/poetry/bin/python -> python3.11

@phillxnet
Copy link
Member Author

We have the following incidental update:
as a result of the associated Py3.9 to Py3.11 change in pyproject.toml to normalise on Py3.11 during this Poetry upadate focused issue:

Updating setuptools (68.2.2 -> 69.0.2)

phillxnet added a commit to phillxnet/rockstor-core that referenced this issue Nov 23, 2023
Uninstall prior Poetry 1.1.15, if found, using official
installer script, and install 1.7.1 using Python 3.11 and
OS pipx package: `build.sh`.
## Includes:
- New Poetry install location:
 `/root/.local/bin` to `/usr/local/bin`
- Update rockstor.service & rockstor-pre.service Poetry path.
- Python 3.9 to Python 3.11 in pyproject.toml.
- Refreshed poetry.lock created using Poetry 1.7.1.
- Incidental update of setuptools (68.2.2 -> 69.0.2).
- Incidental clarification re developer instructions in build.sh.
- .gitignore addition re poetry-installer-error logs.
@phillxnet phillxnet changed the title Update Poetry build system Update Poetry build system & normalise on Python 3.11 Nov 24, 2023
phillxnet added a commit that referenced this issue Nov 24, 2023
Update Poetry build system & normalise on Python 3.11 #2703 #2754 #2693
@phillxnet
Copy link
Member Author

Closing as:
Fixed by #2755

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant