Skip to contentSkip to conversation

Switch to Python 3 by default

RFC In review Petr Lautrbach 3 participants 8 messages Feb 20, 2019 – Feb 26, 2019 SELinux security module

lore
Share & tools
lore
#0 lore raw

Default instalation seems to be inconsistent a little when PYTHON variable is not used during build. Python 2 versions of selinux and semanage modules are built and installed, but /usr/sbin/semanage and other tools are already changed to use /usr/bin/python3.

I'd like to propose to change to Python 3 by default and leave it on a maintainer to use PYTHON=/usr/bin/python2 when they doesn't have Python 3 available. They would also need to change shebangs of some tools, but this is the same situation as used to be when default was Python 2 and maintainers needed to change shebangs to /usr/bin/python3.

Do you have any objections?

#1 lore raw

PATCH 1/3 Always use /usr/bin/python3 in Python scripts

---
 dbus/selinux_server.py                   | 2 +-
 libsemanage/utils/semanage_migrate_store | 2 +-
 mcstrans/share/util/mlscolor-test        | 2 +-
 mcstrans/share/util/mlstrans-test        | 2 +-
 python/semanage/semanage                 | 2 +-
 sandbox/start                            | 2 +-
 6 files changed, 6 insertions(+), 6 deletions(-)
dbus/selinux_server.py +1 -1
index 6e380e58..98ab53dd 100644
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/python3
 
 import dbus
 import dbus.service
libsemanage/utils/semanage_migrate_store +1 -1
index 018b1a3e..c6caf3bf 100755
@@ -1,4 +1,4 @@
-#!/usr/bin/python -E
+#!/usr/bin/python3 -E
 
 
 from __future__ import print_function
mcstrans/share/util/mlscolor-test +1 -1
index 03fc4be4..240e996d 100644
@@ -1,4 +1,4 @@
-#!/usr/bin/python -E
+#!/usr/bin/python3 -E
 import sys
 import selinux
 
mcstrans/share/util/mlstrans-test +1 -1
index c026d00e..085fa82d 100644
@@ -1,4 +1,4 @@
-#!/usr/bin/python -E
+#!/usr/bin/python3 -E
 import sys
 import selinux
 
python/semanage/semanage +1 -1
index d6d68248..144cc000 100644
@@ -1,4 +1,4 @@
-#! /usr/bin/python3 -Es
+#!/usr/bin/python3 -Es
 # Copyright (C) 2012-2013 Red Hat
 # AUTHOR: Miroslav Grepl <[email protected]>
 # AUTHOR: David Quigley <[email protected]>
sandbox/start +1 -1
index 7f83532f..4ed3cb5c 100644
@@ -1,4 +1,4 @@
-#! /usr/bin/python -Es
+#!/usr/bin/python3 -Es
 try:
     from subprocess import getstatusoutput
 except ImportError:
Signature · 1 line
2.20.1
Acked-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] Always use /usr/bin/python3 in Python scripts

Quoted 2 lines · Petr Lautrbach

For the 3 patches:

Quoted 72 lines
---
 dbus/selinux_server.py                   | 2 +-
 libsemanage/utils/semanage_migrate_store | 2 +-
 mcstrans/share/util/mlscolor-test        | 2 +-
 mcstrans/share/util/mlstrans-test        | 2 +-
 python/semanage/semanage                 | 2 +-
 sandbox/start                            | 2 +-
 6 files changed, 6 insertions(+), 6 deletions(-)
dbus/selinux_server.py +1 -1
index 6e380e58..98ab53dd 100644
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/python3
 
 import dbus
 import dbus.service
libsemanage/utils/semanage_migrate_store +1 -1
index 018b1a3e..c6caf3bf 100755
@@ -1,4 +1,4 @@
-#!/usr/bin/python -E
+#!/usr/bin/python3 -E
 
 
 from __future__ import print_function
