Skip to content

Commit b07ca8f

Browse files
committed
Move Python version check to a common file and add upper bound
1 parent 3ed18e0 commit b07ca8f

File tree

7 files changed

+52
-42
lines changed

7 files changed

+52
-42
lines changed

configure.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919

2020
# This file is the system monitor configuration GUI
2121

22+
from library.pythoncheck import check_python_version
23+
check_python_version()
24+
2225
import glob
2326
import os
2427
import platform
@@ -28,14 +31,6 @@
2831
import requests
2932
import babel
3033

31-
MIN_PYTHON = (3, 9)
32-
if sys.version_info < MIN_PYTHON:
33-
print("[ERROR] Python %s.%s or later is required." % MIN_PYTHON)
34-
try:
35-
sys.exit(0)
36-
except:
37-
os._exit(0)
38-
3934
try:
4035
import tkinter.ttk as ttk
4136
from tkinter import *

library/pythoncheck.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# SPDX-License-Identifier: GPL-3.0-or-later
2+
#
3+
# turing-smart-screen-python - a Python system monitor and library for USB-C displays like Turing Smart Screen or XuanFang
4+
# https://github.com/mathoudebine/turing-smart-screen-python/
5+
#
6+
# Copyright (C) 2021 Matthieu Houdebine (mathoudebine)
7+
#
8+
# This program is free software: you can redistribute it and/or modify
9+
# it under the terms of the GNU General Public License as published by
10+
# the Free Software Foundation, either version 3 of the License, or
11+
# (at your option) any later version.
12+
#
13+
# This program is distributed in the hope that it will be useful,
14+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
# GNU General Public License for more details.
17+
#
18+
# You should have received a copy of the GNU General Public License
19+
# along with this program. If not, see <https://www.gnu.org/licenses/>.
20+
21+
# This file is used to check if Python version used is compatible
22+
import os
23+
import sys
24+
25+
# Oldest / newest version supported
26+
MIN_PYTHON = (3, 9)
27+
MAX_PYTHON = (3, 13)
28+
29+
30+
def check_python_version():
31+
current_version = sys.version_info[:2]
32+
33+
if current_version < MIN_PYTHON or current_version > MAX_PYTHON:
34+
print(f"[ERROR] Python {current_version[0]}.{current_version[1]} is not supported by this program. "
35+
f"Python {MIN_PYTHON[0]}.{MIN_PYTHON[1]}-{MAX_PYTHON[0]}.{MAX_PYTHON[1]} required.")
36+
try:
37+
sys.exit(0)
38+
except:
39+
os._exit(0)

main.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,14 @@
2323
# along with this program. If not, see <https://www.gnu.org/licenses/>.
2424

2525
# This file is the system monitor main program to display HW sensors on your screen using themes (see README)
26+
27+
from library.pythoncheck import check_python_version
28+
check_python_version()
29+
2630
import glob
2731
import os
2832
import sys
2933

30-
MIN_PYTHON = (3, 9)
31-
if sys.version_info < MIN_PYTHON:
32-
print("[ERROR] Python %s.%s or later is required." % MIN_PYTHON)
33-
try:
34-
sys.exit(0)
35-
except:
36-
os._exit(0)
37-
3834
try:
3935
import atexit
4036
import locale

res/fonts/font-preview.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,6 @@
2020
# This file generate PNG previews for available fonts
2121

2222
import os
23-
import sys
24-
25-
MIN_PYTHON = (3, 9)
26-
if sys.version_info < MIN_PYTHON:
27-
print("[ERROR] Python %s.%s or later is required." % MIN_PYTHON)
28-
try:
29-
sys.exit(0)
30-
except:
31-
os._exit(0)
32-
3323
from PIL import Image, ImageDraw, ImageFont
3424
import math
3525
from pathlib import Path

simple-program.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919

2020
# This file is a simple Python test program using the library code to display custom content on screen (see README)
2121

22+
from library.pythoncheck import check_python_version
23+
check_python_version()
24+
2225
import os
2326
import signal
2427
import sys

theme-editor.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
# theme-editor.py: Allow to easily edit themes for System Monitor (main.py) in a preview window on the computer
2121
# The preview window is refreshed as soon as the theme file is modified
2222

23+
from library.pythoncheck import check_python_version
24+
check_python_version()
25+
2326
import locale
2427
import logging
2528
import os
@@ -28,14 +31,6 @@
2831
import sys
2932
import time
3033

31-
MIN_PYTHON = (3, 8)
32-
if sys.version_info < MIN_PYTHON:
33-
print("[ERROR] Python %s.%s or later is required." % MIN_PYTHON)
34-
try:
35-
sys.exit(0)
36-
except:
37-
os._exit(0)
38-
3934
try:
4035
import tkinter
4136
from PIL import ImageTk, Image

tools/turing-theme-extractor.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,6 @@
2727
PNG_SIGNATURE = b'\x89\x50\x4E\x47\x0D\x0A\x1A\x0A'
2828
PNG_IEND = b'\x49\x45\x4E\x44\xAE\x42\x60\x82'
2929

30-
MIN_PYTHON = (3, 8)
31-
if sys.version_info < MIN_PYTHON:
32-
print("[ERROR] Python %s.%s or later is required." % MIN_PYTHON)
33-
try:
34-
sys.exit(0)
35-
except:
36-
os._exit(0)
37-
3830
if len(sys.argv) != 2:
3931
print("Usage :")
4032
print(" turing-theme-extractor.py path/to/theme-file.data")

0 commit comments

Comments
 (0)