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

Force Python 3.11 in Makefile #132

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Force Python 3.11 in Makefile #132

wants to merge 1 commit into from

Conversation

wesleybl
Copy link
Member

@wesleybl wesleybl commented Nov 7, 2023

On most OS, python3 is not the latest version of Python.

@mister-roboto
Copy link

@wesleybl thanks for creating this Pull Request and helping to improve Plone!

TL;DR: Finish pushing changes, pass all other checks, then paste a comment:

@jenkins-plone-org please run jobs

To ensure that these changes do not break other parts of Plone, the Plone test suite matrix needs to pass, but it takes 30-60 min. Other CI checks are usually much faster and the Plone Jenkins resources are limited, so when done pushing changes and all other checks pass either start all Jenkins PR jobs yourself, or simply add the comment above in this PR to start all the jobs automatically.

Happy hacking!

@stevepiercy
Copy link
Contributor

I don't think this PR will solve the issue, but will make it worse, especially if users do not have python3.11 installed.

Also if a developer does not have python3 as a default by now, they got bigger problems.

@wesleybl
Copy link
Member Author

wesleybl commented Nov 7, 2023

I think the developers have python 3.11 installed, or at least I think they should have lol.

@stevepiercy
Copy link
Contributor

python3 allows a developer to set whatever version of Python 3 a developer has installed. Forcing them to use 3.11 is harmful. I might want to test against 3.8, 3.9, 3.10, or 3.12 even, now that it is released.

@davisagli
Copy link
Sponsor Member

Here's a snippet we use toward the top of Makefiles to give a more helpful error message:

# Python version ok?
PYTHON_VERSION=3.11
PYTHON_VERSION_OK=$(shell python3 -c "import sys; print((int(sys.version_info[0]), int(sys.version_info[1])) == tuple(map(int, '$(PYTHON_VERSION)'.split('.'))))")
ifeq ($(PYTHON_VERSION_OK),False)
$(warning "Need python $(PYTHON_VERSION)")
endif

@davisagli
Copy link
Sponsor Member

On the other hand, I think @stevepiercy is right that it should be possible to use the makefile commands to develop a library like this in any supported Python version. The snippet I gave above is used in the context of a project that requires one specific Python version for all developers.

@wesleybl
Copy link
Member Author

wesleybl commented Nov 7, 2023

@stevepiercy @davisagli what I can do is test if Python 3.11 exists and use python3 if it doesn't.

@wesleybl
Copy link
Member Author

wesleybl commented Nov 7, 2023

What I'm wanting here is to use python 3.11 as the default. It could also receive the Python version as a parameter. This way the developer would be able to use other versions.

@wesleybl
Copy link
Member Author

wesleybl commented Nov 7, 2023

@stevepiercy @davisagli I changed the code to use python3.11 by default but added an option to change that version

An option to change the Pythom version using the PYTHON_VERSION
parameter in the make command was also added.
@stevepiercy
Copy link
Contributor

Your preference might not be mine or other developers'. You can do what you want without modifying the Makefile for everyone. You can use pyenv to install multiple versions of Python, and set python3 to point to python3.11 or whatever default you want.

$ which python3
python3: aliased to /Users/stevepiercy/.pyenv/versions/3.10.12/bin/python3

You can also edit pyvenv.cfg. See https://docs.python.org/3/library/venv.html.

home = /Users/stevepiercy/.pyenv/versions/3.10.12/bin
include-system-site-packages = false
version = 3.10.12

@wesleybl
Copy link
Member Author

wesleybl commented Nov 7, 2023

@stevepiercy I have no experience in changing the python3 command. I'm afraid of breaking something in the distribution. I generally use the version specific commands.

But I understand your point. I want to facilitate a situation that is specific to me.

What I can do is leave python3 as the default and keep the PYTHON_VERSION parameter.

@stevepiercy
Copy link
Contributor

I break the distribution often, especially when I bump my default user Python version. I fix it by removing the virtual environment, then recreating it. I never touch my system Python.

However, I cannot recommend pyenv enough. I no longer fear managing Python versions. It also helps me to completely avoid destroying my system Python.

As you suggest, the default should remain python3, and may be overridden by the developer. I would not object to that implementation as it would not effect current workflows.

@ksuess
Copy link
Member

ksuess commented Nov 8, 2023

@stevepiercy I have no experience in changing the python3 command. I'm afraid of breaking something in the distribution. I generally use the version specific commands.

But I understand your point. I want to facilitate a situation that is specific to me.

What I can do is leave python3 as the default and keep the PYTHON_VERSION parameter.

I break the distribution often, especially when I bump my default user Python version. I fix it by removing the virtual environment, then recreating it. I never touch my system Python.

However, I cannot recommend pyenv enough. I no longer fear managing Python versions. It also helps me to completely avoid destroying my system Python.

As you suggest, the default should remain python3, and may be overridden by the developer. I would not object to that implementation as it would not effect current workflows.

I am with @stevepiercy. pyenv once set up, it is easy to change the default Python version.
If you want your python3 command to be of version 3.11.6, then you do just

$ pyenv install 3.11.6 
$ pyenv global 3.11.6 

Then you can confirm that the version changed by:

$ python3 -V         
Python 3.11.6

pyenv has an authomatic installer: https://github.com/pyenv/pyenv#automatic-installer

No need to change the Makefile.

@stevepiercy
Copy link
Contributor

Another pyenv tip, set a version of Python for a given project:

pyenv local 3.10.12

See also https://github.com/pyenv/pyenv#switch-between-python-versions

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

Successfully merging this pull request may close these issues.

None yet

5 participants