From ca152234e1903f0ad41e6b27c6a0626025e3f80c Mon Sep 17 00:00:00 2001 From: Emil Velikov Date: Sun, 9 Dec 2018 20:09:49 +0000 Subject: [PATCH] mesa: correctly use os.path.join in our python scripts With Windows in mind, using forward slash isn't the right thing to do. Even if it just works, we might want to fix it. As here, use __file__ instead of argv[0] and sys.path.insert over sys.path.append. With the path tweak being reportedly faster. Suggested-by: Dylan Baker Signed-off-by: Emil Velikov Reviewed-by: Erik Faye-Lund --- src/mapi/mapi_abi.py | 4 ++-- src/mesa/main/get_hash_generator.py | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/mapi/mapi_abi.py b/src/mapi/mapi_abi.py index dc48fa5935f..bb505561e7c 100644 --- a/src/mapi/mapi_abi.py +++ b/src/mapi/mapi_abi.py @@ -29,8 +29,8 @@ from __future__ import print_function import sys # make it possible to import glapi import os -GLAPI = os.path.join(".", os.path.dirname(sys.argv[0]), "glapi/gen") -sys.path.append(GLAPI) +GLAPI = os.path.join(".", os.path.dirname(__file__), "glapi", "gen") +sys.path.insert(0, GLAPI) from operator import attrgetter import re diff --git a/src/mesa/main/get_hash_generator.py b/src/mesa/main/get_hash_generator.py index f742ebff4b8..3e9032bd4c8 100644 --- a/src/mesa/main/get_hash_generator.py +++ b/src/mesa/main/get_hash_generator.py @@ -34,11 +34,10 @@ import os, sys, getopt from collections import defaultdict import get_hash_params -cur_dir = os.path.dirname(sys.argv[0]) -param_desc_file = "%s/get_hash_params.py" % cur_dir +param_desc_file = os.path.join(os.path.dirname(__file__), "get_hash_params.py") -GLAPI = "%s/../../mapi/glapi/gen" % cur_dir -sys.path.append(GLAPI) +GLAPI = os.path.join(os.path.dirname(__file__), "..", "..", "mapi", "glapi", "gen") +sys.path.insert(0, GLAPI) import gl_XML prime_factor = 89 -- 2.30.2