jenkins-bot has submitted this change and it was merged.
Change subject: [FIX] Safely close the files ......................................................................
[FIX] Safely close the files
Change-Id: I0b3f7fcca3b79474fd3cc21257ccb6e82087590b --- M pywikibot/version.py 1 file changed, 7 insertions(+), 5 deletions(-)
Approvals: Nullzero: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/version.py b/pywikibot/version.py index 8826a4d..0b7d873 100644 --- a/pywikibot/version.py +++ b/pywikibot/version.py @@ -143,7 +143,8 @@ # some windows git versions provide git.cmd instead of git.exe cmd = 'git.cmd'
- tag = open(os.path.join(_program_dir, '.git/config'), 'r').read() + with open(os.path.join(_program_dir, '.git/config'), 'r') as f: + tag = f.read() # Try 'origin' and then 'gerrit' as remote name; bail if can't find either. remote_pos = tag.find('[remote "origin"]') if remote_pos == -1: @@ -213,10 +214,11 @@ mtime = None fn = os.path.join(_program_dir, filename) if os.path.exists(fn): - for line in open(fn, 'r').readlines(): - if line.find('__version__') == 0: - exec(line) - break + with open(fn, 'r') as f: + for line in f.readlines(): + if line.find('__version__') == 0: + exec(line) + break stat = os.stat(fn) mtime = datetime.datetime.fromtimestamp(stat.st_mtime).isoformat(' ') if mtime and __version__:
pywikibot-commits@lists.wikimedia.org