Skip to content

Commit

Permalink
use fstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
whoburg committed Jan 5, 2024
1 parent 1417fb1 commit 7c6121a
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions gpkit/build.py
Expand Up @@ -23,9 +23,9 @@ def pathjoin(*args):
def isfile(path):
"Returns true if there's a file at $path. Logs."
if os.path.isfile(path):
log("# Found %s" % path)
log(f"# Found {path}")
return True
log("# Could not find %s" % path)
log(f"# Could not find {path}")
return False


Expand All @@ -40,7 +40,7 @@ def replacedir(path):

def call(cmd):
"Calls subprocess. Logs."
log("# Calling '%s'" % cmd)
log(f"# Calling '{cmd}'")
log("##")
log("### CALL BEGINS")
retcode = subprocess.call(cmd, shell=True)
Expand All @@ -56,8 +56,8 @@ def diff(filename, diff_dict):
for line_number, line in enumerate(a):
if line[:-1].strip() in diff_dict:
newline = diff_dict[line[:-1].strip()]+"\n"
log("#\n# Change in %s"
"on line %i" % (filename, line_number + 1))
log(f"#\n# Change in {filename}"
f" on line {line_number + 1}")
log("# --", line[:-1][:70])
log("# ++", newline[:70])
b.write(newline)
Expand All @@ -71,10 +71,10 @@ class SolverBackend:
name = look = None

def __init__(self):
log("\n# Looking for `%s`" % self.name)
log(f"\n# Looking for `{self.name}`")
found_in = self.look() # pylint: disable=not-callable
if found_in:
log("\nFound %s %s" % (self.name, found_in))
log(f"\nFound {self.name} {found_in}")
self.installed = True
else:
log("# Did not find\n#", self.name)
Expand Down Expand Up @@ -106,27 +106,27 @@ def look(self): # pylint: disable=too-many-return-statements
rootdir = pathjoin(os.path.expanduser("~"), "mosek")
mosek_platform = "linux64x86"
else:
return log("# Platform unsupported: %s" % sys.platform)
return log(f"# Platform unsupported: {sys.platform}")

if "MSKHOME" in os.environ: # allow specification of root dir
rootdir = os.environ["MSKHOME"]
log("# Using MSKHOME environment variable (value %s) instead of"
" OS-default MOSEK home directory" % rootdir)
log(f"# Using MSKHOME environment variable (value {rootdir})"
" instead of OS-default MOSEK home directory")
if not os.path.isdir(rootdir):
return log("# expected MOSEK directory not found: %s" % rootdir)
return log("# expected MOSEK directory not found: {rootdir}")

possible_versions = [f for f in os.listdir(rootdir)
if len(f) == 1 and f < "9"]
if not possible_versions:
return log("# no version folders (e.g. '7', '8') found"
" in mosek directory \"%s\"" % rootdir)
f" in mosek directory \"{rootdir}\"")
version = sorted(possible_versions)[-1]
tools_dir = pathjoin(rootdir, version, "tools")
lib_dir = pathjoin(tools_dir, "platform", mosek_platform)
bin_dir = pathjoin(lib_dir, "bin")
settings["mosek_bin_dir"] = bin_dir
os.environ['PATH'] = os.environ['PATH'] + os.pathsep + bin_dir
log("# Adding %s to the PATH" % bin_dir)
log(f"# Adding {bin_dir} to the PATH")

return self.run("in " + bin_dir)

Expand Down Expand Up @@ -172,7 +172,7 @@ def look(self):
def build():
"Builds GPkit"
import gpkit
log("# Building GPkit version %s" % gpkit.__version__)
log(f"# Building GPkit version {gpkit.__version__}")
log("# Moving to the directory from which GPkit was imported.")
start_dir = os.getcwd()
os.chdir(gpkit.__path__[0])
Expand All @@ -183,8 +183,8 @@ def build():
if not installed_solvers:
log("Can't find any solvers!\n")
if "GPKITSOLVERS" in os.environ:
log("Replaced found solvers (%s) with environment var GPKITSOLVERS"
" (%s)" % (installed_solvers, os.environ["GPKITSOLVERS"]))
log(f"Replaced found solvers ({installed_solvers}) with environment "
f"var GPKITSOLVERS ({os.environ['GPKITSOLVERS']})")
settings["installed_solvers"] = os.environ["GPKITSOLVERS"]
else:
settings["installed_solvers"] = ", ".join(installed_solvers)
Expand All @@ -195,7 +195,7 @@ def build():
replacedir(envpath)
with open(pathjoin(envpath, "settings"), "w") as f:
for setting, value in sorted(settings.items()):
f.write("%s : %s\n" % (setting, value))
f.write(f"{setting} : {value}\n")
with open(pathjoin(envpath, "build.log"), "w") as f:
f.write(LOGSTR)

Expand Down

0 comments on commit 7c6121a

Please sign in to comment.