Skip to content

Commit 9ff0f67

Browse files
update format for backends
1 parent f49b86f commit 9ff0f67

File tree

4 files changed

+127
-75
lines changed

4 files changed

+127
-75
lines changed

mesonui/mesonuilib/backends/backendimpl.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/usr/bin/env python3
22

33
#
4-
# author : Michael Brockus.  
5-
# contact: <mailto:[email protected]>
6-
# license: Apache 2.0 :http://www.apache.org/licenses/LICENSE-2.0
4+
# author : Michael Brockus.
5+
# contact: <mailto:[email protected]>
6+
# license: Apache 2.0 :http://www.apache.org/licenses/LICENSE-2.0
77
#
88
# copyright 2020 The Meson-UI development team
99
#
@@ -15,7 +15,7 @@ def __init__(self, meson_api):
1515

1616
@property
1717
def testinfo(self):
18-
return self.meson_api.get_object(group='tests', extract_method='loader')
18+
return self.meson_api.get_object(group="tests", extract_method="loader")
1919

2020
def generator(self):
2121
raise NotImplementedError('IDE Backend "generate" method not iemented!')
Lines changed: 67 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/usr/bin/env python3
22

33
#
4-
# author : Michael Brockus.  
5-
# contact: <mailto:[email protected]>
6-
# license: Apache 2.0 :http://www.apache.org/licenses/LICENSE-2.0
4+
# author : Michael Brockus.
5+
# contact: <mailto:[email protected]>
6+
# license: Apache 2.0 :http://www.apache.org/licenses/LICENSE-2.0
77
#
88
# copyright 2020 The Meson-UI development team
99
#
@@ -27,81 +27,107 @@
2727

2828
class CodeBlocksBackend(BackendImplementionApi):
2929
def __init__(self, meson_api: MesonAPI):
30-
self.backend: str = '\'codeblocks\''
30+
self.backend: str = "'codeblocks'"
3131
self.projectinfo = ProjectInfo(meson_api=meson_api)
3232
self.mesoninfo = MesonInfo(meson_api=meson_api)
33-
self.buildsystem_files = meson_api.get_object(group='buildsystem-files', extract_method='loader')
34-
self.targetsinfo: any = meson_api.get_object(group='targets', extract_method='loader')
33+
self.buildsystem_files = meson_api.get_object(
34+
group="buildsystem-files", extract_method="loader"
35+
)
36+
self.targetsinfo: any = meson_api.get_object(
37+
group="targets", extract_method="loader"
38+
)
3539
self.ninja = Ninja(self.mesoninfo.sourcedir, self.mesoninfo.builddir)
36-
self.compiler = self.targetsinfo[0]['target_sources'][0]['compiler'][0]
40+
self.compiler = self.targetsinfo[0]["target_sources"][0]["compiler"][0]
3741

3842
def generator(self):
39-
logging.info(f'Generating {self.backend} project')
43+
logging.info(f"Generating {self.backend} project")
4044
self.generate_project()
4145

4246
def generate_project(self):
43-
xml: Builder = Builder(version='1.0', encoding='UTF-8')
44-
with xml.CodeBlocks_project_file(Name=self.projectinfo.descriptive_name, Version='0.1', InternalType='Console'):
45-
xml.FileVersion(major=f'{CBP_VERSION_MAJOR}', minor=f'{CBP_VERSION_MINOR}')
47+
xml: Builder = Builder(version="1.0", encoding="UTF-8")
48+
with xml.CodeBlocks_project_file(
49+
Name=self.projectinfo.descriptive_name,
50+
Version="0.1",
51+
InternalType="Console",
52+
):
53+
xml.FileVersion(major=f"{CBP_VERSION_MAJOR}", minor=f"{CBP_VERSION_MINOR}")
4654
with xml.Project:
4755
xml.Option(title=self.projectinfo.descriptive_name)
4856
xml.Option(compiler=self.compiler)
49-
xml.Option(virtualFolders='Meson Files')
50-
xml.Option(makefile_is_custom='1')
57+
xml.Option(virtualFolders="Meson Files")
58+
xml.Option(makefile_is_custom="1")
5159

