Skip to content

Commit 93a873c

Browse files
committed
STY: format Python files using black
1 parent 9b2f2f2 commit 93a873c

File tree

9 files changed

+206
-208
lines changed

9 files changed

+206
-208
lines changed

jupyter_spaces/magics.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
@magics_class
1010
class SpaceMagic(Magics):
11-
1211
@cell_magic
1312
def space(self, line, cell):
1413
"""Execute cell contents using the space namespace as locals and the
@@ -25,8 +24,7 @@ def space(self, line, cell):
2524
... alpha = 0.50
2625
... print(alpha)
2726
"""
28-
space = space_register.get_space(
29-
name=line, outer_space=self.shell.user_ns)
27+
space = space_register.get_space(name=line, outer_space=self.shell.user_ns)
3028
space.execute(source=cell)
3129

3230
@line_magic

jupyter_spaces/space.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
class SpaceRegister:
5-
__slots__ = ['_register']
5+
__slots__ = ["_register"]
66

77
def __init__(self):
88
"""Instantiate SpaceRegister."""
@@ -44,16 +44,18 @@ def remove_space(self, name):
4444
try:
4545
del self._register[name]
4646
except KeyError:
47-
raise RegistryError('Cannot remove space {name} because '
48-
'it does not exist'.format(name=name))
47+
raise RegistryError(
48+
"Cannot remove space {name} because "
49+
"it does not exist".format(name=name)
50+
)
4951

5052
def remove_all_spaces(self):
5153
"""Remove all Spaces from register."""
5254
self._register.clear()
5355

5456

5557
class Space:
56-
__slots__ = ['_execution_namespace', '_name']
58+
__slots__ = ["_execution_namespace", "_name"]
5759

5860
def __init__(self, name, outer_space):
5961
"""Instantiate Space.
@@ -64,11 +66,13 @@ def __init__(self, name, outer_space):
6466
"""
6567
self._name = name
6668
self._execution_namespace = ExecutionNamespace(
67-
global_references=outer_space, local_references={})
69+
global_references=outer_space, local_references={}
70+
)
6871

6972
def __repr__(self):
70-
return 'Space(name={name}, size={size:d})'.format(
71-
name=self.name, size=len(self.namespace))
73+
return "Space(name={name}, size={size:d})".format(
74+
name=self.name, size=len(self.namespace)
75+
)
7276

7377
@property
7478
def name(self):
@@ -101,7 +105,6 @@ def execute(self, source):
101105

102106

