Skip to content

Commit

Permalink
Use f-strings and other refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
danyeaw authored and pbor committed Dec 30, 2022
1 parent 1a0e6d1 commit 253ce30
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 46 deletions.
30 changes: 4 additions & 26 deletions gvsbuild/deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,31 +151,15 @@ def make_graph(
gr_index %= len(gr_colors)
for d in t.dependencies:
if d in to_skip:
print(
"Skip '%s' for '%s'"
% (
d,
n,
)
)
print(f"Skip '{d}' for '{n}'")
else:
if invert_dep:
fo.write(
' "%s" -> "%s" [color="#%06x"];\n'
% (
d,
n,
gr_colors[gr_index],
)
f' "{d}" -> "{n}" [color="#{gr_colors[gr_index]:06x}"];\n'
)
else:
fo.write(
' "%s" -> "%s" [color="#%06x"];\n'
% (
n,
d,
gr_colors[gr_index],
)
f' "{n}" -> "{d}" [color="#{gr_colors[gr_index]:06x}"];\n'
)
used.add(d)
else:
Expand All @@ -185,13 +169,7 @@ def make_graph(
# Puts all projects that are not referenced from others
for n in Project._names:
if n not in used:
fo.write(
' "%s" -> "%s" [color="#c00080"];\n'
% (
"BUILD",
n,
)
)
fo.write(f' "BUILD" -> "{n}" [color="#c00080"];\n')

fo.write("};\n")

Expand Down
7 changes: 3 additions & 4 deletions gvsbuild/projects/openssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.

import contextlib

from gvsbuild.utils.base_expanders import Tarball
from gvsbuild.utils.base_project import Project, project_add

Expand Down Expand Up @@ -61,11 +63,8 @@ def build(self):
+ common_options
)

try:
with contextlib.suppress(Exception):
self.exec_vs(r"nmake /nologo clean", add_path=add_path)
except: # noqa E722
pass

self.exec_vs(r"nmake /nologo", add_path=add_path)
self.exec_vs(r"%(perl_dir)s\bin\perl.exe mk-ca-bundle.pl -n cert.pem")
self.exec_vs(r"nmake /nologo install", add_path=add_path)
Expand Down
2 changes: 1 addition & 1 deletion gvsbuild/projects/pixman.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def build(self):
add_path = os.path.join(self.builder.opts.msys_dir, "usr", "bin")

self.exec_vs(
r"make -f Makefile.win32 pixman CFG=%(configuration)s " + optimizations,
f"make -f Makefile.win32 pixman CFG=%(configuration)s {optimizations}",
add_path=add_path,
)

Expand Down
11 changes: 3 additions & 8 deletions gvsbuild/utils/base_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,13 @@ def build(
out_of_source=None,
source_part=None,
):
cmake_gen = "Ninja" if use_ninja else "NMake Makefiles"

cmake_config = (
"Debug" if self.builder.opts.configuration == "debug" else "RelWithDebInfo"
)
cmake_gen = "Ninja" if use_ninja else "NMake Makefiles"

# Create the command for cmake
cmd = (
'cmake -G "'
+ cmake_gen
+ '" -DCMAKE_INSTALL_PREFIX="%(pkg_dir)s" -DGTK_DIR="%(gtk_dir)s" -DCMAKE_BUILD_TYPE='
+ cmake_config
)
cmd = f'cmake -G "{cmake_gen}" -DCMAKE_INSTALL_PREFIX="%(pkg_dir)s" -DGTK_DIR="%(gtk_dir)s" -DCMAKE_BUILD_TYPE={cmake_config}'
if cmake_params:
cmd += f" {cmake_params}"
if use_ninja and out_of_source is None:
Expand Down
6 changes: 1 addition & 5 deletions gvsbuild/utils/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,11 +375,7 @@ def __check_good_vs_install(self, opts, vs_path, exit_missing=True):
% (vcvars_bat, vs_path, opts.platform)
)
return subprocess.check_output(
'cmd.exe /c ""%s"%s>NUL && set"'
% (
vcvars_bat,
add_opts,
),
f'cmd.exe /c ""{vcvars_bat}"{add_opts}>NUL && set"',
encoding="utf-8",
shell=True,
text=True,
Expand Down
3 changes: 1 addition & 2 deletions gvsbuild/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ def convert_to_msys(path):
path = path
if path[1] != ":":
raise NotADirectoryError("Path doesn't contain a drive letter like C:")
path = f"/{path[0]}" + path[2:].replace("\\", "/")
return path
return f"/{path[0]}" + path[2:].replace("\\", "/")


def _rmtree_error_handler(func, path, exc_info):
Expand Down

0 comments on commit 253ce30

Please sign in to comment.