5260
with xml.Build:
5361
for targets in self.targetsinfo:
54-
output = join_paths(self.mesoninfo.builddir, targets['id'])
55-
with xml.Target(title=targets['name']):
62+
output = join_paths(self.mesoninfo.builddir, targets["id"])
63+
with xml.Target(title=targets["name"]):
5664
xml.Option(output=output)
5765
xml.Option(working_dir=os.path.split(output)[0])
58-
xml.Option(object_output=join_paths(os.path.split(output)[0], targets['id']))
66+
xml.Option(
67+
object_output=join_paths(
68+
os.path.split(output)[0], targets["id"]
69+
)
70+
)
5971
ty = {
60-
'executable': f'{BUILD_OPTION_EXECUTABLE}',
61-
'static library': f'{BUILD_OPTION_STATIC_LIBRARY}',
62-
'shared library': f'{BUILD_OPTION_SHARED_LIBRARY}',
63-
'custom': f'{BUILD_OPTION_COMMANDS_ONLY}',
64-
'run': f'{BUILD_OPTION_COMMANDS_ONLY}'
65-
}[targets['type']]
72+
"executable": f"{BUILD_OPTION_EXECUTABLE}",
73+
"static library": f"{BUILD_OPTION_STATIC_LIBRARY}",
74+
"shared library": f"{BUILD_OPTION_SHARED_LIBRARY}",
75+
"custom": f"{BUILD_OPTION_COMMANDS_ONLY}",
76+
"run": f"{BUILD_OPTION_COMMANDS_ONLY}",
77+
}[targets["type"]]
6678
xml.Option(type=ty)
6779
compiler = targets
6880
if compiler:
6981
xml.Option(compiler=self.compiler)
7082
with xml.Compiler:
71-
for target in targets['target_sources']:
72-
for defs in target['parameters']:
73-
if defs.startswith('-D'):
74-
logging.info(f'add def: {defs}')
83+
for target in targets["target_sources"]:
84+
for defs in target["parameters"]:
85+
if defs.startswith("-D"):
86+
logging.info(f"add def: {defs}")
7587
xml.Add(option=defs)
7688

77-
for dirs in target['parameters']:
78-
if dirs.startswith('-I') or dirs.startswith('/I'):
79-
logging.info(f'add include: {dirs}')
89+
for dirs in target["parameters"]:
90+
if dirs.startswith("-I") or dirs.startswith("/I"):
91+
logging.info(f"add include: {dirs}")
8092
xml.Add(option=dirs)
8193

8294
with xml.MakeCommands:
8395
xml.Build(command=f'{self.ninja.exe} -v {targets["name"]}')
84-
xml.CompileFile(command=f'{self.ninja.exe} -v {targets["name"]}')
85-
xml.Clean(command=f'{self.ninja.exe} -v clean')
86-
xml.DistClean(command=f'{self.ninja.exe} -v clean')
96+
xml.CompileFile(
97+
command=f'{self.ninja.exe} -v {targets["name"]}'
98+
)
99+
xml.Clean(command=f"{self.ninja.exe} -v clean")
100+
xml.DistClean(command=f"{self.ninja.exe} -v clean")
87101

88102
for targets in self.targetsinfo:
89-
for target in targets['target_sources']:
90-
for file in target['sources']:
91-
with xml.Unit(filename=join_paths(self.mesoninfo.sourcedir, file)):
92-
xml.Option(target=targets['name'])
103+
for target in targets["target_sources"]:
104+
for file in target["sources"]:
105+
with xml.Unit(
106+
filename=join_paths(self.mesoninfo.sourcedir, file)
107+
):
108+
xml.Option(target=targets["name"])
93109

94110
base = os.path.splitext(os.path.basename(file))[0]
95-
header_exts = ('h', 'hpp')
111+
header_exts = ("h", "hpp")
96112
for ext in header_exts:
97113
header_file = os.path.abspath(
98-
join_paths(self.mesoninfo.sourcedir, os.path.dirname(file), f'{base}.{ext}'))
114+
join_paths(
115+
self.mesoninfo.sourcedir,
116+
os.path.dirname(file),
117+
f"{base}.{ext}",
118+
)
119+
)
99120
if os.path.exists(header_file):
100121
with xml.Unit(filename=header_file):
101-
xml.Option(target=targets['name'])
122+
xml.Option(target=targets["name"])
102123
for file in self.buildsystem_files:
103124
with xml.Unit(filename=join_paths(self.mesoninfo.sourcedir, file)):
104-
xml.Option(target=join_paths('Meson Files', os.path.dirname(file)))
125+
xml.Option(target=join_paths("Meson Files", os.path.dirname(file)))
105126

106-
with open(join_paths(self.mesoninfo.builddir, f'{self.projectinfo.descriptive_name}.cbp'), 'w') as ide_file:
127+
with open(
128+
join_paths(
129+
self.mesoninfo.builddir, f"{self.projectinfo.descriptive_name}.cbp"
130+
),
131+
"w",
132+
) as ide_file:
107133
ide_file.write(str(xml))

mesonui/mesonuilib/backends/gnome.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/usr/bin/env python3
22

33
#
4-
# author : Michael Brockus.  
5-
# contact: <mailto:[email protected]>
6-
# license: Apache 2.0 :http://www.apache.org/licenses/LICENSE-2.0
4+
# author : Michael Brockus.
5+
# contact: <mailto:[email protected]>
6+
# license: Apache 2.0 :http://www.apache.org/licenses/LICENSE-2.0
77
#
88
# copyright 2020 The Meson-UI development team
99
#
@@ -15,10 +15,10 @@
1515
class GNOMEBuilderBackend(BackendImplementionApi):
1616
def __init__(self, meson_api: MesonAPI):
1717
super(self.__class__, self).__init__(meson_api)
18-
self.backend: str = '\'gnome\''
18+
self.backend: str = "'gnome'"
1919

2020
def generator(self):
21-
logging.info(f'Generating {self.backend} project')
21+
logging.info(f"Generating {self.backend} project")
2222
self.generate_project()
2323

2424
def generate_project(self):
Lines changed: 51 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/usr/bin/env python3
22

33
#
4-
# author : Michael Brockus.  
5-
# contact: <mailto:[email protected]>
6-
# license: Apache 2.0 :http://www.apache.org/licenses/LICENSE-2.0
4+
# author : Michael Brockus.
5+
# contact: <mailto:[email protected]>
6+
# license: Apache 2.0 :http://www.apache.org/licenses/LICENSE-2.0
77
#
88
# copyright 2020 The Meson-UI development team
99
#
@@ -18,44 +18,70 @@
1818

1919
class QtCreatorBackend(BackendImplementionApi):
2020
def __init__(self, meson_api: MesonAPI):
21-
self.backend: str = '\'qtcreator\''
21+
self.backend: str = "'qtcreator'"
2222
self.projectinfo = ProjectInfo(meson_api=meson_api)
2323
self.mesoninfo = MesonInfo(meson_api=meson_api)
24-
self.buildsystem_files: list = meson_api.get_object(group='buildsystem-files', extract_method='loader')
25-
self.targetsinfo: list = meson_api.get_object(group='targets', extract_method='loader')
24+
self.buildsystem_files: list = meson_api.get_object(
25+
group="buildsystem-files", extract_method="loader"
26+
)
27+
self.targetsinfo: list = meson_api.get_object(
28+
group="targets", extract_method="loader"
29+
)
2630

2731
def generator(self):
28-
logging.info(f'Generating {self.backend} project')
32+
logging.info(f"Generating {self.backend} project")
2933
self.generate_project()
3034

3135
def generate_project(self):
3236
# Generate the .creator file.
33-
with open(join_paths(self.mesoninfo.builddir, f'{self.projectinfo.descriptive_name}.creator'), 'w') as file:
34-
file.write('[General]')
37+
with open(
38+
join_paths(
39+
self.mesoninfo.builddir, f"{self.projectinfo.descriptive_name}.creator"
40+
),
41+
"w",
42+
) as file:
43+
file.write("[General]")
3544

3645
# Generate the .config file.
37-
with open(join_paths(self.mesoninfo.builddir, f'{self.projectinfo.descriptive_name}.config'), 'w') as file:
38-
file.write('// Add predefined macros for your project here. For example:')
39-
file.write('// #define THE_ANSWER 42')
46+
with open(
47+
join_paths(
48+
self.mesoninfo.builddir, f"{self.projectinfo.descriptive_name}.config"
49+
),
50+
"w",
51+
) as file:
52+
file.write("// Add predefined macros for your project here. For example:")
53+
file.write("// #define THE_ANSWER 42")
4054
for targets in self.targetsinfo:
41-
for item in targets['target_sources'][0]['parameters']:
42-
if item.startswith('-D'):
43-
logging.info(f'add def: {item}')
44-
item = ' '.join(item.split('='))
45-
file.write(f'#define {item}\n')
55+
for item in targets["target_sources"][0]["parameters"]:
56+
if item.startswith("-D"):
57+
logging.info(f"add def: {item}")
58+
item = " ".join(item.split("="))
59+
file.write(f"#define {item}\n")
4660

4761
# Generate the .files file.
48-
with open(join_paths(self.mesoninfo.builddir, f'{self.projectinfo.descriptive_name}.files'), 'w') as file:
62+
with open(
63+
join_paths(
64+
self.mesoninfo.builddir, f"{self.projectinfo.descriptive_name}.files"
65+
),
66+
"w",
67+
) as file:
4968
for targets in self.targetsinfo:
50-
for items in targets['target_sources'][0]['sources']:
51-
file.write(os.path.relpath(item, self.mesoninfo.builddir) + '\n')
69+
for items in targets["target_sources"][0]["sources"]:
70+
file.write(os.path.relpath(item, self.mesoninfo.builddir) + "\n")
5271

5372
for item in self.buildsystem_files:
54-
file.write(os.path.relpath(item, self.mesoninfo.builddir) + '\n')
73+
file.write(os.path.relpath(item, self.mesoninfo.builddir) + "\n")
5574

5675
# Generate the .includes file.
57-
with open(join_paths(self.mesoninfo.builddir, f'{self.projectinfo.descriptive_name}.includes'), 'w') as file:
76+
with open(
77+
join_paths(
78+
self.mesoninfo.builddir, f"{self.projectinfo.descriptive_name}.includes"
79+
),
80+
"w",
81+
) as file:
5882
for targets in self.targetsinfo:
59-
for item in targets['target_sources'][0]['parameters']:
60-
if item.startswith('-I') or item.startswith('/I'):
61-
file.write(os.path.relpath(item, self.mesoninfo.builddir) + '\n')
83+
for item in targets["target_sources"][0]["parameters"]:
84+
if item.startswith("-I") or item.startswith("/I"):
85+
file.write(
86+
os.path.relpath(item, self.mesoninfo.builddir) + "\n"
87+
)

0 commit comments

Comments
 (0)