mcstrans/share/util/mlscolor-test +1 -1
index 03fc4be4..240e996d 100644
@@ -1,4 +1,4 @@
-#!/usr/bin/python -E
+#!/usr/bin/python3 -E
 import sys
 import selinux
 
mcstrans/share/util/mlstrans-test +1 -1
index c026d00e..085fa82d 100644
@@ -1,4 +1,4 @@
-#!/usr/bin/python -E
+#!/usr/bin/python3 -E
 import sys
 import selinux
 
python/semanage/semanage +1 -1
index d6d68248..144cc000 100644
@@ -1,4 +1,4 @@
-#! /usr/bin/python3 -Es
+#!/usr/bin/python3 -Es
 # Copyright (C) 2012-2013 Red Hat
 # AUTHOR: Miroslav Grepl <[email protected]>
 # AUTHOR: David Quigley <[email protected]>
sandbox/start +1 -2
index 7f83532f..4ed3cb5c 100644
@@ -1,4 +1,4 @@
-#! /usr/bin/python -Es
+#!/usr/bin/python3 -Es
 try:
     from subprocess import getstatusoutput
 except ImportError:
--

2.20.1

#3 lore raw

Re: [PATCH 1/3] Always use /usr/bin/python3 in Python scripts

Quoted 6 lines · Nicolas Iooss
Quoted 2 lines · Petr Lautrbach

For the 3 patches:

Merged.

Quoted 72 lines
Quoted 72 lines
---
 dbus/selinux_server.py                   | 2 +-
 libsemanage/utils/semanage_migrate_store | 2 +-
 mcstrans/share/util/mlscolor-test        | 2 +-
 mcstrans/share/util/mlstrans-test        | 2 +-
 python/semanage/semanage                 | 2 +-
 sandbox/start                            | 2 +-
 6 files changed, 6 insertions(+), 6 deletions(-)
dbus/selinux_server.py +1 -1
index 6e380e58..98ab53dd 100644
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/python3
 
 import dbus
 import dbus.service
libsemanage/utils/semanage_migrate_store +1 -1
index 018b1a3e..c6caf3bf 100755
@@ -1,4 +1,4 @@
-#!/usr/bin/python -E
+#!/usr/bin/python3 -E
 
 
 from __future__ import print_function
mcstrans/share/util/mlscolor-test +1 -1
index 03fc4be4..240e996d 100644
@@ -1,4 +1,4 @@
-#!/usr/bin/python -E
+#!/usr/bin/python3 -E
 import sys
 import selinux
 
mcstrans/share/util/mlstrans-test +1 -1
index c026d00e..085fa82d 100644
@@ -1,4 +1,4 @@
-#!/usr/bin/python -E
+#!/usr/bin/python3 -E
 import sys
 import selinux
 
python/semanage/semanage +1 -1
index d6d68248..144cc000 100644
@@ -1,4 +1,4 @@
-#! /usr/bin/python3 -Es
+#!/usr/bin/python3 -Es
 # Copyright (C) 2012-2013 Red Hat
 # AUTHOR: Miroslav Grepl <[email protected]>
 # AUTHOR: David Quigley <[email protected]>
sandbox/start +1 -2
index 7f83532f..4ed3cb5c 100644
@@ -1,4 +1,4 @@
-#! /usr/bin/python -Es
+#!/usr/bin/python3 -Es
 try:
     from subprocess import getstatusoutput
 except ImportError:
--

2.20.1

#4 lore raw

PATCH 2/3 Switch to python3 by default

In reply to Petr Lautrbach

- Python 2.7 is planned to be the last of the 2.x releases
- It's generally advised to use Python 3
- Majority of python/ scripts are already switched python3
- Users with python 2 only can still use:

$ make PYTHON=/usr/bin/python ....
---
 libselinux/src/Makefile               | 2 +-
 libsemanage/src/Makefile              | 2 +-
 python/audit2allow/Makefile           | 2 +-
 python/semanage/Makefile              | 2 +-
 python/sepolgen/src/sepolgen/Makefile | 2 +-
 python/sepolgen/tests/Makefile        | 2 +-
 python/sepolicy/Makefile              | 2 +-
 sandbox/Makefile                      | 2 +-
 scripts/env_use_destdir               | 2 +-
 scripts/run-scan-build                | 2 +-
 10 files changed, 10 insertions(+), 10 deletions(-)
libselinux/src/Makefile +1 -1
index 92e30738..e9ed0383 100644
@@ -1,7 +1,7 @@
 # Support building the Python bindings multiple times, against various Python
 # runtimes (e.g. Python 2 vs Python 3) by optionally prefixing the build
 # targets with "PYPREFIX":
-PYTHON ?= python
+PYTHON ?= python3
 PYPREFIX ?= $(shell $(PYTHON) -c 'import sys;print("python-%d.%d" % sys.version_info[:2])')
 RUBY ?= ruby
 RUBYPREFIX ?= $(notdir $(RUBY))
libsemanage/src/Makefile +1 -1
index dea751e5..e029f098 100644
@@ -1,7 +1,7 @@
 # Support building the Python bindings multiple times, against various Python
 # runtimes (e.g. Python 2 vs Python 3) by optionally prefixing the build
 # targets with "PYPREFIX":
-PYTHON ?= python
+PYTHON ?= python3
 PYPREFIX ?= $(shell $(PYTHON) -c 'import sys;print("python-%d.%d" % sys.version_info[:2])')
 RUBY ?= ruby
 RUBYPREFIX ?= $(notdir $(RUBY))
python/audit2allow/Makefile +1 -1
index 18d740d3..15db5490 100644
@@ -1,4 +1,4 @@
-PYTHON ?= python
+PYTHON ?= python3
 SECILC ?= secilc
 
 # Installation directories.
python/semanage/Makefile +1 -1
index 37065268..024e9640 100644
@@ -1,4 +1,4 @@
-PYTHON ?= python
+PYTHON ?= python3
 
 # Installation directories.
 LINGUAS ?= ru
python/sepolgen/src/sepolgen/Makefile +1 -1
index c75809ad..cac8def7 100644
@@ -1,5 +1,5 @@
 PREFIX ?= /usr
-PYTHON ?= python
+PYTHON ?= python3
 PYTHONLIBDIR ?= $(shell $(PYTHON) -c "from distutils.sysconfig import *; print(get_python_lib(prefix='$(PREFIX)'))")
 PACKAGEDIR ?= /$(PYTHONLIBDIR)/sepolgen
 
python/sepolgen/tests/Makefile +1 -1
index e17eef22..83d072f4 100644
@@ -1,4 +1,4 @@
-PYTHON ?= python
+PYTHON ?= python3
 
 clean:
 	rm -f *~ *.pyc
python/sepolicy/Makefile +1 -1
index 7ed039bc..69f29fa9 100644
@@ -1,4 +1,4 @@
-PYTHON ?= python
+PYTHON ?= python3
 
 # Installation directories.
 LINGUAS ?= ru
sandbox/Makefile +1 -1
index 862bffbe..9da5e58d 100644
@@ -1,4 +1,4 @@
-PYTHON ?= python
+PYTHON ?= python3
 
 # Installation directories.
 LINGUAS ?= ru
scripts/env_use_destdir +1 -1
index 4fbfb8de..251987c2 100755
@@ -25,7 +25,7 @@ export LD_LIBRARY_PATH="$DESTDIR/usr/lib:$DESTDIR/lib"
 export PATH="$DESTDIR/usr/sbin:$DESTDIR/usr/bin:$DESTDIR/sbin:$DESTDIR/bin:$PATH"
 
 # shellcheck disable=SC2155
-export PYTHONPATH="$DESTDIR$(${PYTHON:-python} -c "from distutils.sysconfig import *;print(get_python_lib(prefix='/usr'))")"
+export PYTHONPATH="$DESTDIR$(${PYTHON:-python3} -c "from distutils.sysconfig import *;print(get_python_lib(prefix='/usr'))")"
 
 # shellcheck disable=SC2155
 export RUBYLIB="$DESTDIR/$(${RUBY:-ruby} -e 'puts RbConfig::CONFIG["vendorlibdir"]'):$DESTDIR/$(${RUBY:-ruby} -e 'puts RbConfig::CONFIG["vendorarchdir"]')"
scripts/run-scan-build +1 -1
index 8b24a4d0..88fe551c 100755
@@ -17,7 +17,7 @@ fi
 # Make sure to use the newly-installed libraries when running tests
 export LD_LIBRARY_PATH="$DESTDIR/usr/lib:$DESTDIR/lib"
 export PATH="$DESTDIR/usr/sbin:$DESTDIR/usr/bin:$DESTDIR/sbin:$DESTDIR/bin:$PATH"
-export PYTHONPATH="$DESTDIR$(${PYTHON:-python} -c "from distutils.sysconfig import *;print(get_python_lib(prefix='/usr'))")"
+export PYTHONPATH="$DESTDIR$(${PYTHON:-python3} -c "from distutils.sysconfig import *;print(get_python_lib(prefix='/usr'))")"
 export RUBYLIB="$DESTDIR/$(${RUBY:-ruby} -e 'puts RbConfig::CONFIG["vendorlibdir"]'):$DESTDIR/$(${RUBY:-ruby} -e 'puts RbConfig::CONFIG["vendorarchdir"]')"
 
 # Build and analyze
Signature · 1 line
2.20.1
#5 lore raw

PATCH 3/3 README: Update Fedora python 3 dependencies

In reply to Petr Lautrbach
---
 README | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
README +1 -1
index 1c009b01..e4423ca2 100644
@@ -3,7 +3,7 @@ Subscribe by sending "subscribe selinux" in the body of an email
 to [email protected].
 
 Build dependencies on Fedora:
-yum install audit-libs-devel bison bzip2-devel dbus-devel dbus-glib-devel flex flex-devel flex-static glib2-devel libcap-devel libcap-ng-devel pam-devel pcre-devel python-devel setools-devel swig xmlto redhat-rpm-config
+yum install audit-libs-devel bison bzip2-devel dbus-devel dbus-glib-devel flex flex-devel flex-static glib2-devel libcap-devel libcap-ng-devel pam-devel pcre-devel python3-devel python3-setools swig xmlto redhat-rpm-config
 
 To build and install everything under a private directory, run:
 make DESTDIR=~/obj install install-pywrap
Signature · 1 line
2.20.1
#6 lore raw
In reply to Petr Lautrbach
Quoted 7 lines · Petr Lautrbach

Default instalation seems to be inconsistent a little when PYTHON variable is not used during build. Python 2 versions of selinux and semanage modules are built and installed, but /usr/sbin/semanage and other tools are already changed to use /usr/bin/python3.

Quoted 7 lines

I'd like to propose to change to Python 3 by default and leave it on a maintainer to use PYTHON=/usr/bin/python2 when they doesn't have Python 3 available. They would also need to change shebangs of some tools, but this is the same situation as used to be when default was Python 2 and maintainers needed to change shebangs to /usr/bin/python3.

Do you have any objections?

Sounds good to me.

#7 lore raw
Quoted 15 lines · Stephen Smalley
Quoted 13 lines · Petr Lautrbach

Default instalation seems to be inconsistent a little when PYTHON variable is not used during build. Python 2 versions of selinux and semanage modules are built and installed, but /usr/sbin/semanage and other tools are already changed to use /usr/bin/python3.

I'd like to propose to change to Python 3 by default and leave it on a maintainer to use PYTHON=/usr/bin/python2 when they doesn't have Python 3 available. They would also need to change shebangs of some tools, but this is the same situation as used to be when default was Python 2 and maintainers needed to change shebangs to /usr/bin/python3.

Quoted 3 lines
Quoted 1 line

Do you have any objections?

Sounds good to me.

I agree.

Cheers,
Nicolas