Skip to content

Commit c75667d

Browse files
committed
Change from setup.py to pyproject.toml
1 parent b2b2823 commit c75667d

16 files changed

+127
-100
lines changed

Makefile

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,23 @@
11
NAME = $(shell basename $(CURDIR))
22
PYNAME = $(subst -,_,$(NAME))
33

4-
all:
5-
@echo "Type sudo make install|uninstall"
6-
@echo "or make sdist|upload|check|clean"
7-
8-
install:
9-
pip3 install -U --root-user-action=ignore .
10-
11-
uninstall:
12-
pip3 uninstall --root-user-action=ignore $(NAME)
4+
check:
5+
ruff .
6+
flake8 */*.py
7+
mypy */*.py
8+
pyright */*.py
9+
vermin -vv --exclude importlib.resources.files --no-tips -i */*.py */*/*.py
1310

14-
sdist:
11+
build:
1512
rm -rf dist
16-
python3 setup.py sdist bdist_wheel
13+
python3 -m build
1714

18-
upload: sdist
19-
twine3 upload --skip-existing dist/*
15+
upload: build
16+
twine3 upload dist/*
2017

21-
check:
22-
ruff .
23-
vermin --no-tips -i $(PYNAME).py setup.py
24-
python3 setup.py check
25-
shellcheck plugins/*
18+
doc:
19+
update-readme-usage
2620

2721
clean:
28-
@rm -vrf *.egg-info build/ dist/ __pycache__/
22+
@rm -vrf *.egg-info */*.egg-info .venv/ build/ dist/ __pycache__/ \
23+
*/__pycache__ */*/__pycache__

README.md

Lines changed: 46 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,16 @@ default plugins provided are:
1010

1111
1. Plugin to inhibit sleep while any audio is playing.
1212

13-
2. Plugin to inhibit sleep while [Plex](https://plex.tv/) media server is serving
14-
content.
13+
2. Plugins to inhibit sleep while [Plex](https://plex.tv/) or
14+
[Jellyfin](https://jellyfin.org/) media server is serving media
15+
server is serving content.
1516

16-
3. Plugin to inhibit sleep while [Jellyfin](https://jellyfin.org/) media server is serving
17-
content.
18-
19-
4. Plugin to inhibit sleep while a specified process is running. I
17+
3. Plugin to inhibit sleep while a specified process is running. I
2018
use this to prevent sleep while my home backup is running.
2119

2220
You can also create your own custom plugins. They are extremely trivial
2321
to create as can be seen in the [provided
24-
examples](https://github.com/bulletmark/sleep-inhibitor/tree/master/plugins).
22+
examples](sleep_inhibitor/plugins).
2523
A plugin can be created in shell script or any programming language. It
2624
must simply return an exit code to indicate whether the system should can be
2725
slept/suspended, or not. _Sleep-inhibitor_ runs each plugin at the
@@ -31,23 +29,23 @@ inhibit sleep or not until at least the next check period.
3129
The latest version of this document and code is available at
3230
https://github.com/bulletmark/sleep-inhibitor.
3331

34-
:warning: **Warning**: Unfortunately this program is currently slightly
32+
:warning: **Warning**: Unfortunately this program is currently somewhat
3533
handicapped due to [this systemd
3634
issue](https://github.com/systemd/systemd/issues/14812). Until this
3735
issue is addressed, your system may not automatically [re-]suspend if
3836
still idle after it has been inhibited, even though _sleep-inhibitor_
3937
has removed the inhibit.
4038

41-
### Motivation
39+
## Motivation
4240

4341
When looking for a solution for this issue I found the
4442
[autosuspend](https://autosuspend.readthedocs.io/en/3.0/index.html)
45-
package but, apart from providing plugins, that package actually
43+
package but, in addition to providing plugins, that package also
4644
implements the complete sleep, resume, and wakeup logic. I also found
4745
the configuration and documentation confusing. I am happy with and
48-
prefer to use the native sleep systems and I desired a simpler more
49-
lightweight approach that merely provided the ability to inhibit sleep
50-
for some special situations.
46+
prefer to use the native Linux sleep systems and I desired a simpler
47+
more lightweight approach that merely provided the ability to inhibit
48+
these sleep systems for some special situations.
5149

5250
1. On Linux desktop systems, I prefer to use the standard GNOME power
5351
management GUI tools to automatically manage sleep/suspend (via
@@ -67,7 +65,7 @@ inhibit sleep for specified conditions. _Sleep-inhibitor_ uses
6765
[`systemd-inhibit`](https://www.freedesktop.org/software/systemd/man/systemd-inhibit.html)
6866
to execute the sleep inhibition lock.
6967

70-
### Installation
68+
## Installation
7169

7270
[Arch](https://www.archlinux.org/) users can just install
7371
[_sleep-inhibitor_ from the
@@ -77,50 +75,52 @@ the next Configuration section.
7775
Python 3.7 or later is required. The 3rd party ruamel.yaml package is
7876
also required. Note [_sleep-inhibitor_ is on
7977
PyPI](https://pypi.org/project/sleep-inhibitor/) so just ensure that
80-
`python3-pip` and `python3-wheel` are installed then type the following
81-
to install (or upgrade):
78+
[`pipx`](https://pypa.github.io/pipx/) is installed then use it to
79+
install [`pipxx`](https://github.com/bulletmark/pipxx):
80+
81+
$ pipx install pipxx
8282

83-
$ sudo pip3 install -U sleep-inhibitor
83+
Then use `pipxx` to install sleep-inhibitor:
8484

85-
If you want to install it yourself from the source repository:
85+
$ sudo pipxx install sleep-inhibitor
8686

87-
$ git clone https://github.com/bulletmark/sleep-inhibitor.git
88-
$ cd sleep-inhibitor
89-
$ sudo pip3 install -U .
87+
To upgrade:
9088

91-
To uninstall:
89+
$ sudo pipxx upgrade sleep-inhibitor
9290

93-
$ sudo pip3 uninstall sleep-inhibitor
91+
To remove:
92+
93+
$ sudo pipxx uninstall sleep-inhibitor
9494

9595
Some plugins require other software to be installed. E.g. If you use the
96-
[`plex-media-server`](https://github.com/bulletmark/sleep-inhibitor/blob/master/plugins/plex-media-server)
96+
[`plex-media-server`](sleep_inhibitor/plugins/plex-media-server)
9797
or
98-
[`jellyfin-server`](https://github.com/bulletmark/sleep-inhibitor/blob/master/plugins/jellyfin-server)
98+
[`jellyfin-server`](sleep_inhibitor/plugins/jellyfin-server)
9999
plugins then you must install [`curl`](https://curl.se/).
100100

101-
### Configuration
101+
## Configuration
102102

103103
To start, copy the sample
104-
[`sleep-inhibitor.conf`](https://github.com/bulletmark/sleep-inhibitor/blob/master/sleep-inhibitor.conf)
104+
[`sleep-inhibitor.conf`](sleep_inhibitor/sleep-inhibitor.conf)
105105
configuration file to `/etc/sleep-inhibitor.conf` and then edit the
106106
sample settings in that target file to add/configure plugins to your
107107
requirements. The instructions and a description of all configuration
108108
options are fully documented in the [sample configuration
109-
file](https://github.com/bulletmark/sleep-inhibitor/blob/master/sleep-inhibitor.conf).
109+
file](sleep_inhibitor/sleep-inhibitor.conf).
110110

111-
$ sudo cp /usr/share/sleep-inhibitor/sleep-inhibitor.conf /etc
111+
$ sudo cp "$(sleep-inhibitor -P)/sleep-inhibitor.conf" /etc
112112
$ sudoedit /etc/sleep-inhibitor.conf
113113

114-
### Automatic Startup as systemd Service
114+
## Automatic Startup as systemd Service
115115

116116
If you installed from source or via `pip` then copy the included
117-
[`sleep-inhibitor.service`](https://github.com/bulletmark/sleep-inhibitor/blob/master/sleep-inhibitor.service)
117+
[`sleep-inhibitor.service`](sleep-/sleep-inhibitor.service)
118118
to `/etc/systemd/system/` (note that [Arch](https://www.archlinux.org/)
119119
users who installed from
120120
[AUR](https://aur.archlinux.org/packages/sleep-inhibitor) can skip this
121121
first step):
122122

123-
$ sudo cp /usr/share/sleep-inhibitor/sleep-inhibitor.service /etc/systemd/system/
123+
$ sudo cp "$(sleep-inhibitor -P)/sleep-inhibitor.service" /etc/systemd/system/
124124

125125
Start sleep-indicator and enable it to automatically start at reboot with:
126126

@@ -135,37 +135,39 @@ To see status and logs:
135135
$ systemctl status sleep-inhibitor
136136
$ journalctl -u sleep-inhibitor
137137

138-
### Plugins
138+
## Plugins
139139

140140
To use the [standard
141-
plugins](https://github.com/bulletmark/sleep-inhibitor/tree/master/plugins)
141+
plugins](sleep_inhibitor/plugins)
142142
distributed with this package just specify the plugin name (i.e. the
143143
file name) as the `path` parameter in the [configuration
144-
file](https://github.com/bulletmark/sleep-inhibitor/blob/master/sleep-inhibitor.conf).
144+
file](sleep_inhibitor/sleep-inhibitor.conf).
145145
To use your own custom plugins, just specify the absolute path to that
146146
plugin. E.g. you can put your custom plugin at `/home/user/bin/myplugin`
147147
and just specify that full path in the [configuration
148-
file](https://github.com/bulletmark/sleep-inhibitor/blob/master/sleep-inhibitor.conf).
148+
file](sleep_inhibitor/sleep-inhibitor.conf).
149149

150150
A plugin can be any executable script/program which simply returns exit
151151
code 254 to inhibit suspend, or anything else (usually 0 of course) to
152152
not suspend. They can be very trivial to create as the provided [example
153-
plugins](https://github.com/bulletmark/sleep-inhibitor/tree/master/plugins)
153+
plugins](sleep_inhibitor/plugins)
154154
demonstrate. A plugin can be created in any language you prefer such as
155155
Shell, Python, Ruby, C/C++, etc.
156156

157157
The plugin does not normally receive any arguments although you can
158158
choose to specify arbitrary arguments to any plugin via the configuration
159159
file, e.g. a sensitive token/password as the example
160-
[`plex-media-server`](https://github.com/bulletmark/sleep-inhibitor/blob/master/plugins/plex-media-server)
160+
[`plex-media-server`](sleep_inhibitor/plugins/plex-media-server)
161161
plugin requires, or the process name for the example
162-
[`is-process-running`](https://github.com/bulletmark/sleep-inhibitor/blob/master/plugins/is-process-running)
162+
[`is-process-running`](sleep_inhibitor/plugins/is-process-running)
163163
plugin.
164164

165-
### Command Line Usage
165+
## Command Line Usage
166+
167+
Type `sleep-inhibitor -h` to view the usage summary:
166168

167169
```
168-
usage: sleep-inhibitor [-h] [-c CONFIG] [-p PLUGIN_DIR]
170+
usage: sleep-inhibitor [-h] [-c CONFIG] [-p PLUGIN_DIR] [-P]
169171
170172
Program to run plugins to inhibit system sleep/suspend.
171173
@@ -175,9 +177,11 @@ options:
175177
alternative configuration file
176178
-p PLUGIN_DIR, --plugin-dir PLUGIN_DIR
177179
alternative plugin dir
180+
-P, --package-dir just show directory where sample conf/service files,
181+
and default plugins can be found
178182
```
179183

180-
### License
184+
## License
181185

182186
Copyright (C) 2020 Mark Blakeney. This program is distributed under the
183187
terms of the GNU General Public License. This program is free software:

pyproject.toml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
[build-system]
2+
requires = ["setuptools>=61.0", "setuptools-scm[toml]>=6.2"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "sleep-inhibitor"
7+
description = "Program to run plugins to inhibit system sleep/suspend/hibernate"
8+
readme = "README.md"
9+
requires-python = ">=3.7"
10+
keywords = ["bash", "systemd-inhibit", "sleep", "suspend", "hibernate"]
11+
classifiers = [
12+
"Programming Language :: Python :: 3",
13+
]
14+
dynamic = ["version"]
15+
dependencies = [
16+
"ruamel.yaml",
17+
"importlib-resources; python_version < '3.10'",
18+
]
19+
20+
[[project.authors]]
21+
name = "Mark Blakeney"
22+
email = "mark.blakeney@bullet-systems.net"
23+
24+
[project.urls]
25+
Homepage = "https://github.com/bulletmark/sleep-inhibitor"
26+
27+
[project.scripts]
28+
sleep-inhibitor = "sleep_inhibitor.sleep_inhibitor:main"
29+
30+
[project.license]
31+
text = "GPLv3"
32+
33+
[tool.setuptools.package-data]
34+
"*" = ["*.conf", "*.service", "plugins/*"]
35+
36+
[tool.setuptools_scm]
37+
version_scheme = "post-release"
38+
39+
[tool.edit-lint]
40+
linters = [
41+
"ruff",
42+
"flake8",
43+
"mypy",
44+
"pyright",
45+
]
46+
47+
# vim:se sw=2:

setup.py

Lines changed: 0 additions & 37 deletions
This file was deleted.

sleep_inhibitor/__init__.py

Whitespace-only changes.

sleep_inhibitor/__main__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from sys import exit
2+
from . import sleep_inhibitor
3+
if __name__ == '__main__':
4+
exit(sleep_inhibitor.main())
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)