#21 Have a dynamic Python version by default if possible
Merged 3 years ago by churchyard. Opened 4 years ago by churchyard.
tests/ churchyard/python default_version  into  master

file modified
+5 -2
@@ -1,7 +1,10 @@ 

  #!/bin/sh -eux

  

- # set python version

- VERSION=${VERSION:-3.7}

+ # set default version to %{python3_version} if available

+ VERSION=${VERSION:-$(rpm --eval '%{?python3_version}')} || true

+ # ...or 3.8 if that macro is not available or rpm fails for any reason

+ VERSION=${VERSION:-3.8}

+ 

  PYTHON=${PYTHON:-python$VERSION}

  

  # what to skip

file modified
+5 -2
@@ -1,7 +1,10 @@ 

  #!/bin/sh -eux

  

- # set python version

- VERSION=${VERSION:-3.7}

+ # set default version to %{python3_version} if available

+ VERSION=${VERSION:-$(rpm --eval '%{?python3_version}')} || true

+ # ...or 3.8 if that macro is not available or rpm fails for any reason

+ VERSION=${VERSION:-3.8}

+ 

  PYTHON=${PYTHON:-python$VERSION}

  METHOD=${METHOD:-venv}

  TOX=${TOX:-true}

file modified
+4
@@ -13,6 +13,9 @@ 

      tags:

      - classic

      tests:

+     - smoke_default:

+         dir: smoke

+         run: ./venv.sh

      - smoke27:

          dir: smoke

          run: VERSION=2.7 METHOD=virtualenv ./venv.sh
@@ -65,3 +68,4 @@ 

      - python3-tkinter

      - python3-test

      - python3-debug

+     - python3-rpm-macros

(I'm not touching leaktests, because I plan to remove that soon anyway.)

Do I understand correctly that the echo at the end is there for a case when rpm command fails? But then we have to define the default value twice. What about this:

# set python version to %{python3_version} if available
VERSION=${VERSION:-$(rpm --eval '%{?python3_version}')}
# or 3.8 if that macro is not available or rpm fails for any reason
VERSION=${VERSION:-3.8}

The code is untested but seems to be more readable for me not combining three conditions on one line of code. WDYT?

rebased onto a72a17251cbacdc44e328ad90f321de12a67fc68

3 years ago

amended. your code seem to work fine, but the first assignment would exit the script if rpm is missing, so I've added || true

+1, let's see what CI thinks

The Ci thinks this:

++ rpm --eval '%{?python3_version}'
+ VERSION=
+ VERSION=3.8

Now let me install rpm-build.

rpm-build is overkill, python3-rpm-macros will do:

[root@19ca36ea3e81 /]# rpm --eval '%{?python3_version}'

[root@19ca36ea3e81 /]# dnf install python3-devel
...
Installed:
  python3-devel-3.8.2-2.fc33.x86_64                                                                                                                                                                                              

Complete!
[root@19ca36ea3e81 /]# rpm --eval '%{?python3_version}'

[root@19ca36ea3e81 /]# dnf install python3-rpm-macros
...

Installed:
  dwz-0.13-2.fc32.x86_64              efi-srpm-macros-4-4.fc32.noarch      file-5.38-3.fc33.x86_64              findutils-1:4.7.0-4.fc33.x86_64      fonts-srpm-macros-2.0.5-1.fc33.noarch fpc-srpm-macros-1.3-1.fc32.noarch   
  ghc-srpm-macros-1.5.0-2.fc32.noarch gnat-srpm-macros-4-11.fc32.noarch    go-srpm-macros-3.0.8-5.fc32.noarch   nim-srpm-macros-3-2.fc32.noarch      ocaml-srpm-macros-6-2.fc32.noarch     openblas-srpm-macros-2-7.fc32.noarch
  perl-srpm-macros-1-34.fc32.noarch   python-srpm-macros-3.8-2.fc33.noarch python3-rpm-macros-3.8-2.fc33.noarch qt5-srpm-macros-5.14.2-3.fc33.noarch redhat-rpm-config-154-1.fc33.noarch   rust-srpm-macros-13-2.fc33.noarch   
  unzip-6.0-47.fc32.x86_64            zip-3.0-26.fc32.x86_64              

Complete!
[root@19ca36ea3e81 /]# rpm --eval '%{?python3_version}'
3.8

rebased onto 6a9ffe6

3 years ago
++ rpm --eval '%{?python3_version}'
+ VERSION=3.8
+ VERSION=3.8

Good!

Pull-Request has been merged by churchyard

3 years ago