Skip to content

Commit 86b1062

Browse files
committed
Fix determination of plugin dir
1 parent 3ccca2f commit 86b1062

File tree

2 files changed

+9
-23
lines changed

2 files changed

+9
-23
lines changed

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ classifiers = [
1414
dynamic = ["version"]
1515
dependencies = [
1616
"ruamel.yaml",
17-
"importlib-resources; python_version < '3.10'",
1817
]
1918

2019
[[project.authors]]

sleep_inhibitor/sleep_inhibitor.py

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,6 @@
2222

2323
TIMEMULTS = {'s': 1, 'm': 60, 'h': 3600}
2424

25-
def get_package_dir(prog):
26-
if sys.version_info >= (3, 10):
27-
from importlib.resources import files
28-
else:
29-
from importlib_resources import files
30-
31-
return files(Path(prog).stem.replace('-', '_'))
32-
3325
def conv_to_secs(val):
3426
'Convert given time string to float seconds'
3527
# Default input time value (without qualifier) is minutes
@@ -138,8 +130,10 @@ def init():
138130
opt.add_argument('-i', '--inhibit', help=argparse.SUPPRESS)
139131
args = opt.parse_args()
140132

133+
base_dir = Path(__file__).resolve().parent
134+
141135
if args.package_dir:
142-
print(get_package_dir(opt.prog))
136+
print(base_dir)
143137
sys.exit()
144138

145139
# This instance may be a child invocation merely to run and check
@@ -178,25 +172,16 @@ def init():
178172
opts = ' or '.join(SYSTEMD_SLEEP_PROGS)
179173
sys.exit(f'No systemd-inhibitor app installed from one of {opts}.')
180174

181-
# Work out plugin and base dirs for this installation
182-
plugin_dir = Path(sys.prefix) / 'share' / progname / 'plugins'
183-
if plugin_dir.exists():
184-
base_dir = plugin_dir.parent
185-
else:
186-
plugin_dir = None
187-
base_dir = None
188-
189175
# Determine config file path
190176
cname = progname + '.conf'
191177
cfile = Path(args.config).expanduser() if args.config else \
192178
Path(f'/etc/{cname}')
193179

194180
if not cfile.exists():
195-
print(f'Configuration file {cfile} does not exist.', file=sys.stderr)
196-
if base_dir and not args.config:
197-
print(f'Copy {base_dir}/{cname} to /etc and edit appropriately.',
198-
file=sys.stderr)
199-
sys.exit()
181+
err = f'Configuration file {cfile} does not exist.'
182+
if not args.config:
183+
err += f' Copy {base_dir}/{cname} to /etc and edit appropriately.'
184+
sys.exit(err)
200185

201186
from ruamel.yaml import YAML
202187
conf = YAML(typ='safe').load(cfile)
@@ -206,6 +191,8 @@ def init():
206191
sys.exit('No plugins configured')
207192

208193
# Work out plugin dir
194+
plugin_dir = base_dir / 'plugins'
195+
plugin_dir = str(plugin_dir) if plugin_dir.is_dir() else None
209196
plugin_dir = args.plugin_dir or conf.get('plugin_dir', plugin_dir)
210197

211198
# Get some global defaults

0 commit comments

Comments
 (0)