Skip to content

Commit f9f7c52

Browse files
committed
Add back psutil as a dependency
1 parent ef69cad commit f9f7c52

File tree

4 files changed

+24
-40
lines changed

4 files changed

+24
-40
lines changed

CONTRIBUTING.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ We recommend using [pipenv](https://docs.pipenv.org/) to make development easier
1717
```
1818

1919
2. Create an environment that will hold our dependencies.
20-
20+
2121
```bash
2222
cd nbresuse
2323
pipenv --python 3.6
@@ -32,11 +32,9 @@ We recommend using [pipenv](https://docs.pipenv.org/) to make development easier
3232
4. Do a dev install of nbresuse and its dependencies
3333

3434
```bash
35-
pip install --editable .[resources]
35+
pip install --editable .[dev]
3636
```
3737

38-
To test the behavior of NBResuse without `psutil` installed, run `pip install --editable .` instead.
39-
4038
5. Install and enable the nbextension for use with Jupyter Classic Notebook.
4139

4240
```bash
@@ -73,7 +71,7 @@ the pre-commit hook should take care of how it should look. Here is how to set u
7371
```bash
7472
pre-commit run
7573
```
76-
74+
7775
which should run any autoformatting on your code
7876
and tell you about any errors it couldn't fix automatically.
7977
You may also install [black integration](https://github.com/ambv/black#editor-integration)

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@ main toolbar in the notebook itself, refreshing every 5s.
2222
You can currently install this package from PyPI.
2323

2424
```bash
25-
pip install nbresuse[resources]
25+
pip install nbresuse
2626
```
2727

28-
The above command will install NBResuse along with `psutil` Python package (which is used for getting hardware usage information from the system). If you would like to install NBResuse _without_ `psutil` (in which case NBResuse does essentially nothing), run `pip install nbresuse` instead.
29-
3028
**If your notebook version is < 5.3**, you need to enable the extension manually.
3129

3230
```

nbresuse/api.py

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
import json
22

3+
import psutil
34
from notebook.base.handlers import IPythonHandler
45
from tornado import web
56

6-
try:
7-
# since psutil is an optional dependency
8-
import psutil
9-
except ImportError:
10-
psutil = None
11-
127
try:
138
# Traitlets >= 4.3.3
149
from traitlets import Callable
@@ -17,36 +12,30 @@
1712

1813

1914
class ApiHandler(IPythonHandler):
20-
2115
@web.authenticated
2216
async def get(self):
2317
"""
2418
Calculate and return current resource usage metrics
2519
"""
26-
config = self.settings['nbresuse_display_config']
20+
config = self.settings["nbresuse_display_config"]
2721

28-
if psutil:
29-
cur_process = psutil.Process()
30-
all_processes = [cur_process] + cur_process.children(recursive=True)
22+
cur_process = psutil.Process()
23+
all_processes = [cur_process] + cur_process.children(recursive=True)
3124

32-
# Get memory information
33-
rss = sum([p.memory_info().rss for p in all_processes])
25+
# Get memory information
26+
rss = sum([p.memory_info().rss for p in all_processes])
3427

35-
if callable(config.mem_limit):
36-
mem_limit = config.mem_limit(rss=rss)
37-
else: # mem_limit is an Int
38-
mem_limit = config.mem_limit
28+
if callable(config.mem_limit):
29+
mem_limit = config.mem_limit(rss=rss)
30+
else: # mem_limit is an Int
31+
mem_limit = config.mem_limit
3932

40-
limits = {'memory': {
41-
'rss': mem_limit
42-
}}
43-
if config.mem_limit:
44-
limits['memory']['warn'] = (mem_limit - rss) < (
45-
mem_limit * config.mem_warning_threshold)
33+
limits = {"memory": {"rss": mem_limit}}
34+
if config.mem_limit:
35+
limits["memory"]["warn"] = (mem_limit - rss) < (
36+
mem_limit * config.mem_warning_threshold
37+
)
4638

47-
metrics = {
48-
'rss': rss,
49-
'limits': limits,
50-
}
39+
metrics = {"rss": rss, "limits": limits}
5140

52-
self.write(json.dumps(metrics))
41+
self.write(json.dumps(metrics))

setup.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@
2323
"Programming Language :: Python :: 3",
2424
],
2525
packages=setuptools.find_packages(),
26-
install_requires=["notebook>=5.6.0", "prometheus_client"],
27-
extras_require={
28-
"resources": ["psutil>=5.6.0"],
29-
"dev": ["autopep8", "black", "pytest", "flake8", "pytest-cov>=2.6.1", "mock"],
26+
install_requires=["notebook>=5.6.0", "prometheus_client", "psutil>=5.6.0"],
27+
extres_require={
28+
"dev": ["autopep8", "black", "pytest", "flake8", "pytest-cov>=2.6.1", "mock"]
3029
},
3130
data_files=[
3231
("share/jupyter/nbextensions/nbresuse", glob("nbresuse/static/*")),

0 commit comments

Comments
 (0)