103107
class ExecutionNamespace(dict):
104-
105108
def __init__(self, global_references, local_references):
106109
"""Instantiate ExecutionNamespace.
107110

requirements/dev_requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
black==19.10b0

setup.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
#!/usr/bin/env python
22
from setuptools import find_packages, setup
33

4-
NAME = 'jupyter_spaces'
5-
VERSION = '0.1.2'
6-
AUTHOR = 'Davide Sarra'
7-
URL = 'https://github.com/davidesarra/jupyter_spaces'
8-
DESCRIPTION = 'Create parallel namespaces in Jupyter Notebooks'
9-
LICENSE = 'MIT'
4+
NAME = "jupyter_spaces"
5+
VERSION = "0.1.2"
6+
AUTHOR = "Davide Sarra"
7+
URL = "https://github.com/davidesarra/jupyter_spaces"
8+
DESCRIPTION = "Create parallel namespaces in Jupyter Notebooks"
9+
LICENSE = "MIT"
1010
CLASSIFIERS = [
11-
'Environment :: Console',
12-
'Framework :: IPython',
13-
'Framework :: Jupyter',
14-
'Intended Audience :: Developers',
15-
'Intended Audience :: Science/Research',
16-
'License :: OSI Approved :: MIT License',
17-
'Operating System :: OS Independent',
18-
'Programming Language :: Python :: 3',
19-
'Programming Language :: Python :: 3.5',
20-
'Programming Language :: Python :: 3.6',
21-
'Programming Language :: Python :: 3.7',
22-
'Programming Language :: Python :: 3.8',
11+
"Environment :: Console",
12+
"Framework :: IPython",
13+
"Framework :: Jupyter",
14+
"Intended Audience :: Developers",
15+
"Intended Audience :: Science/Research",
16+
"License :: OSI Approved :: MIT License",
17+
"Operating System :: OS Independent",
18+
"Programming Language :: Python :: 3",
19+
"Programming Language :: Python :: 3.5",
20+
"Programming Language :: Python :: 3.6",
21+
"Programming Language :: Python :: 3.7",
22+
"Programming Language :: Python :: 3.8",
2323
]
24-
KEYWORDS = 'jupyter ipython magic extension namespace'
24+
KEYWORDS = "jupyter ipython magic extension namespace"
2525

26-
with open('README.md', 'r') as f:
26+
with open("README.md", "r") as f:
2727
LONG_DESCRIPTION = f.read()
2828

2929
REQUIREMENTS = [
30-
'ipython>=5.0.0',
30+
"ipython>=5.0.0",
3131
]
3232

3333
if __name__ == "__main__":
@@ -41,8 +41,8 @@
4141
keywords=KEYWORDS,
4242
description=DESCRIPTION,
4343
long_description=LONG_DESCRIPTION,
44-
long_description_content_type='text/markdown',
45-
packages=find_packages(exclude=['tests']),
44+
long_description_content_type="text/markdown",
45+
packages=find_packages(exclude=["tests"]),
4646
install_requires=REQUIREMENTS,
47-
python_requires='~=3.5',
47+
python_requires="~=3.5",
4848
)

tests/conftest.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
import pytest
33

44

5-
@pytest.fixture(scope='session')
5+
@pytest.fixture(scope="session")
66
def session_ip():
77
return start_ipython()
88

99

10-
@pytest.fixture(scope='function')
10+
@pytest.fixture(scope="function")
1111
def ip(session_ip):
12-
session_ip.run_line_magic(magic_name='load_ext', line='jupyter_spaces')
12+
session_ip.run_line_magic(magic_name="load_ext", line="jupyter_spaces")
1313
yield session_ip
14-
session_ip.run_line_magic(magic_name='unload_ext', line='jupyter_spaces')
15-
session_ip.run_line_magic(magic_name='reset', line='-f')
14+
session_ip.run_line_magic(magic_name="unload_ext", line="jupyter_spaces")
15+
session_ip.run_line_magic(magic_name="reset", line="-f")

tests/test_magics.py

Lines changed: 79 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -3,154 +3,156 @@
33

44

55
def test_space_can_access_user_namespace_references(ip):
6-
ip.run_cell(raw_cell='x = 100')
7-
ip.run_cell_magic(magic_name='space', line='tomato', cell='x')
6+
ip.run_cell(raw_cell="x = 100")
7+
ip.run_cell_magic(magic_name="space", line="tomato", cell="x")
88

99

1010
def test_space_references_prioritized_over_user_namespace_references(ip):
11-
ip.run_cell(raw_cell='x = 100')
12-
ip.run_cell_magic(magic_name='space', line='tomato',
13-
cell='x = 99; assert x == 99')
11+
ip.run_cell(raw_cell="x = 100")
12+
ip.run_cell_magic(magic_name="space", line="tomato", cell="x = 99; assert x == 99")
1413

1514

1615
def test_space_cannot_alter_user_namespace_immutable_references(ip):
17-
ip.run_cell(raw_cell='x = 100')
18-
ip.run_cell_magic(magic_name='space', line='tomato', cell='x = 99')
19-
assert ip.user_global_ns['x'] == 100
16+
ip.run_cell(raw_cell="x = 100")
17+
ip.run_cell_magic(magic_name="space", line="tomato", cell="x = 99")
18+
assert ip.user_global_ns["x"] == 100
2019

2120

2221
def test_space_can_alter_user_namespace_mutable_references(ip):
23-
ip.run_cell(raw_cell='x = [1, 2, 3]')
24-
ip.run_cell_magic(magic_name='space', line='tomato',
25-
cell='x[-1] = 10')
26-
assert ip.user_global_ns['x'] == [1, 2, 10]
22+
ip.run_cell(raw_cell="x = [1, 2, 3]")
23+
ip.run_cell_magic(magic_name="space", line="tomato", cell="x[-1] = 10")
24+
assert ip.user_global_ns["x"] == [1, 2, 10]
2725

2826

2927
def test_space_cannot_alter_user_namespace_references_using_global(ip):
30-
ip.run_cell(raw_cell='x = 100')
31-
ip.run_cell_magic(magic_name='space', line='tomato',
32-
cell='global x; x = 99')
33-
assert ip.user_global_ns['x'] == 100
28+
ip.run_cell(raw_cell="x = 100")
29+
ip.run_cell_magic(magic_name="space", line="tomato", cell="global x; x = 99")
30+
assert ip.user_global_ns["x"] == 100
3431

3532

3633
def test_space_cannot_remove_user_namespace_references(ip):
37-
ip.run_cell(raw_cell='x = 100')
34+
ip.run_cell(raw_cell="x = 100")
3835
with raises(NameError):
39-
ip.run_cell_magic(magic_name='space', line='tomato', cell='del x')
40-
assert ip.user_global_ns['x'] == 100
36+
ip.run_cell_magic(magic_name="space", line="tomato", cell="del x")
37+
assert ip.user_global_ns["x"] == 100
4138

4239

4340
def test_space_cannot_remove_user_namespace_references_using_global(ip):
44-
ip.run_cell(raw_cell='x = 100')
41+
ip.run_cell(raw_cell="x = 100")
4542
with raises(NameError):
46-
ip.run_cell_magic(magic_name='space', line='tomato',
47-
cell='global x; del x')
48-
assert 'x' in ip.user_global_ns
43+
ip.run_cell_magic(magic_name="space", line="tomato", cell="global x; del x")
44+
assert "x" in ip.user_global_ns
4945

5046

5147
def test_space_cannot_add_user_namespace_references(ip):
52-
ip.run_cell_magic(magic_name='space', line='tomato', cell='x = 99')
53-
assert 'x' not in ip.user_global_ns
48+
ip.run_cell_magic(magic_name="space", line="tomato", cell="x = 99")
49+
assert "x" not in ip.user_global_ns
5450

5551

5652
def test_space_cannot_add_user_namespace_references_using_global(ip):
57-
ip.run_cell_magic(magic_name='space', line='tomato',
58-
cell='global x; x = 99')
59-
assert 'x' not in ip.user_global_ns
53+
ip.run_cell_magic(magic_name="space", line="tomato", cell="global x; x = 99")
54+
assert "x" not in ip.user_global_ns
6055

6156

6257
def test_space_reference_assignments_persist_in_new_magic_call(ip):
63-
ip.run_cell_magic(magic_name='space', line='tomato', cell='x = 99')
64-
ip.run_cell_magic(magic_name='space', line='tomato', cell='assert x == 99')
58+
ip.run_cell_magic(magic_name="space", line="tomato", cell="x = 99")
59+
ip.run_cell_magic(magic_name="space", line="tomato", cell="assert x == 99")
6560

6661

6762
def test_space_reference_deletions_persist_in_new_magic_call(ip):
68-
ip.run_cell_magic(magic_name='space', line='tomato', cell='x = 99')
69-
ip.run_cell_magic(magic_name='space', line='tomato', cell='del x')
63+
ip.run_cell_magic(magic_name="space", line="tomato", cell="x = 99")
64+
ip.run_cell_magic(magic_name="space", line="tomato", cell="del x")
7065
with raises(NameError):
71-
ip.run_cell_magic(magic_name='space', line='tomato', cell='x')
66+
ip.run_cell_magic(magic_name="space", line="tomato", cell="x")
7267

7368

7469
def test_space_references_assignments_are_confined_in_one_space_only(ip):
75-
ip.run_cell_magic(magic_name='space', line='tomato', cell='x = 99')
76-
ip.run_cell_magic(magic_name='space', line='potato', cell='x = 100')
77-
ip.run_cell_magic(magic_name='space', line='tomato', cell='assert x == 99')
70+
ip.run_cell_magic(magic_name="space", line="tomato", cell="x = 99")
71+
ip.run_cell_magic(magic_name="space", line="potato", cell="x = 100")
72+
ip.run_cell_magic(magic_name="space", line="tomato", cell="assert x == 99")
7873

7974

8075
def test_space_references_deletions_are_confined_in_one_space_only(ip):
81-
ip.run_cell_magic(magic_name='space', line='tomato', cell='x = 99')
76+
ip.run_cell_magic(magic_name="space", line="tomato", cell="x = 99")
8277
with raises(NameError):
83-
ip.run_cell_magic(magic_name='space', line='potato', cell='del x')
84-
ip.run_cell_magic(magic_name='space', line='tomato', cell='assert x == 99')
78+
ip.run_cell_magic(magic_name="space", line="potato", cell="del x")
79+
ip.run_cell_magic(magic_name="space", line="tomato", cell="assert x == 99")
8580

8681

8782
def test_space_can_execute_newly_defined_lambda_functions(ip):
88-
ip.run_cell_magic(magic_name='space', line='tomato',
89-
cell='f = lambda x: x + 1; y = f(x=2); assert y == 3')
83+
ip.run_cell_magic(
84+
magic_name="space",
85+
line="tomato",
86+
cell="f = lambda x: x + 1; y = f(x=2); assert y == 3",
87+
)
9088

9189

9290
def test_space_can_execute_newly_defined_functions(ip):
93-
ip.run_cell_magic(magic_name='space', line='tomato',
94-
cell='def f(x): return x + 1; y = f(x=2); assert y == 3')
91+
ip.run_cell_magic(
92+
magic_name="space",
93+
line="tomato",
94+
cell="def f(x): return x + 1; y = f(x=2); assert y == 3",
95+
)
9596

9697

9798
def test_space_can_execute_top_level_non_closure_functions(ip):
98-
ip.run_cell_magic(magic_name='space', line='tomato',
99-
cell=('def f(x): return x + 1\n'
100-
'def g(x): return f(x=x) * 2\n'
101-
'y = g(x=3)'))
102-
ip.run_cell_magic(magic_name='space', line='tomato', cell='assert y == 8')
99+
ip.run_cell_magic(
100+
magic_name="space",
101+
line="tomato",
102+
cell="def f(x): return x + 1\ndef g(x): return f(x=x) * 2\ny = g(x=3)",
103+
)
104+
ip.run_cell_magic(magic_name="space", line="tomato", cell="assert y == 8")
103105

104106

105107
def test_get_spaces_can_access_space_references(ip):
106-
ip.run_cell(raw_cell='from jupyter_spaces import get_spaces')
107-
ip.run_cell_magic(magic_name='space', line='tomato', cell='x = 99')
108-
ip.run_cell(raw_cell='spaces = get_spaces()')
109-
assert ip.user_global_ns['spaces']['tomato'].namespace['x'] == 99
108+
ip.run_cell(raw_cell="from jupyter_spaces import get_spaces")
109+
ip.run_cell_magic(magic_name="space", line="tomato", cell="x = 99")
110+
ip.run_cell(raw_cell="spaces = get_spaces()")
111+
assert ip.user_global_ns["spaces"]["tomato"].namespace["x"] == 99
110112

111113

112114
def test_get_spaces_can_alter_space_references(ip):
113-
ip.run_cell(raw_cell='from jupyter_spaces import get_spaces')
114-
ip.run_cell_magic(magic_name='space', line='tomato', cell='x = 99')
115-
ip.run_cell(raw_cell='spaces = get_spaces()')
115+
ip.run_cell(raw_cell="from jupyter_spaces import get_spaces")
116+
ip.run_cell_magic(magic_name="space", line="tomato", cell="x = 99")
117+
ip.run_cell(raw_cell="spaces = get_spaces()")
116118
ip.run_cell(raw_cell='spaces["tomato"].namespace["x"] = 101')
117-
assert ip.user_global_ns['spaces']['tomato'].namespace['x'] == 101
119+
assert ip.user_global_ns["spaces"]["tomato"].namespace["x"] == 101
118120

119121

120122
def test_get_spaces_can_remove_space_references(ip):
121-
ip.run_cell(raw_cell='from jupyter_spaces import get_spaces')
122-
ip.run_cell_magic(magic_name='space', line='tomato', cell='x = 99')
123-
ip.run_cell(raw_cell='spaces = get_spaces()')
123+
ip.run_cell(raw_cell="from jupyter_spaces import get_spaces")
124+
ip.run_cell_magic(magic_name="space", line="tomato", cell="x = 99")
125+
ip.run_cell(raw_cell="spaces = get_spaces()")
124126
ip.run_cell(raw_cell='del spaces["tomato"].namespace["x"]')
125-
assert 'x' not in ip.user_global_ns['spaces']['tomato'].namespace
127+
assert "x" not in ip.user_global_ns["spaces"]["tomato"].namespace
126128

127129

128130
def test_get_spaces_reflects_space_references_changes(ip):
129-
ip.run_cell(raw_cell='from jupyter_spaces import get_spaces')
130-
ip.run_cell_magic(magic_name='space', line='tomato', cell='x = 99')
131-
ip.run_cell(raw_cell='spaces = get_spaces()')
131+
ip.run_cell(raw_cell="from jupyter_spaces import get_spaces")
132+
ip.run_cell_magic(magic_name="space", line="tomato", cell="x = 99")
133+
ip.run_cell(raw_cell="spaces = get_spaces()")
132134
ip.run_cell(raw_cell='spaces["tomato"].namespace["x"] = 101')
133-
ip.run_cell_magic(magic_name='space', line='tomato', cell='x = 11')
134-
assert ip.user_global_ns['spaces']['tomato'].namespace['x'] == 11
135+
ip.run_cell_magic(magic_name="space", line="tomato", cell="x = 11")
136+
assert ip.user_global_ns["spaces"]["tomato"].namespace["x"] == 11
135137

136138

137139
def test_get_spaces_reflects_space_removal(ip):
138-
ip.run_cell(raw_cell='from jupyter_spaces import get_spaces')
139-
ip.run_cell_magic(magic_name='space', line='tomato', cell='x = 99')
140-
ip.run_cell(raw_cell='spaces = get_spaces()')
141-
ip.run_line_magic(magic_name='remove_space', line='tomato')
142-
assert 'tomato' not in ip.user_global_ns['spaces']
140+
ip.run_cell(raw_cell="from jupyter_spaces import get_spaces")
141+
ip.run_cell_magic(magic_name="space", line="tomato", cell="x = 99")
142+
ip.run_cell(raw_cell="spaces = get_spaces()")
143+
ip.run_line_magic(magic_name="remove_space", line="tomato")
144+
assert "tomato" not in ip.user_global_ns["spaces"]
143145

144146

145147
def test_get_spaces_reflects_extension_reload(ip):
146-
ip.run_cell(raw_cell='from jupyter_spaces import get_spaces')
147-
ip.run_cell_magic(magic_name='space', line='tomato', cell='x = 99')
148-
ip.run_cell(raw_cell='spaces = get_spaces()')
149-
ip.run_line_magic(magic_name='reload_ext', line='jupyter_spaces')
150-
assert not ip.user_global_ns['spaces']
148+
ip.run_cell(raw_cell="from jupyter_spaces import get_spaces")
149+
ip.run_cell_magic(magic_name="space", line="tomato", cell="x = 99")
150+
ip.run_cell(raw_cell="spaces = get_spaces()")
151+
ip.run_line_magic(magic_name="reload_ext", line="jupyter_spaces")
152+
assert not ip.user_global_ns["spaces"]
151153

152154

153155
def test_space_can_print_to_console(ip):
154156
with capture_output() as captured:
155-
ip.run_cell_magic(magic_name='space', line='tomato', cell='print(100)')
156-
assert captured.stdout == '100\n'
157+
ip.run_cell_magic(magic_name="space", line="tomato", cell="print(100)")
158+
assert captured.stdout == "100\n"

0 commit comments

Comments
 (0)