Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
Tutor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Thomas MENARD
Tutor
Commits
c1e47cec
Commit
c1e47cec
authored
5 years ago
by
Régis Behmo
Browse files
Options
Downloads
Patches
Plain Diff
Minor internal function renaming
parent
9b10c1b4
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
tests/test_env.py
+2
-2
2 additions, 2 deletions
tests/test_env.py
tests/test_plugins.py
+2
-2
2 additions, 2 deletions
tests/test_plugins.py
tutor/env.py
+7
-9
7 additions, 9 deletions
tutor/env.py
tutor/plugins.py
+8
-8
8 additions, 8 deletions
tutor/plugins.py
with
19 additions
and
21 deletions
tests/test_env.py
+
2
−
2
View file @
c1e47cec
...
@@ -105,7 +105,7 @@ class EnvTests(unittest.TestCase):
...
@@ -105,7 +105,7 @@ class EnvTests(unittest.TestCase):
# Create a single plugin
# Create a single plugin
with
unittest
.
mock
.
patch
.
object
(
with
unittest
.
mock
.
patch
.
object
(
env
.
plugins
,
env
.
plugins
,
"
iter_templates
"
,
"
iter_template
_root
s
"
,
return_value
=
[(
"
plugin1
"
,
plugin_templates
)],
return_value
=
[(
"
plugin1
"
,
plugin_templates
)],
):
):
with
tempfile
.
TemporaryDirectory
()
as
root
:
with
tempfile
.
TemporaryDirectory
()
as
root
:
...
@@ -136,7 +136,7 @@ class EnvTests(unittest.TestCase):
...
@@ -136,7 +136,7 @@ class EnvTests(unittest.TestCase):
with
unittest
.
mock
.
patch
.
object
(
with
unittest
.
mock
.
patch
.
object
(
env
.
plugins
,
env
.
plugins
,
"
iter_templates
"
,
"
iter_template
_root
s
"
,
return_value
=
[(
"
myplugin
"
,
plugin_templates
)],
return_value
=
[(
"
myplugin
"
,
plugin_templates
)],
):
):
# Load env a second time
# Load env a second time
...
...
This diff is collapsed.
Click to expand it.
tests/test_plugins.py
+
2
−
2
View file @
c1e47cec
...
@@ -179,7 +179,7 @@ class PluginsTests(unittest.TestCase):
...
@@ -179,7 +179,7 @@ class PluginsTests(unittest.TestCase):
[(
"
plugin1
"
,
[
"
myclient
"
])],
list
(
plugins
.
iter_hooks
({},
"
init
"
))
[(
"
plugin1
"
,
[
"
myclient
"
])],
list
(
plugins
.
iter_hooks
({},
"
init
"
))
)
)
def
test_iter_templates
(
self
):
def
test_iter_template
_root
s
(
self
):
class
plugin1
:
class
plugin1
:
templates
=
"
/tmp/templates
"
templates
=
"
/tmp/templates
"
...
@@ -187,7 +187,7 @@ class PluginsTests(unittest.TestCase):
...
@@ -187,7 +187,7 @@ class PluginsTests(unittest.TestCase):
plugins
.
Plugins
,
"
iter_enabled
"
,
return_value
=
[(
"
plugin1
"
,
plugin1
)]
plugins
.
Plugins
,
"
iter_enabled
"
,
return_value
=
[(
"
plugin1
"
,
plugin1
)]
):
):
self
.
assertEqual
(
self
.
assertEqual
(
[(
"
plugin1
"
,
"
/tmp/templates
"
)],
list
(
plugins
.
iter_templates
({}))
[(
"
plugin1
"
,
"
/tmp/templates
"
)],
list
(
plugins
.
iter_template
_root
s
({}))
)
)
def
test_plugins_are_updated_on_config_change
(
self
):
def
test_plugins_are_updated_on_config_change
(
self
):
...
...
This diff is collapsed.
Click to expand it.
tutor/env.py
+
7
−
9
View file @
c1e47cec
...
@@ -29,8 +29,8 @@ class Renderer:
...
@@ -29,8 +29,8 @@ class Renderer:
if
cls
.
ENVIRONMENT_CONFIG
!=
config
:
if
cls
.
ENVIRONMENT_CONFIG
!=
config
:
# Load template roots
# Load template roots
template_roots
=
[
TEMPLATES_ROOT
]
template_roots
=
[
TEMPLATES_ROOT
]
for
_
,
plugin_template
s
in
plugins
.
iter_templates
(
config
):
for
_
,
plugin_template
_root
in
plugins
.
iter_template
_root
s
(
config
):
template_roots
.
append
(
plugin_template
s
)
template_roots
.
append
(
plugin_template
_root
)
# Create environment
# Create environment
environment
=
jinja2
.
Environment
(
environment
=
jinja2
.
Environment
(
...
@@ -119,7 +119,7 @@ def render_full(root, config):
...
@@ -119,7 +119,7 @@ def render_full(root, config):
"""
"""
for
subdir
in
[
"
android
"
,
"
apps
"
,
"
build
"
,
"
dev
"
,
"
k8s
"
,
"
local
"
,
"
webui
"
]:
for
subdir
in
[
"
android
"
,
"
apps
"
,
"
build
"
,
"
dev
"
,
"
k8s
"
,
"
local
"
,
"
webui
"
]:
save_subdir
(
subdir
,
root
,
config
)
save_subdir
(
subdir
,
root
,
config
)
for
plugin
,
path
in
plugins
.
iter_templates
(
config
):
for
plugin
,
path
in
plugins
.
iter_template
_root
s
(
config
):
save_plugin_templates
(
plugin
,
path
,
root
,
config
)
save_plugin_templates
(
plugin
,
path
,
root
,
config
)
save_file
(
VERSION_FILENAME
,
root
,
config
)
save_file
(
VERSION_FILENAME
,
root
,
config
)
save_file
(
"
kustomization.yml
"
,
root
,
config
)
save_file
(
"
kustomization.yml
"
,
root
,
config
)
...
@@ -277,12 +277,10 @@ def is_part_of_env(path):
...
@@ -277,12 +277,10 @@ def is_part_of_env(path):
Determines whether a file should be rendered or not.
Determines whether a file should be rendered or not.
"""
"""
basename
=
os
.
path
.
basename
(
path
)
basename
=
os
.
path
.
basename
(
path
)
return
not
(
is_excluded
=
False
basename
.
startswith
(
"
.
"
)
is_excluded
=
is_excluded
or
basename
.
startswith
(
"
.
"
)
or
basename
.
endswith
(
"
.pyc
"
)
or
basename
.
endswith
(
"
.pyc
"
)
is_excluded
=
is_excluded
or
basename
==
"
__pycache__
"
or
basename
==
"
partials
"
or
basename
==
"
__pycache__
"
return
not
is_excluded
or
basename
==
"
partials
"
)
def
template_path
(
*
path
):
def
template_path
(
*
path
):
...
...
This diff is collapsed.
Click to expand it.
tutor/plugins.py
+
8
−
8
View file @
c1e47cec
...
@@ -46,7 +46,7 @@ class Plugins:
...
@@ -46,7 +46,7 @@ class Plugins:
self
.
config
=
deepcopy
(
config
)
self
.
config
=
deepcopy
(
config
)
self
.
patches
=
{}
self
.
patches
=
{}
self
.
hooks
=
{}
self
.
hooks
=
{}
self
.
templates
=
{}
self
.
template
_root
s
=
{}
for
plugin_name
,
plugin
in
self
.
iter_enabled
():
for
plugin_name
,
plugin
in
self
.
iter_enabled
():
patches
=
get_callable_attr
(
plugin
,
"
patches
"
,
{})
patches
=
get_callable_attr
(
plugin
,
"
patches
"
,
{})
...
@@ -61,9 +61,9 @@ class Plugins:
...
@@ -61,9 +61,9 @@ class Plugins:
self
.
hooks
[
hook_name
]
=
{}
self
.
hooks
[
hook_name
]
=
{}
self
.
hooks
[
hook_name
][
plugin_name
]
=
services
self
.
hooks
[
hook_name
][
plugin_name
]
=
services
templates
=
get_callable_attr
(
plugin
,
"
templates
"
)
templates
_root
=
get_callable_attr
(
plugin
,
"
templates
"
)
if
templates
:
if
templates
_root
:
self
.
templates
[
plugin_name
]
=
templates
self
.
template
_root
s
[
plugin_name
]
=
templates
_root
@classmethod
@classmethod
def
clear
(
cls
):
def
clear
(
cls
):
...
@@ -102,8 +102,8 @@ class Plugins:
...
@@ -102,8 +102,8 @@ class Plugins:
def
iter_hooks
(
self
,
hook_name
):
def
iter_hooks
(
self
,
hook_name
):
yield
from
self
.
hooks
.
get
(
hook_name
,
{}).
items
()
yield
from
self
.
hooks
.
get
(
hook_name
,
{}).
items
()
def
iter_templates
(
self
):
def
iter_template
_root
s
(
self
):
yield
from
self
.
templates
.
items
()
yield
from
self
.
template
_root
s
.
items
()
def
get_callable_attr
(
plugin
,
attr_name
,
default
=
None
):
def
get_callable_attr
(
plugin
,
attr_name
,
default
=
None
):
...
@@ -154,8 +154,8 @@ def iter_hooks(config, hook_name):
...
@@ -154,8 +154,8 @@ def iter_hooks(config, hook_name):
yield
from
Plugins
.
instance
(
config
).
iter_hooks
(
hook_name
)
yield
from
Plugins
.
instance
(
config
).
iter_hooks
(
hook_name
)
def
iter_templates
(
config
):
def
iter_template
_root
s
(
config
):
yield
from
Plugins
.
instance
(
config
).
iter_templates
()
yield
from
Plugins
.
instance
(
config
).
iter_template
_root
s
()
def
iter_commands
():
def
iter_commands
():
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment