Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace file reads and writes utilizing Path (fixes #8) #9

Merged
merged 3 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Changes
3.1 (unreleased)
================

- Nothing changed yet.
- Modify read/write operations to use Path() to avoid dangling file handles


3.0 (2023-02-07)
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import os
from pathlib import Path

from setuptools import find_packages
from setuptools import setup


def read(*rnames):
return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
return Path(os.path.join(os.path.dirname(__file__), *rnames)).read_text()


long_description = (
Expand Down
12 changes: 7 additions & 5 deletions src/zc/zodbrecipes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import logging
import os
from io import StringIO
from pathlib import Path

import zc.buildout
import zc.recipe.egg
Expand Down Expand Up @@ -106,7 +107,7 @@ def install(self):

logrotate = options['logrotate']
if logrotate:
open(logrotate, 'w').write(logrotate_template % dict(
Path(logrotate).write_text(logrotate_template % dict(
logfile=event_log_path,
rc=os.path.join(options['rc-directory'], rc),
conf=zdaemon_conf_path,
Expand Down Expand Up @@ -202,8 +203,8 @@ def install(self):
self.egg.install()
requirements, ws = self.egg.working_set()

open(zeo_conf_path, 'w').write(str(zeo_conf))
open(zdaemon_conf_path, 'w').write(str(zdaemon_conf))
Path(zeo_conf_path).write_text(str(zeo_conf))
Path(zdaemon_conf_path).write_text(str(zdaemon_conf))

if options.get('shell-script') == 'true':
if not os.path.exists(options['zdaemon']):
Expand All @@ -221,8 +222,9 @@ def install(self):
contents = "#!/bin/sh\n%s\n" % contents

dest = os.path.join(options['rc-directory'], rc)
if not (os.path.exists(dest) and open(dest).read() == contents):
open(dest, 'w').write(contents)
if not (os.path.exists(dest) and
Path(dest).read_text() == contents):
Path(dest).write_text(contents)
os.chmod(dest, 0o755)
logger.info("Generated shell script %r.", dest)

Expand Down