mirror of
https://github.com/bndr/pipreqs.git
synced 2025-06-06 03:25:21 +00:00
bugfix: f.close() only required if open succeeded
when open fails, instead of raising the original error, the "f.close()" was erroring in the final clause.
This commit is contained in:
parent
5707a39df6
commit
a7ad636dab
@ -309,9 +309,10 @@ def parse_requirements(file_):
|
|||||||
logging.error("Failed on file: {}".format(file_))
|
logging.error("Failed on file: {}".format(file_))
|
||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
data = [x.strip() for x in f.readlines() if x != "\n"]
|
try:
|
||||||
finally:
|
data = [x.strip() for x in f.readlines() if x != "\n"]
|
||||||
f.close()
|
finally:
|
||||||
|
f.close()
|
||||||
|
|
||||||
data = [x for x in data if x[0].isalpha()]
|
data = [x for x in data if x[0].isalpha()]
|
||||||
|
|
||||||
@ -375,16 +376,17 @@ def clean(file_, imports):
|
|||||||
logging.error("Failed on file: {}".format(file_))
|
logging.error("Failed on file: {}".format(file_))
|
||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
for i in f.readlines():
|
try:
|
||||||
if re_remove.match(i) is None:
|
for i in f.readlines():
|
||||||
to_write.append(i)
|
if re_remove.match(i) is None:
|
||||||
f.seek(0)
|
to_write.append(i)
|
||||||
f.truncate()
|
f.seek(0)
|
||||||
|
f.truncate()
|
||||||
|
|
||||||
for i in to_write:
|
for i in to_write:
|
||||||
f.write(i)
|
f.write(i)
|
||||||
finally:
|
finally:
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
logging.info("Successfully cleaned up requirements in " + file_)
|
logging.info("Successfully cleaned up requirements in " + file_)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user