mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
cleanup: Format using black
This commit is contained in:
parent
4b42016837
commit
af03c2ac0f
36 changed files with 928 additions and 616 deletions
|
@ -37,19 +37,37 @@ class BlueprintApp:
|
|||
self.subparsers = self.parser.add_subparsers(metavar="command")
|
||||
self.parser.set_defaults(func=self.cmd_help)
|
||||
|
||||
compile = self.add_subcommand("compile", "Compile blueprint files", self.cmd_compile)
|
||||
compile = self.add_subcommand(
|
||||
"compile", "Compile blueprint files", self.cmd_compile
|
||||
)
|
||||
compile.add_argument("--output", dest="output", default="-")
|
||||
compile.add_argument("input", metavar="filename", default=sys.stdin, type=argparse.FileType('r'))
|
||||
compile.add_argument(
|
||||
"input", metavar="filename", default=sys.stdin, type=argparse.FileType("r")
|
||||
)
|
||||
|
||||
batch_compile = self.add_subcommand("batch-compile", "Compile many blueprint files at once", self.cmd_batch_compile)
|
||||
batch_compile = self.add_subcommand(
|
||||
"batch-compile",
|
||||
"Compile many blueprint files at once",
|
||||
self.cmd_batch_compile,
|
||||
)
|
||||
batch_compile.add_argument("output_dir", metavar="output-dir")
|
||||
batch_compile.add_argument("input_dir", metavar="input-dir")
|
||||
batch_compile.add_argument("inputs", nargs="+", metavar="filenames", default=sys.stdin, type=argparse.FileType('r'))
|
||||
batch_compile.add_argument(
|
||||
"inputs",
|
||||
nargs="+",
|
||||
metavar="filenames",
|
||||
default=sys.stdin,
|
||||
type=argparse.FileType("r"),
|
||||
)
|
||||
|
||||
port = self.add_subcommand("port", "Interactive porting tool", self.cmd_port)
|
||||
|
||||
lsp = self.add_subcommand("lsp", "Run the language server (for internal use by IDEs)", self.cmd_lsp)
|
||||
lsp.add_argument("--logfile", dest="logfile", default=None, type=argparse.FileType('a'))
|
||||
lsp = self.add_subcommand(
|
||||
"lsp", "Run the language server (for internal use by IDEs)", self.cmd_lsp
|
||||
)
|
||||
lsp.add_argument(
|
||||
"--logfile", dest="logfile", default=None, type=argparse.FileType("a")
|
||||
)
|
||||
|
||||
self.add_subcommand("help", "Show this message", self.cmd_help)
|
||||
|
||||
|
@ -65,17 +83,14 @@ class BlueprintApp:
|
|||
except:
|
||||
report_bug()
|
||||
|
||||
|
||||
def add_subcommand(self, name, help, func):
|
||||
parser = self.subparsers.add_parser(name, help=help)
|
||||
parser.set_defaults(func=func)
|
||||
return parser
|
||||
|
||||
|
||||
def cmd_help(self, opts):
|
||||
self.parser.print_help()
|
||||
|
||||
|
||||
def cmd_compile(self, opts):
|
||||
data = opts.input.read()
|
||||
try:
|
||||
|
@ -93,14 +108,15 @@ class BlueprintApp:
|
|||
e.pretty_print(opts.input.name, data)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def cmd_batch_compile(self, opts):
|
||||
for file in opts.inputs:
|
||||
data = file.read()
|
||||
|
||||
try:
|
||||
if not os.path.commonpath([file.name, opts.input_dir]):
|
||||
print(f"{Colors.RED}{Colors.BOLD}error: input file '{file.name}' is not in input directory '{opts.input_dir}'{Colors.CLEAR}")
|
||||
print(
|
||||
f"{Colors.RED}{Colors.BOLD}error: input file '{file.name}' is not in input directory '{opts.input_dir}'{Colors.CLEAR}"
|
||||
)
|
||||
sys.exit(1)
|
||||
|
||||
xml, warnings = self._compile(data)
|
||||
|
@ -111,9 +127,8 @@ class BlueprintApp:
|
|||
path = os.path.join(
|
||||
opts.output_dir,
|
||||
os.path.relpath(
|
||||
os.path.splitext(file.name)[0] + ".ui",
|
||||
opts.input_dir
|
||||
)
|
||||
os.path.splitext(file.name)[0] + ".ui", opts.input_dir
|
||||
),
|
||||
)
|
||||
os.makedirs(os.path.dirname(path), exist_ok=True)
|
||||
with open(path, "w") as file:
|
||||
|
@ -122,16 +137,13 @@ class BlueprintApp:
|
|||
e.pretty_print(file.name, data)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def cmd_lsp(self, opts):
|
||||
langserv = LanguageServer(opts.logfile)
|
||||
langserv.run()
|
||||
|
||||
|
||||
def cmd_port(self, opts):
|
||||
interactive_port.run(opts)
|
||||
|
||||
|
||||
def _compile(self, data: str) -> T.Tuple[str, T.List[PrintableError]]:
|
||||
tokens = tokenizer.tokenize(data)
|
||||
ast, errors, warnings = parser.parse(tokens)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue