mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Use context manager instead of plain open (#1211)
Context manager with open closes the files after usage. When the object is already a pathlib.Path i used read_text write_text functions In some cases pathlib.Path.open were used in context manager, it is basically the same as builtin open. Thanks, Konstantin Baikov!
This commit is contained in:
parent
a1bcd2fbe5
commit
8e18c79431
17 changed files with 93 additions and 63 deletions
|
|
@ -125,13 +125,13 @@ def cli():
|
|||
@sqlite_extensions
|
||||
def inspect(files, inspect_file, sqlite_extensions):
|
||||
app = Datasette([], immutables=files, sqlite_extensions=sqlite_extensions)
|
||||
if inspect_file == "-":
|
||||
out = sys.stdout
|
||||
else:
|
||||
out = open(inspect_file, "w")
|
||||
loop = asyncio.get_event_loop()
|
||||
inspect_data = loop.run_until_complete(inspect_(files, sqlite_extensions))
|
||||
out.write(json.dumps(inspect_data, indent=2))
|
||||
if inspect_file == "-":
|
||||
sys.stdout.write(json.dumps(inspect_data, indent=2))
|
||||
else:
|
||||
with open(inspect_file, "w") as fp:
|
||||
fp.write(json.dumps(inspect_data, indent=2))
|
||||
|
||||
|
||||
async def inspect_(files, sqlite_extensions):
|
||||
|
|
@ -475,7 +475,8 @@ def serve(
|
|||
|
||||
inspect_data = None
|
||||
if inspect_file:
|
||||
inspect_data = json.load(open(inspect_file))
|
||||
with open(inspect_file) as fp:
|
||||
inspect_data = json.load(fp)
|
||||
|
||||
metadata_data = None
|
||||
if metadata:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue