id int32 0 252k | repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 75 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 |
|---|---|---|---|---|---|---|---|---|---|---|---|
9,400 | ellmetha/django-machina | machina/apps/forum_conversation/forum_polls/views.py | TopicPollVoteView.form_invalid | def form_invalid(self, form):
""" Handles an invalid form. """
messages.error(self.request, form.errors[NON_FIELD_ERRORS])
return redirect(
reverse(
'forum_conversation:topic',
kwargs={
'forum_slug': self.object.topic.forum.slug,
... | python | def form_invalid(self, form):
""" Handles an invalid form. """
messages.error(self.request, form.errors[NON_FIELD_ERRORS])
return redirect(
reverse(
'forum_conversation:topic',
kwargs={
'forum_slug': self.object.topic.forum.slug,
... | [
"def",
"form_invalid",
"(",
"self",
",",
"form",
")",
":",
"messages",
".",
"error",
"(",
"self",
".",
"request",
",",
"form",
".",
"errors",
"[",
"NON_FIELD_ERRORS",
"]",
")",
"return",
"redirect",
"(",
"reverse",
"(",
"'forum_conversation:topic'",
",",
"... | Handles an invalid form. | [
"Handles",
"an",
"invalid",
"form",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_conversation/forum_polls/views.py#L62-L75 |
9,401 | ellmetha/django-machina | machina/templatetags/forum_polls_tags.py | has_been_completed_by | def has_been_completed_by(poll, user):
""" This will return a boolean indicating if the passed user has already voted in the given
poll.
Usage::
{% if poll|has_been_completed_by:user %}...{% endif %}
"""
user_votes = TopicPollVote.objects.filter(
poll_option__poll=poll)
if ... | python | def has_been_completed_by(poll, user):
""" This will return a boolean indicating if the passed user has already voted in the given
poll.
Usage::
{% if poll|has_been_completed_by:user %}...{% endif %}
"""
user_votes = TopicPollVote.objects.filter(
poll_option__poll=poll)
if ... | [
"def",
"has_been_completed_by",
"(",
"poll",
",",
"user",
")",
":",
"user_votes",
"=",
"TopicPollVote",
".",
"objects",
".",
"filter",
"(",
"poll_option__poll",
"=",
"poll",
")",
"if",
"user",
".",
"is_anonymous",
":",
"forum_key",
"=",
"get_anonymous_user_forum... | This will return a boolean indicating if the passed user has already voted in the given
poll.
Usage::
{% if poll|has_been_completed_by:user %}...{% endif %} | [
"This",
"will",
"return",
"a",
"boolean",
"indicating",
"if",
"the",
"passed",
"user",
"has",
"already",
"voted",
"in",
"the",
"given",
"poll",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/templatetags/forum_polls_tags.py#L17-L33 |
9,402 | ellmetha/django-machina | machina/apps/forum_tracking/managers.py | ForumReadTrackManager.get_unread_forums_from_list | def get_unread_forums_from_list(self, forums, user):
""" Filter a list of forums and return only those which are unread.
Given a list of forums find and returns the list of forums that are unread for the passed
user. If a forum is unread all of its ancestors are also unread and will be included... | python | def get_unread_forums_from_list(self, forums, user):
""" Filter a list of forums and return only those which are unread.
Given a list of forums find and returns the list of forums that are unread for the passed
user. If a forum is unread all of its ancestors are also unread and will be included... | [
"def",
"get_unread_forums_from_list",
"(",
"self",
",",
"forums",
",",
"user",
")",
":",
"unread_forums",
"=",
"[",
"]",
"visibility_contents",
"=",
"ForumVisibilityContentTree",
".",
"from_forums",
"(",
"forums",
")",
"forum_ids_to_visibility_nodes",
"=",
"visibility... | Filter a list of forums and return only those which are unread.
Given a list of forums find and returns the list of forums that are unread for the passed
user. If a forum is unread all of its ancestors are also unread and will be included in the
final list. | [
"Filter",
"a",
"list",
"of",
"forums",
"and",
"return",
"only",
"those",
"which",
"are",
"unread",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_tracking/managers.py#L20-L48 |
9,403 | ellmetha/django-machina | machina/apps/forum_member/receivers.py | increase_posts_count | def increase_posts_count(sender, instance, **kwargs):
""" Increases the member's post count after a post save.
This receiver handles the update of the profile related to the user who is the poster of the
forum post being created or updated.
"""
if instance.poster is None:
# An anonymous po... | python | def increase_posts_count(sender, instance, **kwargs):
""" Increases the member's post count after a post save.
This receiver handles the update of the profile related to the user who is the poster of the
forum post being created or updated.
"""
if instance.poster is None:
# An anonymous po... | [
"def",
"increase_posts_count",
"(",
"sender",
",",
"instance",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"instance",
".",
"poster",
"is",
"None",
":",
"# An anonymous post is considered. No profile can be updated in",
"# that case.",
"return",
"profile",
",",
"dummy",
... | Increases the member's post count after a post save.
This receiver handles the update of the profile related to the user who is the poster of the
forum post being created or updated. | [
"Increases",
"the",
"member",
"s",
"post",
"count",
"after",
"a",
"post",
"save",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_member/receivers.py#L25-L54 |
9,404 | ellmetha/django-machina | machina/apps/forum_member/receivers.py | decrease_posts_count_after_post_unaproval | def decrease_posts_count_after_post_unaproval(sender, instance, **kwargs):
""" Decreases the member's post count after a post unaproval.
This receiver handles the unaproval of a forum post: the posts count associated with the post's
author is decreased.
"""
if not instance.pk:
# Do not cons... | python | def decrease_posts_count_after_post_unaproval(sender, instance, **kwargs):
""" Decreases the member's post count after a post unaproval.
This receiver handles the unaproval of a forum post: the posts count associated with the post's
author is decreased.
"""
if not instance.pk:
# Do not cons... | [
"def",
"decrease_posts_count_after_post_unaproval",
"(",
"sender",
",",
"instance",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"not",
"instance",
".",
"pk",
":",
"# Do not consider posts being created.",
"return",
"profile",
",",
"dummy",
"=",
"ForumProfile",
".",
"... | Decreases the member's post count after a post unaproval.
This receiver handles the unaproval of a forum post: the posts count associated with the post's
author is decreased. | [
"Decreases",
"the",
"member",
"s",
"post",
"count",
"after",
"a",
"post",
"unaproval",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_member/receivers.py#L58-L78 |
9,405 | ellmetha/django-machina | machina/apps/forum_member/receivers.py | decrease_posts_count_after_post_deletion | def decrease_posts_count_after_post_deletion(sender, instance, **kwargs):
""" Decreases the member's post count after a post deletion.
This receiver handles the deletion of a forum post: the posts count related to the post's
author is decreased.
"""
if not instance.approved:
# If a post has... | python | def decrease_posts_count_after_post_deletion(sender, instance, **kwargs):
""" Decreases the member's post count after a post deletion.
This receiver handles the deletion of a forum post: the posts count related to the post's
author is decreased.
"""
if not instance.approved:
# If a post has... | [
"def",
"decrease_posts_count_after_post_deletion",
"(",
"sender",
",",
"instance",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"not",
"instance",
".",
"approved",
":",
"# If a post has not been approved, it has not been counted.",
"# So do not decrement count",
"return",
"try"... | Decreases the member's post count after a post deletion.
This receiver handles the deletion of a forum post: the posts count related to the post's
author is decreased. | [
"Decreases",
"the",
"member",
"s",
"post",
"count",
"after",
"a",
"post",
"deletion",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_member/receivers.py#L82-L108 |
9,406 | ellmetha/django-machina | machina/apps/forum_moderation/views.py | TopicLockView.lock | def lock(self, request, *args, **kwargs):
""" Locks the considered topic and retirects the user to the success URL. """
self.object = self.get_object()
success_url = self.get_success_url()
self.object.status = Topic.TOPIC_LOCKED
self.object.save()
messages.success(self.re... | python | def lock(self, request, *args, **kwargs):
""" Locks the considered topic and retirects the user to the success URL. """
self.object = self.get_object()
success_url = self.get_success_url()
self.object.status = Topic.TOPIC_LOCKED
self.object.save()
messages.success(self.re... | [
"def",
"lock",
"(",
"self",
",",
"request",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"object",
"=",
"self",
".",
"get_object",
"(",
")",
"success_url",
"=",
"self",
".",
"get_success_url",
"(",
")",
"self",
".",
"object",
"... | Locks the considered topic and retirects the user to the success URL. | [
"Locks",
"the",
"considered",
"topic",
"and",
"retirects",
"the",
"user",
"to",
"the",
"success",
"URL",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_moderation/views.py#L42-L49 |
9,407 | ellmetha/django-machina | machina/apps/forum_moderation/views.py | TopicUnlockView.unlock | def unlock(self, request, *args, **kwargs):
""" Unlocks the considered topic and retirects the user to the success URL. """
self.object = self.get_object()
success_url = self.get_success_url()
self.object.status = Topic.TOPIC_UNLOCKED
self.object.save()
messages.success(s... | python | def unlock(self, request, *args, **kwargs):
""" Unlocks the considered topic and retirects the user to the success URL. """
self.object = self.get_object()
success_url = self.get_success_url()
self.object.status = Topic.TOPIC_UNLOCKED
self.object.save()
messages.success(s... | [
"def",
"unlock",
"(",
"self",
",",
"request",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"object",
"=",
"self",
".",
"get_object",
"(",
")",
"success_url",
"=",
"self",
".",
"get_success_url",
"(",
")",
"self",
".",
"object",
... | Unlocks the considered topic and retirects the user to the success URL. | [
"Unlocks",
"the",
"considered",
"topic",
"and",
"retirects",
"the",
"user",
"to",
"the",
"success",
"URL",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_moderation/views.py#L91-L98 |
9,408 | ellmetha/django-machina | machina/apps/forum_moderation/views.py | TopicUpdateTypeBaseView.update_type | def update_type(self, request, *args, **kwargs):
""" Updates the type of the considered topic and retirects the user to the success URL.
"""
self.object = self.get_object()
success_url = self.get_success_url()
self.object.type = self.target_type
self.object.save()
... | python | def update_type(self, request, *args, **kwargs):
""" Updates the type of the considered topic and retirects the user to the success URL.
"""
self.object = self.get_object()
success_url = self.get_success_url()
self.object.type = self.target_type
self.object.save()
... | [
"def",
"update_type",
"(",
"self",
",",
"request",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"object",
"=",
"self",
".",
"get_object",
"(",
")",
"success_url",
"=",
"self",
".",
"get_success_url",
"(",
")",
"self",
".",
"objec... | Updates the type of the considered topic and retirects the user to the success URL. | [
"Updates",
"the",
"type",
"of",
"the",
"considered",
"topic",
"and",
"retirects",
"the",
"user",
"to",
"the",
"success",
"URL",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_moderation/views.py#L257-L265 |
9,409 | ellmetha/django-machina | machina/apps/forum_moderation/views.py | PostApproveView.approve | def approve(self, request, *args, **kwargs):
""" Approves the considered post and retirects the user to the success URL. """
self.object = self.get_object()
success_url = self.get_success_url()
self.object.approved = True
self.object.save()
messages.success(self.request, ... | python | def approve(self, request, *args, **kwargs):
""" Approves the considered post and retirects the user to the success URL. """
self.object = self.get_object()
success_url = self.get_success_url()
self.object.approved = True
self.object.save()
messages.success(self.request, ... | [
"def",
"approve",
"(",
"self",
",",
"request",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"object",
"=",
"self",
".",
"get_object",
"(",
")",
"success_url",
"=",
"self",
".",
"get_success_url",
"(",
")",
"self",
".",
"object",
... | Approves the considered post and retirects the user to the success URL. | [
"Approves",
"the",
"considered",
"post",
"and",
"retirects",
"the",
"user",
"to",
"the",
"success",
"URL",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_moderation/views.py#L404-L411 |
9,410 | ellmetha/django-machina | machina/apps/forum_moderation/views.py | PostDisapproveView.disapprove | def disapprove(self, request, *args, **kwargs):
""" Disapproves the considered post and retirects the user to the success URL. """
self.object = self.get_object()
success_url = self.get_success_url()
self.object.delete()
messages.success(self.request, self.success_message)
... | python | def disapprove(self, request, *args, **kwargs):
""" Disapproves the considered post and retirects the user to the success URL. """
self.object = self.get_object()
success_url = self.get_success_url()
self.object.delete()
messages.success(self.request, self.success_message)
... | [
"def",
"disapprove",
"(",
"self",
",",
"request",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"object",
"=",
"self",
".",
"get_object",
"(",
")",
"success_url",
"=",
"self",
".",
"get_success_url",
"(",
")",
"self",
".",
"object... | Disapproves the considered post and retirects the user to the success URL. | [
"Disapproves",
"the",
"considered",
"post",
"and",
"retirects",
"the",
"user",
"to",
"the",
"success",
"URL",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_moderation/views.py#L446-L452 |
9,411 | ellmetha/django-machina | machina/apps/forum_member/views.py | UserPostsView.poster | def poster(self):
""" Returns the considered user. """
user_model = get_user_model()
return get_object_or_404(user_model, pk=self.kwargs[self.user_pk_url_kwarg]) | python | def poster(self):
""" Returns the considered user. """
user_model = get_user_model()
return get_object_or_404(user_model, pk=self.kwargs[self.user_pk_url_kwarg]) | [
"def",
"poster",
"(",
"self",
")",
":",
"user_model",
"=",
"get_user_model",
"(",
")",
"return",
"get_object_or_404",
"(",
"user_model",
",",
"pk",
"=",
"self",
".",
"kwargs",
"[",
"self",
".",
"user_pk_url_kwarg",
"]",
")"
] | Returns the considered user. | [
"Returns",
"the",
"considered",
"user",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_member/views.py#L66-L69 |
9,412 | ellmetha/django-machina | machina/apps/forum_member/views.py | TopicSubscribeView.subscribe | def subscribe(self, request, *args, **kwargs):
""" Performs the subscribe action. """
self.object = self.get_object()
self.object.subscribers.add(request.user)
messages.success(self.request, self.success_message)
return HttpResponseRedirect(self.get_success_url()) | python | def subscribe(self, request, *args, **kwargs):
""" Performs the subscribe action. """
self.object = self.get_object()
self.object.subscribers.add(request.user)
messages.success(self.request, self.success_message)
return HttpResponseRedirect(self.get_success_url()) | [
"def",
"subscribe",
"(",
"self",
",",
"request",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"object",
"=",
"self",
".",
"get_object",
"(",
")",
"self",
".",
"object",
".",
"subscribers",
".",
"add",
"(",
"request",
".",
"user... | Performs the subscribe action. | [
"Performs",
"the",
"subscribe",
"action",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_member/views.py#L145-L150 |
9,413 | ellmetha/django-machina | machina/apps/forum_member/views.py | TopicUnsubscribeView.unsubscribe | def unsubscribe(self, request, *args, **kwargs):
""" Performs the unsubscribe action. """
self.object = self.get_object()
self.object.subscribers.remove(request.user)
messages.success(self.request, self.success_message)
return HttpResponseRedirect(self.get_success_url()) | python | def unsubscribe(self, request, *args, **kwargs):
""" Performs the unsubscribe action. """
self.object = self.get_object()
self.object.subscribers.remove(request.user)
messages.success(self.request, self.success_message)
return HttpResponseRedirect(self.get_success_url()) | [
"def",
"unsubscribe",
"(",
"self",
",",
"request",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"object",
"=",
"self",
".",
"get_object",
"(",
")",
"self",
".",
"object",
".",
"subscribers",
".",
"remove",
"(",
"request",
".",
... | Performs the unsubscribe action. | [
"Performs",
"the",
"unsubscribe",
"action",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_member/views.py#L191-L196 |
9,414 | ellmetha/django-machina | machina/apps/forum_conversation/receivers.py | update_topic_counter | def update_topic_counter(sender, topic, user, request, response, **kwargs):
""" Handles the update of the views counter associated with topics. """
topic.__class__._default_manager.filter(id=topic.id).update(views_count=F('views_count') + 1) | python | def update_topic_counter(sender, topic, user, request, response, **kwargs):
""" Handles the update of the views counter associated with topics. """
topic.__class__._default_manager.filter(id=topic.id).update(views_count=F('views_count') + 1) | [
"def",
"update_topic_counter",
"(",
"sender",
",",
"topic",
",",
"user",
",",
"request",
",",
"response",
",",
"*",
"*",
"kwargs",
")",
":",
"topic",
".",
"__class__",
".",
"_default_manager",
".",
"filter",
"(",
"id",
"=",
"topic",
".",
"id",
")",
"."... | Handles the update of the views counter associated with topics. | [
"Handles",
"the",
"update",
"of",
"the",
"views",
"counter",
"associated",
"with",
"topics",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_conversation/receivers.py#L16-L18 |
9,415 | ellmetha/django-machina | machina/apps/forum_conversation/views.py | TopicView.get_topic | def get_topic(self):
""" Returns the topic to consider. """
if not hasattr(self, 'topic'):
self.topic = get_object_or_404(
Topic.objects.select_related('forum').all(), pk=self.kwargs['pk'],
)
return self.topic | python | def get_topic(self):
""" Returns the topic to consider. """
if not hasattr(self, 'topic'):
self.topic = get_object_or_404(
Topic.objects.select_related('forum').all(), pk=self.kwargs['pk'],
)
return self.topic | [
"def",
"get_topic",
"(",
"self",
")",
":",
"if",
"not",
"hasattr",
"(",
"self",
",",
"'topic'",
")",
":",
"self",
".",
"topic",
"=",
"get_object_or_404",
"(",
"Topic",
".",
"objects",
".",
"select_related",
"(",
"'forum'",
")",
".",
"all",
"(",
")",
... | Returns the topic to consider. | [
"Returns",
"the",
"topic",
"to",
"consider",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_conversation/views.py#L73-L79 |
9,416 | ellmetha/django-machina | machina/apps/forum_conversation/views.py | BasePostFormView.init_attachment_cache | def init_attachment_cache(self):
""" Initializes the attachment cache for the current view. """
if self.request.method == 'GET':
# Invalidates previous attachments
attachments_cache.delete(self.get_attachments_cache_key(self.request))
return
# Try to restore ... | python | def init_attachment_cache(self):
""" Initializes the attachment cache for the current view. """
if self.request.method == 'GET':
# Invalidates previous attachments
attachments_cache.delete(self.get_attachments_cache_key(self.request))
return
# Try to restore ... | [
"def",
"init_attachment_cache",
"(",
"self",
")",
":",
"if",
"self",
".",
"request",
".",
"method",
"==",
"'GET'",
":",
"# Invalidates previous attachments",
"attachments_cache",
".",
"delete",
"(",
"self",
".",
"get_attachments_cache_key",
"(",
"self",
".",
"requ... | Initializes the attachment cache for the current view. | [
"Initializes",
"the",
"attachment",
"cache",
"for",
"the",
"current",
"view",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_conversation/views.py#L179-L195 |
9,417 | ellmetha/django-machina | machina/apps/forum_conversation/views.py | BasePostFormView.get_post_form_kwargs | def get_post_form_kwargs(self):
""" Returns the keyword arguments for instantiating the post form. """
kwargs = {
'user': self.request.user,
'forum': self.get_forum(),
'topic': self.get_topic(),
}
post = self.get_post()
if post:
kw... | python | def get_post_form_kwargs(self):
""" Returns the keyword arguments for instantiating the post form. """
kwargs = {
'user': self.request.user,
'forum': self.get_forum(),
'topic': self.get_topic(),
}
post = self.get_post()
if post:
kw... | [
"def",
"get_post_form_kwargs",
"(",
"self",
")",
":",
"kwargs",
"=",
"{",
"'user'",
":",
"self",
".",
"request",
".",
"user",
",",
"'forum'",
":",
"self",
".",
"get_forum",
"(",
")",
",",
"'topic'",
":",
"self",
".",
"get_topic",
"(",
")",
",",
"}",
... | Returns the keyword arguments for instantiating the post form. | [
"Returns",
"the",
"keyword",
"arguments",
"for",
"instantiating",
"the",
"post",
"form",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_conversation/views.py#L209-L226 |
9,418 | ellmetha/django-machina | machina/apps/forum_conversation/views.py | BasePostFormView.get_attachment_formset | def get_attachment_formset(self, formset_class):
""" Returns an instance of the attachment formset to be used in the view. """
if (
self.request.forum_permission_handler.can_attach_files(
self.get_forum(), self.request.user,
)
):
return formset... | python | def get_attachment_formset(self, formset_class):
""" Returns an instance of the attachment formset to be used in the view. """
if (
self.request.forum_permission_handler.can_attach_files(
self.get_forum(), self.request.user,
)
):
return formset... | [
"def",
"get_attachment_formset",
"(",
"self",
",",
"formset_class",
")",
":",
"if",
"(",
"self",
".",
"request",
".",
"forum_permission_handler",
".",
"can_attach_files",
"(",
"self",
".",
"get_forum",
"(",
")",
",",
"self",
".",
"request",
".",
"user",
",",... | Returns an instance of the attachment formset to be used in the view. | [
"Returns",
"an",
"instance",
"of",
"the",
"attachment",
"formset",
"to",
"be",
"used",
"in",
"the",
"view",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_conversation/views.py#L228-L235 |
9,419 | ellmetha/django-machina | machina/apps/forum_conversation/views.py | BasePostFormView.get_attachment_formset_kwargs | def get_attachment_formset_kwargs(self):
""" Returns the keyword arguments for instantiating the attachment formset. """
kwargs = {
'prefix': 'attachment',
}
if self.request.method in ('POST', 'PUT'):
kwargs.update({
'data': self.request.POST,
... | python | def get_attachment_formset_kwargs(self):
""" Returns the keyword arguments for instantiating the attachment formset. """
kwargs = {
'prefix': 'attachment',
}
if self.request.method in ('POST', 'PUT'):
kwargs.update({
'data': self.request.POST,
... | [
"def",
"get_attachment_formset_kwargs",
"(",
"self",
")",
":",
"kwargs",
"=",
"{",
"'prefix'",
":",
"'attachment'",
",",
"}",
"if",
"self",
".",
"request",
".",
"method",
"in",
"(",
"'POST'",
",",
"'PUT'",
")",
":",
"kwargs",
".",
"update",
"(",
"{",
"... | Returns the keyword arguments for instantiating the attachment formset. | [
"Returns",
"the",
"keyword",
"arguments",
"for",
"instantiating",
"the",
"attachment",
"formset",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_conversation/views.py#L241-L258 |
9,420 | ellmetha/django-machina | machina/apps/forum_conversation/views.py | BasePostFormView.get_forum | def get_forum(self):
""" Returns the considered forum. """
pk = self.kwargs.get(self.forum_pk_url_kwarg, None)
if not pk: # pragma: no cover
# This should never happen
return
if not hasattr(self, '_forum'):
self._forum = get_object_or_404(Forum, pk=pk... | python | def get_forum(self):
""" Returns the considered forum. """
pk = self.kwargs.get(self.forum_pk_url_kwarg, None)
if not pk: # pragma: no cover
# This should never happen
return
if not hasattr(self, '_forum'):
self._forum = get_object_or_404(Forum, pk=pk... | [
"def",
"get_forum",
"(",
"self",
")",
":",
"pk",
"=",
"self",
".",
"kwargs",
".",
"get",
"(",
"self",
".",
"forum_pk_url_kwarg",
",",
"None",
")",
"if",
"not",
"pk",
":",
"# pragma: no cover",
"# This should never happen",
"return",
"if",
"not",
"hasattr",
... | Returns the considered forum. | [
"Returns",
"the",
"considered",
"forum",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_conversation/views.py#L295-L303 |
9,421 | ellmetha/django-machina | machina/apps/forum_conversation/views.py | BasePostFormView.get_topic | def get_topic(self):
""" Returns the considered topic if applicable. """
pk = self.kwargs.get(self.topic_pk_url_kwarg, None)
if not pk:
return
if not hasattr(self, '_topic'):
self._topic = get_object_or_404(Topic, pk=pk)
return self._topic | python | def get_topic(self):
""" Returns the considered topic if applicable. """
pk = self.kwargs.get(self.topic_pk_url_kwarg, None)
if not pk:
return
if not hasattr(self, '_topic'):
self._topic = get_object_or_404(Topic, pk=pk)
return self._topic | [
"def",
"get_topic",
"(",
"self",
")",
":",
"pk",
"=",
"self",
".",
"kwargs",
".",
"get",
"(",
"self",
".",
"topic_pk_url_kwarg",
",",
"None",
")",
"if",
"not",
"pk",
":",
"return",
"if",
"not",
"hasattr",
"(",
"self",
",",
"'_topic'",
")",
":",
"se... | Returns the considered topic if applicable. | [
"Returns",
"the",
"considered",
"topic",
"if",
"applicable",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_conversation/views.py#L305-L312 |
9,422 | ellmetha/django-machina | machina/apps/forum_conversation/views.py | BasePostFormView.get_post | def get_post(self):
""" Returns the considered post if applicable. """
pk = self.kwargs.get(self.post_pk_url_kwarg, None)
if not pk:
return
if not hasattr(self, '_forum_post'):
self._forum_post = get_object_or_404(Post, pk=pk)
return self._forum_post | python | def get_post(self):
""" Returns the considered post if applicable. """
pk = self.kwargs.get(self.post_pk_url_kwarg, None)
if not pk:
return
if not hasattr(self, '_forum_post'):
self._forum_post = get_object_or_404(Post, pk=pk)
return self._forum_post | [
"def",
"get_post",
"(",
"self",
")",
":",
"pk",
"=",
"self",
".",
"kwargs",
".",
"get",
"(",
"self",
".",
"post_pk_url_kwarg",
",",
"None",
")",
"if",
"not",
"pk",
":",
"return",
"if",
"not",
"hasattr",
"(",
"self",
",",
"'_forum_post'",
")",
":",
... | Returns the considered post if applicable. | [
"Returns",
"the",
"considered",
"post",
"if",
"applicable",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_conversation/views.py#L314-L321 |
9,423 | ellmetha/django-machina | machina/apps/forum_conversation/views.py | BaseTopicFormView.get_poll_option_formset | def get_poll_option_formset(self, formset_class):
""" Returns an instance of the poll option formset to be used in the view. """
if self.request.forum_permission_handler.can_create_polls(
self.get_forum(), self.request.user,
):
return formset_class(**self.get_poll_option_... | python | def get_poll_option_formset(self, formset_class):
""" Returns an instance of the poll option formset to be used in the view. """
if self.request.forum_permission_handler.can_create_polls(
self.get_forum(), self.request.user,
):
return formset_class(**self.get_poll_option_... | [
"def",
"get_poll_option_formset",
"(",
"self",
",",
"formset_class",
")",
":",
"if",
"self",
".",
"request",
".",
"forum_permission_handler",
".",
"can_create_polls",
"(",
"self",
".",
"get_forum",
"(",
")",
",",
"self",
".",
"request",
".",
"user",
",",
")"... | Returns an instance of the poll option formset to be used in the view. | [
"Returns",
"an",
"instance",
"of",
"the",
"poll",
"option",
"formset",
"to",
"be",
"used",
"in",
"the",
"view",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_conversation/views.py#L448-L453 |
9,424 | ellmetha/django-machina | machina/apps/forum_conversation/views.py | BaseTopicFormView.get_poll_option_formset_kwargs | def get_poll_option_formset_kwargs(self):
""" Returns the keyword arguments for instantiating the poll option formset. """
kwargs = {
'prefix': 'poll',
}
if self.request.method in ('POST', 'PUT'):
kwargs.update({
'data': self.request.POST,
... | python | def get_poll_option_formset_kwargs(self):
""" Returns the keyword arguments for instantiating the poll option formset. """
kwargs = {
'prefix': 'poll',
}
if self.request.method in ('POST', 'PUT'):
kwargs.update({
'data': self.request.POST,
... | [
"def",
"get_poll_option_formset_kwargs",
"(",
"self",
")",
":",
"kwargs",
"=",
"{",
"'prefix'",
":",
"'poll'",
",",
"}",
"if",
"self",
".",
"request",
".",
"method",
"in",
"(",
"'POST'",
",",
"'PUT'",
")",
":",
"kwargs",
".",
"update",
"(",
"{",
"'data... | Returns the keyword arguments for instantiating the poll option formset. | [
"Returns",
"the",
"keyword",
"arguments",
"for",
"instantiating",
"the",
"poll",
"option",
"formset",
"."
] | 89ac083c1eaf1cfdeae6686ee094cc86362e8c69 | https://github.com/ellmetha/django-machina/blob/89ac083c1eaf1cfdeae6686ee094cc86362e8c69/machina/apps/forum_conversation/views.py#L459-L476 |
9,425 | e1ven/Robohash | robohash/robohash.py | Robohash._remove_exts | def _remove_exts(self,string):
"""
Sets the string, to create the Robohash
"""
# If the user hasn't disabled it, we will detect image extensions, such as .png, .jpg, etc.
# We'll remove them from the string before hashing.
# This ensures that /Bear.png and /Bear.bmp will... | python | def _remove_exts(self,string):
"""
Sets the string, to create the Robohash
"""
# If the user hasn't disabled it, we will detect image extensions, such as .png, .jpg, etc.
# We'll remove them from the string before hashing.
# This ensures that /Bear.png and /Bear.bmp will... | [
"def",
"_remove_exts",
"(",
"self",
",",
"string",
")",
":",
"# If the user hasn't disabled it, we will detect image extensions, such as .png, .jpg, etc.",
"# We'll remove them from the string before hashing.",
"# This ensures that /Bear.png and /Bear.bmp will send back the same image, in differ... | Sets the string, to create the Robohash | [
"Sets",
"the",
"string",
"to",
"create",
"the",
"Robohash"
] | 8dbbf9e69948ae2abc93c27511ef04f90b56c4d3 | https://github.com/e1ven/Robohash/blob/8dbbf9e69948ae2abc93c27511ef04f90b56c4d3/robohash/robohash.py#L46-L61 |
9,426 | e1ven/Robohash | robohash/robohash.py | Robohash._get_list_of_files | def _get_list_of_files(self,path):
"""
Go through each subdirectory of `path`, and choose one file from each to use in our hash.
Continue to increase self.iter, so we use a different 'slot' of randomness each time.
"""
chosen_files = []
# Get a list of all subdirectories... | python | def _get_list_of_files(self,path):
"""
Go through each subdirectory of `path`, and choose one file from each to use in our hash.
Continue to increase self.iter, so we use a different 'slot' of randomness each time.
"""
chosen_files = []
# Get a list of all subdirectories... | [
"def",
"_get_list_of_files",
"(",
"self",
",",
"path",
")",
":",
"chosen_files",
"=",
"[",
"]",
"# Get a list of all subdirectories",
"directories",
"=",
"[",
"]",
"for",
"root",
",",
"dirs",
",",
"files",
"in",
"natsort",
".",
"natsorted",
"(",
"os",
".",
... | Go through each subdirectory of `path`, and choose one file from each to use in our hash.
Continue to increase self.iter, so we use a different 'slot' of randomness each time. | [
"Go",
"through",
"each",
"subdirectory",
"of",
"path",
"and",
"choose",
"one",
"file",
"from",
"each",
"to",
"use",
"in",
"our",
"hash",
".",
"Continue",
"to",
"increase",
"self",
".",
"iter",
"so",
"we",
"use",
"a",
"different",
"slot",
"of",
"randomnes... | 8dbbf9e69948ae2abc93c27511ef04f90b56c4d3 | https://github.com/e1ven/Robohash/blob/8dbbf9e69948ae2abc93c27511ef04f90b56c4d3/robohash/robohash.py#L85-L113 |
9,427 | e1ven/Robohash | robohash/robohash.py | Robohash.assemble | def assemble(self,roboset=None,color=None,format=None,bgset=None,sizex=300,sizey=300):
"""
Build our Robot!
Returns the robot image itself.
"""
# Allow users to manually specify a robot 'set' that they like.
# Ensure that this is one of the allowed choices, or allow all
... | python | def assemble(self,roboset=None,color=None,format=None,bgset=None,sizex=300,sizey=300):
"""
Build our Robot!
Returns the robot image itself.
"""
# Allow users to manually specify a robot 'set' that they like.
# Ensure that this is one of the allowed choices, or allow all
... | [
"def",
"assemble",
"(",
"self",
",",
"roboset",
"=",
"None",
",",
"color",
"=",
"None",
",",
"format",
"=",
"None",
",",
"bgset",
"=",
"None",
",",
"sizex",
"=",
"300",
",",
"sizey",
"=",
"300",
")",
":",
"# Allow users to manually specify a robot 'set' th... | Build our Robot!
Returns the robot image itself. | [
"Build",
"our",
"Robot!",
"Returns",
"the",
"robot",
"image",
"itself",
"."
] | 8dbbf9e69948ae2abc93c27511ef04f90b56c4d3 | https://github.com/e1ven/Robohash/blob/8dbbf9e69948ae2abc93c27511ef04f90b56c4d3/robohash/robohash.py#L115-L198 |
9,428 | tensorflow/skflow | scripts/docs/docs.py | collect_members | def collect_members(module_to_name):
"""Collect all symbols from a list of modules.
Args:
module_to_name: Dictionary mapping modules to short names.
Returns:
Dictionary mapping name to (fullname, member) pairs.
"""
members = {}
for module, module_name in module_to_name.items():
all_names = get... | python | def collect_members(module_to_name):
"""Collect all symbols from a list of modules.
Args:
module_to_name: Dictionary mapping modules to short names.
Returns:
Dictionary mapping name to (fullname, member) pairs.
"""
members = {}
for module, module_name in module_to_name.items():
all_names = get... | [
"def",
"collect_members",
"(",
"module_to_name",
")",
":",
"members",
"=",
"{",
"}",
"for",
"module",
",",
"module_name",
"in",
"module_to_name",
".",
"items",
"(",
")",
":",
"all_names",
"=",
"getattr",
"(",
"module",
",",
"\"__all__\"",
",",
"None",
")",... | Collect all symbols from a list of modules.
Args:
module_to_name: Dictionary mapping modules to short names.
Returns:
Dictionary mapping name to (fullname, member) pairs. | [
"Collect",
"all",
"symbols",
"from",
"a",
"list",
"of",
"modules",
"."
] | f8da498a1abb7562f57dfc7010941578103061b6 | https://github.com/tensorflow/skflow/blob/f8da498a1abb7562f57dfc7010941578103061b6/scripts/docs/docs.py#L103-L132 |
9,429 | tensorflow/skflow | scripts/docs/docs.py | _get_anchor | def _get_anchor(module_to_name, fullname):
"""Turn a full member name into an anchor.
Args:
module_to_name: Dictionary mapping modules to short names.
fullname: Fully qualified name of symbol.
Returns:
HTML anchor string. The longest module name prefix of fullname is
removed to make the anchor.... | python | def _get_anchor(module_to_name, fullname):
"""Turn a full member name into an anchor.
Args:
module_to_name: Dictionary mapping modules to short names.
fullname: Fully qualified name of symbol.
Returns:
HTML anchor string. The longest module name prefix of fullname is
removed to make the anchor.... | [
"def",
"_get_anchor",
"(",
"module_to_name",
",",
"fullname",
")",
":",
"if",
"not",
"_anchor_re",
".",
"match",
"(",
"fullname",
")",
":",
"raise",
"ValueError",
"(",
"\"'%s' is not a valid anchor\"",
"%",
"fullname",
")",
"anchor",
"=",
"fullname",
"for",
"m... | Turn a full member name into an anchor.
Args:
module_to_name: Dictionary mapping modules to short names.
fullname: Fully qualified name of symbol.
Returns:
HTML anchor string. The longest module name prefix of fullname is
removed to make the anchor.
Raises:
ValueError: If fullname uses cha... | [
"Turn",
"a",
"full",
"member",
"name",
"into",
"an",
"anchor",
"."
] | f8da498a1abb7562f57dfc7010941578103061b6 | https://github.com/tensorflow/skflow/blob/f8da498a1abb7562f57dfc7010941578103061b6/scripts/docs/docs.py#L135-L158 |
9,430 | tensorflow/skflow | scripts/docs/docs.py | write_libraries | def write_libraries(dir, libraries):
"""Write a list of libraries to disk.
Args:
dir: Output directory.
libraries: List of (filename, library) pairs.
"""
files = [open(os.path.join(dir, k), "w") for k, _ in libraries]
# Document mentioned symbols for all libraries
for f, (_, v) in zip(files, librar... | python | def write_libraries(dir, libraries):
"""Write a list of libraries to disk.
Args:
dir: Output directory.
libraries: List of (filename, library) pairs.
"""
files = [open(os.path.join(dir, k), "w") for k, _ in libraries]
# Document mentioned symbols for all libraries
for f, (_, v) in zip(files, librar... | [
"def",
"write_libraries",
"(",
"dir",
",",
"libraries",
")",
":",
"files",
"=",
"[",
"open",
"(",
"os",
".",
"path",
".",
"join",
"(",
"dir",
",",
"k",
")",
",",
"\"w\"",
")",
"for",
"k",
",",
"_",
"in",
"libraries",
"]",
"# Document mentioned symbol... | Write a list of libraries to disk.
Args:
dir: Output directory.
libraries: List of (filename, library) pairs. | [
"Write",
"a",
"list",
"of",
"libraries",
"to",
"disk",
"."
] | f8da498a1abb7562f57dfc7010941578103061b6 | https://github.com/tensorflow/skflow/blob/f8da498a1abb7562f57dfc7010941578103061b6/scripts/docs/docs.py#L514-L530 |
9,431 | tensorflow/skflow | scripts/docs/docs.py | Index.write_markdown_to_file | def write_markdown_to_file(self, f):
"""Writes this index to file `f`.
The output is formatted as an unordered list. Each list element
contains the title of the library, followed by a list of symbols
in that library hyperlinked to the corresponding anchor in that
library.
Args:
f: The ou... | python | def write_markdown_to_file(self, f):
"""Writes this index to file `f`.
The output is formatted as an unordered list. Each list element
contains the title of the library, followed by a list of symbols
in that library hyperlinked to the corresponding anchor in that
library.
Args:
f: The ou... | [
"def",
"write_markdown_to_file",
"(",
"self",
",",
"f",
")",
":",
"print",
"(",
"\"---\"",
",",
"file",
"=",
"f",
")",
"print",
"(",
"\"---\"",
",",
"file",
"=",
"f",
")",
"print",
"(",
"\"<!-- This file is machine generated: DO NOT EDIT! -->\"",
",",
"file",
... | Writes this index to file `f`.
The output is formatted as an unordered list. Each list element
contains the title of the library, followed by a list of symbols
in that library hyperlinked to the corresponding anchor in that
library.
Args:
f: The output file. | [
"Writes",
"this",
"index",
"to",
"file",
"f",
"."
] | f8da498a1abb7562f57dfc7010941578103061b6 | https://github.com/tensorflow/skflow/blob/f8da498a1abb7562f57dfc7010941578103061b6/scripts/docs/docs.py#L68-L100 |
9,432 | tensorflow/skflow | scripts/docs/docs.py | Library._should_include_member | def _should_include_member(self, name, member):
"""Returns True if this member should be included in the document."""
# Always exclude symbols matching _always_drop_symbol_re.
if _always_drop_symbol_re.match(name):
return False
# Finally, exclude any specifically-excluded symbols.
if name in s... | python | def _should_include_member(self, name, member):
"""Returns True if this member should be included in the document."""
# Always exclude symbols matching _always_drop_symbol_re.
if _always_drop_symbol_re.match(name):
return False
# Finally, exclude any specifically-excluded symbols.
if name in s... | [
"def",
"_should_include_member",
"(",
"self",
",",
"name",
",",
"member",
")",
":",
"# Always exclude symbols matching _always_drop_symbol_re.",
"if",
"_always_drop_symbol_re",
".",
"match",
"(",
"name",
")",
":",
"return",
"False",
"# Finally, exclude any specifically-excl... | Returns True if this member should be included in the document. | [
"Returns",
"True",
"if",
"this",
"member",
"should",
"be",
"included",
"in",
"the",
"document",
"."
] | f8da498a1abb7562f57dfc7010941578103061b6 | https://github.com/tensorflow/skflow/blob/f8da498a1abb7562f57dfc7010941578103061b6/scripts/docs/docs.py#L209-L217 |
9,433 | tensorflow/skflow | scripts/docs/docs.py | Library.get_imported_modules | def get_imported_modules(self, module):
"""Returns the list of modules imported from `module`."""
for name, member in inspect.getmembers(module):
if inspect.ismodule(member):
yield name, member | python | def get_imported_modules(self, module):
"""Returns the list of modules imported from `module`."""
for name, member in inspect.getmembers(module):
if inspect.ismodule(member):
yield name, member | [
"def",
"get_imported_modules",
"(",
"self",
",",
"module",
")",
":",
"for",
"name",
",",
"member",
"in",
"inspect",
".",
"getmembers",
"(",
"module",
")",
":",
"if",
"inspect",
".",
"ismodule",
"(",
"member",
")",
":",
"yield",
"name",
",",
"member"
] | Returns the list of modules imported from `module`. | [
"Returns",
"the",
"list",
"of",
"modules",
"imported",
"from",
"module",
"."
] | f8da498a1abb7562f57dfc7010941578103061b6 | https://github.com/tensorflow/skflow/blob/f8da498a1abb7562f57dfc7010941578103061b6/scripts/docs/docs.py#L219-L223 |
9,434 | tensorflow/skflow | scripts/docs/docs.py | Library.get_class_members | def get_class_members(self, cls_name, cls):
"""Returns the list of class members to document in `cls`.
This function filters the class member to ONLY return those
defined by the class. It drops the inherited ones.
Args:
cls_name: Qualified name of `cls`.
cls: An inspect object of type 'cl... | python | def get_class_members(self, cls_name, cls):
"""Returns the list of class members to document in `cls`.
This function filters the class member to ONLY return those
defined by the class. It drops the inherited ones.
Args:
cls_name: Qualified name of `cls`.
cls: An inspect object of type 'cl... | [
"def",
"get_class_members",
"(",
"self",
",",
"cls_name",
",",
"cls",
")",
":",
"for",
"name",
",",
"member",
"in",
"inspect",
".",
"getmembers",
"(",
"cls",
")",
":",
"# Only show methods and properties presently. In Python 3,",
"# methods register as isfunction.",
... | Returns the list of class members to document in `cls`.
This function filters the class member to ONLY return those
defined by the class. It drops the inherited ones.
Args:
cls_name: Qualified name of `cls`.
cls: An inspect object of type 'class'.
Yields:
name, member tuples. | [
"Returns",
"the",
"list",
"of",
"class",
"members",
"to",
"document",
"in",
"cls",
"."
] | f8da498a1abb7562f57dfc7010941578103061b6 | https://github.com/tensorflow/skflow/blob/f8da498a1abb7562f57dfc7010941578103061b6/scripts/docs/docs.py#L225-L246 |
9,435 | tensorflow/skflow | scripts/docs/docs.py | Library._generate_signature_for_function | def _generate_signature_for_function(self, func):
"""Given a function, returns a string representing its args."""
args_list = []
argspec = inspect.getargspec(func)
first_arg_with_default = (
len(argspec.args or []) - len(argspec.defaults or []))
for arg in argspec.args[:first_arg_with_defaul... | python | def _generate_signature_for_function(self, func):
"""Given a function, returns a string representing its args."""
args_list = []
argspec = inspect.getargspec(func)
first_arg_with_default = (
len(argspec.args or []) - len(argspec.defaults or []))
for arg in argspec.args[:first_arg_with_defaul... | [
"def",
"_generate_signature_for_function",
"(",
"self",
",",
"func",
")",
":",
"args_list",
"=",
"[",
"]",
"argspec",
"=",
"inspect",
".",
"getargspec",
"(",
"func",
")",
"first_arg_with_default",
"=",
"(",
"len",
"(",
"argspec",
".",
"args",
"or",
"[",
"]... | Given a function, returns a string representing its args. | [
"Given",
"a",
"function",
"returns",
"a",
"string",
"representing",
"its",
"args",
"."
] | f8da498a1abb7562f57dfc7010941578103061b6 | https://github.com/tensorflow/skflow/blob/f8da498a1abb7562f57dfc7010941578103061b6/scripts/docs/docs.py#L248-L279 |
9,436 | tensorflow/skflow | scripts/docs/docs.py | Library._remove_docstring_indent | def _remove_docstring_indent(self, docstring):
"""Remove indenting.
We follow Python's convention and remove the minimum indent of the lines
after the first, see:
https://www.python.org/dev/peps/pep-0257/#handling-docstring-indentation
preserving relative indentation.
Args:
docstring: A ... | python | def _remove_docstring_indent(self, docstring):
"""Remove indenting.
We follow Python's convention and remove the minimum indent of the lines
after the first, see:
https://www.python.org/dev/peps/pep-0257/#handling-docstring-indentation
preserving relative indentation.
Args:
docstring: A ... | [
"def",
"_remove_docstring_indent",
"(",
"self",
",",
"docstring",
")",
":",
"docstring",
"=",
"docstring",
"or",
"\"\"",
"lines",
"=",
"docstring",
".",
"strip",
"(",
")",
".",
"split",
"(",
"\"\\n\"",
")",
"min_indent",
"=",
"len",
"(",
"docstring",
")",
... | Remove indenting.
We follow Python's convention and remove the minimum indent of the lines
after the first, see:
https://www.python.org/dev/peps/pep-0257/#handling-docstring-indentation
preserving relative indentation.
Args:
docstring: A docstring.
Returns:
A list of strings, one ... | [
"Remove",
"indenting",
"."
] | f8da498a1abb7562f57dfc7010941578103061b6 | https://github.com/tensorflow/skflow/blob/f8da498a1abb7562f57dfc7010941578103061b6/scripts/docs/docs.py#L281-L311 |
9,437 | tensorflow/skflow | scripts/docs/docs.py | Library._print_formatted_docstring | def _print_formatted_docstring(self, docstring, f):
"""Formats the given `docstring` as Markdown and prints it to `f`."""
lines = self._remove_docstring_indent(docstring)
# Output the lines, identifying "Args" and other section blocks.
i = 0
def _at_start_of_section():
"""Returns the header ... | python | def _print_formatted_docstring(self, docstring, f):
"""Formats the given `docstring` as Markdown and prints it to `f`."""
lines = self._remove_docstring_indent(docstring)
# Output the lines, identifying "Args" and other section blocks.
i = 0
def _at_start_of_section():
"""Returns the header ... | [
"def",
"_print_formatted_docstring",
"(",
"self",
",",
"docstring",
",",
"f",
")",
":",
"lines",
"=",
"self",
".",
"_remove_docstring_indent",
"(",
"docstring",
")",
"# Output the lines, identifying \"Args\" and other section blocks.",
"i",
"=",
"0",
"def",
"_at_start_o... | Formats the given `docstring` as Markdown and prints it to `f`. | [
"Formats",
"the",
"given",
"docstring",
"as",
"Markdown",
"and",
"prints",
"it",
"to",
"f",
"."
] | f8da498a1abb7562f57dfc7010941578103061b6 | https://github.com/tensorflow/skflow/blob/f8da498a1abb7562f57dfc7010941578103061b6/scripts/docs/docs.py#L313-L364 |
9,438 | tensorflow/skflow | scripts/docs/docs.py | Library._print_function | def _print_function(self, f, prefix, fullname, func):
"""Prints the given function to `f`."""
heading = prefix + " `" + fullname
if not isinstance(func, property):
heading += self._generate_signature_for_function(func)
heading += "` {#%s}" % _get_anchor(self._module_to_name, fullname)
print(he... | python | def _print_function(self, f, prefix, fullname, func):
"""Prints the given function to `f`."""
heading = prefix + " `" + fullname
if not isinstance(func, property):
heading += self._generate_signature_for_function(func)
heading += "` {#%s}" % _get_anchor(self._module_to_name, fullname)
print(he... | [
"def",
"_print_function",
"(",
"self",
",",
"f",
",",
"prefix",
",",
"fullname",
",",
"func",
")",
":",
"heading",
"=",
"prefix",
"+",
"\" `\"",
"+",
"fullname",
"if",
"not",
"isinstance",
"(",
"func",
",",
"property",
")",
":",
"heading",
"+=",
"self"... | Prints the given function to `f`. | [
"Prints",
"the",
"given",
"function",
"to",
"f",
"."
] | f8da498a1abb7562f57dfc7010941578103061b6 | https://github.com/tensorflow/skflow/blob/f8da498a1abb7562f57dfc7010941578103061b6/scripts/docs/docs.py#L366-L375 |
9,439 | tensorflow/skflow | scripts/docs/docs.py | Library._write_member_markdown_to_file | def _write_member_markdown_to_file(self, f, prefix, name, member):
"""Print `member` to `f`."""
if (inspect.isfunction(member) or inspect.ismethod(member) or
isinstance(member, property)):
print("- - -", file=f)
print("", file=f)
self._print_function(f, prefix, name, member)
prin... | python | def _write_member_markdown_to_file(self, f, prefix, name, member):
"""Print `member` to `f`."""
if (inspect.isfunction(member) or inspect.ismethod(member) or
isinstance(member, property)):
print("- - -", file=f)
print("", file=f)
self._print_function(f, prefix, name, member)
prin... | [
"def",
"_write_member_markdown_to_file",
"(",
"self",
",",
"f",
",",
"prefix",
",",
"name",
",",
"member",
")",
":",
"if",
"(",
"inspect",
".",
"isfunction",
"(",
"member",
")",
"or",
"inspect",
".",
"ismethod",
"(",
"member",
")",
"or",
"isinstance",
"(... | Print `member` to `f`. | [
"Print",
"member",
"to",
"f",
"."
] | f8da498a1abb7562f57dfc7010941578103061b6 | https://github.com/tensorflow/skflow/blob/f8da498a1abb7562f57dfc7010941578103061b6/scripts/docs/docs.py#L377-L395 |
9,440 | tensorflow/skflow | scripts/docs/docs.py | Library._write_class_markdown_to_file | def _write_class_markdown_to_file(self, f, name, cls):
"""Write the class doc to `f`.
Args:
f: File to write to.
prefix: Prefix for names.
cls: class object.
name: name to use.
"""
# Build the list of class methods to document.
methods = dict(self.get_class_members(name, cls... | python | def _write_class_markdown_to_file(self, f, name, cls):
"""Write the class doc to `f`.
Args:
f: File to write to.
prefix: Prefix for names.
cls: class object.
name: name to use.
"""
# Build the list of class methods to document.
methods = dict(self.get_class_members(name, cls... | [
"def",
"_write_class_markdown_to_file",
"(",
"self",
",",
"f",
",",
"name",
",",
"cls",
")",
":",
"# Build the list of class methods to document.",
"methods",
"=",
"dict",
"(",
"self",
".",
"get_class_members",
"(",
"name",
",",
"cls",
")",
")",
"# Used later to c... | Write the class doc to `f`.
Args:
f: File to write to.
prefix: Prefix for names.
cls: class object.
name: name to use. | [
"Write",
"the",
"class",
"doc",
"to",
"f",
"."
] | f8da498a1abb7562f57dfc7010941578103061b6 | https://github.com/tensorflow/skflow/blob/f8da498a1abb7562f57dfc7010941578103061b6/scripts/docs/docs.py#L414-L448 |
9,441 | tensorflow/skflow | scripts/docs/docs.py | Library.write_markdown_to_file | def write_markdown_to_file(self, f):
"""Prints this library to file `f`.
Args:
f: File to write to.
Returns:
Dictionary of documented members.
"""
print("---", file=f)
print("---", file=f)
print("<!-- This file is machine generated: DO NOT EDIT! -->", file=f)
print("", file... | python | def write_markdown_to_file(self, f):
"""Prints this library to file `f`.
Args:
f: File to write to.
Returns:
Dictionary of documented members.
"""
print("---", file=f)
print("---", file=f)
print("<!-- This file is machine generated: DO NOT EDIT! -->", file=f)
print("", file... | [
"def",
"write_markdown_to_file",
"(",
"self",
",",
"f",
")",
":",
"print",
"(",
"\"---\"",
",",
"file",
"=",
"f",
")",
"print",
"(",
"\"---\"",
",",
"file",
"=",
"f",
")",
"print",
"(",
"\"<!-- This file is machine generated: DO NOT EDIT! -->\"",
",",
"file",
... | Prints this library to file `f`.
Args:
f: File to write to.
Returns:
Dictionary of documented members. | [
"Prints",
"this",
"library",
"to",
"file",
"f",
"."
] | f8da498a1abb7562f57dfc7010941578103061b6 | https://github.com/tensorflow/skflow/blob/f8da498a1abb7562f57dfc7010941578103061b6/scripts/docs/docs.py#L455-L476 |
9,442 | tensorflow/skflow | scripts/docs/docs.py | Library.write_other_members | def write_other_members(self, f, catch_all=False):
"""Writes the leftover members to `f`.
Args:
f: File to write to.
catch_all: If true, document all missing symbols from any module.
Otherwise, document missing symbols from just this module.
"""
if catch_all:
names = self._mem... | python | def write_other_members(self, f, catch_all=False):
"""Writes the leftover members to `f`.
Args:
f: File to write to.
catch_all: If true, document all missing symbols from any module.
Otherwise, document missing symbols from just this module.
"""
if catch_all:
names = self._mem... | [
"def",
"write_other_members",
"(",
"self",
",",
"f",
",",
"catch_all",
"=",
"False",
")",
":",
"if",
"catch_all",
":",
"names",
"=",
"self",
".",
"_members",
".",
"items",
"(",
")",
"else",
":",
"names",
"=",
"inspect",
".",
"getmembers",
"(",
"self",
... | Writes the leftover members to `f`.
Args:
f: File to write to.
catch_all: If true, document all missing symbols from any module.
Otherwise, document missing symbols from just this module. | [
"Writes",
"the",
"leftover",
"members",
"to",
"f",
"."
] | f8da498a1abb7562f57dfc7010941578103061b6 | https://github.com/tensorflow/skflow/blob/f8da498a1abb7562f57dfc7010941578103061b6/scripts/docs/docs.py#L478-L501 |
9,443 | tensorflow/skflow | scripts/docs/docs.py | Library.assert_no_leftovers | def assert_no_leftovers(self):
"""Generate an error if there are leftover members."""
leftovers = []
for name in self._members.keys():
if name in self._members and name not in self._documented:
leftovers.append(name)
if leftovers:
raise RuntimeError("%s: undocumented members: %s" %
... | python | def assert_no_leftovers(self):
"""Generate an error if there are leftover members."""
leftovers = []
for name in self._members.keys():
if name in self._members and name not in self._documented:
leftovers.append(name)
if leftovers:
raise RuntimeError("%s: undocumented members: %s" %
... | [
"def",
"assert_no_leftovers",
"(",
"self",
")",
":",
"leftovers",
"=",
"[",
"]",
"for",
"name",
"in",
"self",
".",
"_members",
".",
"keys",
"(",
")",
":",
"if",
"name",
"in",
"self",
".",
"_members",
"and",
"name",
"not",
"in",
"self",
".",
"_documen... | Generate an error if there are leftover members. | [
"Generate",
"an",
"error",
"if",
"there",
"are",
"leftover",
"members",
"."
] | f8da498a1abb7562f57dfc7010941578103061b6 | https://github.com/tensorflow/skflow/blob/f8da498a1abb7562f57dfc7010941578103061b6/scripts/docs/docs.py#L503-L511 |
9,444 | rycus86/prometheus_flask_exporter | prometheus_flask_exporter/multiprocess.py | MultiprocessPrometheusMetrics.start_http_server | def start_http_server(self, port, host='0.0.0.0', endpoint=None):
"""
Start an HTTP server for exposing the metrics, if the
`should_start_http_server` function says we should, otherwise just return.
Uses the implementation from `prometheus_client` rather than a Flask app.
:param... | python | def start_http_server(self, port, host='0.0.0.0', endpoint=None):
"""
Start an HTTP server for exposing the metrics, if the
`should_start_http_server` function says we should, otherwise just return.
Uses the implementation from `prometheus_client` rather than a Flask app.
:param... | [
"def",
"start_http_server",
"(",
"self",
",",
"port",
",",
"host",
"=",
"'0.0.0.0'",
",",
"endpoint",
"=",
"None",
")",
":",
"if",
"self",
".",
"should_start_http_server",
"(",
")",
":",
"pc_start_http_server",
"(",
"port",
",",
"host",
",",
"registry",
"=... | Start an HTTP server for exposing the metrics, if the
`should_start_http_server` function says we should, otherwise just return.
Uses the implementation from `prometheus_client` rather than a Flask app.
:param port: the HTTP port to expose the metrics endpoint on
:param host: the HTTP h... | [
"Start",
"an",
"HTTP",
"server",
"for",
"exposing",
"the",
"metrics",
"if",
"the",
"should_start_http_server",
"function",
"says",
"we",
"should",
"otherwise",
"just",
"return",
".",
"Uses",
"the",
"implementation",
"from",
"prometheus_client",
"rather",
"than",
"... | 678dbf3097e82a0ddb697268406004cc1f4a26bc | https://github.com/rycus86/prometheus_flask_exporter/blob/678dbf3097e82a0ddb697268406004cc1f4a26bc/prometheus_flask_exporter/multiprocess.py#L75-L87 |
9,445 | rycus86/prometheus_flask_exporter | prometheus_flask_exporter/__init__.py | PrometheusMetrics.init_app | def init_app(self, app):
"""
This callback can be used to initialize an application for the
use with this prometheus reporter setup.
This is usually used with a flask "app factory" configuration. Please
see: http://flask.pocoo.org/docs/1.0/patterns/appfactories/
Note, t... | python | def init_app(self, app):
"""
This callback can be used to initialize an application for the
use with this prometheus reporter setup.
This is usually used with a flask "app factory" configuration. Please
see: http://flask.pocoo.org/docs/1.0/patterns/appfactories/
Note, t... | [
"def",
"init_app",
"(",
"self",
",",
"app",
")",
":",
"if",
"self",
".",
"path",
":",
"self",
".",
"register_endpoint",
"(",
"self",
".",
"path",
",",
"app",
")",
"if",
"self",
".",
"_export_defaults",
":",
"self",
".",
"export_defaults",
"(",
"self",
... | This callback can be used to initialize an application for the
use with this prometheus reporter setup.
This is usually used with a flask "app factory" configuration. Please
see: http://flask.pocoo.org/docs/1.0/patterns/appfactories/
Note, that you need to use `PrometheusMetrics(app=No... | [
"This",
"callback",
"can",
"be",
"used",
"to",
"initialize",
"an",
"application",
"for",
"the",
"use",
"with",
"this",
"prometheus",
"reporter",
"setup",
"."
] | 678dbf3097e82a0ddb697268406004cc1f4a26bc | https://github.com/rycus86/prometheus_flask_exporter/blob/678dbf3097e82a0ddb697268406004cc1f4a26bc/prometheus_flask_exporter/__init__.py#L133-L154 |
9,446 | rycus86/prometheus_flask_exporter | prometheus_flask_exporter/__init__.py | PrometheusMetrics.register_endpoint | def register_endpoint(self, path, app=None):
"""
Register the metrics endpoint on the Flask application.
:param path: the path of the endpoint
:param app: the Flask application to register the endpoint on
(by default it is the application registered with this class)
... | python | def register_endpoint(self, path, app=None):
"""
Register the metrics endpoint on the Flask application.
:param path: the path of the endpoint
:param app: the Flask application to register the endpoint on
(by default it is the application registered with this class)
... | [
"def",
"register_endpoint",
"(",
"self",
",",
"path",
",",
"app",
"=",
"None",
")",
":",
"if",
"is_running_from_reloader",
"(",
")",
"and",
"not",
"os",
".",
"environ",
".",
"get",
"(",
"'DEBUG_METRICS'",
")",
":",
"return",
"if",
"app",
"is",
"None",
... | Register the metrics endpoint on the Flask application.
:param path: the path of the endpoint
:param app: the Flask application to register the endpoint on
(by default it is the application registered with this class) | [
"Register",
"the",
"metrics",
"endpoint",
"on",
"the",
"Flask",
"application",
"."
] | 678dbf3097e82a0ddb697268406004cc1f4a26bc | https://github.com/rycus86/prometheus_flask_exporter/blob/678dbf3097e82a0ddb697268406004cc1f4a26bc/prometheus_flask_exporter/__init__.py#L156-L189 |
9,447 | rycus86/prometheus_flask_exporter | prometheus_flask_exporter/__init__.py | PrometheusMetrics.start_http_server | def start_http_server(self, port, host='0.0.0.0', endpoint='/metrics'):
"""
Start an HTTP server for exposing the metrics.
This will be an individual Flask application,
not the one registered with this class.
:param port: the HTTP port to expose the metrics endpoint on
:... | python | def start_http_server(self, port, host='0.0.0.0', endpoint='/metrics'):
"""
Start an HTTP server for exposing the metrics.
This will be an individual Flask application,
not the one registered with this class.
:param port: the HTTP port to expose the metrics endpoint on
:... | [
"def",
"start_http_server",
"(",
"self",
",",
"port",
",",
"host",
"=",
"'0.0.0.0'",
",",
"endpoint",
"=",
"'/metrics'",
")",
":",
"if",
"is_running_from_reloader",
"(",
")",
":",
"return",
"app",
"=",
"Flask",
"(",
"'prometheus-flask-exporter-%d'",
"%",
"port... | Start an HTTP server for exposing the metrics.
This will be an individual Flask application,
not the one registered with this class.
:param port: the HTTP port to expose the metrics endpoint on
:param host: the HTTP host to listen on (default: `0.0.0.0`)
:param endpoint: the URL... | [
"Start",
"an",
"HTTP",
"server",
"for",
"exposing",
"the",
"metrics",
".",
"This",
"will",
"be",
"an",
"individual",
"Flask",
"application",
"not",
"the",
"one",
"registered",
"with",
"this",
"class",
"."
] | 678dbf3097e82a0ddb697268406004cc1f4a26bc | https://github.com/rycus86/prometheus_flask_exporter/blob/678dbf3097e82a0ddb697268406004cc1f4a26bc/prometheus_flask_exporter/__init__.py#L191-L214 |
9,448 | rycus86/prometheus_flask_exporter | prometheus_flask_exporter/__init__.py | PrometheusMetrics.histogram | def histogram(self, name, description, labels=None, **kwargs):
"""
Use a Histogram to track the execution time and invocation count
of the method.
:param name: the name of the metric
:param description: the description of the metric
:param labels: a dictionary of `{label... | python | def histogram(self, name, description, labels=None, **kwargs):
"""
Use a Histogram to track the execution time and invocation count
of the method.
:param name: the name of the metric
:param description: the description of the metric
:param labels: a dictionary of `{label... | [
"def",
"histogram",
"(",
"self",
",",
"name",
",",
"description",
",",
"labels",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"self",
".",
"_track",
"(",
"Histogram",
",",
"lambda",
"metric",
",",
"time",
":",
"metric",
".",
"observe",
"... | Use a Histogram to track the execution time and invocation count
of the method.
:param name: the name of the metric
:param description: the description of the metric
:param labels: a dictionary of `{labelname: callable_or_value}` for labels
:param kwargs: additional keyword argu... | [
"Use",
"a",
"Histogram",
"to",
"track",
"the",
"execution",
"time",
"and",
"invocation",
"count",
"of",
"the",
"method",
"."
] | 678dbf3097e82a0ddb697268406004cc1f4a26bc | https://github.com/rycus86/prometheus_flask_exporter/blob/678dbf3097e82a0ddb697268406004cc1f4a26bc/prometheus_flask_exporter/__init__.py#L317-L333 |
9,449 | rycus86/prometheus_flask_exporter | prometheus_flask_exporter/__init__.py | PrometheusMetrics.summary | def summary(self, name, description, labels=None, **kwargs):
"""
Use a Summary to track the execution time and invocation count
of the method.
:param name: the name of the metric
:param description: the description of the metric
:param labels: a dictionary of `{labelname... | python | def summary(self, name, description, labels=None, **kwargs):
"""
Use a Summary to track the execution time and invocation count
of the method.
:param name: the name of the metric
:param description: the description of the metric
:param labels: a dictionary of `{labelname... | [
"def",
"summary",
"(",
"self",
",",
"name",
",",
"description",
",",
"labels",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"self",
".",
"_track",
"(",
"Summary",
",",
"lambda",
"metric",
",",
"time",
":",
"metric",
".",
"observe",
"(",
... | Use a Summary to track the execution time and invocation count
of the method.
:param name: the name of the metric
:param description: the description of the metric
:param labels: a dictionary of `{labelname: callable_or_value}` for labels
:param kwargs: additional keyword argume... | [
"Use",
"a",
"Summary",
"to",
"track",
"the",
"execution",
"time",
"and",
"invocation",
"count",
"of",
"the",
"method",
"."
] | 678dbf3097e82a0ddb697268406004cc1f4a26bc | https://github.com/rycus86/prometheus_flask_exporter/blob/678dbf3097e82a0ddb697268406004cc1f4a26bc/prometheus_flask_exporter/__init__.py#L335-L351 |
9,450 | rycus86/prometheus_flask_exporter | prometheus_flask_exporter/__init__.py | PrometheusMetrics.gauge | def gauge(self, name, description, labels=None, **kwargs):
"""
Use a Gauge to track the number of invocations in progress
for the method.
:param name: the name of the metric
:param description: the description of the metric
:param labels: a dictionary of `{labelname: cal... | python | def gauge(self, name, description, labels=None, **kwargs):
"""
Use a Gauge to track the number of invocations in progress
for the method.
:param name: the name of the metric
:param description: the description of the metric
:param labels: a dictionary of `{labelname: cal... | [
"def",
"gauge",
"(",
"self",
",",
"name",
",",
"description",
",",
"labels",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"self",
".",
"_track",
"(",
"Gauge",
",",
"lambda",
"metric",
",",
"time",
":",
"metric",
".",
"dec",
"(",
")",
... | Use a Gauge to track the number of invocations in progress
for the method.
:param name: the name of the metric
:param description: the description of the metric
:param labels: a dictionary of `{labelname: callable_or_value}` for labels
:param kwargs: additional keyword arguments... | [
"Use",
"a",
"Gauge",
"to",
"track",
"the",
"number",
"of",
"invocations",
"in",
"progress",
"for",
"the",
"method",
"."
] | 678dbf3097e82a0ddb697268406004cc1f4a26bc | https://github.com/rycus86/prometheus_flask_exporter/blob/678dbf3097e82a0ddb697268406004cc1f4a26bc/prometheus_flask_exporter/__init__.py#L353-L370 |
9,451 | rycus86/prometheus_flask_exporter | prometheus_flask_exporter/__init__.py | PrometheusMetrics.counter | def counter(self, name, description, labels=None, **kwargs):
"""
Use a Counter to track the total number of invocations of the method.
:param name: the name of the metric
:param description: the description of the metric
:param labels: a dictionary of `{labelname: callable_or_va... | python | def counter(self, name, description, labels=None, **kwargs):
"""
Use a Counter to track the total number of invocations of the method.
:param name: the name of the metric
:param description: the description of the metric
:param labels: a dictionary of `{labelname: callable_or_va... | [
"def",
"counter",
"(",
"self",
",",
"name",
",",
"description",
",",
"labels",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"self",
".",
"_track",
"(",
"Counter",
",",
"lambda",
"metric",
",",
"time",
":",
"metric",
".",
"inc",
"(",
")... | Use a Counter to track the total number of invocations of the method.
:param name: the name of the metric
:param description: the description of the metric
:param labels: a dictionary of `{labelname: callable_or_value}` for labels
:param kwargs: additional keyword arguments for creating... | [
"Use",
"a",
"Counter",
"to",
"track",
"the",
"total",
"number",
"of",
"invocations",
"of",
"the",
"method",
"."
] | 678dbf3097e82a0ddb697268406004cc1f4a26bc | https://github.com/rycus86/prometheus_flask_exporter/blob/678dbf3097e82a0ddb697268406004cc1f4a26bc/prometheus_flask_exporter/__init__.py#L372-L387 |
9,452 | rycus86/prometheus_flask_exporter | prometheus_flask_exporter/__init__.py | PrometheusMetrics._track | def _track(metric_type, metric_call, metric_kwargs, name, description, labels,
registry, before=None):
"""
Internal method decorator logic.
:param metric_type: the type of the metric from the `prometheus_client` library
:param metric_call: the invocation to execute as a c... | python | def _track(metric_type, metric_call, metric_kwargs, name, description, labels,
registry, before=None):
"""
Internal method decorator logic.
:param metric_type: the type of the metric from the `prometheus_client` library
:param metric_call: the invocation to execute as a c... | [
"def",
"_track",
"(",
"metric_type",
",",
"metric_call",
",",
"metric_kwargs",
",",
"name",
",",
"description",
",",
"labels",
",",
"registry",
",",
"before",
"=",
"None",
")",
":",
"if",
"labels",
"is",
"not",
"None",
"and",
"not",
"isinstance",
"(",
"l... | Internal method decorator logic.
:param metric_type: the type of the metric from the `prometheus_client` library
:param metric_call: the invocation to execute as a callable with `(metric, time)`
:param metric_kwargs: additional keyword arguments for creating the metric
:param name: the ... | [
"Internal",
"method",
"decorator",
"logic",
"."
] | 678dbf3097e82a0ddb697268406004cc1f4a26bc | https://github.com/rycus86/prometheus_flask_exporter/blob/678dbf3097e82a0ddb697268406004cc1f4a26bc/prometheus_flask_exporter/__init__.py#L390-L477 |
9,453 | rycus86/prometheus_flask_exporter | prometheus_flask_exporter/__init__.py | PrometheusMetrics.do_not_track | def do_not_track():
"""
Decorator to skip the default metrics collection for the method.
*Note*: explicit metrics decorators will still collect the data
"""
def decorator(f):
@functools.wraps(f)
def func(*args, **kwargs):
request.prom_do_... | python | def do_not_track():
"""
Decorator to skip the default metrics collection for the method.
*Note*: explicit metrics decorators will still collect the data
"""
def decorator(f):
@functools.wraps(f)
def func(*args, **kwargs):
request.prom_do_... | [
"def",
"do_not_track",
"(",
")",
":",
"def",
"decorator",
"(",
"f",
")",
":",
"@",
"functools",
".",
"wraps",
"(",
"f",
")",
"def",
"func",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"request",
".",
"prom_do_not_track",
"=",
"True",
"retu... | Decorator to skip the default metrics collection for the method.
*Note*: explicit metrics decorators will still collect the data | [
"Decorator",
"to",
"skip",
"the",
"default",
"metrics",
"collection",
"for",
"the",
"method",
"."
] | 678dbf3097e82a0ddb697268406004cc1f4a26bc | https://github.com/rycus86/prometheus_flask_exporter/blob/678dbf3097e82a0ddb697268406004cc1f4a26bc/prometheus_flask_exporter/__init__.py#L480-L495 |
9,454 | rycus86/prometheus_flask_exporter | prometheus_flask_exporter/__init__.py | PrometheusMetrics.info | def info(self, name, description, labelnames=None, labelvalues=None, **labels):
"""
Report any information as a Prometheus metric.
This will create a `Gauge` with the initial value of 1.
The easiest way to use it is:
metrics = PrometheusMetrics(app)
metrics.info... | python | def info(self, name, description, labelnames=None, labelvalues=None, **labels):
"""
Report any information as a Prometheus metric.
This will create a `Gauge` with the initial value of 1.
The easiest way to use it is:
metrics = PrometheusMetrics(app)
metrics.info... | [
"def",
"info",
"(",
"self",
",",
"name",
",",
"description",
",",
"labelnames",
"=",
"None",
",",
"labelvalues",
"=",
"None",
",",
"*",
"*",
"labels",
")",
":",
"if",
"labels",
"and",
"labelnames",
":",
"raise",
"ValueError",
"(",
"'Cannot have labels defi... | Report any information as a Prometheus metric.
This will create a `Gauge` with the initial value of 1.
The easiest way to use it is:
metrics = PrometheusMetrics(app)
metrics.info(
'app_info', 'Application info',
version='1.0', major=1, minor=0
... | [
"Report",
"any",
"information",
"as",
"a",
"Prometheus",
"metric",
".",
"This",
"will",
"create",
"a",
"Gauge",
"with",
"the",
"initial",
"value",
"of",
"1",
"."
] | 678dbf3097e82a0ddb697268406004cc1f4a26bc | https://github.com/rycus86/prometheus_flask_exporter/blob/678dbf3097e82a0ddb697268406004cc1f4a26bc/prometheus_flask_exporter/__init__.py#L497-L550 |
9,455 | berdario/pew | pew/pew.py | inve | def inve(env, command, *args, **kwargs):
"""Run a command in the given virtual environment.
Pass additional keyword arguments to ``subprocess.check_call()``."""
# we don't strictly need to restore the environment, since pew runs in
# its own process, but it feels like the right thing to do
with tem... | python | def inve(env, command, *args, **kwargs):
"""Run a command in the given virtual environment.
Pass additional keyword arguments to ``subprocess.check_call()``."""
# we don't strictly need to restore the environment, since pew runs in
# its own process, but it feels like the right thing to do
with tem... | [
"def",
"inve",
"(",
"env",
",",
"command",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"# we don't strictly need to restore the environment, since pew runs in",
"# its own process, but it feels like the right thing to do",
"with",
"temp_environ",
"(",
")",
":",
"... | Run a command in the given virtual environment.
Pass additional keyword arguments to ``subprocess.check_call()``. | [
"Run",
"a",
"command",
"in",
"the",
"given",
"virtual",
"environment",
"."
] | 37d9ff79342336b8ef6437d9a551008be07afe9b | https://github.com/berdario/pew/blob/37d9ff79342336b8ef6437d9a551008be07afe9b/pew/pew.py#L130-L152 |
9,456 | berdario/pew | pew/pew.py | ls_cmd | def ls_cmd(argv):
"""List available environments."""
parser = argparse.ArgumentParser()
p_group = parser.add_mutually_exclusive_group()
p_group.add_argument('-b', '--brief', action='store_false')
p_group.add_argument('-l', '--long', action='store_true')
args = parser.parse_args(argv)
lsvirtu... | python | def ls_cmd(argv):
"""List available environments."""
parser = argparse.ArgumentParser()
p_group = parser.add_mutually_exclusive_group()
p_group.add_argument('-b', '--brief', action='store_false')
p_group.add_argument('-l', '--long', action='store_true')
args = parser.parse_args(argv)
lsvirtu... | [
"def",
"ls_cmd",
"(",
"argv",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
")",
"p_group",
"=",
"parser",
".",
"add_mutually_exclusive_group",
"(",
")",
"p_group",
".",
"add_argument",
"(",
"'-b'",
",",
"'--brief'",
",",
"action",
"=",
... | List available environments. | [
"List",
"available",
"environments",
"."
] | 37d9ff79342336b8ef6437d9a551008be07afe9b | https://github.com/berdario/pew/blob/37d9ff79342336b8ef6437d9a551008be07afe9b/pew/pew.py#L345-L352 |
9,457 | berdario/pew | pew/pew.py | workon_cmd | def workon_cmd(argv):
"""List or change working virtual environments."""
parser = argparse.ArgumentParser(prog='pew workon')
parser.add_argument('envname', nargs='?')
parser.add_argument(
'-n', '--no-cd', action='store_true',
help=('Do not change working directory to project directory af... | python | def workon_cmd(argv):
"""List or change working virtual environments."""
parser = argparse.ArgumentParser(prog='pew workon')
parser.add_argument('envname', nargs='?')
parser.add_argument(
'-n', '--no-cd', action='store_true',
help=('Do not change working directory to project directory af... | [
"def",
"workon_cmd",
"(",
"argv",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"prog",
"=",
"'pew workon'",
")",
"parser",
".",
"add_argument",
"(",
"'envname'",
",",
"nargs",
"=",
"'?'",
")",
"parser",
".",
"add_argument",
"(",
"'-n'",... | List or change working virtual environments. | [
"List",
"or",
"change",
"working",
"virtual",
"environments",
"."
] | 37d9ff79342336b8ef6437d9a551008be07afe9b | https://github.com/berdario/pew/blob/37d9ff79342336b8ef6437d9a551008be07afe9b/pew/pew.py#L367-L390 |
9,458 | berdario/pew | pew/pew.py | add_cmd | def add_cmd(argv):
"""Add the specified directories to the Python path for the currently active virtualenv.
This will be done by placing the directory names in a path file named
"virtualenv_path_extensions.pth" inside the virtualenv's site-packages
directory; if this file does not exists, it will be created first.... | python | def add_cmd(argv):
"""Add the specified directories to the Python path for the currently active virtualenv.
This will be done by placing the directory names in a path file named
"virtualenv_path_extensions.pth" inside the virtualenv's site-packages
directory; if this file does not exists, it will be created first.... | [
"def",
"add_cmd",
"(",
"argv",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
")",
"parser",
".",
"add_argument",
"(",
"'-d'",
",",
"dest",
"=",
"'remove'",
",",
"action",
"=",
"'store_true'",
")",
"parser",
".",
"add_argument",
"(",
"'... | Add the specified directories to the Python path for the currently active virtualenv.
This will be done by placing the directory names in a path file named
"virtualenv_path_extensions.pth" inside the virtualenv's site-packages
directory; if this file does not exists, it will be created first. | [
"Add",
"the",
"specified",
"directories",
"to",
"the",
"Python",
"path",
"for",
"the",
"currently",
"active",
"virtualenv",
"."
] | 37d9ff79342336b8ef6437d9a551008be07afe9b | https://github.com/berdario/pew/blob/37d9ff79342336b8ef6437d9a551008be07afe9b/pew/pew.py#L402-L433 |
9,459 | berdario/pew | pew/pew.py | lssitepackages_cmd | def lssitepackages_cmd(argv):
"""Show the content of the site-packages directory of the current virtualenv."""
site = sitepackages_dir()
print(*sorted(site.iterdir()), sep=os.linesep)
extra_paths = site / '_virtualenv_path_extensions.pth'
if extra_paths.exists():
print('from _virtualenv_path... | python | def lssitepackages_cmd(argv):
"""Show the content of the site-packages directory of the current virtualenv."""
site = sitepackages_dir()
print(*sorted(site.iterdir()), sep=os.linesep)
extra_paths = site / '_virtualenv_path_extensions.pth'
if extra_paths.exists():
print('from _virtualenv_path... | [
"def",
"lssitepackages_cmd",
"(",
"argv",
")",
":",
"site",
"=",
"sitepackages_dir",
"(",
")",
"print",
"(",
"*",
"sorted",
"(",
"site",
".",
"iterdir",
"(",
")",
")",
",",
"sep",
"=",
"os",
".",
"linesep",
")",
"extra_paths",
"=",
"site",
"/",
"'_vi... | Show the content of the site-packages directory of the current virtualenv. | [
"Show",
"the",
"content",
"of",
"the",
"site",
"-",
"packages",
"directory",
"of",
"the",
"current",
"virtualenv",
"."
] | 37d9ff79342336b8ef6437d9a551008be07afe9b | https://github.com/berdario/pew/blob/37d9ff79342336b8ef6437d9a551008be07afe9b/pew/pew.py#L440-L448 |
9,460 | berdario/pew | pew/pew.py | toggleglobalsitepackages_cmd | def toggleglobalsitepackages_cmd(argv):
"""Toggle the current virtualenv between having and not having access to the global site-packages."""
quiet = argv == ['-q']
site = sitepackages_dir()
ngsp_file = site.parent / 'no-global-site-packages.txt'
if ngsp_file.exists():
ngsp_file.unlink()
... | python | def toggleglobalsitepackages_cmd(argv):
"""Toggle the current virtualenv between having and not having access to the global site-packages."""
quiet = argv == ['-q']
site = sitepackages_dir()
ngsp_file = site.parent / 'no-global-site-packages.txt'
if ngsp_file.exists():
ngsp_file.unlink()
... | [
"def",
"toggleglobalsitepackages_cmd",
"(",
"argv",
")",
":",
"quiet",
"=",
"argv",
"==",
"[",
"'-q'",
"]",
"site",
"=",
"sitepackages_dir",
"(",
")",
"ngsp_file",
"=",
"site",
".",
"parent",
"/",
"'no-global-site-packages.txt'",
"if",
"ngsp_file",
".",
"exist... | Toggle the current virtualenv between having and not having access to the global site-packages. | [
"Toggle",
"the",
"current",
"virtualenv",
"between",
"having",
"and",
"not",
"having",
"access",
"to",
"the",
"global",
"site",
"-",
"packages",
"."
] | 37d9ff79342336b8ef6437d9a551008be07afe9b | https://github.com/berdario/pew/blob/37d9ff79342336b8ef6437d9a551008be07afe9b/pew/pew.py#L451-L463 |
9,461 | berdario/pew | pew/pew.py | cp_cmd | def cp_cmd(argv):
"""Duplicate the named virtualenv to make a new one."""
parser = argparse.ArgumentParser()
parser.add_argument('source')
parser.add_argument('target', nargs='?')
parser.add_argument('-d', '--dont-activate', action='store_false',
default=True, dest='activate'... | python | def cp_cmd(argv):
"""Duplicate the named virtualenv to make a new one."""
parser = argparse.ArgumentParser()
parser.add_argument('source')
parser.add_argument('target', nargs='?')
parser.add_argument('-d', '--dont-activate', action='store_false',
default=True, dest='activate'... | [
"def",
"cp_cmd",
"(",
"argv",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
")",
"parser",
".",
"add_argument",
"(",
"'source'",
")",
"parser",
".",
"add_argument",
"(",
"'target'",
",",
"nargs",
"=",
"'?'",
")",
"parser",
".",
"add_ar... | Duplicate the named virtualenv to make a new one. | [
"Duplicate",
"the",
"named",
"virtualenv",
"to",
"make",
"a",
"new",
"one",
"."
] | 37d9ff79342336b8ef6437d9a551008be07afe9b | https://github.com/berdario/pew/blob/37d9ff79342336b8ef6437d9a551008be07afe9b/pew/pew.py#L466-L479 |
9,462 | berdario/pew | pew/pew.py | rename_cmd | def rename_cmd(argv):
"""Rename a virtualenv"""
parser = argparse.ArgumentParser()
parser.add_argument('source')
parser.add_argument('target')
pargs = parser.parse_args(argv)
copy_virtualenv_project(pargs.source, pargs.target)
return rmvirtualenvs([pargs.source]) | python | def rename_cmd(argv):
"""Rename a virtualenv"""
parser = argparse.ArgumentParser()
parser.add_argument('source')
parser.add_argument('target')
pargs = parser.parse_args(argv)
copy_virtualenv_project(pargs.source, pargs.target)
return rmvirtualenvs([pargs.source]) | [
"def",
"rename_cmd",
"(",
"argv",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
")",
"parser",
".",
"add_argument",
"(",
"'source'",
")",
"parser",
".",
"add_argument",
"(",
"'target'",
")",
"pargs",
"=",
"parser",
".",
"parse_args",
"("... | Rename a virtualenv | [
"Rename",
"a",
"virtualenv"
] | 37d9ff79342336b8ef6437d9a551008be07afe9b | https://github.com/berdario/pew/blob/37d9ff79342336b8ef6437d9a551008be07afe9b/pew/pew.py#L503-L510 |
9,463 | berdario/pew | pew/pew.py | setproject_cmd | def setproject_cmd(argv):
"""Given a virtualenv directory and a project directory, set the \
virtualenv up to be associated with the project."""
args = dict(enumerate(argv))
project = os.path.abspath(args.get(1, '.'))
env = args.get(0, os.environ.get('VIRTUAL_ENV'))
if not env:
sys.exit(... | python | def setproject_cmd(argv):
"""Given a virtualenv directory and a project directory, set the \
virtualenv up to be associated with the project."""
args = dict(enumerate(argv))
project = os.path.abspath(args.get(1, '.'))
env = args.get(0, os.environ.get('VIRTUAL_ENV'))
if not env:
sys.exit(... | [
"def",
"setproject_cmd",
"(",
"argv",
")",
":",
"args",
"=",
"dict",
"(",
"enumerate",
"(",
"argv",
")",
")",
"project",
"=",
"os",
".",
"path",
".",
"abspath",
"(",
"args",
".",
"get",
"(",
"1",
",",
"'.'",
")",
")",
"env",
"=",
"args",
".",
"... | Given a virtualenv directory and a project directory, set the \
virtualenv up to be associated with the project. | [
"Given",
"a",
"virtualenv",
"directory",
"and",
"a",
"project",
"directory",
"set",
"the",
"\\",
"virtualenv",
"up",
"to",
"be",
"associated",
"with",
"the",
"project",
"."
] | 37d9ff79342336b8ef6437d9a551008be07afe9b | https://github.com/berdario/pew/blob/37d9ff79342336b8ef6437d9a551008be07afe9b/pew/pew.py#L519-L531 |
9,464 | berdario/pew | pew/pew.py | getproject_cmd | def getproject_cmd(argv):
"""Print a virtualenv's project directory, if set.
If called without providing a virtualenv name as argument, print the
current virtualenv's project directory.
"""
# Parse command line arguments
parser = argparse.ArgumentParser(
description="Print an environmen... | python | def getproject_cmd(argv):
"""Print a virtualenv's project directory, if set.
If called without providing a virtualenv name as argument, print the
current virtualenv's project directory.
"""
# Parse command line arguments
parser = argparse.ArgumentParser(
description="Print an environmen... | [
"def",
"getproject_cmd",
"(",
"argv",
")",
":",
"# Parse command line arguments",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"description",
"=",
"\"Print an environment's project directory.\"",
",",
")",
"parser",
".",
"add_argument",
"(",
"'envname'",
",",
... | Print a virtualenv's project directory, if set.
If called without providing a virtualenv name as argument, print the
current virtualenv's project directory. | [
"Print",
"a",
"virtualenv",
"s",
"project",
"directory",
"if",
"set",
"."
] | 37d9ff79342336b8ef6437d9a551008be07afe9b | https://github.com/berdario/pew/blob/37d9ff79342336b8ef6437d9a551008be07afe9b/pew/pew.py#L534-L564 |
9,465 | berdario/pew | pew/pew.py | mkproject_cmd | def mkproject_cmd(argv):
"""Create a new project directory and its associated virtualenv."""
if '-l' in argv or '--list' in argv:
templates = [t.name[9:] for t in workon_home.glob("template_*")]
print("Available project templates:", *templates, sep='\n')
return
parser = mkvirtualenv... | python | def mkproject_cmd(argv):
"""Create a new project directory and its associated virtualenv."""
if '-l' in argv or '--list' in argv:
templates = [t.name[9:] for t in workon_home.glob("template_*")]
print("Available project templates:", *templates, sep='\n')
return
parser = mkvirtualenv... | [
"def",
"mkproject_cmd",
"(",
"argv",
")",
":",
"if",
"'-l'",
"in",
"argv",
"or",
"'--list'",
"in",
"argv",
":",
"templates",
"=",
"[",
"t",
".",
"name",
"[",
"9",
":",
"]",
"for",
"t",
"in",
"workon_home",
".",
"glob",
"(",
"\"template_*\"",
")",
"... | Create a new project directory and its associated virtualenv. | [
"Create",
"a",
"new",
"project",
"directory",
"and",
"its",
"associated",
"virtualenv",
"."
] | 37d9ff79342336b8ef6437d9a551008be07afe9b | https://github.com/berdario/pew/blob/37d9ff79342336b8ef6437d9a551008be07afe9b/pew/pew.py#L567-L603 |
9,466 | berdario/pew | pew/pew.py | mktmpenv_cmd | def mktmpenv_cmd(argv):
"""Create a temporary virtualenv."""
parser = mkvirtualenv_argparser()
env = '.'
while (workon_home / env).exists():
env = hex(random.getrandbits(64))[2:-1]
args, rest = parser.parse_known_args(argv)
mkvirtualenv(env, args.python, args.packages, requirements=arg... | python | def mktmpenv_cmd(argv):
"""Create a temporary virtualenv."""
parser = mkvirtualenv_argparser()
env = '.'
while (workon_home / env).exists():
env = hex(random.getrandbits(64))[2:-1]
args, rest = parser.parse_known_args(argv)
mkvirtualenv(env, args.python, args.packages, requirements=arg... | [
"def",
"mktmpenv_cmd",
"(",
"argv",
")",
":",
"parser",
"=",
"mkvirtualenv_argparser",
"(",
")",
"env",
"=",
"'.'",
"while",
"(",
"workon_home",
"/",
"env",
")",
".",
"exists",
"(",
")",
":",
"env",
"=",
"hex",
"(",
"random",
".",
"getrandbits",
"(",
... | Create a temporary virtualenv. | [
"Create",
"a",
"temporary",
"virtualenv",
"."
] | 37d9ff79342336b8ef6437d9a551008be07afe9b | https://github.com/berdario/pew/blob/37d9ff79342336b8ef6437d9a551008be07afe9b/pew/pew.py#L606-L623 |
9,467 | berdario/pew | pew/pew.py | inall_cmd | def inall_cmd(argv):
"""Run a command in each virtualenv."""
envs = lsenvs()
errors = False
for env in envs:
print("\n%s:" % env)
try:
inve(env, *argv)
except CalledProcessError as e:
errors = True
err(e)
sys.exit(errors) | python | def inall_cmd(argv):
"""Run a command in each virtualenv."""
envs = lsenvs()
errors = False
for env in envs:
print("\n%s:" % env)
try:
inve(env, *argv)
except CalledProcessError as e:
errors = True
err(e)
sys.exit(errors) | [
"def",
"inall_cmd",
"(",
"argv",
")",
":",
"envs",
"=",
"lsenvs",
"(",
")",
"errors",
"=",
"False",
"for",
"env",
"in",
"envs",
":",
"print",
"(",
"\"\\n%s:\"",
"%",
"env",
")",
"try",
":",
"inve",
"(",
"env",
",",
"*",
"argv",
")",
"except",
"Ca... | Run a command in each virtualenv. | [
"Run",
"a",
"command",
"in",
"each",
"virtualenv",
"."
] | 37d9ff79342336b8ef6437d9a551008be07afe9b | https://github.com/berdario/pew/blob/37d9ff79342336b8ef6437d9a551008be07afe9b/pew/pew.py#L649-L660 |
9,468 | berdario/pew | pew/pew.py | in_cmd | def in_cmd(argv):
"""Run a command in the given virtualenv."""
if len(argv) == 1:
return workon_cmd(argv)
parse_envname(argv, lambda : sys.exit('You must provide a valid virtualenv to target'))
return inve(*argv) | python | def in_cmd(argv):
"""Run a command in the given virtualenv."""
if len(argv) == 1:
return workon_cmd(argv)
parse_envname(argv, lambda : sys.exit('You must provide a valid virtualenv to target'))
return inve(*argv) | [
"def",
"in_cmd",
"(",
"argv",
")",
":",
"if",
"len",
"(",
"argv",
")",
"==",
"1",
":",
"return",
"workon_cmd",
"(",
"argv",
")",
"parse_envname",
"(",
"argv",
",",
"lambda",
":",
"sys",
".",
"exit",
"(",
"'You must provide a valid virtualenv to target'",
"... | Run a command in the given virtualenv. | [
"Run",
"a",
"command",
"in",
"the",
"given",
"virtualenv",
"."
] | 37d9ff79342336b8ef6437d9a551008be07afe9b | https://github.com/berdario/pew/blob/37d9ff79342336b8ef6437d9a551008be07afe9b/pew/pew.py#L663-L671 |
9,469 | berdario/pew | pew/pew.py | restore_cmd | def restore_cmd(argv):
"""Try to restore a broken virtualenv by reinstalling the same python version on top of it"""
if len(argv) < 1:
sys.exit('You must provide a valid virtualenv to target')
env = argv[0]
path = workon_home / env
py = path / env_bin_dir / ('python.exe' if windows else 'p... | python | def restore_cmd(argv):
"""Try to restore a broken virtualenv by reinstalling the same python version on top of it"""
if len(argv) < 1:
sys.exit('You must provide a valid virtualenv to target')
env = argv[0]
path = workon_home / env
py = path / env_bin_dir / ('python.exe' if windows else 'p... | [
"def",
"restore_cmd",
"(",
"argv",
")",
":",
"if",
"len",
"(",
"argv",
")",
"<",
"1",
":",
"sys",
".",
"exit",
"(",
"'You must provide a valid virtualenv to target'",
")",
"env",
"=",
"argv",
"[",
"0",
"]",
"path",
"=",
"workon_home",
"/",
"env",
"py",
... | Try to restore a broken virtualenv by reinstalling the same python version on top of it | [
"Try",
"to",
"restore",
"a",
"broken",
"virtualenv",
"by",
"reinstalling",
"the",
"same",
"python",
"version",
"on",
"top",
"of",
"it"
] | 37d9ff79342336b8ef6437d9a551008be07afe9b | https://github.com/berdario/pew/blob/37d9ff79342336b8ef6437d9a551008be07afe9b/pew/pew.py#L674-L685 |
9,470 | berdario/pew | pew/pew.py | dir_cmd | def dir_cmd(argv):
"""Print the path for the virtualenv directory"""
env = parse_envname(argv, lambda : sys.exit('You must provide a valid virtualenv to target'))
print(workon_home / env) | python | def dir_cmd(argv):
"""Print the path for the virtualenv directory"""
env = parse_envname(argv, lambda : sys.exit('You must provide a valid virtualenv to target'))
print(workon_home / env) | [
"def",
"dir_cmd",
"(",
"argv",
")",
":",
"env",
"=",
"parse_envname",
"(",
"argv",
",",
"lambda",
":",
"sys",
".",
"exit",
"(",
"'You must provide a valid virtualenv to target'",
")",
")",
"print",
"(",
"workon_home",
"/",
"env",
")"
] | Print the path for the virtualenv directory | [
"Print",
"the",
"path",
"for",
"the",
"virtualenv",
"directory"
] | 37d9ff79342336b8ef6437d9a551008be07afe9b | https://github.com/berdario/pew/blob/37d9ff79342336b8ef6437d9a551008be07afe9b/pew/pew.py#L688-L691 |
9,471 | berdario/pew | pew/pew.py | install_cmd | def install_cmd(argv):
'''Use Pythonz to download and build the specified Python version'''
installer = InstallCommand()
options, versions = installer.parser.parse_args(argv)
if len(versions) != 1:
installer.parser.print_help()
sys.exit(1)
else:
try:
actual_instal... | python | def install_cmd(argv):
'''Use Pythonz to download and build the specified Python version'''
installer = InstallCommand()
options, versions = installer.parser.parse_args(argv)
if len(versions) != 1:
installer.parser.print_help()
sys.exit(1)
else:
try:
actual_instal... | [
"def",
"install_cmd",
"(",
"argv",
")",
":",
"installer",
"=",
"InstallCommand",
"(",
")",
"options",
",",
"versions",
"=",
"installer",
".",
"parser",
".",
"parse_args",
"(",
"argv",
")",
"if",
"len",
"(",
"versions",
")",
"!=",
"1",
":",
"installer",
... | Use Pythonz to download and build the specified Python version | [
"Use",
"Pythonz",
"to",
"download",
"and",
"build",
"the",
"specified",
"Python",
"version"
] | 37d9ff79342336b8ef6437d9a551008be07afe9b | https://github.com/berdario/pew/blob/37d9ff79342336b8ef6437d9a551008be07afe9b/pew/pew.py#L694-L706 |
9,472 | berdario/pew | pew/pew.py | version_cmd | def version_cmd(argv):
"""Prints current pew version"""
import pkg_resources
try:
__version__ = pkg_resources.get_distribution('pew').version
except pkg_resources.DistributionNotFound:
__version__ = 'unknown'
print('Setuptools has some issues here, failed to get our own package.... | python | def version_cmd(argv):
"""Prints current pew version"""
import pkg_resources
try:
__version__ = pkg_resources.get_distribution('pew').version
except pkg_resources.DistributionNotFound:
__version__ = 'unknown'
print('Setuptools has some issues here, failed to get our own package.... | [
"def",
"version_cmd",
"(",
"argv",
")",
":",
"import",
"pkg_resources",
"try",
":",
"__version__",
"=",
"pkg_resources",
".",
"get_distribution",
"(",
"'pew'",
")",
".",
"version",
"except",
"pkg_resources",
".",
"DistributionNotFound",
":",
"__version__",
"=",
... | Prints current pew version | [
"Prints",
"current",
"pew",
"version"
] | 37d9ff79342336b8ef6437d9a551008be07afe9b | https://github.com/berdario/pew/blob/37d9ff79342336b8ef6437d9a551008be07afe9b/pew/pew.py#L724-L734 |
9,473 | peterbe/premailer | premailer/merge_style.py | csstext_to_pairs | def csstext_to_pairs(csstext):
"""
csstext_to_pairs takes css text and make it to list of
tuple of key,value.
"""
# The lock is required to avoid ``cssutils`` concurrency
# issues documented in issue #65
with csstext_to_pairs._lock:
return sorted(
[
(prop.... | python | def csstext_to_pairs(csstext):
"""
csstext_to_pairs takes css text and make it to list of
tuple of key,value.
"""
# The lock is required to avoid ``cssutils`` concurrency
# issues documented in issue #65
with csstext_to_pairs._lock:
return sorted(
[
(prop.... | [
"def",
"csstext_to_pairs",
"(",
"csstext",
")",
":",
"# The lock is required to avoid ``cssutils`` concurrency",
"# issues documented in issue #65",
"with",
"csstext_to_pairs",
".",
"_lock",
":",
"return",
"sorted",
"(",
"[",
"(",
"prop",
".",
"name",
".",
"strip",
"(",... | csstext_to_pairs takes css text and make it to list of
tuple of key,value. | [
"csstext_to_pairs",
"takes",
"css",
"text",
"and",
"make",
"it",
"to",
"list",
"of",
"tuple",
"of",
"key",
"value",
"."
] | 4d74656fb12e8e44683fa787ae71c0735282376b | https://github.com/peterbe/premailer/blob/4d74656fb12e8e44683fa787ae71c0735282376b/premailer/merge_style.py#L23-L37 |
9,474 | peterbe/premailer | premailer/merge_style.py | merge_styles | def merge_styles(inline_style, new_styles, classes, remove_unset_properties=False):
"""
This will merge all new styles where the order is important
The last one will override the first
When that is done it will apply old inline style again
The old inline style is always important and... | python | def merge_styles(inline_style, new_styles, classes, remove_unset_properties=False):
"""
This will merge all new styles where the order is important
The last one will override the first
When that is done it will apply old inline style again
The old inline style is always important and... | [
"def",
"merge_styles",
"(",
"inline_style",
",",
"new_styles",
",",
"classes",
",",
"remove_unset_properties",
"=",
"False",
")",
":",
"# building classes",
"styles",
"=",
"OrderedDict",
"(",
"[",
"(",
"\"\"",
",",
"OrderedDict",
"(",
")",
")",
"]",
")",
"fo... | This will merge all new styles where the order is important
The last one will override the first
When that is done it will apply old inline style again
The old inline style is always important and override
all new ones. The inline style must be valid.
Args:
inline_st... | [
"This",
"will",
"merge",
"all",
"new",
"styles",
"where",
"the",
"order",
"is",
"important",
"The",
"last",
"one",
"will",
"override",
"the",
"first",
"When",
"that",
"is",
"done",
"it",
"will",
"apply",
"old",
"inline",
"style",
"again",
"The",
"old",
"... | 4d74656fb12e8e44683fa787ae71c0735282376b | https://github.com/peterbe/premailer/blob/4d74656fb12e8e44683fa787ae71c0735282376b/premailer/merge_style.py#L43-L110 |
9,475 | peterbe/premailer | premailer/premailer.py | make_important | def make_important(bulk):
"""makes every property in a string !important.
"""
return ";".join(
"%s !important" % p if not p.endswith("!important") else p
for p in bulk.split(";")
) | python | def make_important(bulk):
"""makes every property in a string !important.
"""
return ";".join(
"%s !important" % p if not p.endswith("!important") else p
for p in bulk.split(";")
) | [
"def",
"make_important",
"(",
"bulk",
")",
":",
"return",
"\";\"",
".",
"join",
"(",
"\"%s !important\"",
"%",
"p",
"if",
"not",
"p",
".",
"endswith",
"(",
"\"!important\"",
")",
"else",
"p",
"for",
"p",
"in",
"bulk",
".",
"split",
"(",
"\";\"",
")",
... | makes every property in a string !important. | [
"makes",
"every",
"property",
"in",
"a",
"string",
"!important",
"."
] | 4d74656fb12e8e44683fa787ae71c0735282376b | https://github.com/peterbe/premailer/blob/4d74656fb12e8e44683fa787ae71c0735282376b/premailer/premailer.py#L53-L59 |
9,476 | peterbe/premailer | premailer/premailer.py | capitalize_float_margin | def capitalize_float_margin(css_body):
"""Capitalize float and margin CSS property names
"""
def _capitalize_property(match):
return "{0}:{1}{2}".format(
match.group("property").capitalize(),
match.group("value"),
match.group("terminator"),
)
return ... | python | def capitalize_float_margin(css_body):
"""Capitalize float and margin CSS property names
"""
def _capitalize_property(match):
return "{0}:{1}{2}".format(
match.group("property").capitalize(),
match.group("value"),
match.group("terminator"),
)
return ... | [
"def",
"capitalize_float_margin",
"(",
"css_body",
")",
":",
"def",
"_capitalize_property",
"(",
"match",
")",
":",
"return",
"\"{0}:{1}{2}\"",
".",
"format",
"(",
"match",
".",
"group",
"(",
"\"property\"",
")",
".",
"capitalize",
"(",
")",
",",
"match",
".... | Capitalize float and margin CSS property names | [
"Capitalize",
"float",
"and",
"margin",
"CSS",
"property",
"names"
] | 4d74656fb12e8e44683fa787ae71c0735282376b | https://github.com/peterbe/premailer/blob/4d74656fb12e8e44683fa787ae71c0735282376b/premailer/premailer.py#L100-L111 |
9,477 | peterbe/premailer | premailer/premailer.py | Premailer._load_external | def _load_external(self, url):
"""loads an external stylesheet from a remote url or local path
"""
if url.startswith("//"):
# then we have to rely on the base_url
if self.base_url and "https://" in self.base_url:
url = "https:" + url
else:
... | python | def _load_external(self, url):
"""loads an external stylesheet from a remote url or local path
"""
if url.startswith("//"):
# then we have to rely on the base_url
if self.base_url and "https://" in self.base_url:
url = "https:" + url
else:
... | [
"def",
"_load_external",
"(",
"self",
",",
"url",
")",
":",
"if",
"url",
".",
"startswith",
"(",
"\"//\"",
")",
":",
"# then we have to rely on the base_url",
"if",
"self",
".",
"base_url",
"and",
"\"https://\"",
"in",
"self",
".",
"base_url",
":",
"url",
"=... | loads an external stylesheet from a remote url or local path | [
"loads",
"an",
"external",
"stylesheet",
"from",
"a",
"remote",
"url",
"or",
"local",
"path"
] | 4d74656fb12e8e44683fa787ae71c0735282376b | https://github.com/peterbe/premailer/blob/4d74656fb12e8e44683fa787ae71c0735282376b/premailer/premailer.py#L546-L573 |
9,478 | peterbe/premailer | premailer/premailer.py | Premailer._css_rules_to_string | def _css_rules_to_string(self, rules):
"""given a list of css rules returns a css string
"""
lines = []
for item in rules:
if isinstance(item, tuple):
k, v = item
lines.append("%s {%s}" % (k, make_important(v)))
# media rule
... | python | def _css_rules_to_string(self, rules):
"""given a list of css rules returns a css string
"""
lines = []
for item in rules:
if isinstance(item, tuple):
k, v = item
lines.append("%s {%s}" % (k, make_important(v)))
# media rule
... | [
"def",
"_css_rules_to_string",
"(",
"self",
",",
"rules",
")",
":",
"lines",
"=",
"[",
"]",
"for",
"item",
"in",
"rules",
":",
"if",
"isinstance",
"(",
"item",
",",
"tuple",
")",
":",
"k",
",",
"v",
"=",
"item",
"lines",
".",
"append",
"(",
"\"%s {... | given a list of css rules returns a css string | [
"given",
"a",
"list",
"of",
"css",
"rules",
"returns",
"a",
"css",
"string"
] | 4d74656fb12e8e44683fa787ae71c0735282376b | https://github.com/peterbe/premailer/blob/4d74656fb12e8e44683fa787ae71c0735282376b/premailer/premailer.py#L631-L656 |
9,479 | vatlab/SoS | src/sos/workers.py | WorkerManager.check_workers | def check_workers(self):
'''Kill workers that have been pending for a while and check if all workers
are alive. '''
if time.time() - self._worker_alive_time > 5:
self._worker_alive_time = time.time()
# join processes if they are now gone, it should not do anything bad
... | python | def check_workers(self):
'''Kill workers that have been pending for a while and check if all workers
are alive. '''
if time.time() - self._worker_alive_time > 5:
self._worker_alive_time = time.time()
# join processes if they are now gone, it should not do anything bad
... | [
"def",
"check_workers",
"(",
"self",
")",
":",
"if",
"time",
".",
"time",
"(",
")",
"-",
"self",
".",
"_worker_alive_time",
">",
"5",
":",
"self",
".",
"_worker_alive_time",
"=",
"time",
".",
"time",
"(",
")",
"# join processes if they are now gone, it should ... | Kill workers that have been pending for a while and check if all workers
are alive. | [
"Kill",
"workers",
"that",
"have",
"been",
"pending",
"for",
"a",
"while",
"and",
"check",
"if",
"all",
"workers",
"are",
"alive",
"."
] | 6b60ed0770916d135e17322e469520d778e9d4e7 | https://github.com/vatlab/SoS/blob/6b60ed0770916d135e17322e469520d778e9d4e7/src/sos/workers.py#L515-L527 |
9,480 | vatlab/SoS | src/sos/workers.py | WorkerManager.kill_all | def kill_all(self):
'''Kill all workers'''
while self._num_workers > 0 and self._worker_backend_socket.poll(1000):
msg = self._worker_backend_socket.recv_pyobj()
self._worker_backend_socket.send_pyobj(None)
self._num_workers -= 1
self.report(f'Kill {msg[1:... | python | def kill_all(self):
'''Kill all workers'''
while self._num_workers > 0 and self._worker_backend_socket.poll(1000):
msg = self._worker_backend_socket.recv_pyobj()
self._worker_backend_socket.send_pyobj(None)
self._num_workers -= 1
self.report(f'Kill {msg[1:... | [
"def",
"kill_all",
"(",
"self",
")",
":",
"while",
"self",
".",
"_num_workers",
">",
"0",
"and",
"self",
".",
"_worker_backend_socket",
".",
"poll",
"(",
"1000",
")",
":",
"msg",
"=",
"self",
".",
"_worker_backend_socket",
".",
"recv_pyobj",
"(",
")",
"s... | Kill all workers | [
"Kill",
"all",
"workers"
] | 6b60ed0770916d135e17322e469520d778e9d4e7 | https://github.com/vatlab/SoS/blob/6b60ed0770916d135e17322e469520d778e9d4e7/src/sos/workers.py#L529-L537 |
9,481 | vatlab/SoS | src/sos/targets_python.py | Py_Module._install | def _install(self, name, autoinstall):
'''Check existence of Python module and install it using command
pip install if necessary.'''
import importlib
import pkg_resources
spam_spec = importlib.util.find_spec(name)
reinstall = False
if spam_spec is not None:
... | python | def _install(self, name, autoinstall):
'''Check existence of Python module and install it using command
pip install if necessary.'''
import importlib
import pkg_resources
spam_spec = importlib.util.find_spec(name)
reinstall = False
if spam_spec is not None:
... | [
"def",
"_install",
"(",
"self",
",",
"name",
",",
"autoinstall",
")",
":",
"import",
"importlib",
"import",
"pkg_resources",
"spam_spec",
"=",
"importlib",
".",
"util",
".",
"find_spec",
"(",
"name",
")",
"reinstall",
"=",
"False",
"if",
"spam_spec",
"is",
... | Check existence of Python module and install it using command
pip install if necessary. | [
"Check",
"existence",
"of",
"Python",
"module",
"and",
"install",
"it",
"using",
"command",
"pip",
"install",
"if",
"necessary",
"."
] | 6b60ed0770916d135e17322e469520d778e9d4e7 | https://github.com/vatlab/SoS/blob/6b60ed0770916d135e17322e469520d778e9d4e7/src/sos/targets_python.py#L38-L118 |
9,482 | vatlab/SoS | src/sos/task_executor.py | execute_task | def execute_task(task_id,
verbosity=None,
runmode='run',
sigmode=None,
monitor_interval=5,
resource_monitor_interval=60):
'''Execute single or master task, return a dictionary'''
tf = TaskFile(task_id)
# this will automati... | python | def execute_task(task_id,
verbosity=None,
runmode='run',
sigmode=None,
monitor_interval=5,
resource_monitor_interval=60):
'''Execute single or master task, return a dictionary'''
tf = TaskFile(task_id)
# this will automati... | [
"def",
"execute_task",
"(",
"task_id",
",",
"verbosity",
"=",
"None",
",",
"runmode",
"=",
"'run'",
",",
"sigmode",
"=",
"None",
",",
"monitor_interval",
"=",
"5",
",",
"resource_monitor_interval",
"=",
"60",
")",
":",
"tf",
"=",
"TaskFile",
"(",
"task_id"... | Execute single or master task, return a dictionary | [
"Execute",
"single",
"or",
"master",
"task",
"return",
"a",
"dictionary"
] | 6b60ed0770916d135e17322e469520d778e9d4e7 | https://github.com/vatlab/SoS/blob/6b60ed0770916d135e17322e469520d778e9d4e7/src/sos/task_executor.py#L129-L178 |
9,483 | vatlab/SoS | src/sos/targets.py | textMD5 | def textMD5(text):
'''Get md5 of a piece of text'''
m = hash_md5()
if isinstance(text, str):
m.update(text.encode())
else:
m.update(text)
return m.hexdigest() | python | def textMD5(text):
'''Get md5 of a piece of text'''
m = hash_md5()
if isinstance(text, str):
m.update(text.encode())
else:
m.update(text)
return m.hexdigest() | [
"def",
"textMD5",
"(",
"text",
")",
":",
"m",
"=",
"hash_md5",
"(",
")",
"if",
"isinstance",
"(",
"text",
",",
"str",
")",
":",
"m",
".",
"update",
"(",
"text",
".",
"encode",
"(",
")",
")",
"else",
":",
"m",
".",
"update",
"(",
"text",
")",
... | Get md5 of a piece of text | [
"Get",
"md5",
"of",
"a",
"piece",
"of",
"text"
] | 6b60ed0770916d135e17322e469520d778e9d4e7 | https://github.com/vatlab/SoS/blob/6b60ed0770916d135e17322e469520d778e9d4e7/src/sos/targets.py#L89-L96 |
9,484 | vatlab/SoS | src/sos/targets.py | objectMD5 | def objectMD5(obj):
'''Get md5 of an object'''
if hasattr(obj, 'target_name'):
return obj.target_name()
try:
return textMD5(pickle.dumps(obj))
except:
return '' | python | def objectMD5(obj):
'''Get md5 of an object'''
if hasattr(obj, 'target_name'):
return obj.target_name()
try:
return textMD5(pickle.dumps(obj))
except:
return '' | [
"def",
"objectMD5",
"(",
"obj",
")",
":",
"if",
"hasattr",
"(",
"obj",
",",
"'target_name'",
")",
":",
"return",
"obj",
".",
"target_name",
"(",
")",
"try",
":",
"return",
"textMD5",
"(",
"pickle",
".",
"dumps",
"(",
"obj",
")",
")",
"except",
":",
... | Get md5 of an object | [
"Get",
"md5",
"of",
"an",
"object"
] | 6b60ed0770916d135e17322e469520d778e9d4e7 | https://github.com/vatlab/SoS/blob/6b60ed0770916d135e17322e469520d778e9d4e7/src/sos/targets.py#L99-L106 |
9,485 | vatlab/SoS | src/sos/targets.py | fileMD5 | def fileMD5(filename, partial=True):
'''Calculate partial MD5, basically the first and last 8M
of the file for large files. This should signicicantly reduce
the time spent on the creation and comparison of file signature
when dealing with large bioinformat ics datasets. '''
filesize = os.path.getsiz... | python | def fileMD5(filename, partial=True):
'''Calculate partial MD5, basically the first and last 8M
of the file for large files. This should signicicantly reduce
the time spent on the creation and comparison of file signature
when dealing with large bioinformat ics datasets. '''
filesize = os.path.getsiz... | [
"def",
"fileMD5",
"(",
"filename",
",",
"partial",
"=",
"True",
")",
":",
"filesize",
"=",
"os",
".",
"path",
".",
"getsize",
"(",
"filename",
")",
"# calculate md5 for specified file",
"md5",
"=",
"hash_md5",
"(",
")",
"block_size",
"=",
"2",
"**",
"20",
... | Calculate partial MD5, basically the first and last 8M
of the file for large files. This should signicicantly reduce
the time spent on the creation and comparison of file signature
when dealing with large bioinformat ics datasets. | [
"Calculate",
"partial",
"MD5",
"basically",
"the",
"first",
"and",
"last",
"8M",
"of",
"the",
"file",
"for",
"large",
"files",
".",
"This",
"should",
"signicicantly",
"reduce",
"the",
"time",
"spent",
"on",
"the",
"creation",
"and",
"comparison",
"of",
"file... | 6b60ed0770916d135e17322e469520d778e9d4e7 | https://github.com/vatlab/SoS/blob/6b60ed0770916d135e17322e469520d778e9d4e7/src/sos/targets.py#L109-L142 |
9,486 | vatlab/SoS | src/sos/targets.py | file_target.target_signature | def target_signature(self):
'''Return file signature'''
if self.exists():
if not self._md5:
self._md5 = fileMD5(self)
return (os.path.getmtime(self), os.path.getsize(self), self._md5)
elif (self + '.zapped').is_file():
with open(self + '.zapped... | python | def target_signature(self):
'''Return file signature'''
if self.exists():
if not self._md5:
self._md5 = fileMD5(self)
return (os.path.getmtime(self), os.path.getsize(self), self._md5)
elif (self + '.zapped').is_file():
with open(self + '.zapped... | [
"def",
"target_signature",
"(",
"self",
")",
":",
"if",
"self",
".",
"exists",
"(",
")",
":",
"if",
"not",
"self",
".",
"_md5",
":",
"self",
".",
"_md5",
"=",
"fileMD5",
"(",
"self",
")",
"return",
"(",
"os",
".",
"path",
".",
"getmtime",
"(",
"s... | Return file signature | [
"Return",
"file",
"signature"
] | 6b60ed0770916d135e17322e469520d778e9d4e7 | https://github.com/vatlab/SoS/blob/6b60ed0770916d135e17322e469520d778e9d4e7/src/sos/targets.py#L747-L760 |
9,487 | vatlab/SoS | src/sos/targets.py | file_target.validate | def validate(self, sig=None):
'''Check if file matches its signature'''
if sig is not None:
sig_mtime, sig_size, sig_md5 = sig
else:
try:
with open(self.sig_file()) as sig:
sig_mtime, sig_size, sig_md5 = sig.read().strip().split()
... | python | def validate(self, sig=None):
'''Check if file matches its signature'''
if sig is not None:
sig_mtime, sig_size, sig_md5 = sig
else:
try:
with open(self.sig_file()) as sig:
sig_mtime, sig_size, sig_md5 = sig.read().strip().split()
... | [
"def",
"validate",
"(",
"self",
",",
"sig",
"=",
"None",
")",
":",
"if",
"sig",
"is",
"not",
"None",
":",
"sig_mtime",
",",
"sig_size",
",",
"sig_md5",
"=",
"sig",
"else",
":",
"try",
":",
"with",
"open",
"(",
"self",
".",
"sig_file",
"(",
")",
"... | Check if file matches its signature | [
"Check",
"if",
"file",
"matches",
"its",
"signature"
] | 6b60ed0770916d135e17322e469520d778e9d4e7 | https://github.com/vatlab/SoS/blob/6b60ed0770916d135e17322e469520d778e9d4e7/src/sos/targets.py#L766-L786 |
9,488 | vatlab/SoS | src/sos/targets.py | file_target.write_sig | def write_sig(self):
'''Write signature to sig store'''
if not self._md5:
self._md5 = fileMD5(self)
with open(self.sig_file(), 'w') as sig:
sig.write(
f'{os.path.getmtime(self)}\t{os.path.getsize(self)}\t{self._md5}'
) | python | def write_sig(self):
'''Write signature to sig store'''
if not self._md5:
self._md5 = fileMD5(self)
with open(self.sig_file(), 'w') as sig:
sig.write(
f'{os.path.getmtime(self)}\t{os.path.getsize(self)}\t{self._md5}'
) | [
"def",
"write_sig",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"_md5",
":",
"self",
".",
"_md5",
"=",
"fileMD5",
"(",
"self",
")",
"with",
"open",
"(",
"self",
".",
"sig_file",
"(",
")",
",",
"'w'",
")",
"as",
"sig",
":",
"sig",
".",
"wri... | Write signature to sig store | [
"Write",
"signature",
"to",
"sig",
"store"
] | 6b60ed0770916d135e17322e469520d778e9d4e7 | https://github.com/vatlab/SoS/blob/6b60ed0770916d135e17322e469520d778e9d4e7/src/sos/targets.py#L788-L795 |
9,489 | vatlab/SoS | src/sos/targets.py | sos_targets.remove_targets | def remove_targets(self, type, kept=None):
'''Remove targets of certain type'''
if kept is None:
kept = [
i for i, x in enumerate(self._targets)
if not isinstance(x, type)
]
if len(kept) == len(self._targets):
return self
... | python | def remove_targets(self, type, kept=None):
'''Remove targets of certain type'''
if kept is None:
kept = [
i for i, x in enumerate(self._targets)
if not isinstance(x, type)
]
if len(kept) == len(self._targets):
return self
... | [
"def",
"remove_targets",
"(",
"self",
",",
"type",
",",
"kept",
"=",
"None",
")",
":",
"if",
"kept",
"is",
"None",
":",
"kept",
"=",
"[",
"i",
"for",
"i",
",",
"x",
"in",
"enumerate",
"(",
"self",
".",
"_targets",
")",
"if",
"not",
"isinstance",
... | Remove targets of certain type | [
"Remove",
"targets",
"of",
"certain",
"type"
] | 6b60ed0770916d135e17322e469520d778e9d4e7 | https://github.com/vatlab/SoS/blob/6b60ed0770916d135e17322e469520d778e9d4e7/src/sos/targets.py#L1406-L1429 |
9,490 | vatlab/SoS | src/sos/targets.py | sos_targets.resolve_remote | def resolve_remote(self):
'''If target is of remote type, resolve it'''
for idx, target in enumerate(self._targets):
if isinstance(target, remote):
resolved = target.resolve()
if isinstance(resolved, str):
resolved = interpolate(resolved, e... | python | def resolve_remote(self):
'''If target is of remote type, resolve it'''
for idx, target in enumerate(self._targets):
if isinstance(target, remote):
resolved = target.resolve()
if isinstance(resolved, str):
resolved = interpolate(resolved, e... | [
"def",
"resolve_remote",
"(",
"self",
")",
":",
"for",
"idx",
",",
"target",
"in",
"enumerate",
"(",
"self",
".",
"_targets",
")",
":",
"if",
"isinstance",
"(",
"target",
",",
"remote",
")",
":",
"resolved",
"=",
"target",
".",
"resolve",
"(",
")",
"... | If target is of remote type, resolve it | [
"If",
"target",
"is",
"of",
"remote",
"type",
"resolve",
"it"
] | 6b60ed0770916d135e17322e469520d778e9d4e7 | https://github.com/vatlab/SoS/blob/6b60ed0770916d135e17322e469520d778e9d4e7/src/sos/targets.py#L1431-L1439 |
9,491 | vatlab/SoS | src/sos/targets.py | sos_targets._handle_paired_with | def _handle_paired_with(self, paired_with):
'''Handle input option paired_with'''
if paired_with is None or not paired_with:
var_name = []
var_value = []
elif isinstance(paired_with, str):
var_name = ['_' + paired_with]
if paired_with not in env.so... | python | def _handle_paired_with(self, paired_with):
'''Handle input option paired_with'''
if paired_with is None or not paired_with:
var_name = []
var_value = []
elif isinstance(paired_with, str):
var_name = ['_' + paired_with]
if paired_with not in env.so... | [
"def",
"_handle_paired_with",
"(",
"self",
",",
"paired_with",
")",
":",
"if",
"paired_with",
"is",
"None",
"or",
"not",
"paired_with",
":",
"var_name",
"=",
"[",
"]",
"var_value",
"=",
"[",
"]",
"elif",
"isinstance",
"(",
"paired_with",
",",
"str",
")",
... | Handle input option paired_with | [
"Handle",
"input",
"option",
"paired_with"
] | 6b60ed0770916d135e17322e469520d778e9d4e7 | https://github.com/vatlab/SoS/blob/6b60ed0770916d135e17322e469520d778e9d4e7/src/sos/targets.py#L1685-L1718 |
9,492 | vatlab/SoS | src/sos/targets.py | sos_targets._handle_group_with | def _handle_group_with(self, group_with):
'''Handle input option group_with'''
if group_with is None or not group_with:
var_name = []
var_value = []
elif isinstance(group_with, str):
var_name = ['_' + group_with]
if group_with not in env.sos_dict:
... | python | def _handle_group_with(self, group_with):
'''Handle input option group_with'''
if group_with is None or not group_with:
var_name = []
var_value = []
elif isinstance(group_with, str):
var_name = ['_' + group_with]
if group_with not in env.sos_dict:
... | [
"def",
"_handle_group_with",
"(",
"self",
",",
"group_with",
")",
":",
"if",
"group_with",
"is",
"None",
"or",
"not",
"group_with",
":",
"var_name",
"=",
"[",
"]",
"var_value",
"=",
"[",
"]",
"elif",
"isinstance",
"(",
"group_with",
",",
"str",
")",
":",... | Handle input option group_with | [
"Handle",
"input",
"option",
"group_with"
] | 6b60ed0770916d135e17322e469520d778e9d4e7 | https://github.com/vatlab/SoS/blob/6b60ed0770916d135e17322e469520d778e9d4e7/src/sos/targets.py#L1720-L1752 |
9,493 | vatlab/SoS | src/sos/targets.py | sos_targets._handle_extract_pattern | def _handle_extract_pattern(self, pattern):
'''Handle input option pattern'''
if pattern is None or not pattern:
patterns = []
elif isinstance(pattern, str):
patterns = [pattern]
elif isinstance(pattern, Iterable):
patterns = pattern
else:
... | python | def _handle_extract_pattern(self, pattern):
'''Handle input option pattern'''
if pattern is None or not pattern:
patterns = []
elif isinstance(pattern, str):
patterns = [pattern]
elif isinstance(pattern, Iterable):
patterns = pattern
else:
... | [
"def",
"_handle_extract_pattern",
"(",
"self",
",",
"pattern",
")",
":",
"if",
"pattern",
"is",
"None",
"or",
"not",
"pattern",
":",
"patterns",
"=",
"[",
"]",
"elif",
"isinstance",
"(",
"pattern",
",",
"str",
")",
":",
"patterns",
"=",
"[",
"pattern",
... | Handle input option pattern | [
"Handle",
"input",
"option",
"pattern"
] | 6b60ed0770916d135e17322e469520d778e9d4e7 | https://github.com/vatlab/SoS/blob/6b60ed0770916d135e17322e469520d778e9d4e7/src/sos/targets.py#L1754-L1770 |
9,494 | vatlab/SoS | src/sos/targets.py | RuntimeInfo.write | def write(self):
'''Write signature file with signature of script, input, output and dependent files.
Because local input and output files can only be determined after the execution
of workflow. They are not part of the construction.
'''
if not self.output_files.valid():
... | python | def write(self):
'''Write signature file with signature of script, input, output and dependent files.
Because local input and output files can only be determined after the execution
of workflow. They are not part of the construction.
'''
if not self.output_files.valid():
... | [
"def",
"write",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"output_files",
".",
"valid",
"(",
")",
":",
"raise",
"ValueError",
"(",
"f'Cannot write signature with undetermined output {self.output_files}'",
")",
"else",
":",
"if",
"'TARGET'",
"in",
"env",
"... | Write signature file with signature of script, input, output and dependent files.
Because local input and output files can only be determined after the execution
of workflow. They are not part of the construction. | [
"Write",
"signature",
"file",
"with",
"signature",
"of",
"script",
"input",
"output",
"and",
"dependent",
"files",
".",
"Because",
"local",
"input",
"and",
"output",
"files",
"can",
"only",
"be",
"determined",
"after",
"the",
"execution",
"of",
"workflow",
"."... | 6b60ed0770916d135e17322e469520d778e9d4e7 | https://github.com/vatlab/SoS/blob/6b60ed0770916d135e17322e469520d778e9d4e7/src/sos/targets.py#L2219-L2259 |
9,495 | vatlab/SoS | src/sos/executor_utils.py | clear_output | def clear_output(output=None):
'''
Remove file targets in `_output` when a step fails to complete
'''
for target in env.sos_dict['_output'] if output is None else output:
if isinstance(target, file_target) and target.exists():
try:
target.unlink()
except E... | python | def clear_output(output=None):
'''
Remove file targets in `_output` when a step fails to complete
'''
for target in env.sos_dict['_output'] if output is None else output:
if isinstance(target, file_target) and target.exists():
try:
target.unlink()
except E... | [
"def",
"clear_output",
"(",
"output",
"=",
"None",
")",
":",
"for",
"target",
"in",
"env",
".",
"sos_dict",
"[",
"'_output'",
"]",
"if",
"output",
"is",
"None",
"else",
"output",
":",
"if",
"isinstance",
"(",
"target",
",",
"file_target",
")",
"and",
"... | Remove file targets in `_output` when a step fails to complete | [
"Remove",
"file",
"targets",
"in",
"_output",
"when",
"a",
"step",
"fails",
"to",
"complete"
] | 6b60ed0770916d135e17322e469520d778e9d4e7 | https://github.com/vatlab/SoS/blob/6b60ed0770916d135e17322e469520d778e9d4e7/src/sos/executor_utils.py#L121-L130 |
9,496 | vatlab/SoS | src/sos/workflow_executor.py | Base_Executor.add_forward_workflow | def add_forward_workflow(self, dag, sections, satisfies=None):
'''Add a forward-workflow, return number of nodes added
'''
dag.new_forward_workflow()
if 'DAG' in env.config['SOS_DEBUG'] or 'ALL' in env.config['SOS_DEBUG']:
env.log_to_file(
'DAG', f'Adding min... | python | def add_forward_workflow(self, dag, sections, satisfies=None):
'''Add a forward-workflow, return number of nodes added
'''
dag.new_forward_workflow()
if 'DAG' in env.config['SOS_DEBUG'] or 'ALL' in env.config['SOS_DEBUG']:
env.log_to_file(
'DAG', f'Adding min... | [
"def",
"add_forward_workflow",
"(",
"self",
",",
"dag",
",",
"sections",
",",
"satisfies",
"=",
"None",
")",
":",
"dag",
".",
"new_forward_workflow",
"(",
")",
"if",
"'DAG'",
"in",
"env",
".",
"config",
"[",
"'SOS_DEBUG'",
"]",
"or",
"'ALL'",
"in",
"env"... | Add a forward-workflow, return number of nodes added | [
"Add",
"a",
"forward",
"-",
"workflow",
"return",
"number",
"of",
"nodes",
"added"
] | 6b60ed0770916d135e17322e469520d778e9d4e7 | https://github.com/vatlab/SoS/blob/6b60ed0770916d135e17322e469520d778e9d4e7/src/sos/workflow_executor.py#L702-L758 |
9,497 | vatlab/SoS | src/sos/workflow_executor.py | Base_Executor.initialize_dag | def initialize_dag(self,
targets: Optional[List[str]] = [],
nested: bool = False) -> SoS_DAG:
'''Create a DAG by analyzing sections statically.'''
self.reset_dict()
dag = SoS_DAG(name=self.md5)
targets = sos_targets(targets)
self.ad... | python | def initialize_dag(self,
targets: Optional[List[str]] = [],
nested: bool = False) -> SoS_DAG:
'''Create a DAG by analyzing sections statically.'''
self.reset_dict()
dag = SoS_DAG(name=self.md5)
targets = sos_targets(targets)
self.ad... | [
"def",
"initialize_dag",
"(",
"self",
",",
"targets",
":",
"Optional",
"[",
"List",
"[",
"str",
"]",
"]",
"=",
"[",
"]",
",",
"nested",
":",
"bool",
"=",
"False",
")",
"->",
"SoS_DAG",
":",
"self",
".",
"reset_dict",
"(",
")",
"dag",
"=",
"SoS_DAG"... | Create a DAG by analyzing sections statically. | [
"Create",
"a",
"DAG",
"by",
"analyzing",
"sections",
"statically",
"."
] | 6b60ed0770916d135e17322e469520d778e9d4e7 | https://github.com/vatlab/SoS/blob/6b60ed0770916d135e17322e469520d778e9d4e7/src/sos/workflow_executor.py#L831-L859 |
9,498 | vatlab/SoS | src/sos/utils.py | short_repr | def short_repr(obj, noneAsNA=False):
'''Return a short representation of obj for clarity.'''
if obj is None:
return 'unspecified' if noneAsNA else 'None'
elif isinstance(obj, str) and len(obj) > 80:
return '{}...{}'.format(obj[:60].replace('\n', '\\n'),
obj[-2... | python | def short_repr(obj, noneAsNA=False):
'''Return a short representation of obj for clarity.'''
if obj is None:
return 'unspecified' if noneAsNA else 'None'
elif isinstance(obj, str) and len(obj) > 80:
return '{}...{}'.format(obj[:60].replace('\n', '\\n'),
obj[-2... | [
"def",
"short_repr",
"(",
"obj",
",",
"noneAsNA",
"=",
"False",
")",
":",
"if",
"obj",
"is",
"None",
":",
"return",
"'unspecified'",
"if",
"noneAsNA",
"else",
"'None'",
"elif",
"isinstance",
"(",
"obj",
",",
"str",
")",
"and",
"len",
"(",
"obj",
")",
... | Return a short representation of obj for clarity. | [
"Return",
"a",
"short",
"representation",
"of",
"obj",
"for",
"clarity",
"."
] | 6b60ed0770916d135e17322e469520d778e9d4e7 | https://github.com/vatlab/SoS/blob/6b60ed0770916d135e17322e469520d778e9d4e7/src/sos/utils.py#L138-L181 |
9,499 | vatlab/SoS | src/sos/utils.py | tail_of_file | def tail_of_file(filename, n, ansi2html=False):
"""Reads a n lines from f with an offset of offset lines. """
avg_line_length = 74
to_read = n
with open(filename) as f:
while 1:
try:
f.seek(-(avg_line_length * to_read), 2)
except IOError:
... | python | def tail_of_file(filename, n, ansi2html=False):
"""Reads a n lines from f with an offset of offset lines. """
avg_line_length = 74
to_read = n
with open(filename) as f:
while 1:
try:
f.seek(-(avg_line_length * to_read), 2)
except IOError:
... | [
"def",
"tail_of_file",
"(",
"filename",
",",
"n",
",",
"ansi2html",
"=",
"False",
")",
":",
"avg_line_length",
"=",
"74",
"to_read",
"=",
"n",
"with",
"open",
"(",
"filename",
")",
"as",
"f",
":",
"while",
"1",
":",
"try",
":",
"f",
".",
"seek",
"(... | Reads a n lines from f with an offset of offset lines. | [
"Reads",
"a",
"n",
"lines",
"from",
"f",
"with",
"an",
"offset",
"of",
"offset",
"lines",
"."
] | 6b60ed0770916d135e17322e469520d778e9d4e7 | https://github.com/vatlab/SoS/blob/6b60ed0770916d135e17322e469520d778e9d4e7/src/sos/utils.py#L1476-L1495 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.