Skip to content
This repository was archived by the owner on May 8, 2025. It is now read-only.

Commit f238dc2

Browse files
authored
Merge pull request #217 from PrieJos/feature-python-build
Enhance control over python build during pyenv install execution
2 parents 03f6451 + 7b4ce30 commit f238dc2

File tree

4 files changed

+98
-5
lines changed

4 files changed

+98
-5
lines changed

README.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,28 @@ Here is the list of all variables and their default values:
3434
- `pyenv_update_git_install: true` (get latest pyenv from git)
3535
- `pyenv_enable_autocompletion: false`
3636
- `pyenv_enable_virtualenvs: true`
37-
- `pyenv_shellrc_file "{% if pyenv_env == 'user' %}~/.bashrc{% else %}/etc/profile.d/pyenv.sh{% endif %}"`
37+
- `pyenv_shellrc_file: "{% if pyenv_env == 'user' %}~/.bashrc{% else %}/etc/profile.d/pyenv.sh{% endif %}"`
38+
- `pyenv_tmpdir: (must be explicitly defined)` - env variable `TMPDIR` used by [python-build][python-build] as described in [Special Environment Variables][special-env-vars].
39+
- `pyenv_python_build_build_path: (must be explicitly defined)` - env variable `PYTHON_BUILD_BUILD_PATH` used by [python-build][python-build] as described in [Special Environment Variables][special-env-vars].
40+
- `pyenv_python_build_cache_path: (must be explicitly defined)` - env variable `PYTHON_BUILD_CACHE_PATH` used by [python-build][python-build] as described in [Special Environment Variables][special-env-vars].
41+
- `pyenv_python_build_mirror_url: (must be explicitly defined)` - env variable `PYTHON_BUILD_MIRROR_URL` used by [python-build][python-build] as described in [Special Environment Variables][special-env-vars].
42+
- `pyenv_python_build_mirror_url_skip_checksum: (must be explicitly defined)` - env variable `PYTHON_BUILD_MIRROR_URL_SKIP_CHECKSUM` used by [python-build][python-build] as described in [Special Environment Variables][special-env-vars].
43+
- `pyenv_python_build_skip_mirror: (must be explicitly defined)` - env variable `PYTHON_BUILD_SKIP_MIRROR` used by [python-build][python-build] as described in [Special Environment Variables][special-env-vars].
44+
- `pyenv_python_build_skip_homebrew: (must be explicitly defined)` - env variable `PYTHON_BUILD_SKIP_HOMEBREW` used by [python-build][python-build] as described in [Special Environment Variables][special-env-vars].
45+
- `pyenv_python_build_root: (must be explicitly defined)` - env variable `PYTHON_BUILD_ROOT` used by [python-build][python-build] as described in [Special Environment Variables][special-env-vars].
46+
- `pyenv_python_build_definitions: (must be explicitly defined)` - env variable `PYTHON_BUILD_DEFINITIONS` used by [python-build][python-build] as described in [Special Environment Variables][special-env-vars].
47+
- `pyenv_python_configure_opts: (must be explicitly defined)` - env variable `PYTHON_CONFIGURE_OPTS` used by [python-build][python-build] as described in [Special Environment Variables][special-env-vars].
48+
- `pyenv_python_cflags: (must be explicitly defined)` - env variable `PYTHON_CFLAGS` used by [python-build][python-build] as described in [Special Environment Variables][special-env-vars].
49+
- `pyenv_python_make_opts: (must be explicitly defined)` - env variable `PYTHON_MAKE_OPTS` used by [python-build][python-build] as described in [Special Environment Variables][special-env-vars].
50+
- `pyenv_python_make_install_opts: (must be explicitly defined)` - env variable `PYTHON_MAKE_INSTALL_OPTS` used by [python-build][python-build] as described in [Special Environment Variables][special-env-vars].
51+
- `pyenv_configure_opts: (must be explicitly defined)` - env variable `CONFIGURE_OPTS` used by [python-build][python-build] as described in [Special Environment Variables][special-env-vars].
52+
- `pyenv_cc: (must be explicitly defined)` - env variable `CC` used by [python-build][python-build] as described in [Special Environment Variables][special-env-vars].
53+
- `pyenv_make: (must be explicitly defined)` - env variable `MAKE` used by [python-build][python-build] as described in [Special Environment Variables][special-env-vars].
54+
- `pyenv_make_opts: (must be explicitly defined)` - env variable `MAKE_OPTS` used by [python-build][python-build] as described in [Special Environment Variables][special-env-vars].
55+
- `pyenv_make_install_opts: (must be explicitly defined)` - env variable `MAKE_INSTALL_OPTS` used by [python-build][python-build] as described in [Special Environment Variables][special-env-vars].
56+
- `pyenv_profile_task: (must be explicitly defined)` - env variable `PROFILE_TASK` to customize the task used for profile guided optimization as described in [building Python for maximum performance][max-performance]. See also [here](https://docs.python.org/3/using/configure.html#cmdoption-enable-optimizations).
57+
- `pyenv_custom_pyenvrc_file: (must be explicitly defined)` - path to a custom `.pyenvrc` shell file that will be sourced from `{{ pyenvrc_path }}/.pyenvrc`. It allows you to freely customize the environment to be used during `pyenv` execution. If defined, this file will be copied as `{{ pyenvrc_path }}/.pyenvrc.custom`.
58+
- `pyenv_install_extra_opts: ("" -no extra options added-)` - check output of `pyenv install --help` for available additional options.
3859

3960
## Dependencies
4061

@@ -66,6 +87,10 @@ None.
6687
py_version: 3.11.4
6788
- venv_name: latest_v310
6889
py_version: 3.10.12
90+
pyenv_make_opts: "-j4"
91+
pyenv_python_configure_opts: "--enable-optimizations --with-lto --with-ensurepip=upgrade"
92+
pyenv_python_cflags: "-march=native -mtune=native"
93+
pyenv_profile_task: "-m test.regrtest --pgo -j0"
6994
```
7095
7196
## License
@@ -81,3 +106,6 @@ _Ansible role Pyenv_ is free and open source software.
81106
[mit]: https://opensource.org/licenses/MIT
82107
[pyenv]: https://github.com/yyuu/pyenv
83108
[staticdev]: https://github.com/staticdev
109+
[python-build]: https://github.com/pyenv/pyenv/tree/master/plugins/python-build "python-build plugin"
110+
[special-env-vars]: https://github.com/pyenv/pyenv/blob/master/plugins/python-build/README.md#special-environment-variables "Special environment variables"
111+
[max-performance]: https://github.com/pyenv/pyenv/blob/master/plugins/python-build/README.md#building-for-maximum-performance "Building for maximum performance"

defaults/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pyenv_init_options: "{% if pyenv_env != 'user' %}--no-rehash{% endif %}"
2525
pyenv_update: false
2626

2727
# additional options for the build process, e.g "--enable-shared"
28+
pyenv_install_extra_opts: ""
2829
pyenv_python_configure_opts: ""
2930
pyenv_uninstall_python_w_wrong_configure_opts: false
3031

tasks/install.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@
2929
owner: "{{ pyenv_owner }}"
3030
mode: "0644"
3131

32+
- name: Install custom .pyenvrc
33+
ansible.builtin.copy:
34+
src: "{{ pyenv_custom_pyenvrc_file }}"
35+
dest: "{{ pyenvrc_path }}/.pyenvrc.custom"
36+
owner: "{{ pyenv_owner }}"
37+
mode: "0644"
38+
when: pyenv_custom_pyenvrc_file is defined
39+
3240
- name: Use legacy variable pyenv_setting_path if available
3341
ansible.builtin.set_fact:
3442
pyenv_shellrc_file: "{{ pyenv_setting_path }}"
@@ -71,9 +79,7 @@
7179
when: pyenv_uninstall_python_w_wrong_configure_opts
7280

7381
- name: "Install Python interpreters {{ pyenv_python_versions }}"
74-
ansible.builtin.shell: ". {{ pyenvrc_path }}/.pyenvrc && pyenv install {{ item }}"
75-
environment:
76-
PYTHON_CONFIGURE_OPTS: "{{ pyenv_python_configure_opts }}"
82+
ansible.builtin.shell: ". {{ pyenvrc_path }}/.pyenvrc && pyenv install {{ pyenv_install_extra_opts }} {{ item }}"
7783
args:
7884
creates: "{{ pyenv_path }}/versions/{{ item }}/bin/python"
7985
with_items: "{{ pyenv_python_versions }}"

templates/.pyenvrc.j2

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,63 @@
22
# -------------------------------------
33
export PYENV_ROOT="{{ pyenv_path }}"
44
export PATH="$PYENV_ROOT/bin:$PATH"
5+
{% if pyenv_tmpdir is defined %}
6+
export TMPDIR="{{ pyenv_tmpdir }}"
7+
{% endif %}
8+
{% if pyenv_python_build_build_path is defined %}
9+
export PYTHON_BUILD_BUILD_PATH="{{ pyenv_python_build_build_path }}"
10+
{% endif %}
11+
{% if pyenv_python_build_cache_path is defined %}
12+
export PYTHON_BUILD_CACHE_PATH="{{ pyenv_python_build_cache_path }}"
13+
{% endif %}
14+
{% if pyenv_python_build_mirror_url is defined %}
15+
export PYTHON_BUILD_MIRROR_URL="{{ pyenv_python_build_mirror_url }}"
16+
{% endif %}
17+
{% if pyenv_python_build_mirror_url_skip_checksum is defined %}
18+
export PYTHON_BUILD_MIRROR_URL_SKIP_CHECKSUM="{{ pyenv_python_build_mirror_url_skip_checksum }}"
19+
{% endif %}
20+
{% if pyenv_python_build_skip_mirror is defined %}
21+
export PYTHON_BUILD_SKIP_MIRROR="{{ pyenv_python_build_skip_mirror }}"
22+
{% endif %}
23+
{% if pyenv_python_build_skip_homebrew is defined %}
24+
export PYTHON_BUILD_SKIP_HOMEBREW="{{ pyenv_python_build_skip_homebrew }}"
25+
{% endif %}
26+
{% if pyenv_python_build_root is defined %}
27+
export PYTHON_BUILD_ROOT="{{ pyenv_python_build_root }}"
28+
{% endif %}
29+
{% if pyenv_python_build_definitions is defined %}
30+
export PYTHON_BUILD_DEFINITIONS="{{ pyenv_python_build_definitions }}"
31+
{% endif %}
32+
{% if pyenv_python_configure_opts is defined %}
33+
export PYTHON_CONFIGURE_OPTS="{{ pyenv_python_configure_opts }}"
34+
{% endif %}
35+
{% if pyenv_python_cflags is defined %}
36+
export PYTHON_CFLAGS="{{ pyenv_python_cflags }}"
37+
{% endif %}
38+
{% if pyenv_python_make_opts is defined %}
39+
export PYTHON_MAKE_OPTS="{{ pyenv_python_make_opts }}"
40+
{% endif %}
41+
{% if pyenv_python_make_install_opts is defined %}
42+
export PYTHON_MAKE_INSTALL_OPTS="{{ pyenv_python_make_install_opts }}"
43+
{% endif %}
44+
{% if pyenv_configure_opts is defined %}
45+
export CONFIGURE_OPTS="{{ pyenv_configure_opts }}"
46+
{% endif %}
47+
{% if pyenv_cc is defined %}
48+
export CC="{{ pyenv_cc }}"
49+
{% endif %}
50+
{% if pyenv_make is defined %}
51+
export MAKE="{{ pyenv_make }}"
52+
{% endif %}
53+
{% if pyenv_make_opts is defined %}
54+
export MAKE_OPTS="{{ pyenv_make_opts }}"
55+
{% endif %}
56+
{% if pyenv_make_install_opts is defined %}
57+
export MAKE_INSTALL_OPTS="{{ pyenv_make_install_opts }}"
58+
{% endif %}
59+
{% if pyenv_profile_task is defined %}
60+
export PROFILE_TASK="{{ pyenv_profile_task }}"
61+
{% endif %}
62+
[ -f "{{ pyenvrc_path }}/.pyenvrc.custom" ] && source "{{ pyenvrc_path }}/.pyenvrc.custom"
563
eval "$(pyenv init --path)"
6-
eval "$(pyenv init - {{ pyenv_init_options}})"
64+
eval "$(pyenv init - {{ pyenv_init_options }})"

0 commit comments

Comments
 (0)