Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
slapos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Steven Gueguen
slapos
Commits
1e69e4aa
Commit
1e69e4aa
authored
Jun 02, 2023
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Plain Diff
stack/macros: Simplify pythonpath macro
See merge request
nexedi/slapos!1398
parents
7b5b1967
43e5bde0
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
70 additions
and
67 deletions
+70
-67
component/macros/macro.pythonpath.eggs.cfg
component/macros/macro.pythonpath.eggs.cfg
+10
-18
software/jupyter/test/test.py
software/jupyter/test/test.py
+60
-49
No files found.
component/macros/macro.pythonpath.eggs.cfg
View file @
1e69e4aa
...
...
@@ -3,22 +3,14 @@ parts =
[macro.pythonpath.eggs]
recipe = slapos.recipe.build
_name_ = ${:_buildout_section_name_}
init =
prerequisite = """
[.%(_name_)s.prerequisite]
recipe = slapos.recipe.build
init =
section = self.buildout['%(_name_)s']
self.eggs = [e.strip() for e in section['eggs'].splitlines() if e.strip()]
update =
self.eggs = [e.strip() for e in options['eggs'].splitlines() if e.strip()]
update =
from zc.buildout.easy_install import working_set
buildout = self.buildout['buildout']
eggs_directory = buildout['eggs-directory']
develop_eggs_directory = buildout['develop-eggs-directory']
dists = working_set(self.eggs, [develop_eggs_directory, eggs_directory])
paths = ':'.join(dist.location for dist in dists)
self.buildout['%(environment)s'
]['PYTHONPATH'] = paths
self.buildout[options['environment']
]['PYTHONPATH'] = paths
print("PYTHONPATH=" + paths)
""" % options
self.buildout.parse(prerequisite)
software/jupyter/test/test.py
View file @
1e69e4aa
...
...
@@ -32,6 +32,7 @@ import os
import
requests
import
sqlite3
import
subprocess
import
tempfile
from
slapos.proxy.db_version
import
DB_VERSION
from
slapos.testing.testcase
import
makeModuleSetUpAndTestCaseClass
...
...
@@ -271,65 +272,75 @@ class TestJupyterCustomAdditional(SelectMixin, InstanceTestCase):
r
.
destroyed
()
class
TestIPython
(
InstanceTestCase
):
converted_notebook
=
'test.nbconvert.ipynb'
notebook_filename
=
'test.ipynb'
test_sentence
=
'test'
class
IPythonNotebook
(
object
):
def
__init__
(
self
,
name
,
binary
):
self
.
tempdir
=
tempdir
=
tempfile
.
TemporaryDirectory
()
path
=
os
.
path
.
join
(
tempdir
.
name
,
name
)
self
.
path
=
path
+
'.ipynb'
# input notebook
self
.
output_path
=
path
+
'.nbconvert.ipynb'
# output notebook
self
.
binary
=
binary
def
setUp
(
self
):
super
().
setUp
()
notebook_source
=
{
def
write
(
self
,
code
):
content
=
{
"cells"
:
[
{
"cell_type"
:
"code"
,
"execution_count"
:
None
,
"metadata"
:
{},
"outputs"
:
[],
"source"
:
[
"import sys
\
n
"
,
"print('"
+
self
.
test_sentence
+
"')"
]
"source"
:
code
.
splitlines
(
keepends
=
True
)
}
],
"metadata"
:
{},
"nbformat"
:
4
,
"nbformat_minor"
:
4
}
with
open
(
self
.
notebook_filename
,
'w'
)
as
notebook
:
notebook
.
write
(
json
.
dumps
(
notebook_source
))
with
open
(
self
.
path
,
'w'
)
as
notebook
:
notebook
.
write
(
json
.
dumps
(
content
))
def
run
(
self
):
return
subprocess
.
check_output
(
(
self
.
binary
,
'--execute'
,
'--to'
,
'notebook'
,
self
.
path
),
stderr
=
subprocess
.
STDOUT
,
text
=
True
)
def
readResult
(
self
):
with
open
(
self
.
output_path
)
as
result
:
return
json
.
loads
(
result
.
read
())[
'cells'
][
0
][
'outputs'
][
0
][
'text'
][
0
]
def
__enter__
(
self
):
return
self
def
__exit__
(
self
,
*
args
):
if
self
.
tempdir
:
self
.
tempdir
.
cleanup
()
del
self
.
tempdir
def
tearDown
(
self
):
os
.
remove
(
self
.
notebook_filename
)
if
os
.
path
.
exists
(
self
.
converted_notebook
):
os
.
remove
(
self
.
converted_notebook
)
super
().
tearDown
()
class
TestIPython
(
InstanceTestCase
):
message
=
'test_sys'
module
=
'sys'
def
test
(
self
):
conversion_output
=
subprocess
.
check_output
([
os
.
path
.
join
(
binary
=
os
.
path
.
join
(
self
.
computer_partition_root_path
,
'software_release'
,
'bin'
,
'jupyter-nbconvert'
,
),
'--execute'
,
'--to'
,
'notebook'
,
self
.
notebook_filename
,
],
stderr
=
subprocess
.
STDOUT
,
text
=
True
)
'software_release'
,
'bin'
,
'jupyter-nbconvert'
)
with
IPythonNotebook
(
'test'
,
binary
)
as
notebook
:
notebook
.
write
(
"import %s
\
n
print(%r)"
%
(
self
.
module
,
self
.
message
))
out
=
notebook
.
run
()
self
.
assertIn
(
'[NbConvertApp] Converting notebook %s to notebook'
%
self
.
notebook_filename
,
conversion_outp
ut
,
"[NbConvertApp] Converting notebook %s to notebook"
%
notebook
.
path
,
o
ut
,
)
self
.
assertRegex
(
conversion_outp
ut
,
r'\
[N
bConvertApp\
] W
riting \
d+
bytes to %s'
%
self
.
converted_notebook
o
ut
,
r"\
[N
bConvertApp\
] W
riting \
d+
bytes to %s"
%
notebook
.
output_path
)
self
.
assertTrue
(
os
.
path
.
exists
(
self
.
converted_notebook
))
with
open
(
self
.
converted_notebook
)
as
json_result
:
self
.
assertEqual
(
json
.
loads
(
json_result
.
read
())[
'cells'
][
0
][
'outputs'
][
0
][
'text'
][
0
],
self
.
test_sentence
+
'
\
n
'
,
)
self
.
assertTrue
(
os
.
path
.
exists
(
notebook
.
output_path
))
self
.
assertEqual
(
notebook
.
readResult
(),
self
.
message
+
'
\
n
'
)
class
TestIPythonNumpy
(
TestIPython
):
message
=
'test_numpy'
module
=
'numpy'
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment