repo stringlengths 7 55 | path stringlengths 4 223 | func_name stringlengths 1 134 | original_string stringlengths 75 104k | language stringclasses 1
value | code stringlengths 75 104k | code_tokens listlengths 19 28.4k | docstring stringlengths 1 46.9k | docstring_tokens listlengths 1 1.97k | sha stringlengths 40 40 | url stringlengths 87 315 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
doconix/django-mako-plus | django_mako_plus/engine.py | MakoTemplates.from_string | def from_string(self, template_code):
'''
Compiles a template from the given string.
This is one of the required methods of Django template engines.
'''
dmp = apps.get_app_config('django_mako_plus')
mako_template = Template(template_code, imports=dmp.template_imports, inp... | python | def from_string(self, template_code):
'''
Compiles a template from the given string.
This is one of the required methods of Django template engines.
'''
dmp = apps.get_app_config('django_mako_plus')
mako_template = Template(template_code, imports=dmp.template_imports, inp... | [
"def",
"from_string",
"(",
"self",
",",
"template_code",
")",
":",
"dmp",
"=",
"apps",
".",
"get_app_config",
"(",
"'django_mako_plus'",
")",
"mako_template",
"=",
"Template",
"(",
"template_code",
",",
"imports",
"=",
"dmp",
".",
"template_imports",
",",
"inp... | Compiles a template from the given string.
This is one of the required methods of Django template engines. | [
"Compiles",
"a",
"template",
"from",
"the",
"given",
"string",
".",
"This",
"is",
"one",
"of",
"the",
"required",
"methods",
"of",
"Django",
"template",
"engines",
"."
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/engine.py#L58-L65 | train |
doconix/django-mako-plus | django_mako_plus/engine.py | MakoTemplates.get_template | def get_template(self, template_name):
'''
Retrieves a template object from the pattern "app_name/template.html".
This is one of the required methods of Django template engines.
Because DMP templates are always app-specific (Django only searches
a global set of directories), the... | python | def get_template(self, template_name):
'''
Retrieves a template object from the pattern "app_name/template.html".
This is one of the required methods of Django template engines.
Because DMP templates are always app-specific (Django only searches
a global set of directories), the... | [
"def",
"get_template",
"(",
"self",
",",
"template_name",
")",
":",
"dmp",
"=",
"apps",
".",
"get_app_config",
"(",
"'django_mako_plus'",
")",
"match",
"=",
"RE_TEMPLATE_NAME",
".",
"match",
"(",
"template_name",
")",
"if",
"match",
"is",
"None",
"or",
"matc... | Retrieves a template object from the pattern "app_name/template.html".
This is one of the required methods of Django template engines.
Because DMP templates are always app-specific (Django only searches
a global set of directories), the template_name MUST be in the format:
"app_name/tem... | [
"Retrieves",
"a",
"template",
"object",
"from",
"the",
"pattern",
"app_name",
"/",
"template",
".",
"html",
".",
"This",
"is",
"one",
"of",
"the",
"required",
"methods",
"of",
"Django",
"template",
"engines",
"."
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/engine.py#L68-L87 | train |
doconix/django-mako-plus | django_mako_plus/engine.py | MakoTemplates.get_template_loader | def get_template_loader(self, app, subdir='templates', create=False):
'''
Returns a template loader object for the given app name in the given subdir.
For example, get_template_loader('homepage', 'styles') will return
a loader for the styles/ directory in the homepage app.
The a... | python | def get_template_loader(self, app, subdir='templates', create=False):
'''
Returns a template loader object for the given app name in the given subdir.
For example, get_template_loader('homepage', 'styles') will return
a loader for the styles/ directory in the homepage app.
The a... | [
"def",
"get_template_loader",
"(",
"self",
",",
"app",
",",
"subdir",
"=",
"'templates'",
",",
"create",
"=",
"False",
")",
":",
"# ensure we have an AppConfig",
"if",
"app",
"is",
"None",
":",
"raise",
"TemplateDoesNotExist",
"(",
"\"Cannot locate loader when app i... | Returns a template loader object for the given app name in the given subdir.
For example, get_template_loader('homepage', 'styles') will return
a loader for the styles/ directory in the homepage app.
The app parameter can be either an app name or an AppConfig instance.
The subdir parame... | [
"Returns",
"a",
"template",
"loader",
"object",
"for",
"the",
"given",
"app",
"name",
"in",
"the",
"given",
"subdir",
".",
"For",
"example",
"get_template_loader",
"(",
"homepage",
"styles",
")",
"will",
"return",
"a",
"loader",
"for",
"the",
"styles",
"/",
... | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/engine.py#L90-L129 | train |
doconix/django-mako-plus | django_mako_plus/engine.py | MakoTemplates.get_template_loader_for_path | def get_template_loader_for_path(self, path, use_cache=True):
'''
Returns a template loader object for the given directory path.
For example, get_template_loader('/var/mytemplates/') will return
a loader for that specific directory.
Normally, you should not have to call this met... | python | def get_template_loader_for_path(self, path, use_cache=True):
'''
Returns a template loader object for the given directory path.
For example, get_template_loader('/var/mytemplates/') will return
a loader for that specific directory.
Normally, you should not have to call this met... | [
"def",
"get_template_loader_for_path",
"(",
"self",
",",
"path",
",",
"use_cache",
"=",
"True",
")",
":",
"# get from the cache if we are able",
"if",
"use_cache",
":",
"try",
":",
"return",
"self",
".",
"template_loaders",
"[",
"path",
"]",
"except",
"KeyError",
... | Returns a template loader object for the given directory path.
For example, get_template_loader('/var/mytemplates/') will return
a loader for that specific directory.
Normally, you should not have to call this method. Django automatically
adds request.dmp.render() and request.dmp.rende... | [
"Returns",
"a",
"template",
"loader",
"object",
"for",
"the",
"given",
"directory",
"path",
".",
"For",
"example",
"get_template_loader",
"(",
"/",
"var",
"/",
"mytemplates",
"/",
")",
"will",
"return",
"a",
"loader",
"for",
"that",
"specific",
"directory",
... | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/engine.py#L132-L165 | train |
doconix/django-mako-plus | django_mako_plus/converter/base.py | ParameterConverter._register_converter | def _register_converter(cls, conv_func, conv_type):
'''Triggered by the @converter_function decorator'''
cls.converters.append(ConverterFunctionInfo(conv_func, conv_type, len(cls.converters)))
cls._sort_converters() | python | def _register_converter(cls, conv_func, conv_type):
'''Triggered by the @converter_function decorator'''
cls.converters.append(ConverterFunctionInfo(conv_func, conv_type, len(cls.converters)))
cls._sort_converters() | [
"def",
"_register_converter",
"(",
"cls",
",",
"conv_func",
",",
"conv_type",
")",
":",
"cls",
".",
"converters",
".",
"append",
"(",
"ConverterFunctionInfo",
"(",
"conv_func",
",",
"conv_type",
",",
"len",
"(",
"cls",
".",
"converters",
")",
")",
")",
"cl... | Triggered by the @converter_function decorator | [
"Triggered",
"by",
"the"
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/converter/base.py#L83-L86 | train |
doconix/django-mako-plus | django_mako_plus/converter/base.py | ParameterConverter._sort_converters | def _sort_converters(cls, app_ready=False):
'''Sorts the converter functions'''
# app_ready is True when called from DMP's AppConfig.ready()
# we can't sort before then because models aren't ready
cls._sorting_enabled = cls._sorting_enabled or app_ready
if cls._sorting_enabled:
... | python | def _sort_converters(cls, app_ready=False):
'''Sorts the converter functions'''
# app_ready is True when called from DMP's AppConfig.ready()
# we can't sort before then because models aren't ready
cls._sorting_enabled = cls._sorting_enabled or app_ready
if cls._sorting_enabled:
... | [
"def",
"_sort_converters",
"(",
"cls",
",",
"app_ready",
"=",
"False",
")",
":",
"# app_ready is True when called from DMP's AppConfig.ready()",
"# we can't sort before then because models aren't ready",
"cls",
".",
"_sorting_enabled",
"=",
"cls",
".",
"_sorting_enabled",
"or",... | Sorts the converter functions | [
"Sorts",
"the",
"converter",
"functions"
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/converter/base.py#L90-L98 | train |
doconix/django-mako-plus | django_mako_plus/converter/base.py | ParameterConverter.convert_parameters | def convert_parameters(self, request, *args, **kwargs):
'''
Iterates the urlparams and converts them according to the
type hints in the current view function. This is the primary
function of the class.
'''
args = list(args)
urlparam_i = 0
parameters = se... | python | def convert_parameters(self, request, *args, **kwargs):
'''
Iterates the urlparams and converts them according to the
type hints in the current view function. This is the primary
function of the class.
'''
args = list(args)
urlparam_i = 0
parameters = se... | [
"def",
"convert_parameters",
"(",
"self",
",",
"request",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"args",
"=",
"list",
"(",
"args",
")",
"urlparam_i",
"=",
"0",
"parameters",
"=",
"self",
".",
"view_parameters",
".",
"get",
"(",
"request",... | Iterates the urlparams and converts them according to the
type hints in the current view function. This is the primary
function of the class. | [
"Iterates",
"the",
"urlparams",
"and",
"converts",
"them",
"according",
"to",
"the",
"type",
"hints",
"in",
"the",
"current",
"view",
"function",
".",
"This",
"is",
"the",
"primary",
"function",
"of",
"the",
"class",
"."
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/converter/base.py#L101-L134 | train |
doconix/django-mako-plus | django_mako_plus/converter/base.py | ParameterConverter.convert_value | def convert_value(self, value, parameter, request):
'''
Converts a parameter value in the view function call.
value: value from request.dmp.urlparams to convert
The value will always be a string, even if empty '' (never None).
parameter: an instanc... | python | def convert_value(self, value, parameter, request):
'''
Converts a parameter value in the view function call.
value: value from request.dmp.urlparams to convert
The value will always be a string, even if empty '' (never None).
parameter: an instanc... | [
"def",
"convert_value",
"(",
"self",
",",
"value",
",",
"parameter",
",",
"request",
")",
":",
"try",
":",
"# we don't convert anything without type hints",
"if",
"parameter",
".",
"type",
"is",
"inspect",
".",
"Parameter",
".",
"empty",
":",
"if",
"log",
".",... | Converts a parameter value in the view function call.
value: value from request.dmp.urlparams to convert
The value will always be a string, even if empty '' (never None).
parameter: an instance of django_mako_plus.ViewParameter that holds this parameter's
... | [
"Converts",
"a",
"parameter",
"value",
"in",
"the",
"view",
"function",
"call",
"."
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/converter/base.py#L137-L195 | train |
doconix/django-mako-plus | django_mako_plus/management/commands/dmp_webpack.py | Command.create_entry_file | def create_entry_file(self, filename, script_map, enapps):
'''Creates an entry file for the given script map'''
if len(script_map) == 0:
return
# create the entry file
template = MakoTemplate('''
<%! import os %>
// dynamic imports are within functions so they don't happen u... | python | def create_entry_file(self, filename, script_map, enapps):
'''Creates an entry file for the given script map'''
if len(script_map) == 0:
return
# create the entry file
template = MakoTemplate('''
<%! import os %>
// dynamic imports are within functions so they don't happen u... | [
"def",
"create_entry_file",
"(",
"self",
",",
"filename",
",",
"script_map",
",",
"enapps",
")",
":",
"if",
"len",
"(",
"script_map",
")",
"==",
"0",
":",
"return",
"# create the entry file",
"template",
"=",
"MakoTemplate",
"(",
"'''\n<%! import os %>\n// dynamic... | Creates an entry file for the given script map | [
"Creates",
"an",
"entry",
"file",
"for",
"the",
"given",
"script",
"map"
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/management/commands/dmp_webpack.py#L89-L136 | train |
doconix/django-mako-plus | django_mako_plus/management/commands/dmp_webpack.py | Command.generate_script_map | def generate_script_map(self, config):
'''
Maps templates in this app to their scripts. This function deep searches
app/templates/* for the templates of this app. Returns the following
dictionary with absolute paths:
{
( 'appname', 'template1' ): [ '/abs/path/to/sc... | python | def generate_script_map(self, config):
'''
Maps templates in this app to their scripts. This function deep searches
app/templates/* for the templates of this app. Returns the following
dictionary with absolute paths:
{
( 'appname', 'template1' ): [ '/abs/path/to/sc... | [
"def",
"generate_script_map",
"(",
"self",
",",
"config",
")",
":",
"script_map",
"=",
"OrderedDict",
"(",
")",
"template_root",
"=",
"os",
".",
"path",
".",
"join",
"(",
"os",
".",
"path",
".",
"relpath",
"(",
"config",
".",
"path",
",",
"settings",
"... | Maps templates in this app to their scripts. This function deep searches
app/templates/* for the templates of this app. Returns the following
dictionary with absolute paths:
{
( 'appname', 'template1' ): [ '/abs/path/to/scripts/template1.js', '/abs/path/to/scripts/supertemplate1.j... | [
"Maps",
"templates",
"in",
"this",
"app",
"to",
"their",
"scripts",
".",
"This",
"function",
"deep",
"searches",
"app",
"/",
"templates",
"/",
"*",
"for",
"the",
"templates",
"of",
"this",
"app",
".",
"Returns",
"the",
"following",
"dictionary",
"with",
"a... | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/management/commands/dmp_webpack.py#L138-L175 | train |
doconix/django-mako-plus | django_mako_plus/management/commands/dmp_webpack.py | Command.template_scripts | def template_scripts(self, config, template_name):
'''
Returns a list of scripts used by the given template object AND its ancestors.
This runs a ProviderRun on the given template (as if it were being displayed).
This allows the WEBPACK_PROVIDERS to provide the JS files to us.
'... | python | def template_scripts(self, config, template_name):
'''
Returns a list of scripts used by the given template object AND its ancestors.
This runs a ProviderRun on the given template (as if it were being displayed).
This allows the WEBPACK_PROVIDERS to provide the JS files to us.
'... | [
"def",
"template_scripts",
"(",
"self",
",",
"config",
",",
"template_name",
")",
":",
"dmp",
"=",
"apps",
".",
"get_app_config",
"(",
"'django_mako_plus'",
")",
"template_obj",
"=",
"dmp",
".",
"engine",
".",
"get_template_loader",
"(",
"config",
",",
"create... | Returns a list of scripts used by the given template object AND its ancestors.
This runs a ProviderRun on the given template (as if it were being displayed).
This allows the WEBPACK_PROVIDERS to provide the JS files to us. | [
"Returns",
"a",
"list",
"of",
"scripts",
"used",
"by",
"the",
"given",
"template",
"object",
"AND",
"its",
"ancestors",
"."
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/management/commands/dmp_webpack.py#L178-L195 | train |
doconix/django-mako-plus | django_mako_plus/exceptions.py | RedirectException.get_response | def get_response(self, request, *args, **kwargs):
'''Returns the redirect response for this exception.'''
# normal process
response = HttpResponseRedirect(self.redirect_to)
response[REDIRECT_HEADER_KEY] = self.redirect_to
return response | python | def get_response(self, request, *args, **kwargs):
'''Returns the redirect response for this exception.'''
# normal process
response = HttpResponseRedirect(self.redirect_to)
response[REDIRECT_HEADER_KEY] = self.redirect_to
return response | [
"def",
"get_response",
"(",
"self",
",",
"request",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"# normal process",
"response",
"=",
"HttpResponseRedirect",
"(",
"self",
".",
"redirect_to",
")",
"response",
"[",
"REDIRECT_HEADER_KEY",
"]",
"=",
"sel... | Returns the redirect response for this exception. | [
"Returns",
"the",
"redirect",
"response",
"for",
"this",
"exception",
"."
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/exceptions.py#L54-L59 | train |
doconix/django-mako-plus | django_mako_plus/exceptions.py | JavascriptRedirectException.get_response | def get_response(self, request):
'''Returns the redirect response for this exception.'''
# the redirect key is already placed in the response by HttpResponseJavascriptRedirect
return HttpResponseJavascriptRedirect(self.redirect_to, *self.args, **self.kwargs) | python | def get_response(self, request):
'''Returns the redirect response for this exception.'''
# the redirect key is already placed in the response by HttpResponseJavascriptRedirect
return HttpResponseJavascriptRedirect(self.redirect_to, *self.args, **self.kwargs) | [
"def",
"get_response",
"(",
"self",
",",
"request",
")",
":",
"# the redirect key is already placed in the response by HttpResponseJavascriptRedirect",
"return",
"HttpResponseJavascriptRedirect",
"(",
"self",
".",
"redirect_to",
",",
"*",
"self",
".",
"args",
",",
"*",
"*... | Returns the redirect response for this exception. | [
"Returns",
"the",
"redirect",
"response",
"for",
"this",
"exception",
"."
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/exceptions.py#L114-L117 | train |
doconix/django-mako-plus | django_mako_plus/convenience.py | get_template_loader | def get_template_loader(app, subdir='templates'):
'''
Convenience method that calls get_template_loader() on the DMP
template engine instance.
'''
dmp = apps.get_app_config('django_mako_plus')
return dmp.engine.get_template_loader(app, subdir, create=True) | python | def get_template_loader(app, subdir='templates'):
'''
Convenience method that calls get_template_loader() on the DMP
template engine instance.
'''
dmp = apps.get_app_config('django_mako_plus')
return dmp.engine.get_template_loader(app, subdir, create=True) | [
"def",
"get_template_loader",
"(",
"app",
",",
"subdir",
"=",
"'templates'",
")",
":",
"dmp",
"=",
"apps",
".",
"get_app_config",
"(",
"'django_mako_plus'",
")",
"return",
"dmp",
".",
"engine",
".",
"get_template_loader",
"(",
"app",
",",
"subdir",
",",
"cre... | Convenience method that calls get_template_loader() on the DMP
template engine instance. | [
"Convenience",
"method",
"that",
"calls",
"get_template_loader",
"()",
"on",
"the",
"DMP",
"template",
"engine",
"instance",
"."
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/convenience.py#L9-L15 | train |
doconix/django-mako-plus | django_mako_plus/convenience.py | render_template | def render_template(request, app, template_name, context=None, subdir="templates", def_name=None):
'''
Convenience method that directly renders a template, given the app and template names.
'''
return get_template(app, template_name, subdir).render(context, request, def_name) | python | def render_template(request, app, template_name, context=None, subdir="templates", def_name=None):
'''
Convenience method that directly renders a template, given the app and template names.
'''
return get_template(app, template_name, subdir).render(context, request, def_name) | [
"def",
"render_template",
"(",
"request",
",",
"app",
",",
"template_name",
",",
"context",
"=",
"None",
",",
"subdir",
"=",
"\"templates\"",
",",
"def_name",
"=",
"None",
")",
":",
"return",
"get_template",
"(",
"app",
",",
"template_name",
",",
"subdir",
... | Convenience method that directly renders a template, given the app and template names. | [
"Convenience",
"method",
"that",
"directly",
"renders",
"a",
"template",
"given",
"the",
"app",
"and",
"template",
"names",
"."
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/convenience.py#L27-L31 | train |
doconix/django-mako-plus | django_mako_plus/convenience.py | get_template_loader_for_path | def get_template_loader_for_path(path, use_cache=True):
'''
Convenience method that calls get_template_loader_for_path() on the DMP
template engine instance.
'''
dmp = apps.get_app_config('django_mako_plus')
return dmp.engine.get_template_loader_for_path(path, use_cache) | python | def get_template_loader_for_path(path, use_cache=True):
'''
Convenience method that calls get_template_loader_for_path() on the DMP
template engine instance.
'''
dmp = apps.get_app_config('django_mako_plus')
return dmp.engine.get_template_loader_for_path(path, use_cache) | [
"def",
"get_template_loader_for_path",
"(",
"path",
",",
"use_cache",
"=",
"True",
")",
":",
"dmp",
"=",
"apps",
".",
"get_app_config",
"(",
"'django_mako_plus'",
")",
"return",
"dmp",
".",
"engine",
".",
"get_template_loader_for_path",
"(",
"path",
",",
"use_ca... | Convenience method that calls get_template_loader_for_path() on the DMP
template engine instance. | [
"Convenience",
"method",
"that",
"calls",
"get_template_loader_for_path",
"()",
"on",
"the",
"DMP",
"template",
"engine",
"instance",
"."
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/convenience.py#L34-L40 | train |
doconix/django-mako-plus | django_mako_plus/convenience.py | get_template_for_path | def get_template_for_path(path, use_cache=True):
'''
Convenience method that retrieves a template given a direct path to it.
'''
dmp = apps.get_app_config('django_mako_plus')
app_path, template_name = os.path.split(path)
return dmp.engine.get_template_loader_for_path(app_path, use_cache=use_cach... | python | def get_template_for_path(path, use_cache=True):
'''
Convenience method that retrieves a template given a direct path to it.
'''
dmp = apps.get_app_config('django_mako_plus')
app_path, template_name = os.path.split(path)
return dmp.engine.get_template_loader_for_path(app_path, use_cache=use_cach... | [
"def",
"get_template_for_path",
"(",
"path",
",",
"use_cache",
"=",
"True",
")",
":",
"dmp",
"=",
"apps",
".",
"get_app_config",
"(",
"'django_mako_plus'",
")",
"app_path",
",",
"template_name",
"=",
"os",
".",
"path",
".",
"split",
"(",
"path",
")",
"retu... | Convenience method that retrieves a template given a direct path to it. | [
"Convenience",
"method",
"that",
"retrieves",
"a",
"template",
"given",
"a",
"direct",
"path",
"to",
"it",
"."
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/convenience.py#L43-L49 | train |
doconix/django-mako-plus | django_mako_plus/convenience.py | render_template_for_path | def render_template_for_path(request, path, context=None, use_cache=True, def_name=None):
'''
Convenience method that directly renders a template, given a direct path to it.
'''
return get_template_for_path(path, use_cache).render(context, request, def_name) | python | def render_template_for_path(request, path, context=None, use_cache=True, def_name=None):
'''
Convenience method that directly renders a template, given a direct path to it.
'''
return get_template_for_path(path, use_cache).render(context, request, def_name) | [
"def",
"render_template_for_path",
"(",
"request",
",",
"path",
",",
"context",
"=",
"None",
",",
"use_cache",
"=",
"True",
",",
"def_name",
"=",
"None",
")",
":",
"return",
"get_template_for_path",
"(",
"path",
",",
"use_cache",
")",
".",
"render",
"(",
"... | Convenience method that directly renders a template, given a direct path to it. | [
"Convenience",
"method",
"that",
"directly",
"renders",
"a",
"template",
"given",
"a",
"direct",
"path",
"to",
"it",
"."
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/convenience.py#L52-L56 | train |
doconix/django-mako-plus | django_mako_plus/util/reflect.py | qualified_name | def qualified_name(obj):
'''Returns the fully-qualified name of the given object'''
if not hasattr(obj, '__module__'):
obj = obj.__class__
module = obj.__module__
if module is None or module == str.__class__.__module__:
return obj.__qualname__
return '{}.{}'.format(module, obj.__qual... | python | def qualified_name(obj):
'''Returns the fully-qualified name of the given object'''
if not hasattr(obj, '__module__'):
obj = obj.__class__
module = obj.__module__
if module is None or module == str.__class__.__module__:
return obj.__qualname__
return '{}.{}'.format(module, obj.__qual... | [
"def",
"qualified_name",
"(",
"obj",
")",
":",
"if",
"not",
"hasattr",
"(",
"obj",
",",
"'__module__'",
")",
":",
"obj",
"=",
"obj",
".",
"__class__",
"module",
"=",
"obj",
".",
"__module__",
"if",
"module",
"is",
"None",
"or",
"module",
"==",
"str",
... | Returns the fully-qualified name of the given object | [
"Returns",
"the",
"fully",
"-",
"qualified",
"name",
"of",
"the",
"given",
"object"
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/util/reflect.py#L4-L11 | train |
doconix/django-mako-plus | django_mako_plus/util/reflect.py | import_qualified | def import_qualified(name):
'''
Imports a fully-qualified name from a module:
cls = import_qualified('homepage.views.index.MyForm')
Raises an ImportError if it can't be ipmorted.
'''
parts = name.rsplit('.', 1)
if len(parts) != 2:
raise ImportError('Invalid fully-qualified name... | python | def import_qualified(name):
'''
Imports a fully-qualified name from a module:
cls = import_qualified('homepage.views.index.MyForm')
Raises an ImportError if it can't be ipmorted.
'''
parts = name.rsplit('.', 1)
if len(parts) != 2:
raise ImportError('Invalid fully-qualified name... | [
"def",
"import_qualified",
"(",
"name",
")",
":",
"parts",
"=",
"name",
".",
"rsplit",
"(",
"'.'",
",",
"1",
")",
"if",
"len",
"(",
"parts",
")",
"!=",
"2",
":",
"raise",
"ImportError",
"(",
"'Invalid fully-qualified name: {}'",
".",
"format",
"(",
"name... | Imports a fully-qualified name from a module:
cls = import_qualified('homepage.views.index.MyForm')
Raises an ImportError if it can't be ipmorted. | [
"Imports",
"a",
"fully",
"-",
"qualified",
"name",
"from",
"a",
"module",
":"
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/util/reflect.py#L14-L28 | train |
doconix/django-mako-plus | django_mako_plus/provider/__init__.py | links | def links(tself, group=None):
'''Returns the HTML for the given provider group (or all groups if None)'''
pr = ProviderRun(tself, group)
pr.run()
return mark_safe(pr.getvalue()) | python | def links(tself, group=None):
'''Returns the HTML for the given provider group (or all groups if None)'''
pr = ProviderRun(tself, group)
pr.run()
return mark_safe(pr.getvalue()) | [
"def",
"links",
"(",
"tself",
",",
"group",
"=",
"None",
")",
":",
"pr",
"=",
"ProviderRun",
"(",
"tself",
",",
"group",
")",
"pr",
".",
"run",
"(",
")",
"return",
"mark_safe",
"(",
"pr",
".",
"getvalue",
"(",
")",
")"
] | Returns the HTML for the given provider group (or all groups if None) | [
"Returns",
"the",
"HTML",
"for",
"the",
"given",
"provider",
"group",
"(",
"or",
"all",
"groups",
"if",
"None",
")"
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/provider/__init__.py#L12-L16 | train |
doconix/django-mako-plus | django_mako_plus/provider/__init__.py | template_links | def template_links(request, app, template_name, context=None, group=None, force=True):
'''
Returns the HTML for the given provider group, using an app and template name.
This method should not normally be used (use links() instead). The use of
this method is when provider need to be called from regular... | python | def template_links(request, app, template_name, context=None, group=None, force=True):
'''
Returns the HTML for the given provider group, using an app and template name.
This method should not normally be used (use links() instead). The use of
this method is when provider need to be called from regular... | [
"def",
"template_links",
"(",
"request",
",",
"app",
",",
"template_name",
",",
"context",
"=",
"None",
",",
"group",
"=",
"None",
",",
"force",
"=",
"True",
")",
":",
"if",
"isinstance",
"(",
"app",
",",
"str",
")",
":",
"app",
"=",
"apps",
".",
"... | Returns the HTML for the given provider group, using an app and template name.
This method should not normally be used (use links() instead). The use of
this method is when provider need to be called from regular python code instead
of from within a rendering template environment. | [
"Returns",
"the",
"HTML",
"for",
"the",
"given",
"provider",
"group",
"using",
"an",
"app",
"and",
"template",
"name",
".",
"This",
"method",
"should",
"not",
"normally",
"be",
"used",
"(",
"use",
"links",
"()",
"instead",
")",
".",
"The",
"use",
"of",
... | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/provider/__init__.py#L19-L32 | train |
doconix/django-mako-plus | django_mako_plus/provider/__init__.py | template_obj_links | def template_obj_links(request, template_obj, context=None, group=None):
'''
Returns the HTML for the given provider group, using a template object.
This method should not normally be used (use links() instead). The use of
this method is when provider need to be called from regular python code instead
... | python | def template_obj_links(request, template_obj, context=None, group=None):
'''
Returns the HTML for the given provider group, using a template object.
This method should not normally be used (use links() instead). The use of
this method is when provider need to be called from regular python code instead
... | [
"def",
"template_obj_links",
"(",
"request",
",",
"template_obj",
",",
"context",
"=",
"None",
",",
"group",
"=",
"None",
")",
":",
"# the template_obj can be a MakoTemplateAdapter or a Mako Template",
"# if our DMP-defined MakoTemplateAdapter, switch to the embedded Mako Template"... | Returns the HTML for the given provider group, using a template object.
This method should not normally be used (use links() instead). The use of
this method is when provider need to be called from regular python code instead
of from within a rendering template environment. | [
"Returns",
"the",
"HTML",
"for",
"the",
"given",
"provider",
"group",
"using",
"a",
"template",
"object",
".",
"This",
"method",
"should",
"not",
"normally",
"be",
"used",
"(",
"use",
"links",
"()",
"instead",
")",
".",
"The",
"use",
"of",
"this",
"metho... | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/provider/__init__.py#L35-L55 | train |
doconix/django-mako-plus | django_mako_plus/provider/link.py | CssLinkProvider.build_default_link | def build_default_link(self):
'''Called when 'link' is not defined in the settings'''
attrs = {}
attrs["rel"] = "stylesheet"
attrs["href"] ="{}?{:x}".format(
os.path.join(settings.STATIC_URL, self.filepath).replace(os.path.sep, '/'),
self.version_id,
)
... | python | def build_default_link(self):
'''Called when 'link' is not defined in the settings'''
attrs = {}
attrs["rel"] = "stylesheet"
attrs["href"] ="{}?{:x}".format(
os.path.join(settings.STATIC_URL, self.filepath).replace(os.path.sep, '/'),
self.version_id,
)
... | [
"def",
"build_default_link",
"(",
"self",
")",
":",
"attrs",
"=",
"{",
"}",
"attrs",
"[",
"\"rel\"",
"]",
"=",
"\"stylesheet\"",
"attrs",
"[",
"\"href\"",
"]",
"=",
"\"{}?{:x}\"",
".",
"format",
"(",
"os",
".",
"path",
".",
"join",
"(",
"settings",
"."... | Called when 'link' is not defined in the settings | [
"Called",
"when",
"link",
"is",
"not",
"defined",
"in",
"the",
"settings"
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/provider/link.py#L155-L165 | train |
doconix/django-mako-plus | django_mako_plus/provider/link.py | JsLinkProvider.build_default_filepath | def build_default_filepath(self):
'''Called when 'filepath' is not defined in the settings'''
return os.path.join(
self.app_config.name,
'scripts',
self.template_relpath + '.js',
) | python | def build_default_filepath(self):
'''Called when 'filepath' is not defined in the settings'''
return os.path.join(
self.app_config.name,
'scripts',
self.template_relpath + '.js',
) | [
"def",
"build_default_filepath",
"(",
"self",
")",
":",
"return",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"app_config",
".",
"name",
",",
"'scripts'",
",",
"self",
".",
"template_relpath",
"+",
"'.js'",
",",
")"
] | Called when 'filepath' is not defined in the settings | [
"Called",
"when",
"filepath",
"is",
"not",
"defined",
"in",
"the",
"settings"
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/provider/link.py#L180-L186 | train |
doconix/django-mako-plus | django_mako_plus/tags.py | django_include | def django_include(context, template_name, **kwargs):
'''
Mako tag to include a Django template withing the current DMP (Mako) template.
Since this is a Django template, it is search for using the Django search
algorithm (instead of the DMP app-based concept).
See https://docs.djangoproject.com/en/2... | python | def django_include(context, template_name, **kwargs):
'''
Mako tag to include a Django template withing the current DMP (Mako) template.
Since this is a Django template, it is search for using the Django search
algorithm (instead of the DMP app-based concept).
See https://docs.djangoproject.com/en/2... | [
"def",
"django_include",
"(",
"context",
",",
"template_name",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"djengine",
"=",
"engines",
"[",
"'django'",
"]",
"except",
"KeyError",
"as",
"e",
":",
"raise",
"TemplateDoesNotExist",
"(",
"\"Django template engin... | Mako tag to include a Django template withing the current DMP (Mako) template.
Since this is a Django template, it is search for using the Django search
algorithm (instead of the DMP app-based concept).
See https://docs.djangoproject.com/en/2.1/topics/templates/.
The current context is sent to the incl... | [
"Mako",
"tag",
"to",
"include",
"a",
"Django",
"template",
"withing",
"the",
"current",
"DMP",
"(",
"Mako",
")",
"template",
".",
"Since",
"this",
"is",
"a",
"Django",
"template",
"it",
"is",
"search",
"for",
"using",
"the",
"Django",
"search",
"algorithm"... | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/tags.py#L14-L33 | train |
doconix/django-mako-plus | django_mako_plus/tags.py | _toggle_autoescape | def _toggle_autoescape(context, escape_on=True):
'''
Internal method to toggle autoescaping on or off. This function
needs access to the caller, so the calling method must be
decorated with @supports_caller.
'''
previous = is_autoescape(context)
setattr(context.caller_stack, AUTOESCAPE_KEY, ... | python | def _toggle_autoescape(context, escape_on=True):
'''
Internal method to toggle autoescaping on or off. This function
needs access to the caller, so the calling method must be
decorated with @supports_caller.
'''
previous = is_autoescape(context)
setattr(context.caller_stack, AUTOESCAPE_KEY, ... | [
"def",
"_toggle_autoescape",
"(",
"context",
",",
"escape_on",
"=",
"True",
")",
":",
"previous",
"=",
"is_autoescape",
"(",
"context",
")",
"setattr",
"(",
"context",
".",
"caller_stack",
",",
"AUTOESCAPE_KEY",
",",
"escape_on",
")",
"try",
":",
"context",
... | Internal method to toggle autoescaping on or off. This function
needs access to the caller, so the calling method must be
decorated with @supports_caller. | [
"Internal",
"method",
"to",
"toggle",
"autoescaping",
"on",
"or",
"off",
".",
"This",
"function",
"needs",
"access",
"to",
"the",
"caller",
"so",
"the",
"calling",
"method",
"must",
"be",
"decorated",
"with"
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/tags.py#L48-L59 | train |
doconix/django-mako-plus | django_mako_plus/management/commands/dmp_cleanup.py | pretty_relpath | def pretty_relpath(path, start):
'''
Returns a relative path, but only if it doesn't start with a non-pretty parent directory ".."
'''
relpath = os.path.relpath(path, start)
if relpath.startswith('..'):
return path
return relpath | python | def pretty_relpath(path, start):
'''
Returns a relative path, but only if it doesn't start with a non-pretty parent directory ".."
'''
relpath = os.path.relpath(path, start)
if relpath.startswith('..'):
return path
return relpath | [
"def",
"pretty_relpath",
"(",
"path",
",",
"start",
")",
":",
"relpath",
"=",
"os",
".",
"path",
".",
"relpath",
"(",
"path",
",",
"start",
")",
"if",
"relpath",
".",
"startswith",
"(",
"'..'",
")",
":",
"return",
"path",
"return",
"relpath"
] | Returns a relative path, but only if it doesn't start with a non-pretty parent directory ".." | [
"Returns",
"a",
"relative",
"path",
"but",
"only",
"if",
"it",
"doesn",
"t",
"start",
"with",
"a",
"non",
"-",
"pretty",
"parent",
"directory",
".."
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/management/commands/dmp_cleanup.py#L84-L91 | train |
doconix/django-mako-plus | django_mako_plus/router/decorators.py | view_function.is_decorated | def is_decorated(cls, f):
'''Returns True if the given function is decorated with @view_function'''
real_func = inspect.unwrap(f)
return real_func in cls.DECORATED_FUNCTIONS | python | def is_decorated(cls, f):
'''Returns True if the given function is decorated with @view_function'''
real_func = inspect.unwrap(f)
return real_func in cls.DECORATED_FUNCTIONS | [
"def",
"is_decorated",
"(",
"cls",
",",
"f",
")",
":",
"real_func",
"=",
"inspect",
".",
"unwrap",
"(",
"f",
")",
"return",
"real_func",
"in",
"cls",
".",
"DECORATED_FUNCTIONS"
] | Returns True if the given function is decorated with @view_function | [
"Returns",
"True",
"if",
"the",
"given",
"function",
"is",
"decorated",
"with"
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/router/decorators.py#L56-L59 | train |
doconix/django-mako-plus | django_mako_plus/provider/runner.py | ProviderRun.initialize_providers | def initialize_providers(cls):
'''Initializes the providers (called from dmp app ready())'''
dmp = apps.get_app_config('django_mako_plus')
# regular content providers
cls.CONTENT_PROVIDERS = []
for provider_settings in dmp.options[cls.SETTINGS_KEY]:
# import the class... | python | def initialize_providers(cls):
'''Initializes the providers (called from dmp app ready())'''
dmp = apps.get_app_config('django_mako_plus')
# regular content providers
cls.CONTENT_PROVIDERS = []
for provider_settings in dmp.options[cls.SETTINGS_KEY]:
# import the class... | [
"def",
"initialize_providers",
"(",
"cls",
")",
":",
"dmp",
"=",
"apps",
".",
"get_app_config",
"(",
"'django_mako_plus'",
")",
"# regular content providers",
"cls",
".",
"CONTENT_PROVIDERS",
"=",
"[",
"]",
"for",
"provider_settings",
"in",
"dmp",
".",
"options",
... | Initializes the providers (called from dmp app ready()) | [
"Initializes",
"the",
"providers",
"(",
"called",
"from",
"dmp",
"app",
"ready",
"()",
")"
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/provider/runner.py#L34-L52 | train |
doconix/django-mako-plus | django_mako_plus/provider/runner.py | ProviderRun.run | def run(self):
'''Performs the run through the templates and their providers'''
for tpl in self.templates:
for provider in tpl.providers:
provider.provide() | python | def run(self):
'''Performs the run through the templates and their providers'''
for tpl in self.templates:
for provider in tpl.providers:
provider.provide() | [
"def",
"run",
"(",
"self",
")",
":",
"for",
"tpl",
"in",
"self",
".",
"templates",
":",
"for",
"provider",
"in",
"tpl",
".",
"providers",
":",
"provider",
".",
"provide",
"(",
")"
] | Performs the run through the templates and their providers | [
"Performs",
"the",
"run",
"through",
"the",
"templates",
"and",
"their",
"providers"
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/provider/runner.py#L87-L91 | train |
doconix/django-mako-plus | django_mako_plus/provider/runner.py | ProviderRun.write | def write(self, content):
'''Provider instances use this to write to the buffer'''
self.buffer.write(content)
if settings.DEBUG:
self.buffer.write('\n') | python | def write(self, content):
'''Provider instances use this to write to the buffer'''
self.buffer.write(content)
if settings.DEBUG:
self.buffer.write('\n') | [
"def",
"write",
"(",
"self",
",",
"content",
")",
":",
"self",
".",
"buffer",
".",
"write",
"(",
"content",
")",
"if",
"settings",
".",
"DEBUG",
":",
"self",
".",
"buffer",
".",
"write",
"(",
"'\\n'",
")"
] | Provider instances use this to write to the buffer | [
"Provider",
"instances",
"use",
"this",
"to",
"write",
"to",
"the",
"buffer"
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/provider/runner.py#L93-L97 | train |
doconix/django-mako-plus | django_mako_plus/converter/info.py | ConverterFunctionInfo.prepare_sort_key | def prepare_sort_key(self):
'''
Triggered by view_function._sort_converters when our sort key should be created.
This can't be called in the constructor because Django models might not be ready yet.
'''
if isinstance(self.convert_type, str):
try:
app_n... | python | def prepare_sort_key(self):
'''
Triggered by view_function._sort_converters when our sort key should be created.
This can't be called in the constructor because Django models might not be ready yet.
'''
if isinstance(self.convert_type, str):
try:
app_n... | [
"def",
"prepare_sort_key",
"(",
"self",
")",
":",
"if",
"isinstance",
"(",
"self",
".",
"convert_type",
",",
"str",
")",
":",
"try",
":",
"app_name",
",",
"model_name",
"=",
"self",
".",
"convert_type",
".",
"split",
"(",
"'.'",
")",
"except",
"ValueErro... | Triggered by view_function._sort_converters when our sort key should be created.
This can't be called in the constructor because Django models might not be ready yet. | [
"Triggered",
"by",
"view_function",
".",
"_sort_converters",
"when",
"our",
"sort",
"key",
"should",
"be",
"created",
".",
"This",
"can",
"t",
"be",
"called",
"in",
"the",
"constructor",
"because",
"Django",
"models",
"might",
"not",
"be",
"ready",
"yet",
".... | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/converter/info.py#L19-L36 | train |
doconix/django-mako-plus | django_mako_plus/provider/compile.py | CompileProvider.build_command | def build_command(self):
'''Returns the command to run, as a list (see subprocess module)'''
# if defined in settings, run the function or return the string
if self.options['command']:
return self.options['command'](self) if callable(self.options['command']) else self.options['comman... | python | def build_command(self):
'''Returns the command to run, as a list (see subprocess module)'''
# if defined in settings, run the function or return the string
if self.options['command']:
return self.options['command'](self) if callable(self.options['command']) else self.options['comman... | [
"def",
"build_command",
"(",
"self",
")",
":",
"# if defined in settings, run the function or return the string",
"if",
"self",
".",
"options",
"[",
"'command'",
"]",
":",
"return",
"self",
".",
"options",
"[",
"'command'",
"]",
"(",
"self",
")",
"if",
"callable",... | Returns the command to run, as a list (see subprocess module) | [
"Returns",
"the",
"command",
"to",
"run",
"as",
"a",
"list",
"(",
"see",
"subprocess",
"module",
")"
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/provider/compile.py#L104-L110 | train |
doconix/django-mako-plus | django_mako_plus/provider/compile.py | CompileProvider.needs_compile | def needs_compile(self):
'''Returns True if self.sourcepath is newer than self.targetpath'''
try:
source_mtime = os.stat(self.sourcepath).st_mtime
except OSError: # no source for this template, so just return
return False
try:
target_mtime = os.stat(s... | python | def needs_compile(self):
'''Returns True if self.sourcepath is newer than self.targetpath'''
try:
source_mtime = os.stat(self.sourcepath).st_mtime
except OSError: # no source for this template, so just return
return False
try:
target_mtime = os.stat(s... | [
"def",
"needs_compile",
"(",
"self",
")",
":",
"try",
":",
"source_mtime",
"=",
"os",
".",
"stat",
"(",
"self",
".",
"sourcepath",
")",
".",
"st_mtime",
"except",
"OSError",
":",
"# no source for this template, so just return",
"return",
"False",
"try",
":",
"... | Returns True if self.sourcepath is newer than self.targetpath | [
"Returns",
"True",
"if",
"self",
".",
"sourcepath",
"is",
"newer",
"than",
"self",
".",
"targetpath"
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/provider/compile.py#L117-L128 | train |
doconix/django-mako-plus | django_mako_plus/template/util.py | template_inheritance | def template_inheritance(obj):
'''
Generator that iterates the template and its ancestors.
The order is from most specialized (furthest descendant) to
most general (furthest ancestor).
obj can be either:
1. Mako Template object
2. Mako `self` object (available within a rendering tem... | python | def template_inheritance(obj):
'''
Generator that iterates the template and its ancestors.
The order is from most specialized (furthest descendant) to
most general (furthest ancestor).
obj can be either:
1. Mako Template object
2. Mako `self` object (available within a rendering tem... | [
"def",
"template_inheritance",
"(",
"obj",
")",
":",
"if",
"isinstance",
"(",
"obj",
",",
"MakoTemplate",
")",
":",
"obj",
"=",
"create_mako_context",
"(",
"obj",
")",
"[",
"'self'",
"]",
"elif",
"isinstance",
"(",
"obj",
",",
"MakoContext",
")",
":",
"o... | Generator that iterates the template and its ancestors.
The order is from most specialized (furthest descendant) to
most general (furthest ancestor).
obj can be either:
1. Mako Template object
2. Mako `self` object (available within a rendering template) | [
"Generator",
"that",
"iterates",
"the",
"template",
"and",
"its",
"ancestors",
".",
"The",
"order",
"is",
"from",
"most",
"specialized",
"(",
"furthest",
"descendant",
")",
"to",
"most",
"general",
"(",
"furthest",
"ancestor",
")",
"."
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/template/util.py#L11-L27 | train |
doconix/django-mako-plus | django_mako_plus/template/util.py | get_template_debug | def get_template_debug(template_name, error):
'''
This structure is what Django wants when errors occur in templates.
It gives the user a nice stack trace in the error page during debug.
'''
# This is taken from mako.exceptions.html_error_template(), which has an issue
# in Py3 where files get l... | python | def get_template_debug(template_name, error):
'''
This structure is what Django wants when errors occur in templates.
It gives the user a nice stack trace in the error page during debug.
'''
# This is taken from mako.exceptions.html_error_template(), which has an issue
# in Py3 where files get l... | [
"def",
"get_template_debug",
"(",
"template_name",
",",
"error",
")",
":",
"# This is taken from mako.exceptions.html_error_template(), which has an issue",
"# in Py3 where files get loaded as bytes but `lines = src.split('\\n')` below",
"# splits with a string. Not sure if this is a bug or if I... | This structure is what Django wants when errors occur in templates.
It gives the user a nice stack trace in the error page during debug. | [
"This",
"structure",
"is",
"what",
"Django",
"wants",
"when",
"errors",
"occur",
"in",
"templates",
".",
"It",
"gives",
"the",
"user",
"a",
"nice",
"stack",
"trace",
"in",
"the",
"error",
"page",
"during",
"debug",
"."
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/template/util.py#L40-L170 | train |
doconix/django-mako-plus | django_mako_plus/template/adapter.py | MakoTemplateAdapter.name | def name(self):
'''Returns the name of this template (if created from a file) or "string" if not'''
if self.mako_template.filename:
return os.path.basename(self.mako_template.filename)
return 'string' | python | def name(self):
'''Returns the name of this template (if created from a file) or "string" if not'''
if self.mako_template.filename:
return os.path.basename(self.mako_template.filename)
return 'string' | [
"def",
"name",
"(",
"self",
")",
":",
"if",
"self",
".",
"mako_template",
".",
"filename",
":",
"return",
"os",
".",
"path",
".",
"basename",
"(",
"self",
".",
"mako_template",
".",
"filename",
")",
"return",
"'string'"
] | Returns the name of this template (if created from a file) or "string" if not | [
"Returns",
"the",
"name",
"of",
"this",
"template",
"(",
"if",
"created",
"from",
"a",
"file",
")",
"or",
"string",
"if",
"not"
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/template/adapter.py#L39-L43 | train |
doconix/django-mako-plus | django_mako_plus/template/adapter.py | MakoTemplateAdapter.render | def render(self, context=None, request=None, def_name=None):
'''
Renders a template using the Mako system. This method signature conforms to
the Django template API, which specifies that template.render() returns a string.
@context A dictionary of name=value variables to send to t... | python | def render(self, context=None, request=None, def_name=None):
'''
Renders a template using the Mako system. This method signature conforms to
the Django template API, which specifies that template.render() returns a string.
@context A dictionary of name=value variables to send to t... | [
"def",
"render",
"(",
"self",
",",
"context",
"=",
"None",
",",
"request",
"=",
"None",
",",
"def_name",
"=",
"None",
")",
":",
"dmp",
"=",
"apps",
".",
"get_app_config",
"(",
"'django_mako_plus'",
")",
"# set up the context dictionary, which is the variables avai... | Renders a template using the Mako system. This method signature conforms to
the Django template API, which specifies that template.render() returns a string.
@context A dictionary of name=value variables to send to the template page. This can be a real dictionary
or a Djang... | [
"Renders",
"a",
"template",
"using",
"the",
"Mako",
"system",
".",
"This",
"method",
"signature",
"conforms",
"to",
"the",
"Django",
"template",
"API",
"which",
"specifies",
"that",
"template",
".",
"render",
"()",
"returns",
"a",
"string",
"."
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/template/adapter.py#L57-L131 | train |
doconix/django-mako-plus | django_mako_plus/template/adapter.py | MakoTemplateAdapter.render_to_response | def render_to_response(self, context=None, request=None, def_name=None, content_type=None, status=None, charset=None):
'''
Renders the template and returns an HttpRequest object containing its content.
This method returns a django.http.Http404 exception if the template is not found.
If ... | python | def render_to_response(self, context=None, request=None, def_name=None, content_type=None, status=None, charset=None):
'''
Renders the template and returns an HttpRequest object containing its content.
This method returns a django.http.Http404 exception if the template is not found.
If ... | [
"def",
"render_to_response",
"(",
"self",
",",
"context",
"=",
"None",
",",
"request",
"=",
"None",
",",
"def_name",
"=",
"None",
",",
"content_type",
"=",
"None",
",",
"status",
"=",
"None",
",",
"charset",
"=",
"None",
")",
":",
"try",
":",
"if",
"... | Renders the template and returns an HttpRequest object containing its content.
This method returns a django.http.Http404 exception if the template is not found.
If the template raises a django_mako_plus.RedirectException, the browser is redirected to
the given page, and a new request from the b... | [
"Renders",
"the",
"template",
"and",
"returns",
"an",
"HttpRequest",
"object",
"containing",
"its",
"content",
"."
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/template/adapter.py#L134-L184 | train |
doconix/django-mako-plus | django_mako_plus/management/mixins.py | DMPCommandMixIn.get_action_by_dest | def get_action_by_dest(self, parser, dest):
'''Retrieves the given parser action object by its dest= attribute'''
for action in parser._actions:
if action.dest == dest:
return action
return None | python | def get_action_by_dest(self, parser, dest):
'''Retrieves the given parser action object by its dest= attribute'''
for action in parser._actions:
if action.dest == dest:
return action
return None | [
"def",
"get_action_by_dest",
"(",
"self",
",",
"parser",
",",
"dest",
")",
":",
"for",
"action",
"in",
"parser",
".",
"_actions",
":",
"if",
"action",
".",
"dest",
"==",
"dest",
":",
"return",
"action",
"return",
"None"
] | Retrieves the given parser action object by its dest= attribute | [
"Retrieves",
"the",
"given",
"parser",
"action",
"object",
"by",
"its",
"dest",
"=",
"attribute"
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/management/mixins.py#L34-L39 | train |
doconix/django-mako-plus | django_mako_plus/management/mixins.py | DMPCommandMixIn.execute | def execute(self, *args, **options):
'''Placing this in execute because then subclass handle() don't have to call super'''
if options['verbose']:
options['verbosity'] = 3
if options['quiet']:
options['verbosity'] = 0
self.verbosity = options.get('verbosity', 1)
... | python | def execute(self, *args, **options):
'''Placing this in execute because then subclass handle() don't have to call super'''
if options['verbose']:
options['verbosity'] = 3
if options['quiet']:
options['verbosity'] = 0
self.verbosity = options.get('verbosity', 1)
... | [
"def",
"execute",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"options",
")",
":",
"if",
"options",
"[",
"'verbose'",
"]",
":",
"options",
"[",
"'verbosity'",
"]",
"=",
"3",
"if",
"options",
"[",
"'quiet'",
"]",
":",
"options",
"[",
"'verbosity'",
... | Placing this in execute because then subclass handle() don't have to call super | [
"Placing",
"this",
"in",
"execute",
"because",
"then",
"subclass",
"handle",
"()",
"don",
"t",
"have",
"to",
"call",
"super"
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/management/mixins.py#L42-L49 | train |
doconix/django-mako-plus | django_mako_plus/management/mixins.py | DMPCommandMixIn.message | def message(self, msg='', level=1, tab=0):
'''Print a message to the console'''
if self.verbosity >= level:
self.stdout.write('{}{}'.format(' ' * tab, msg)) | python | def message(self, msg='', level=1, tab=0):
'''Print a message to the console'''
if self.verbosity >= level:
self.stdout.write('{}{}'.format(' ' * tab, msg)) | [
"def",
"message",
"(",
"self",
",",
"msg",
"=",
"''",
",",
"level",
"=",
"1",
",",
"tab",
"=",
"0",
")",
":",
"if",
"self",
".",
"verbosity",
">=",
"level",
":",
"self",
".",
"stdout",
".",
"write",
"(",
"'{}{}'",
".",
"format",
"(",
"' '",
... | Print a message to the console | [
"Print",
"a",
"message",
"to",
"the",
"console"
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/management/mixins.py#L57-L60 | train |
doconix/django-mako-plus | django_mako_plus/util/base58.py | b58enc | def b58enc(uid):
'''Encodes a UID to an 11-length string, encoded using base58 url-safe alphabet'''
# note: i tested a buffer array too, but string concat was 2x faster
if not isinstance(uid, int):
raise ValueError('Invalid integer: {}'.format(uid))
if uid == 0:
return BASE58CHARS[0]
... | python | def b58enc(uid):
'''Encodes a UID to an 11-length string, encoded using base58 url-safe alphabet'''
# note: i tested a buffer array too, but string concat was 2x faster
if not isinstance(uid, int):
raise ValueError('Invalid integer: {}'.format(uid))
if uid == 0:
return BASE58CHARS[0]
... | [
"def",
"b58enc",
"(",
"uid",
")",
":",
"# note: i tested a buffer array too, but string concat was 2x faster",
"if",
"not",
"isinstance",
"(",
"uid",
",",
"int",
")",
":",
"raise",
"ValueError",
"(",
"'Invalid integer: {}'",
".",
"format",
"(",
"uid",
")",
")",
"i... | Encodes a UID to an 11-length string, encoded using base58 url-safe alphabet | [
"Encodes",
"a",
"UID",
"to",
"an",
"11",
"-",
"length",
"string",
"encoded",
"using",
"base58",
"url",
"-",
"safe",
"alphabet"
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/util/base58.py#L9-L20 | train |
doconix/django-mako-plus | django_mako_plus/util/base58.py | b58dec | def b58dec(enc_uid):
'''Decodes a UID from base58, url-safe alphabet back to int.'''
if isinstance(enc_uid, str):
pass
elif isinstance(enc_uid, bytes):
enc_uid = enc_uid.decode('utf8')
else:
raise ValueError('Cannot decode this type: {}'.format(enc_uid))
uid = 0
try:
... | python | def b58dec(enc_uid):
'''Decodes a UID from base58, url-safe alphabet back to int.'''
if isinstance(enc_uid, str):
pass
elif isinstance(enc_uid, bytes):
enc_uid = enc_uid.decode('utf8')
else:
raise ValueError('Cannot decode this type: {}'.format(enc_uid))
uid = 0
try:
... | [
"def",
"b58dec",
"(",
"enc_uid",
")",
":",
"if",
"isinstance",
"(",
"enc_uid",
",",
"str",
")",
":",
"pass",
"elif",
"isinstance",
"(",
"enc_uid",
",",
"bytes",
")",
":",
"enc_uid",
"=",
"enc_uid",
".",
"decode",
"(",
"'utf8'",
")",
"else",
":",
"rai... | Decodes a UID from base58, url-safe alphabet back to int. | [
"Decodes",
"a",
"UID",
"from",
"base58",
"url",
"-",
"safe",
"alphabet",
"back",
"to",
"int",
"."
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/util/base58.py#L22-L36 | train |
doconix/django-mako-plus | django_mako_plus/management/commands/dmp_collectstatic.py | minify | def minify(text, minifier):
'''Minifies the source text (if needed)'''
# there really isn't a good way to know if a file is already minified.
# our heuristic is if source is more than 50 bytes greater of dest OR
# if a hard return is found in the first 50 chars, we assume it is not minified.
minifie... | python | def minify(text, minifier):
'''Minifies the source text (if needed)'''
# there really isn't a good way to know if a file is already minified.
# our heuristic is if source is more than 50 bytes greater of dest OR
# if a hard return is found in the first 50 chars, we assume it is not minified.
minifie... | [
"def",
"minify",
"(",
"text",
",",
"minifier",
")",
":",
"# there really isn't a good way to know if a file is already minified.",
"# our heuristic is if source is more than 50 bytes greater of dest OR",
"# if a hard return is found in the first 50 chars, we assume it is not minified.",
"minif... | Minifies the source text (if needed) | [
"Minifies",
"the",
"source",
"text",
"(",
"if",
"needed",
")"
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/management/commands/dmp_collectstatic.py#L235-L243 | train |
doconix/django-mako-plus | django_mako_plus/management/commands/dmp_collectstatic.py | Rule.match | def match(self, fname, flevel, ftype):
'''Returns the result score if the file matches this rule'''
# if filetype is the same
# and level isn't set or level is the same
# and pattern matche the filename
if self.filetype == ftype and (self.level is None or self.level == flevel) an... | python | def match(self, fname, flevel, ftype):
'''Returns the result score if the file matches this rule'''
# if filetype is the same
# and level isn't set or level is the same
# and pattern matche the filename
if self.filetype == ftype and (self.level is None or self.level == flevel) an... | [
"def",
"match",
"(",
"self",
",",
"fname",
",",
"flevel",
",",
"ftype",
")",
":",
"# if filetype is the same",
"# and level isn't set or level is the same",
"# and pattern matche the filename",
"if",
"self",
".",
"filetype",
"==",
"ftype",
"and",
"(",
"self",
".",
"... | Returns the result score if the file matches this rule | [
"Returns",
"the",
"result",
"score",
"if",
"the",
"file",
"matches",
"this",
"rule"
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/management/commands/dmp_collectstatic.py#L31-L38 | train |
doconix/django-mako-plus | django_mako_plus/management/commands/dmp_collectstatic.py | Command.create_rules | def create_rules(self):
'''Adds rules for the command line options'''
dmp = apps.get_app_config('django_mako_plus')
# the default
rules = [
# files are included by default
Rule('*', level=None, filetype=TYPE_FILE, score=1),
... | python | def create_rules(self):
'''Adds rules for the command line options'''
dmp = apps.get_app_config('django_mako_plus')
# the default
rules = [
# files are included by default
Rule('*', level=None, filetype=TYPE_FILE, score=1),
... | [
"def",
"create_rules",
"(",
"self",
")",
":",
"dmp",
"=",
"apps",
".",
"get_app_config",
"(",
"'django_mako_plus'",
")",
"# the default",
"rules",
"=",
"[",
"# files are included by default",
"Rule",
"(",
"'*'",
",",
"level",
"=",
"None",
",",
"filetype",
"=",... | Adds rules for the command line options | [
"Adds",
"rules",
"for",
"the",
"command",
"line",
"options"
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/management/commands/dmp_collectstatic.py#L125-L165 | train |
doconix/django-mako-plus | django_mako_plus/management/commands/dmp_collectstatic.py | Command.copy_dir | def copy_dir(self, source, dest, level=0):
'''Copies the static files from one directory to another. If this command is run, we assume the user wants to overwrite any existing files.'''
encoding = settings.DEFAULT_CHARSET or 'utf8'
msglevel = 2 if level == 0 else 3
self.message('Directo... | python | def copy_dir(self, source, dest, level=0):
'''Copies the static files from one directory to another. If this command is run, we assume the user wants to overwrite any existing files.'''
encoding = settings.DEFAULT_CHARSET or 'utf8'
msglevel = 2 if level == 0 else 3
self.message('Directo... | [
"def",
"copy_dir",
"(",
"self",
",",
"source",
",",
"dest",
",",
"level",
"=",
"0",
")",
":",
"encoding",
"=",
"settings",
".",
"DEFAULT_CHARSET",
"or",
"'utf8'",
"msglevel",
"=",
"2",
"if",
"level",
"==",
"0",
"else",
"3",
"self",
".",
"message",
"(... | Copies the static files from one directory to another. If this command is run, we assume the user wants to overwrite any existing files. | [
"Copies",
"the",
"static",
"files",
"from",
"one",
"directory",
"to",
"another",
".",
"If",
"this",
"command",
"is",
"run",
"we",
"assume",
"the",
"user",
"wants",
"to",
"overwrite",
"any",
"existing",
"files",
"."
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/management/commands/dmp_collectstatic.py#L168-L228 | train |
doconix/django-mako-plus | django_mako_plus/templatetags/django_mako_plus.py | dmp_include | def dmp_include(context, template_name, def_name=None, **kwargs):
'''
Includes a DMP (Mako) template into a normal django template.
context: automatically provided
template_name: specified as "app/template"
def_name: optional block to render within the template
Example:
{... | python | def dmp_include(context, template_name, def_name=None, **kwargs):
'''
Includes a DMP (Mako) template into a normal django template.
context: automatically provided
template_name: specified as "app/template"
def_name: optional block to render within the template
Example:
{... | [
"def",
"dmp_include",
"(",
"context",
",",
"template_name",
",",
"def_name",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"dmp",
"=",
"apps",
".",
"get_app_config",
"(",
"'django_mako_plus'",
")",
"template",
"=",
"dmp",
".",
"engine",
".",
"get_templat... | Includes a DMP (Mako) template into a normal django template.
context: automatically provided
template_name: specified as "app/template"
def_name: optional block to render within the template
Example:
{% load django_mako_plus %}
{% dmp_include "homepage/bsnav_dj.html" %}
... | [
"Includes",
"a",
"DMP",
"(",
"Mako",
")",
"template",
"into",
"a",
"normal",
"django",
"template",
"."
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/templatetags/django_mako_plus.py#L17-L39 | train |
doconix/django-mako-plus | django_mako_plus/router/data.py | RoutingData.render | def render(self, template, context=None, def_name=None, subdir='templates', content_type=None, status=None, charset=None):
'''App-specific render function that renders templates in the *current app*, attached to the request for convenience'''
template_adapter = self.get_template_loader(subdir).get_templ... | python | def render(self, template, context=None, def_name=None, subdir='templates', content_type=None, status=None, charset=None):
'''App-specific render function that renders templates in the *current app*, attached to the request for convenience'''
template_adapter = self.get_template_loader(subdir).get_templ... | [
"def",
"render",
"(",
"self",
",",
"template",
",",
"context",
"=",
"None",
",",
"def_name",
"=",
"None",
",",
"subdir",
"=",
"'templates'",
",",
"content_type",
"=",
"None",
",",
"status",
"=",
"None",
",",
"charset",
"=",
"None",
")",
":",
"template_... | App-specific render function that renders templates in the *current app*, attached to the request for convenience | [
"App",
"-",
"specific",
"render",
"function",
"that",
"renders",
"templates",
"in",
"the",
"*",
"current",
"app",
"*",
"attached",
"to",
"the",
"request",
"for",
"convenience"
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/router/data.py#L87-L90 | train |
doconix/django-mako-plus | django_mako_plus/router/data.py | RoutingData.render_to_string | def render_to_string(self, template, context=None, def_name=None, subdir='templates'):
'''App-specific render function that renders templates in the *current app*, attached to the request for convenience'''
template_adapter = self.get_template_loader(subdir).get_template(template)
return getattr... | python | def render_to_string(self, template, context=None, def_name=None, subdir='templates'):
'''App-specific render function that renders templates in the *current app*, attached to the request for convenience'''
template_adapter = self.get_template_loader(subdir).get_template(template)
return getattr... | [
"def",
"render_to_string",
"(",
"self",
",",
"template",
",",
"context",
"=",
"None",
",",
"def_name",
"=",
"None",
",",
"subdir",
"=",
"'templates'",
")",
":",
"template_adapter",
"=",
"self",
".",
"get_template_loader",
"(",
"subdir",
")",
".",
"get_templa... | App-specific render function that renders templates in the *current app*, attached to the request for convenience | [
"App",
"-",
"specific",
"render",
"function",
"that",
"renders",
"templates",
"in",
"the",
"*",
"current",
"app",
"*",
"attached",
"to",
"the",
"request",
"for",
"convenience"
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/router/data.py#L93-L96 | train |
doconix/django-mako-plus | django_mako_plus/router/data.py | RoutingData.get_template_loader | def get_template_loader(self, subdir='templates'):
'''App-specific function to get the current app's template loader'''
if self.request is None:
raise ValueError("this method can only be called after the view middleware is run. Check that `django_mako_plus.middleware` is in MIDDLEWARE.")
... | python | def get_template_loader(self, subdir='templates'):
'''App-specific function to get the current app's template loader'''
if self.request is None:
raise ValueError("this method can only be called after the view middleware is run. Check that `django_mako_plus.middleware` is in MIDDLEWARE.")
... | [
"def",
"get_template_loader",
"(",
"self",
",",
"subdir",
"=",
"'templates'",
")",
":",
"if",
"self",
".",
"request",
"is",
"None",
":",
"raise",
"ValueError",
"(",
"\"this method can only be called after the view middleware is run. Check that `django_mako_plus.middleware` is... | App-specific function to get the current app's template loader | [
"App",
"-",
"specific",
"function",
"to",
"get",
"the",
"current",
"app",
"s",
"template",
"loader"
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/router/data.py#L104-L109 | train |
doconix/django-mako-plus | django_mako_plus/apps.py | Config.ready | def ready(self):
'''Called by Django when the app is ready for use.'''
# set up the options
self.options = {}
self.options.update(DEFAULT_OPTIONS)
for template_engine in settings.TEMPLATES:
if template_engine.get('BACKEND', '').startswith('django_mako_plus'):
... | python | def ready(self):
'''Called by Django when the app is ready for use.'''
# set up the options
self.options = {}
self.options.update(DEFAULT_OPTIONS)
for template_engine in settings.TEMPLATES:
if template_engine.get('BACKEND', '').startswith('django_mako_plus'):
... | [
"def",
"ready",
"(",
"self",
")",
":",
"# set up the options",
"self",
".",
"options",
"=",
"{",
"}",
"self",
".",
"options",
".",
"update",
"(",
"DEFAULT_OPTIONS",
")",
"for",
"template_engine",
"in",
"settings",
".",
"TEMPLATES",
":",
"if",
"template_engin... | Called by Django when the app is ready for use. | [
"Called",
"by",
"Django",
"when",
"the",
"app",
"is",
"ready",
"for",
"use",
"."
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/apps.py#L18-L46 | train |
doconix/django-mako-plus | django_mako_plus/apps.py | Config.register_app | def register_app(self, app=None):
'''
Registers an app as a "DMP-enabled" app. Normally, DMP does this
automatically when included in urls.py.
If app is None, the DEFAULT_APP is registered.
'''
app = app or self.options['DEFAULT_APP']
if not app:
rai... | python | def register_app(self, app=None):
'''
Registers an app as a "DMP-enabled" app. Normally, DMP does this
automatically when included in urls.py.
If app is None, the DEFAULT_APP is registered.
'''
app = app or self.options['DEFAULT_APP']
if not app:
rai... | [
"def",
"register_app",
"(",
"self",
",",
"app",
"=",
"None",
")",
":",
"app",
"=",
"app",
"or",
"self",
".",
"options",
"[",
"'DEFAULT_APP'",
"]",
"if",
"not",
"app",
":",
"raise",
"ImproperlyConfigured",
"(",
"'An app name is required because DEFAULT_APP is emp... | Registers an app as a "DMP-enabled" app. Normally, DMP does this
automatically when included in urls.py.
If app is None, the DEFAULT_APP is registered. | [
"Registers",
"an",
"app",
"as",
"a",
"DMP",
"-",
"enabled",
"app",
".",
"Normally",
"DMP",
"does",
"this",
"automatically",
"when",
"included",
"in",
"urls",
".",
"py",
"."
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/apps.py#L49-L80 | train |
doconix/django-mako-plus | django_mako_plus/apps.py | Config.is_registered_app | def is_registered_app(self, app):
'''Returns true if the given app/app name is registered with DMP'''
if app is None:
return False
if isinstance(app, AppConfig):
app = app.name
return app in self.registered_apps | python | def is_registered_app(self, app):
'''Returns true if the given app/app name is registered with DMP'''
if app is None:
return False
if isinstance(app, AppConfig):
app = app.name
return app in self.registered_apps | [
"def",
"is_registered_app",
"(",
"self",
",",
"app",
")",
":",
"if",
"app",
"is",
"None",
":",
"return",
"False",
"if",
"isinstance",
"(",
"app",
",",
"AppConfig",
")",
":",
"app",
"=",
"app",
".",
"name",
"return",
"app",
"in",
"self",
".",
"registe... | Returns true if the given app/app name is registered with DMP | [
"Returns",
"true",
"if",
"the",
"given",
"app",
"/",
"app",
"name",
"is",
"registered",
"with",
"DMP"
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/apps.py#L88-L94 | train |
doconix/django-mako-plus | django_mako_plus/router/urlparams.py | URLParamList.get | def get(self, idx, default=''):
'''Returns the element at idx, or default if idx is beyond the length of the list'''
# if the index is beyond the length of the list, return ''
if isinstance(idx, int) and (idx >= len(self) or idx < -1 * len(self)):
return default
# else do the... | python | def get(self, idx, default=''):
'''Returns the element at idx, or default if idx is beyond the length of the list'''
# if the index is beyond the length of the list, return ''
if isinstance(idx, int) and (idx >= len(self) or idx < -1 * len(self)):
return default
# else do the... | [
"def",
"get",
"(",
"self",
",",
"idx",
",",
"default",
"=",
"''",
")",
":",
"# if the index is beyond the length of the list, return ''",
"if",
"isinstance",
"(",
"idx",
",",
"int",
")",
"and",
"(",
"idx",
">=",
"len",
"(",
"self",
")",
"or",
"idx",
"<",
... | Returns the element at idx, or default if idx is beyond the length of the list | [
"Returns",
"the",
"element",
"at",
"idx",
"or",
"default",
"if",
"idx",
"is",
"beyond",
"the",
"length",
"of",
"the",
"list"
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/router/urlparams.py#L16-L22 | train |
doconix/django-mako-plus | django_mako_plus/converter/converters.py | convert_int | def convert_int(value, parameter):
'''
Converts to int or float:
'', '-', None convert to parameter default
Anything else uses int() or float() constructor
'''
value = _check_default(value, parameter, ( '', '-', None ))
if value is None or isinstance(value, int):
return value... | python | def convert_int(value, parameter):
'''
Converts to int or float:
'', '-', None convert to parameter default
Anything else uses int() or float() constructor
'''
value = _check_default(value, parameter, ( '', '-', None ))
if value is None or isinstance(value, int):
return value... | [
"def",
"convert_int",
"(",
"value",
",",
"parameter",
")",
":",
"value",
"=",
"_check_default",
"(",
"value",
",",
"parameter",
",",
"(",
"''",
",",
"'-'",
",",
"None",
")",
")",
"if",
"value",
"is",
"None",
"or",
"isinstance",
"(",
"value",
",",
"in... | Converts to int or float:
'', '-', None convert to parameter default
Anything else uses int() or float() constructor | [
"Converts",
"to",
"int",
"or",
"float",
":",
"-",
"None",
"convert",
"to",
"parameter",
"default",
"Anything",
"else",
"uses",
"int",
"()",
"or",
"float",
"()",
"constructor"
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/converter/converters.py#L41-L53 | train |
doconix/django-mako-plus | django_mako_plus/converter/converters.py | convert_float | def convert_float(value, parameter):
'''
Converts to int or float:
'', '-', None convert to parameter default
Anything else uses int() or float() constructor
'''
value = _check_default(value, parameter, ( '', '-', None ))
if value is None or isinstance(value, float):
return v... | python | def convert_float(value, parameter):
'''
Converts to int or float:
'', '-', None convert to parameter default
Anything else uses int() or float() constructor
'''
value = _check_default(value, parameter, ( '', '-', None ))
if value is None or isinstance(value, float):
return v... | [
"def",
"convert_float",
"(",
"value",
",",
"parameter",
")",
":",
"value",
"=",
"_check_default",
"(",
"value",
",",
"parameter",
",",
"(",
"''",
",",
"'-'",
",",
"None",
")",
")",
"if",
"value",
"is",
"None",
"or",
"isinstance",
"(",
"value",
",",
"... | Converts to int or float:
'', '-', None convert to parameter default
Anything else uses int() or float() constructor | [
"Converts",
"to",
"int",
"or",
"float",
":",
"-",
"None",
"convert",
"to",
"parameter",
"default",
"Anything",
"else",
"uses",
"int",
"()",
"or",
"float",
"()",
"constructor"
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/converter/converters.py#L59-L71 | train |
doconix/django-mako-plus | django_mako_plus/converter/converters.py | convert_decimal | def convert_decimal(value, parameter):
'''
Converts to decimal.Decimal:
'', '-', None convert to parameter default
Anything else uses Decimal constructor
'''
value = _check_default(value, parameter, ( '', '-', None ))
if value is None or isinstance(value, decimal.Decimal):
re... | python | def convert_decimal(value, parameter):
'''
Converts to decimal.Decimal:
'', '-', None convert to parameter default
Anything else uses Decimal constructor
'''
value = _check_default(value, parameter, ( '', '-', None ))
if value is None or isinstance(value, decimal.Decimal):
re... | [
"def",
"convert_decimal",
"(",
"value",
",",
"parameter",
")",
":",
"value",
"=",
"_check_default",
"(",
"value",
",",
"parameter",
",",
"(",
"''",
",",
"'-'",
",",
"None",
")",
")",
"if",
"value",
"is",
"None",
"or",
"isinstance",
"(",
"value",
",",
... | Converts to decimal.Decimal:
'', '-', None convert to parameter default
Anything else uses Decimal constructor | [
"Converts",
"to",
"decimal",
".",
"Decimal",
":",
"-",
"None",
"convert",
"to",
"parameter",
"default",
"Anything",
"else",
"uses",
"Decimal",
"constructor"
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/converter/converters.py#L77-L89 | train |
doconix/django-mako-plus | django_mako_plus/converter/converters.py | convert_boolean | def convert_boolean(value, parameter, default=False):
'''
Converts to boolean (only the first char of the value is used):
'', '-', None convert to parameter default
'f', 'F', '0', False always convert to False
Anything else converts to True.
'''
value = _check_default(value, para... | python | def convert_boolean(value, parameter, default=False):
'''
Converts to boolean (only the first char of the value is used):
'', '-', None convert to parameter default
'f', 'F', '0', False always convert to False
Anything else converts to True.
'''
value = _check_default(value, para... | [
"def",
"convert_boolean",
"(",
"value",
",",
"parameter",
",",
"default",
"=",
"False",
")",
":",
"value",
"=",
"_check_default",
"(",
"value",
",",
"parameter",
",",
"(",
"''",
",",
"'-'",
",",
"None",
")",
")",
"if",
"isinstance",
"(",
"value",
",",
... | Converts to boolean (only the first char of the value is used):
'', '-', None convert to parameter default
'f', 'F', '0', False always convert to False
Anything else converts to True. | [
"Converts",
"to",
"boolean",
"(",
"only",
"the",
"first",
"char",
"of",
"the",
"value",
"is",
"used",
")",
":",
"-",
"None",
"convert",
"to",
"parameter",
"default",
"f",
"F",
"0",
"False",
"always",
"convert",
"to",
"False",
"Anything",
"else",
"convert... | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/converter/converters.py#L95-L107 | train |
doconix/django-mako-plus | django_mako_plus/converter/converters.py | convert_datetime | def convert_datetime(value, parameter):
'''
Converts to datetime.datetime:
'', '-', None convert to parameter default
The first matching format in settings.DATETIME_INPUT_FORMATS converts to datetime
'''
value = _check_default(value, parameter, ( '', '-', None ))
if value is None or ... | python | def convert_datetime(value, parameter):
'''
Converts to datetime.datetime:
'', '-', None convert to parameter default
The first matching format in settings.DATETIME_INPUT_FORMATS converts to datetime
'''
value = _check_default(value, parameter, ( '', '-', None ))
if value is None or ... | [
"def",
"convert_datetime",
"(",
"value",
",",
"parameter",
")",
":",
"value",
"=",
"_check_default",
"(",
"value",
",",
"parameter",
",",
"(",
"''",
",",
"'-'",
",",
"None",
")",
")",
"if",
"value",
"is",
"None",
"or",
"isinstance",
"(",
"value",
",",
... | Converts to datetime.datetime:
'', '-', None convert to parameter default
The first matching format in settings.DATETIME_INPUT_FORMATS converts to datetime | [
"Converts",
"to",
"datetime",
".",
"datetime",
":",
"-",
"None",
"convert",
"to",
"parameter",
"default",
"The",
"first",
"matching",
"format",
"in",
"settings",
".",
"DATETIME_INPUT_FORMATS",
"converts",
"to",
"datetime"
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/converter/converters.py#L113-L127 | train |
doconix/django-mako-plus | django_mako_plus/converter/converters.py | convert_date | def convert_date(value, parameter):
'''
Converts to datetime.date:
'', '-', None convert to parameter default
The first matching format in settings.DATE_INPUT_FORMATS converts to datetime
'''
value = _check_default(value, parameter, ( '', '-', None ))
if value is None or isinstance(v... | python | def convert_date(value, parameter):
'''
Converts to datetime.date:
'', '-', None convert to parameter default
The first matching format in settings.DATE_INPUT_FORMATS converts to datetime
'''
value = _check_default(value, parameter, ( '', '-', None ))
if value is None or isinstance(v... | [
"def",
"convert_date",
"(",
"value",
",",
"parameter",
")",
":",
"value",
"=",
"_check_default",
"(",
"value",
",",
"parameter",
",",
"(",
"''",
",",
"'-'",
",",
"None",
")",
")",
"if",
"value",
"is",
"None",
"or",
"isinstance",
"(",
"value",
",",
"d... | Converts to datetime.date:
'', '-', None convert to parameter default
The first matching format in settings.DATE_INPUT_FORMATS converts to datetime | [
"Converts",
"to",
"datetime",
".",
"date",
":",
"-",
"None",
"convert",
"to",
"parameter",
"default",
"The",
"first",
"matching",
"format",
"in",
"settings",
".",
"DATE_INPUT_FORMATS",
"converts",
"to",
"datetime"
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/converter/converters.py#L133-L147 | train |
doconix/django-mako-plus | django_mako_plus/converter/converters.py | convert_id_to_model | def convert_id_to_model(value, parameter):
'''
Converts to a Model object.
'', '-', '0', None convert to parameter default
Anything else is assumed an object id and sent to `.get(id=value)`.
'''
value = _check_default(value, parameter, ( '', '-', '0', None ))
if isinstance(value, (in... | python | def convert_id_to_model(value, parameter):
'''
Converts to a Model object.
'', '-', '0', None convert to parameter default
Anything else is assumed an object id and sent to `.get(id=value)`.
'''
value = _check_default(value, parameter, ( '', '-', '0', None ))
if isinstance(value, (in... | [
"def",
"convert_id_to_model",
"(",
"value",
",",
"parameter",
")",
":",
"value",
"=",
"_check_default",
"(",
"value",
",",
"parameter",
",",
"(",
"''",
",",
"'-'",
",",
"'0'",
",",
"None",
")",
")",
"if",
"isinstance",
"(",
"value",
",",
"(",
"int",
... | Converts to a Model object.
'', '-', '0', None convert to parameter default
Anything else is assumed an object id and sent to `.get(id=value)`. | [
"Converts",
"to",
"a",
"Model",
"object",
".",
"-",
"0",
"None",
"convert",
"to",
"parameter",
"default",
"Anything",
"else",
"is",
"assumed",
"an",
"object",
"id",
"and",
"sent",
"to",
".",
"get",
"(",
"id",
"=",
"value",
")",
"."
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/converter/converters.py#L153-L165 | train |
doconix/django-mako-plus | django_mako_plus/converter/converters.py | _check_default | def _check_default(value, parameter, default_chars):
'''Returns the default if the value is "empty"'''
# not using a set here because it fails when value is unhashable
if value in default_chars:
if parameter.default is inspect.Parameter.empty:
raise ValueError('Value was empty, but no de... | python | def _check_default(value, parameter, default_chars):
'''Returns the default if the value is "empty"'''
# not using a set here because it fails when value is unhashable
if value in default_chars:
if parameter.default is inspect.Parameter.empty:
raise ValueError('Value was empty, but no de... | [
"def",
"_check_default",
"(",
"value",
",",
"parameter",
",",
"default_chars",
")",
":",
"# not using a set here because it fails when value is unhashable",
"if",
"value",
"in",
"default_chars",
":",
"if",
"parameter",
".",
"default",
"is",
"inspect",
".",
"Parameter",
... | Returns the default if the value is "empty" | [
"Returns",
"the",
"default",
"if",
"the",
"value",
"is",
"empty"
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/converter/converters.py#L171-L178 | train |
doconix/django-mako-plus | django_mako_plus/converter/decorators.py | parameter_converter | def parameter_converter(*convert_types):
'''
Decorator that denotes a function as a url parameter converter.
'''
def inner(func):
for ct in convert_types:
ParameterConverter._register_converter(func, ct)
return func
return inner | python | def parameter_converter(*convert_types):
'''
Decorator that denotes a function as a url parameter converter.
'''
def inner(func):
for ct in convert_types:
ParameterConverter._register_converter(func, ct)
return func
return inner | [
"def",
"parameter_converter",
"(",
"*",
"convert_types",
")",
":",
"def",
"inner",
"(",
"func",
")",
":",
"for",
"ct",
"in",
"convert_types",
":",
"ParameterConverter",
".",
"_register_converter",
"(",
"func",
",",
"ct",
")",
"return",
"func",
"return",
"inn... | Decorator that denotes a function as a url parameter converter. | [
"Decorator",
"that",
"denotes",
"a",
"function",
"as",
"a",
"url",
"parameter",
"converter",
"."
] | a90f9b4af19e5fa9f83452989cdcaed21569a181 | https://github.com/doconix/django-mako-plus/blob/a90f9b4af19e5fa9f83452989cdcaed21569a181/django_mako_plus/converter/decorators.py#L5-L13 | train |
insilichem/ommprotocol | ommprotocol/md.py | protocol | def protocol(handler, cfg):
"""
Run all the stages in protocol
Parameters
----------
handler : SystemHandler
Container of initial conditions of simulation
cfg : dict
Imported YAML file.
"""
# Stages
if 'stages' not in cfg:
raise ValueError('Protocol must inc... | python | def protocol(handler, cfg):
"""
Run all the stages in protocol
Parameters
----------
handler : SystemHandler
Container of initial conditions of simulation
cfg : dict
Imported YAML file.
"""
# Stages
if 'stages' not in cfg:
raise ValueError('Protocol must inc... | [
"def",
"protocol",
"(",
"handler",
",",
"cfg",
")",
":",
"# Stages",
"if",
"'stages'",
"not",
"in",
"cfg",
":",
"raise",
"ValueError",
"(",
"'Protocol must include stages of simulation'",
")",
"pos",
",",
"vel",
",",
"box",
"=",
"handler",
".",
"positions",
... | Run all the stages in protocol
Parameters
----------
handler : SystemHandler
Container of initial conditions of simulation
cfg : dict
Imported YAML file. | [
"Run",
"all",
"the",
"stages",
"in",
"protocol"
] | 7283fddba7203e5ac3542fdab41fc1279d3b444e | https://github.com/insilichem/ommprotocol/blob/7283fddba7203e5ac3542fdab41fc1279d3b444e/ommprotocol/md.py#L65-L92 | train |
insilichem/ommprotocol | ommprotocol/md.py | Stage.run | def run(self):
"""
Launch MD simulation, which may consist of:
1. Optional minimization
2. Actual MD simulation, with n steps.
This method also handles reporters.
Returns
-------
positions, velocities : unit.Quantity([natoms, 3])
Position, ve... | python | def run(self):
"""
Launch MD simulation, which may consist of:
1. Optional minimization
2. Actual MD simulation, with n steps.
This method also handles reporters.
Returns
-------
positions, velocities : unit.Quantity([natoms, 3])
Position, ve... | [
"def",
"run",
"(",
"self",
")",
":",
"if",
"self",
".",
"verbose",
":",
"status",
"=",
"'#{}'",
".",
"format",
"(",
"self",
".",
"stage_index",
")",
"if",
"self",
".",
"total_stages",
"is",
"not",
"None",
":",
"status",
"+=",
"'/{}'",
".",
"format",
... | Launch MD simulation, which may consist of:
1. Optional minimization
2. Actual MD simulation, with n steps.
This method also handles reporters.
Returns
-------
positions, velocities : unit.Quantity([natoms, 3])
Position, velocity of each atom in the system
... | [
"Launch",
"MD",
"simulation",
"which",
"may",
"consist",
"of",
":",
"1",
".",
"Optional",
"minimization",
"2",
".",
"Actual",
"MD",
"simulation",
"with",
"n",
"steps",
"."
] | 7283fddba7203e5ac3542fdab41fc1279d3b444e | https://github.com/insilichem/ommprotocol/blob/7283fddba7203e5ac3542fdab41fc1279d3b444e/ommprotocol/md.py#L272-L352 | train |
insilichem/ommprotocol | ommprotocol/md.py | Stage.minimize | def minimize(self, tolerance=None, max_iterations=None):
"""
Minimize energy of the system until meeting `tolerance` or
performing `max_iterations`.
"""
if tolerance is None:
tolerance = self.minimization_tolerance
if max_iterations is None:
max_it... | python | def minimize(self, tolerance=None, max_iterations=None):
"""
Minimize energy of the system until meeting `tolerance` or
performing `max_iterations`.
"""
if tolerance is None:
tolerance = self.minimization_tolerance
if max_iterations is None:
max_it... | [
"def",
"minimize",
"(",
"self",
",",
"tolerance",
"=",
"None",
",",
"max_iterations",
"=",
"None",
")",
":",
"if",
"tolerance",
"is",
"None",
":",
"tolerance",
"=",
"self",
".",
"minimization_tolerance",
"if",
"max_iterations",
"is",
"None",
":",
"max_iterat... | Minimize energy of the system until meeting `tolerance` or
performing `max_iterations`. | [
"Minimize",
"energy",
"of",
"the",
"system",
"until",
"meeting",
"tolerance",
"or",
"performing",
"max_iterations",
"."
] | 7283fddba7203e5ac3542fdab41fc1279d3b444e | https://github.com/insilichem/ommprotocol/blob/7283fddba7203e5ac3542fdab41fc1279d3b444e/ommprotocol/md.py#L354-L363 | train |
insilichem/ommprotocol | ommprotocol/md.py | Stage.simulate | def simulate(self, steps=None):
"""
Advance simulation n steps
"""
if steps is None:
steps = self.steps
self.simulation.step(steps) | python | def simulate(self, steps=None):
"""
Advance simulation n steps
"""
if steps is None:
steps = self.steps
self.simulation.step(steps) | [
"def",
"simulate",
"(",
"self",
",",
"steps",
"=",
"None",
")",
":",
"if",
"steps",
"is",
"None",
":",
"steps",
"=",
"self",
".",
"steps",
"self",
".",
"simulation",
".",
"step",
"(",
"steps",
")"
] | Advance simulation n steps | [
"Advance",
"simulation",
"n",
"steps"
] | 7283fddba7203e5ac3542fdab41fc1279d3b444e | https://github.com/insilichem/ommprotocol/blob/7283fddba7203e5ac3542fdab41fc1279d3b444e/ommprotocol/md.py#L365-L371 | train |
insilichem/ommprotocol | ommprotocol/md.py | Stage.restraint_force | def restraint_force(self, indices=None, strength=5.0):
"""
Force that restrains atoms to fix their positions, while allowing
tiny movement to resolve severe clashes and so on.
Returns
-------
force : simtk.openmm.CustomExternalForce
A custom force to restrain... | python | def restraint_force(self, indices=None, strength=5.0):
"""
Force that restrains atoms to fix their positions, while allowing
tiny movement to resolve severe clashes and so on.
Returns
-------
force : simtk.openmm.CustomExternalForce
A custom force to restrain... | [
"def",
"restraint_force",
"(",
"self",
",",
"indices",
"=",
"None",
",",
"strength",
"=",
"5.0",
")",
":",
"if",
"self",
".",
"system",
".",
"usesPeriodicBoundaryConditions",
"(",
")",
":",
"expression",
"=",
"'k*periodicdistance(x, y, z, x0, y0, z0)^2'",
"else",
... | Force that restrains atoms to fix their positions, while allowing
tiny movement to resolve severe clashes and so on.
Returns
-------
force : simtk.openmm.CustomExternalForce
A custom force to restrain the selected atoms | [
"Force",
"that",
"restrains",
"atoms",
"to",
"fix",
"their",
"positions",
"while",
"allowing",
"tiny",
"movement",
"to",
"resolve",
"severe",
"clashes",
"and",
"so",
"on",
"."
] | 7283fddba7203e5ac3542fdab41fc1279d3b444e | https://github.com/insilichem/ommprotocol/blob/7283fddba7203e5ac3542fdab41fc1279d3b444e/ommprotocol/md.py#L511-L535 | train |
insilichem/ommprotocol | ommprotocol/md.py | Stage.distance_restraint_force | def distance_restraint_force(self, atoms, distances, strengths):
"""
Parameters
----------
atoms : tuple of tuple of int or str
Pair of atom indices to be restrained, with shape (n, 2),
like ((a1, a2), (a3, a4)). Items can be str compatible with MDTraj DSL.
... | python | def distance_restraint_force(self, atoms, distances, strengths):
"""
Parameters
----------
atoms : tuple of tuple of int or str
Pair of atom indices to be restrained, with shape (n, 2),
like ((a1, a2), (a3, a4)). Items can be str compatible with MDTraj DSL.
... | [
"def",
"distance_restraint_force",
"(",
"self",
",",
"atoms",
",",
"distances",
",",
"strengths",
")",
":",
"system",
"=",
"self",
".",
"system",
"force",
"=",
"mm",
".",
"HarmonicBondForce",
"(",
")",
"force",
".",
"setUsesPeriodicBoundaryConditions",
"(",
"s... | Parameters
----------
atoms : tuple of tuple of int or str
Pair of atom indices to be restrained, with shape (n, 2),
like ((a1, a2), (a3, a4)). Items can be str compatible with MDTraj DSL.
distances : tuple of float
Equilibrium distances for each pair
... | [
"Parameters",
"----------",
"atoms",
":",
"tuple",
"of",
"tuple",
"of",
"int",
"or",
"str",
"Pair",
"of",
"atom",
"indices",
"to",
"be",
"restrained",
"with",
"shape",
"(",
"n",
"2",
")",
"like",
"((",
"a1",
"a2",
")",
"(",
"a3",
"a4",
"))",
".",
"... | 7283fddba7203e5ac3542fdab41fc1279d3b444e | https://github.com/insilichem/ommprotocol/blob/7283fddba7203e5ac3542fdab41fc1279d3b444e/ommprotocol/md.py#L537-L571 | train |
insilichem/ommprotocol | ommprotocol/md.py | Stage.subset | def subset(self, selector):
"""
Returns a list of atom indices corresponding to a MDTraj DSL
query. Also will accept list of numbers, which will be coerced
to int and returned.
"""
if isinstance(selector, (list, tuple)):
return map(int, selector)
selec... | python | def subset(self, selector):
"""
Returns a list of atom indices corresponding to a MDTraj DSL
query. Also will accept list of numbers, which will be coerced
to int and returned.
"""
if isinstance(selector, (list, tuple)):
return map(int, selector)
selec... | [
"def",
"subset",
"(",
"self",
",",
"selector",
")",
":",
"if",
"isinstance",
"(",
"selector",
",",
"(",
"list",
",",
"tuple",
")",
")",
":",
"return",
"map",
"(",
"int",
",",
"selector",
")",
"selector",
"=",
"SELECTORS",
".",
"get",
"(",
"selector",... | Returns a list of atom indices corresponding to a MDTraj DSL
query. Also will accept list of numbers, which will be coerced
to int and returned. | [
"Returns",
"a",
"list",
"of",
"atom",
"indices",
"corresponding",
"to",
"a",
"MDTraj",
"DSL",
"query",
".",
"Also",
"will",
"accept",
"list",
"of",
"numbers",
"which",
"will",
"be",
"coerced",
"to",
"int",
"and",
"returned",
"."
] | 7283fddba7203e5ac3542fdab41fc1279d3b444e | https://github.com/insilichem/ommprotocol/blob/7283fddba7203e5ac3542fdab41fc1279d3b444e/ommprotocol/md.py#L573-L583 | train |
insilichem/ommprotocol | ommprotocol/md.py | Stage.handle_exceptions | def handle_exceptions(self, verbose=True):
"""
Handle Ctrl+C and accidental exceptions and attempt to save
the current state of the simulation
"""
try:
yield
except (KeyboardInterrupt, Exception) as ex:
if not self.attempt_rescue:
r... | python | def handle_exceptions(self, verbose=True):
"""
Handle Ctrl+C and accidental exceptions and attempt to save
the current state of the simulation
"""
try:
yield
except (KeyboardInterrupt, Exception) as ex:
if not self.attempt_rescue:
r... | [
"def",
"handle_exceptions",
"(",
"self",
",",
"verbose",
"=",
"True",
")",
":",
"try",
":",
"yield",
"except",
"(",
"KeyboardInterrupt",
",",
"Exception",
")",
"as",
"ex",
":",
"if",
"not",
"self",
".",
"attempt_rescue",
":",
"raise",
"ex",
"if",
"isinst... | Handle Ctrl+C and accidental exceptions and attempt to save
the current state of the simulation | [
"Handle",
"Ctrl",
"+",
"C",
"and",
"accidental",
"exceptions",
"and",
"attempt",
"to",
"save",
"the",
"current",
"state",
"of",
"the",
"simulation"
] | 7283fddba7203e5ac3542fdab41fc1279d3b444e | https://github.com/insilichem/ommprotocol/blob/7283fddba7203e5ac3542fdab41fc1279d3b444e/ommprotocol/md.py#L694-L726 | train |
insilichem/ommprotocol | ommprotocol/md.py | Stage.backup_simulation | def backup_simulation(self):
"""
Creates an emergency report run, .state included
"""
path = self.new_filename(suffix='_emergency.state')
self.simulation.saveState(path)
uses_pbc = self.system.usesPeriodicBoundaryConditions()
state_kw = dict(getPositions=True, get... | python | def backup_simulation(self):
"""
Creates an emergency report run, .state included
"""
path = self.new_filename(suffix='_emergency.state')
self.simulation.saveState(path)
uses_pbc = self.system.usesPeriodicBoundaryConditions()
state_kw = dict(getPositions=True, get... | [
"def",
"backup_simulation",
"(",
"self",
")",
":",
"path",
"=",
"self",
".",
"new_filename",
"(",
"suffix",
"=",
"'_emergency.state'",
")",
"self",
".",
"simulation",
".",
"saveState",
"(",
"path",
")",
"uses_pbc",
"=",
"self",
".",
"system",
".",
"usesPer... | Creates an emergency report run, .state included | [
"Creates",
"an",
"emergency",
"report",
"run",
".",
"state",
"included"
] | 7283fddba7203e5ac3542fdab41fc1279d3b444e | https://github.com/insilichem/ommprotocol/blob/7283fddba7203e5ac3542fdab41fc1279d3b444e/ommprotocol/md.py#L728-L741 | train |
insilichem/ommprotocol | ommprotocol/io.py | prepare_input | def prepare_input(argv=None):
"""
Get, parse and prepare input file.
"""
p = ArgumentParser(description='InsiliChem Ommprotocol: '
'easy to deploy MD protocols for OpenMM')
p.add_argument('input', metavar='INPUT FILE', type=extant_file,
help='YAML input file... | python | def prepare_input(argv=None):
"""
Get, parse and prepare input file.
"""
p = ArgumentParser(description='InsiliChem Ommprotocol: '
'easy to deploy MD protocols for OpenMM')
p.add_argument('input', metavar='INPUT FILE', type=extant_file,
help='YAML input file... | [
"def",
"prepare_input",
"(",
"argv",
"=",
"None",
")",
":",
"p",
"=",
"ArgumentParser",
"(",
"description",
"=",
"'InsiliChem Ommprotocol: '",
"'easy to deploy MD protocols for OpenMM'",
")",
"p",
".",
"add_argument",
"(",
"'input'",
",",
"metavar",
"=",
"'INPUT FIL... | Get, parse and prepare input file. | [
"Get",
"parse",
"and",
"prepare",
"input",
"file",
"."
] | 7283fddba7203e5ac3542fdab41fc1279d3b444e | https://github.com/insilichem/ommprotocol/blob/7283fddba7203e5ac3542fdab41fc1279d3b444e/ommprotocol/io.py#L883-L913 | train |
insilichem/ommprotocol | ommprotocol/io.py | prepare_handler | def prepare_handler(cfg):
"""
Load all files into single object.
"""
positions, velocities, box = None, None, None
_path = cfg.get('_path', './')
forcefield = cfg.pop('forcefield', None)
topology_args = sanitize_args_for_file(cfg.pop('topology'), _path)
if 'checkpoint' in cfg:
r... | python | def prepare_handler(cfg):
"""
Load all files into single object.
"""
positions, velocities, box = None, None, None
_path = cfg.get('_path', './')
forcefield = cfg.pop('forcefield', None)
topology_args = sanitize_args_for_file(cfg.pop('topology'), _path)
if 'checkpoint' in cfg:
r... | [
"def",
"prepare_handler",
"(",
"cfg",
")",
":",
"positions",
",",
"velocities",
",",
"box",
"=",
"None",
",",
"None",
",",
"None",
"_path",
"=",
"cfg",
".",
"get",
"(",
"'_path'",
",",
"'./'",
")",
"forcefield",
"=",
"cfg",
".",
"pop",
"(",
"'forcefi... | Load all files into single object. | [
"Load",
"all",
"files",
"into",
"single",
"object",
"."
] | 7283fddba7203e5ac3542fdab41fc1279d3b444e | https://github.com/insilichem/ommprotocol/blob/7283fddba7203e5ac3542fdab41fc1279d3b444e/ommprotocol/io.py#L916-L951 | train |
insilichem/ommprotocol | ommprotocol/io.py | prepare_system_options | def prepare_system_options(cfg, defaults=None):
"""
Retrieve and delete (pop) system options from input configuration.
"""
d = {} if defaults is None else defaults.copy()
if 'nonbondedMethod' in cfg:
d['nonbondedMethod'] = warned_getattr(openmm_app, cfg.pop('nonbondedMethod'), None)
if '... | python | def prepare_system_options(cfg, defaults=None):
"""
Retrieve and delete (pop) system options from input configuration.
"""
d = {} if defaults is None else defaults.copy()
if 'nonbondedMethod' in cfg:
d['nonbondedMethod'] = warned_getattr(openmm_app, cfg.pop('nonbondedMethod'), None)
if '... | [
"def",
"prepare_system_options",
"(",
"cfg",
",",
"defaults",
"=",
"None",
")",
":",
"d",
"=",
"{",
"}",
"if",
"defaults",
"is",
"None",
"else",
"defaults",
".",
"copy",
"(",
")",
"if",
"'nonbondedMethod'",
"in",
"cfg",
":",
"d",
"[",
"'nonbondedMethod'"... | Retrieve and delete (pop) system options from input configuration. | [
"Retrieve",
"and",
"delete",
"(",
"pop",
")",
"system",
"options",
"from",
"input",
"configuration",
"."
] | 7283fddba7203e5ac3542fdab41fc1279d3b444e | https://github.com/insilichem/ommprotocol/blob/7283fddba7203e5ac3542fdab41fc1279d3b444e/ommprotocol/io.py#L954-L974 | train |
insilichem/ommprotocol | ommprotocol/io.py | process_forcefield | def process_forcefield(*forcefields):
"""
Given a list of filenames, check which ones are `frcmods`. If so,
convert them to ffxml. Else, just return them.
"""
for forcefield in forcefields:
if forcefield.endswith('.frcmod'):
gaffmol2 = os.path.splitext(forcefield)[0] + '.gaff.mol... | python | def process_forcefield(*forcefields):
"""
Given a list of filenames, check which ones are `frcmods`. If so,
convert them to ffxml. Else, just return them.
"""
for forcefield in forcefields:
if forcefield.endswith('.frcmod'):
gaffmol2 = os.path.splitext(forcefield)[0] + '.gaff.mol... | [
"def",
"process_forcefield",
"(",
"*",
"forcefields",
")",
":",
"for",
"forcefield",
"in",
"forcefields",
":",
"if",
"forcefield",
".",
"endswith",
"(",
"'.frcmod'",
")",
":",
"gaffmol2",
"=",
"os",
".",
"path",
".",
"splitext",
"(",
"forcefield",
")",
"["... | Given a list of filenames, check which ones are `frcmods`. If so,
convert them to ffxml. Else, just return them. | [
"Given",
"a",
"list",
"of",
"filenames",
"check",
"which",
"ones",
"are",
"frcmods",
".",
"If",
"so",
"convert",
"them",
"to",
"ffxml",
".",
"Else",
"just",
"return",
"them",
"."
] | 7283fddba7203e5ac3542fdab41fc1279d3b444e | https://github.com/insilichem/ommprotocol/blob/7283fddba7203e5ac3542fdab41fc1279d3b444e/ommprotocol/io.py#L981-L991 | train |
insilichem/ommprotocol | ommprotocol/io.py | statexml2pdb | def statexml2pdb(topology, state, output=None):
"""
Given an OpenMM xml file containing the state of the simulation,
generate a PDB snapshot for easy visualization.
"""
state = Restart.from_xml(state)
system = SystemHandler.load(topology, positions=state.positions)
if output is None:
... | python | def statexml2pdb(topology, state, output=None):
"""
Given an OpenMM xml file containing the state of the simulation,
generate a PDB snapshot for easy visualization.
"""
state = Restart.from_xml(state)
system = SystemHandler.load(topology, positions=state.positions)
if output is None:
... | [
"def",
"statexml2pdb",
"(",
"topology",
",",
"state",
",",
"output",
"=",
"None",
")",
":",
"state",
"=",
"Restart",
".",
"from_xml",
"(",
"state",
")",
"system",
"=",
"SystemHandler",
".",
"load",
"(",
"topology",
",",
"positions",
"=",
"state",
".",
... | Given an OpenMM xml file containing the state of the simulation,
generate a PDB snapshot for easy visualization. | [
"Given",
"an",
"OpenMM",
"xml",
"file",
"containing",
"the",
"state",
"of",
"the",
"simulation",
"generate",
"a",
"PDB",
"snapshot",
"for",
"easy",
"visualization",
"."
] | 7283fddba7203e5ac3542fdab41fc1279d3b444e | https://github.com/insilichem/ommprotocol/blob/7283fddba7203e5ac3542fdab41fc1279d3b444e/ommprotocol/io.py#L994-L1003 | train |
insilichem/ommprotocol | ommprotocol/io.py | export_frame_coordinates | def export_frame_coordinates(topology, trajectory, nframe, output=None):
"""
Extract a single frame structure from a trajectory.
"""
if output is None:
basename, ext = os.path.splitext(trajectory)
output = '{}.frame{}.inpcrd'.format(basename, nframe)
# ParmEd sometimes struggles wit... | python | def export_frame_coordinates(topology, trajectory, nframe, output=None):
"""
Extract a single frame structure from a trajectory.
"""
if output is None:
basename, ext = os.path.splitext(trajectory)
output = '{}.frame{}.inpcrd'.format(basename, nframe)
# ParmEd sometimes struggles wit... | [
"def",
"export_frame_coordinates",
"(",
"topology",
",",
"trajectory",
",",
"nframe",
",",
"output",
"=",
"None",
")",
":",
"if",
"output",
"is",
"None",
":",
"basename",
",",
"ext",
"=",
"os",
".",
"path",
".",
"splitext",
"(",
"trajectory",
")",
"outpu... | Extract a single frame structure from a trajectory. | [
"Extract",
"a",
"single",
"frame",
"structure",
"from",
"a",
"trajectory",
"."
] | 7283fddba7203e5ac3542fdab41fc1279d3b444e | https://github.com/insilichem/ommprotocol/blob/7283fddba7203e5ac3542fdab41fc1279d3b444e/ommprotocol/io.py#L1006-L1031 | train |
insilichem/ommprotocol | ommprotocol/io.py | YamlLoader.construct_include | def construct_include(self, node):
"""Include file referenced at node."""
filename = os.path.join(self._root, self.construct_scalar(node))
filename = os.path.abspath(filename)
extension = os.path.splitext(filename)[1].lstrip('.')
with open(filename, 'r') as f:
if ex... | python | def construct_include(self, node):
"""Include file referenced at node."""
filename = os.path.join(self._root, self.construct_scalar(node))
filename = os.path.abspath(filename)
extension = os.path.splitext(filename)[1].lstrip('.')
with open(filename, 'r') as f:
if ex... | [
"def",
"construct_include",
"(",
"self",
",",
"node",
")",
":",
"filename",
"=",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"_root",
",",
"self",
".",
"construct_scalar",
"(",
"node",
")",
")",
"filename",
"=",
"os",
".",
"path",
".",
"abspath... | Include file referenced at node. | [
"Include",
"file",
"referenced",
"at",
"node",
"."
] | 7283fddba7203e5ac3542fdab41fc1279d3b444e | https://github.com/insilichem/ommprotocol/blob/7283fddba7203e5ac3542fdab41fc1279d3b444e/ommprotocol/io.py#L81-L92 | train |
insilichem/ommprotocol | ommprotocol/io.py | SystemHandler.from_pdb | def from_pdb(cls, path, forcefield=None, loader=PDBFile, strict=True, **kwargs):
"""
Loads topology, positions and, potentially, velocities and vectors,
from a PDB or PDBx file
Parameters
----------
path : str
Path to PDB/PDBx file
forcefields : list ... | python | def from_pdb(cls, path, forcefield=None, loader=PDBFile, strict=True, **kwargs):
"""
Loads topology, positions and, potentially, velocities and vectors,
from a PDB or PDBx file
Parameters
----------
path : str
Path to PDB/PDBx file
forcefields : list ... | [
"def",
"from_pdb",
"(",
"cls",
",",
"path",
",",
"forcefield",
"=",
"None",
",",
"loader",
"=",
"PDBFile",
",",
"strict",
"=",
"True",
",",
"*",
"*",
"kwargs",
")",
":",
"pdb",
"=",
"loader",
"(",
"path",
")",
"box",
"=",
"kwargs",
".",
"pop",
"(... | Loads topology, positions and, potentially, velocities and vectors,
from a PDB or PDBx file
Parameters
----------
path : str
Path to PDB/PDBx file
forcefields : list of str
Paths to FFXML and/or FRCMOD forcefields. REQUIRED.
Returns
-----... | [
"Loads",
"topology",
"positions",
"and",
"potentially",
"velocities",
"and",
"vectors",
"from",
"a",
"PDB",
"or",
"PDBx",
"file"
] | 7283fddba7203e5ac3542fdab41fc1279d3b444e | https://github.com/insilichem/ommprotocol/blob/7283fddba7203e5ac3542fdab41fc1279d3b444e/ommprotocol/io.py#L222-L252 | train |
insilichem/ommprotocol | ommprotocol/io.py | SystemHandler.from_amber | def from_amber(cls, path, positions=None, strict=True, **kwargs):
"""
Loads Amber Parm7 parameters and topology file
Parameters
----------
path : str
Path to *.prmtop or *.top file
positions : simtk.unit.Quantity
Atomic positions
Returns
... | python | def from_amber(cls, path, positions=None, strict=True, **kwargs):
"""
Loads Amber Parm7 parameters and topology file
Parameters
----------
path : str
Path to *.prmtop or *.top file
positions : simtk.unit.Quantity
Atomic positions
Returns
... | [
"def",
"from_amber",
"(",
"cls",
",",
"path",
",",
"positions",
"=",
"None",
",",
"strict",
"=",
"True",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"strict",
"and",
"positions",
"is",
"None",
":",
"raise",
"ValueError",
"(",
"'Amber TOP/PRMTOP files require ... | Loads Amber Parm7 parameters and topology file
Parameters
----------
path : str
Path to *.prmtop or *.top file
positions : simtk.unit.Quantity
Atomic positions
Returns
-------
prmtop : SystemHandler
SystemHandler with topology | [
"Loads",
"Amber",
"Parm7",
"parameters",
"and",
"topology",
"file"
] | 7283fddba7203e5ac3542fdab41fc1279d3b444e | https://github.com/insilichem/ommprotocol/blob/7283fddba7203e5ac3542fdab41fc1279d3b444e/ommprotocol/io.py#L260-L281 | train |
insilichem/ommprotocol | ommprotocol/io.py | SystemHandler.from_charmm | def from_charmm(cls, path, positions=None, forcefield=None, strict=True, **kwargs):
"""
Loads PSF Charmm structure from `path`. Requires `charmm_parameters`.
Parameters
----------
path : str
Path to PSF file
forcefield : list of str
Paths to Charm... | python | def from_charmm(cls, path, positions=None, forcefield=None, strict=True, **kwargs):
"""
Loads PSF Charmm structure from `path`. Requires `charmm_parameters`.
Parameters
----------
path : str
Path to PSF file
forcefield : list of str
Paths to Charm... | [
"def",
"from_charmm",
"(",
"cls",
",",
"path",
",",
"positions",
"=",
"None",
",",
"forcefield",
"=",
"None",
",",
"strict",
"=",
"True",
",",
"*",
"*",
"kwargs",
")",
":",
"psf",
"=",
"CharmmPsfFile",
"(",
"path",
")",
"if",
"strict",
"and",
"forcef... | Loads PSF Charmm structure from `path`. Requires `charmm_parameters`.
Parameters
----------
path : str
Path to PSF file
forcefield : list of str
Paths to Charmm parameters files, such as *.par or *.str. REQUIRED
Returns
-------
psf : Syst... | [
"Loads",
"PSF",
"Charmm",
"structure",
"from",
"path",
".",
"Requires",
"charmm_parameters",
"."
] | 7283fddba7203e5ac3542fdab41fc1279d3b444e | https://github.com/insilichem/ommprotocol/blob/7283fddba7203e5ac3542fdab41fc1279d3b444e/ommprotocol/io.py#L284-L309 | train |
insilichem/ommprotocol | ommprotocol/io.py | SystemHandler.from_desmond | def from_desmond(cls, path, **kwargs):
"""
Loads a topology from a Desmond DMS file located at `path`.
Arguments
---------
path : str
Path to a Desmond DMS file
"""
dms = DesmondDMSFile(path)
pos = kwargs.pop('positions', dms.getPositions())
... | python | def from_desmond(cls, path, **kwargs):
"""
Loads a topology from a Desmond DMS file located at `path`.
Arguments
---------
path : str
Path to a Desmond DMS file
"""
dms = DesmondDMSFile(path)
pos = kwargs.pop('positions', dms.getPositions())
... | [
"def",
"from_desmond",
"(",
"cls",
",",
"path",
",",
"*",
"*",
"kwargs",
")",
":",
"dms",
"=",
"DesmondDMSFile",
"(",
"path",
")",
"pos",
"=",
"kwargs",
".",
"pop",
"(",
"'positions'",
",",
"dms",
".",
"getPositions",
"(",
")",
")",
"return",
"cls",
... | Loads a topology from a Desmond DMS file located at `path`.
Arguments
---------
path : str
Path to a Desmond DMS file | [
"Loads",
"a",
"topology",
"from",
"a",
"Desmond",
"DMS",
"file",
"located",
"at",
"path",
"."
] | 7283fddba7203e5ac3542fdab41fc1279d3b444e | https://github.com/insilichem/ommprotocol/blob/7283fddba7203e5ac3542fdab41fc1279d3b444e/ommprotocol/io.py#L312-L324 | train |
insilichem/ommprotocol | ommprotocol/io.py | SystemHandler.from_gromacs | def from_gromacs(cls, path, positions=None, forcefield=None, strict=True, **kwargs):
"""
Loads a topology from a Gromacs TOP file located at `path`.
Additional root directory for parameters can be specified with `forcefield`.
Arguments
---------
path : str
P... | python | def from_gromacs(cls, path, positions=None, forcefield=None, strict=True, **kwargs):
"""
Loads a topology from a Gromacs TOP file located at `path`.
Additional root directory for parameters can be specified with `forcefield`.
Arguments
---------
path : str
P... | [
"def",
"from_gromacs",
"(",
"cls",
",",
"path",
",",
"positions",
"=",
"None",
",",
"forcefield",
"=",
"None",
",",
"strict",
"=",
"True",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"strict",
"and",
"positions",
"is",
"None",
":",
"raise",
"ValueError",
... | Loads a topology from a Gromacs TOP file located at `path`.
Additional root directory for parameters can be specified with `forcefield`.
Arguments
---------
path : str
Path to a Gromacs TOP file
positions : simtk.unit.Quantity
Atomic positions
fo... | [
"Loads",
"a",
"topology",
"from",
"a",
"Gromacs",
"TOP",
"file",
"located",
"at",
"path",
"."
] | 7283fddba7203e5ac3542fdab41fc1279d3b444e | https://github.com/insilichem/ommprotocol/blob/7283fddba7203e5ac3542fdab41fc1279d3b444e/ommprotocol/io.py#L327-L347 | train |
insilichem/ommprotocol | ommprotocol/io.py | SystemHandler.from_parmed | def from_parmed(cls, path, *args, **kwargs):
"""
Try to load a file automatically with ParmEd. Not guaranteed to work, but
might be useful if it succeeds.
Arguments
---------
path : str
Path to file that ParmEd can load
"""
st = parmed.load_fi... | python | def from_parmed(cls, path, *args, **kwargs):
"""
Try to load a file automatically with ParmEd. Not guaranteed to work, but
might be useful if it succeeds.
Arguments
---------
path : str
Path to file that ParmEd can load
"""
st = parmed.load_fi... | [
"def",
"from_parmed",
"(",
"cls",
",",
"path",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"st",
"=",
"parmed",
".",
"load_file",
"(",
"path",
",",
"structure",
"=",
"True",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"box",
"=",
"... | Try to load a file automatically with ParmEd. Not guaranteed to work, but
might be useful if it succeeds.
Arguments
---------
path : str
Path to file that ParmEd can load | [
"Try",
"to",
"load",
"a",
"file",
"automatically",
"with",
"ParmEd",
".",
"Not",
"guaranteed",
"to",
"work",
"but",
"might",
"be",
"useful",
"if",
"it",
"succeeds",
"."
] | 7283fddba7203e5ac3542fdab41fc1279d3b444e | https://github.com/insilichem/ommprotocol/blob/7283fddba7203e5ac3542fdab41fc1279d3b444e/ommprotocol/io.py#L350-L365 | train |
insilichem/ommprotocol | ommprotocol/io.py | SystemHandler._pickle_load | def _pickle_load(path):
"""
Loads pickled topology. Careful with Python versions though!
"""
_, ext = os.path.splitext(path)
topology = None
if sys.version_info.major == 2:
if ext == '.pickle2':
with open(path, 'rb') as f:
t... | python | def _pickle_load(path):
"""
Loads pickled topology. Careful with Python versions though!
"""
_, ext = os.path.splitext(path)
topology = None
if sys.version_info.major == 2:
if ext == '.pickle2':
with open(path, 'rb') as f:
t... | [
"def",
"_pickle_load",
"(",
"path",
")",
":",
"_",
",",
"ext",
"=",
"os",
".",
"path",
".",
"splitext",
"(",
"path",
")",
"topology",
"=",
"None",
"if",
"sys",
".",
"version_info",
".",
"major",
"==",
"2",
":",
"if",
"ext",
"==",
"'.pickle2'",
":",... | Loads pickled topology. Careful with Python versions though! | [
"Loads",
"pickled",
"topology",
".",
"Careful",
"with",
"Python",
"versions",
"though!"
] | 7283fddba7203e5ac3542fdab41fc1279d3b444e | https://github.com/insilichem/ommprotocol/blob/7283fddba7203e5ac3542fdab41fc1279d3b444e/ommprotocol/io.py#L380-L402 | train |
insilichem/ommprotocol | ommprotocol/io.py | SystemHandler.create_system | def create_system(self, **system_options):
"""
Create an OpenMM system for every supported topology file with given system options
"""
if self.master is None:
raise ValueError('Handler {} is not able to create systems.'.format(self))
if isinstance(self.master, ForceF... | python | def create_system(self, **system_options):
"""
Create an OpenMM system for every supported topology file with given system options
"""
if self.master is None:
raise ValueError('Handler {} is not able to create systems.'.format(self))
if isinstance(self.master, ForceF... | [
"def",
"create_system",
"(",
"self",
",",
"*",
"*",
"system_options",
")",
":",
"if",
"self",
".",
"master",
"is",
"None",
":",
"raise",
"ValueError",
"(",
"'Handler {} is not able to create systems.'",
".",
"format",
"(",
"self",
")",
")",
"if",
"isinstance",... | Create an OpenMM system for every supported topology file with given system options | [
"Create",
"an",
"OpenMM",
"system",
"for",
"every",
"supported",
"topology",
"file",
"with",
"given",
"system",
"options"
] | 7283fddba7203e5ac3542fdab41fc1279d3b444e | https://github.com/insilichem/ommprotocol/blob/7283fddba7203e5ac3542fdab41fc1279d3b444e/ommprotocol/io.py#L412-L432 | train |
insilichem/ommprotocol | ommprotocol/io.py | SystemHandler.write_pdb | def write_pdb(self, path):
"""
Outputs a PDB file with the current contents of the system
"""
if self.master is None and self.positions is None:
raise ValueError('Topology and positions are needed to write output files.')
with open(path, 'w') as f:
PDBFile... | python | def write_pdb(self, path):
"""
Outputs a PDB file with the current contents of the system
"""
if self.master is None and self.positions is None:
raise ValueError('Topology and positions are needed to write output files.')
with open(path, 'w') as f:
PDBFile... | [
"def",
"write_pdb",
"(",
"self",
",",
"path",
")",
":",
"if",
"self",
".",
"master",
"is",
"None",
"and",
"self",
".",
"positions",
"is",
"None",
":",
"raise",
"ValueError",
"(",
"'Topology and positions are needed to write output files.'",
")",
"with",
"open",
... | Outputs a PDB file with the current contents of the system | [
"Outputs",
"a",
"PDB",
"file",
"with",
"the",
"current",
"contents",
"of",
"the",
"system"
] | 7283fddba7203e5ac3542fdab41fc1279d3b444e | https://github.com/insilichem/ommprotocol/blob/7283fddba7203e5ac3542fdab41fc1279d3b444e/ommprotocol/io.py#L434-L441 | train |
insilichem/ommprotocol | ommprotocol/io.py | BoxVectors.from_xsc | def from_xsc(cls, path):
""" Returns u.Quantity with box vectors from XSC file """
def parse(path):
"""
Open and parses an XSC file into its fields
Parameters
----------
path : str
Path to XSC file
Returns
... | python | def from_xsc(cls, path):
""" Returns u.Quantity with box vectors from XSC file """
def parse(path):
"""
Open and parses an XSC file into its fields
Parameters
----------
path : str
Path to XSC file
Returns
... | [
"def",
"from_xsc",
"(",
"cls",
",",
"path",
")",
":",
"def",
"parse",
"(",
"path",
")",
":",
"\"\"\"\n Open and parses an XSC file into its fields\n\n Parameters\n ----------\n path : str\n Path to XSC file\n\n Returns... | Returns u.Quantity with box vectors from XSC file | [
"Returns",
"u",
".",
"Quantity",
"with",
"box",
"vectors",
"from",
"XSC",
"file"
] | 7283fddba7203e5ac3542fdab41fc1279d3b444e | https://github.com/insilichem/ommprotocol/blob/7283fddba7203e5ac3542fdab41fc1279d3b444e/ommprotocol/io.py#L554-L579 | train |
insilichem/ommprotocol | ommprotocol/io.py | BoxVectors.from_csv | def from_csv(cls, path):
"""
Get box vectors from comma-separated values in file `path`.
The csv file must containt only one line, which in turn can contain
three values (orthogonal vectors) or nine values (triclinic box).
The values should be in nanometers.
Parameters... | python | def from_csv(cls, path):
"""
Get box vectors from comma-separated values in file `path`.
The csv file must containt only one line, which in turn can contain
three values (orthogonal vectors) or nine values (triclinic box).
The values should be in nanometers.
Parameters... | [
"def",
"from_csv",
"(",
"cls",
",",
"path",
")",
":",
"with",
"open",
"(",
"path",
")",
"as",
"f",
":",
"fields",
"=",
"map",
"(",
"float",
",",
"next",
"(",
"f",
")",
".",
"split",
"(",
"','",
")",
")",
"if",
"len",
"(",
"fields",
")",
"==",... | Get box vectors from comma-separated values in file `path`.
The csv file must containt only one line, which in turn can contain
three values (orthogonal vectors) or nine values (triclinic box).
The values should be in nanometers.
Parameters
----------
path : str
... | [
"Get",
"box",
"vectors",
"from",
"comma",
"-",
"separated",
"values",
"in",
"file",
"path",
"."
] | 7283fddba7203e5ac3542fdab41fc1279d3b444e | https://github.com/insilichem/ommprotocol/blob/7283fddba7203e5ac3542fdab41fc1279d3b444e/ommprotocol/io.py#L582-L613 | train |
insilichem/ommprotocol | ommprotocol/io.py | ProgressBarReporter.describeNextReport | def describeNextReport(self, simulation):
"""Get information about the next report this object will generate.
Parameters
----------
simulation : Simulation
The Simulation to generate a report for
Returns
-------
tuple
A five element tuple... | python | def describeNextReport(self, simulation):
"""Get information about the next report this object will generate.
Parameters
----------
simulation : Simulation
The Simulation to generate a report for
Returns
-------
tuple
A five element tuple... | [
"def",
"describeNextReport",
"(",
"self",
",",
"simulation",
")",
":",
"steps",
"=",
"self",
".",
"interval",
"-",
"simulation",
".",
"currentStep",
"%",
"self",
".",
"interval",
"return",
"steps",
",",
"False",
",",
"False",
",",
"False",
",",
"False"
] | Get information about the next report this object will generate.
Parameters
----------
simulation : Simulation
The Simulation to generate a report for
Returns
-------
tuple
A five element tuple. The first element is the number of steps
... | [
"Get",
"information",
"about",
"the",
"next",
"report",
"this",
"object",
"will",
"generate",
"."
] | 7283fddba7203e5ac3542fdab41fc1279d3b444e | https://github.com/insilichem/ommprotocol/blob/7283fddba7203e5ac3542fdab41fc1279d3b444e/ommprotocol/io.py#L720-L737 | train |
insilichem/ommprotocol | ommprotocol/io.py | ProgressBarReporter.report | def report(self, simulation, state):
"""Generate a report.
Parameters
----------
simulation : Simulation
The Simulation to generate a report for
state : State
The current state of the simulation
"""
if not self._initialized:
se... | python | def report(self, simulation, state):
"""Generate a report.
Parameters
----------
simulation : Simulation
The Simulation to generate a report for
state : State
The current state of the simulation
"""
if not self._initialized:
se... | [
"def",
"report",
"(",
"self",
",",
"simulation",
",",
"state",
")",
":",
"if",
"not",
"self",
".",
"_initialized",
":",
"self",
".",
"_initial_clock_time",
"=",
"datetime",
".",
"now",
"(",
")",
"self",
".",
"_initial_simulation_time",
"=",
"state",
".",
... | Generate a report.
Parameters
----------
simulation : Simulation
The Simulation to generate a report for
state : State
The current state of the simulation | [
"Generate",
"a",
"report",
"."
] | 7283fddba7203e5ac3542fdab41fc1279d3b444e | https://github.com/insilichem/ommprotocol/blob/7283fddba7203e5ac3542fdab41fc1279d3b444e/ommprotocol/io.py#L739-L773 | train |
insilichem/ommprotocol | ommprotocol/io.py | SerializedReporter.report | def report(self, simulation, state):
"""Generate a report.
Parameters
----------
simulation : Simulation
The Simulation to generate a report for
state : State
The current state of the simulation
"""
if not self._initialized:
se... | python | def report(self, simulation, state):
"""Generate a report.
Parameters
----------
simulation : Simulation
The Simulation to generate a report for
state : State
The current state of the simulation
"""
if not self._initialized:
se... | [
"def",
"report",
"(",
"self",
",",
"simulation",
",",
"state",
")",
":",
"if",
"not",
"self",
".",
"_initialized",
":",
"self",
".",
"_initialized",
"=",
"True",
"self",
".",
"_steps",
"[",
"0",
"]",
"+=",
"self",
".",
"interval",
"positions",
"=",
"... | Generate a report.
Parameters
----------
simulation : Simulation
The Simulation to generate a report for
state : State
The current state of the simulation | [
"Generate",
"a",
"report",
"."
] | 7283fddba7203e5ac3542fdab41fc1279d3b444e | https://github.com/insilichem/ommprotocol/blob/7283fddba7203e5ac3542fdab41fc1279d3b444e/ommprotocol/io.py#L827-L848 | train |
insilichem/ommprotocol | ommprotocol/utils.py | assert_not_exists | def assert_not_exists(path, sep='.'):
"""
If path exists, modify to add a counter in the filename. Useful
for preventing accidental overrides. For example, if `file.txt`
exists, check if `file.1.txt` also exists. Repeat until we find
a non-existing version, such as `file.12.txt`.
Parameters
... | python | def assert_not_exists(path, sep='.'):
"""
If path exists, modify to add a counter in the filename. Useful
for preventing accidental overrides. For example, if `file.txt`
exists, check if `file.1.txt` also exists. Repeat until we find
a non-existing version, such as `file.12.txt`.
Parameters
... | [
"def",
"assert_not_exists",
"(",
"path",
",",
"sep",
"=",
"'.'",
")",
":",
"name",
",",
"ext",
"=",
"os",
".",
"path",
".",
"splitext",
"(",
"path",
")",
"i",
"=",
"1",
"while",
"os",
".",
"path",
".",
"exists",
"(",
"path",
")",
":",
"path",
"... | If path exists, modify to add a counter in the filename. Useful
for preventing accidental overrides. For example, if `file.txt`
exists, check if `file.1.txt` also exists. Repeat until we find
a non-existing version, such as `file.12.txt`.
Parameters
----------
path : str
Path to be chec... | [
"If",
"path",
"exists",
"modify",
"to",
"add",
"a",
"counter",
"in",
"the",
"filename",
".",
"Useful",
"for",
"preventing",
"accidental",
"overrides",
".",
"For",
"example",
"if",
"file",
".",
"txt",
"exists",
"check",
"if",
"file",
".",
"1",
".",
"txt",... | 7283fddba7203e5ac3542fdab41fc1279d3b444e | https://github.com/insilichem/ommprotocol/blob/7283fddba7203e5ac3542fdab41fc1279d3b444e/ommprotocol/utils.py#L34-L56 | train |
insilichem/ommprotocol | ommprotocol/utils.py | assertinstance | def assertinstance(obj, types):
"""
Make sure object `obj` is of type `types`. Else, raise TypeError.
"""
if isinstance(obj, types):
return obj
raise TypeError('{} must be instance of {}'.format(obj, types)) | python | def assertinstance(obj, types):
"""
Make sure object `obj` is of type `types`. Else, raise TypeError.
"""
if isinstance(obj, types):
return obj
raise TypeError('{} must be instance of {}'.format(obj, types)) | [
"def",
"assertinstance",
"(",
"obj",
",",
"types",
")",
":",
"if",
"isinstance",
"(",
"obj",
",",
"types",
")",
":",
"return",
"obj",
"raise",
"TypeError",
"(",
"'{} must be instance of {}'",
".",
"format",
"(",
"obj",
",",
"types",
")",
")"
] | Make sure object `obj` is of type `types`. Else, raise TypeError. | [
"Make",
"sure",
"object",
"obj",
"is",
"of",
"type",
"types",
".",
"Else",
"raise",
"TypeError",
"."
] | 7283fddba7203e5ac3542fdab41fc1279d3b444e | https://github.com/insilichem/ommprotocol/blob/7283fddba7203e5ac3542fdab41fc1279d3b444e/ommprotocol/utils.py#L59-L65 | train |
insilichem/ommprotocol | ommprotocol/utils.py | extant_file | def extant_file(path):
"""
Check if file exists with argparse
"""
if not os.path.exists(path):
raise argparse.ArgumentTypeError("{} does not exist".format(path))
return path | python | def extant_file(path):
"""
Check if file exists with argparse
"""
if not os.path.exists(path):
raise argparse.ArgumentTypeError("{} does not exist".format(path))
return path | [
"def",
"extant_file",
"(",
"path",
")",
":",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"path",
")",
":",
"raise",
"argparse",
".",
"ArgumentTypeError",
"(",
"\"{} does not exist\"",
".",
"format",
"(",
"path",
")",
")",
"return",
"path"
] | Check if file exists with argparse | [
"Check",
"if",
"file",
"exists",
"with",
"argparse"
] | 7283fddba7203e5ac3542fdab41fc1279d3b444e | https://github.com/insilichem/ommprotocol/blob/7283fddba7203e5ac3542fdab41fc1279d3b444e/ommprotocol/utils.py#L89-L95 | train |
insilichem/ommprotocol | ommprotocol/utils.py | sort_key_for_numeric_suffixes | def sort_key_for_numeric_suffixes(path, sep='.', suffix_index=-2):
"""
Sort files taking into account potentially absent suffixes like
somefile.dcd
somefile.1000.dcd
somefile.2000.dcd
To be used with sorted(..., key=callable).
"""
chunks = path.split(sep)
# Remove suffix... | python | def sort_key_for_numeric_suffixes(path, sep='.', suffix_index=-2):
"""
Sort files taking into account potentially absent suffixes like
somefile.dcd
somefile.1000.dcd
somefile.2000.dcd
To be used with sorted(..., key=callable).
"""
chunks = path.split(sep)
# Remove suffix... | [
"def",
"sort_key_for_numeric_suffixes",
"(",
"path",
",",
"sep",
"=",
"'.'",
",",
"suffix_index",
"=",
"-",
"2",
")",
":",
"chunks",
"=",
"path",
".",
"split",
"(",
"sep",
")",
"# Remove suffix from path and convert to int",
"if",
"chunks",
"[",
"suffix_index",
... | Sort files taking into account potentially absent suffixes like
somefile.dcd
somefile.1000.dcd
somefile.2000.dcd
To be used with sorted(..., key=callable). | [
"Sort",
"files",
"taking",
"into",
"account",
"potentially",
"absent",
"suffixes",
"like",
"somefile",
".",
"dcd",
"somefile",
".",
"1000",
".",
"dcd",
"somefile",
".",
"2000",
".",
"dcd"
] | 7283fddba7203e5ac3542fdab41fc1279d3b444e | https://github.com/insilichem/ommprotocol/blob/7283fddba7203e5ac3542fdab41fc1279d3b444e/ommprotocol/utils.py#L123-L136 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.