Skip to content

Commit

Permalink
update config parser due to deprecated function usage
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinBubel committed Dec 2, 2023
1 parent 53254cd commit f485af7
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions GPy/util/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,46 @@
# This loads the configuration
#
import os

try:
#Attempt Python 2 ConfigParser setup
# Attempt Python 2 ConfigParser setup
import ConfigParser

config = ConfigParser.ConfigParser()
from ConfigParser import NoOptionError
except ImportError:
#Attempt Python 3 ConfigParser setup
# Attempt Python 3 ConfigParser setup
import configparser

config = configparser.ConfigParser()
from configparser import NoOptionError

# This is the default configuration file that always needs to be present.
default_file = os.path.abspath(os.path.join(os.path.dirname( __file__ ), '..', 'defaults.cfg'))
default_file = os.path.abspath(
os.path.join(os.path.dirname(__file__), "..", "defaults.cfg")
)

# These files are optional
# This specifies configurations that are typically specific to the machine (it is found alongside the GPy installation).
local_file = os.path.abspath(os.path.join(os.path.dirname( __file__ ), '..', 'installation.cfg'))
local_file = os.path.abspath(
os.path.join(os.path.dirname(__file__), "..", "installation.cfg")
)

# This specifies configurations specific to the user (it is found in the user home directory)
home = os.getenv('HOME') or os.getenv('USERPROFILE') or ''
user_file = os.path.join(home,'.config','GPy', 'user.cfg')
home = os.getenv("HOME") or os.getenv("USERPROFILE") or ""
user_file = os.path.join(home, ".config", "GPy", "user.cfg")

# Read in the given files.
config.readfp(open(default_file))
config.read_file(open(default_file))
config.read([local_file, user_file])

if not config:
raise ValueError("No configuration file found at either " + user_file + " or " + local_file + " or " + default_file + ".")
raise ValueError(
"No configuration file found at either "
+ user_file
+ " or "
+ local_file
+ " or "
+ default_file
+ "."
)

0 comments on commit f485af7

Please sign in to comment.