fix: file open leaks (#3067)
This commit is contained in:
parent
569869e211
commit
747a1848d4
4 changed files with 57 additions and 54 deletions
|
|
@ -22,7 +22,8 @@ class JsonAgentComponent(LCAgentComponent):
|
|||
|
||||
def build_agent(self) -> AgentExecutor:
|
||||
if self.path.endswith("yaml") or self.path.endswith("yml"):
|
||||
yaml_dict = yaml.load(open(self.path, "r"), Loader=yaml.FullLoader)
|
||||
with open(self.path, "r") as file:
|
||||
yaml_dict = yaml.load(file, Loader=yaml.FullLoader)
|
||||
spec = JsonSpec(dict_=yaml_dict)
|
||||
else:
|
||||
spec = JsonSpec.from_file(Path(self.path))
|
||||
|
|
|
|||
|
|
@ -24,7 +24,8 @@ class OpenAPIAgentComponent(LCAgentComponent):
|
|||
|
||||
def build_agent(self) -> AgentExecutor:
|
||||
if self.path.endswith("yaml") or self.path.endswith("yml"):
|
||||
yaml_dict = yaml.load(open(self.path, "r"), Loader=yaml.FullLoader)
|
||||
with open(self.path, "r") as file:
|
||||
yaml_dict = yaml.load(file, Loader=yaml.FullLoader)
|
||||
spec = JsonSpec(dict_=yaml_dict)
|
||||
else:
|
||||
spec = JsonSpec.from_file(Path(self.path))
|
||||
|
|
|
|||
|
|
@ -20,7 +20,8 @@ def upload(file_path, host, flow_id):
|
|||
"""
|
||||
try:
|
||||
url = f"{host}/api/v1/upload/{flow_id}"
|
||||
response = httpx.post(url, files={"file": open(file_path, "rb")})
|
||||
with open(file_path, "rb") as file:
|
||||
response = httpx.post(url, files={"file": file})
|
||||
if response.status_code == 200:
|
||||
return response.json()
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -169,7 +169,7 @@ class DatabaseService(Service):
|
|||
# which is a buffer
|
||||
# I don't want to output anything
|
||||
# subprocess.DEVNULL is an int
|
||||
buffer = open(self.script_location / "alembic.log", "w")
|
||||
with open(self.script_location / "alembic.log", "w") as buffer:
|
||||
alembic_cfg = Config(stdout=buffer)
|
||||
# alembic_cfg.attributes["connection"] = session
|
||||
alembic_cfg.set_main_option("script_location", str(self.script_location))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue