Beispiel #1
0
def require(mod):
    """
    Load a module, cleaning it first from sys.modules.
    """
    def loader():
        reload(mod)
        return sk.import_later(mod)

    return sk.deferred(loader)
Beispiel #2
0
from sidekick import deferred

from ej_users.models import User
from ej_conversations.models import Conversation, Comment

_first = lambda cls: deferred(lambda: cls.objects.first())

# User app
admin = deferred(lambda: User.objects.filter(is_superuser=True).first())
user = deferred(lambda: User.objects.filter(is_superuser=False).first())

# Conversation app
conversation = _first(Conversation)
comment = _first(Comment)
Beispiel #3
0
    """
    base = _base() / 'cache'
    return base if sub is None else base / sub


def _base():
    base = Path(__file__).parent
    if os.path.islink(base):
        base = os.readlink(base)
    return Path(base).parent


#
# Information about PNAD years
#
PNAD_YEARS = deferred(lambda: np.array(
    sorted(int(yy) for yy in os.listdir(str(data_path())) if yy.isdigit())))
HAS_FULL_RACE_INFO_YEARS = deferred(lambda: [1982, *years(1987, ...)])


def years(*args):
    """
    Return all years in the given range in which PNAD occurred. Can use None
    or Ellipsis (...) in either a or b in order to select an open range.

    Example:
        >>> years()                                         # doctest: +ELLIPSIS
        [1976, 1977, 1978, ...]  # Full list of years
        >>> years(..., 1980) # using ellipsis to select an open range.
        [1976, 1977, 1978, 1979]

        >>> years((1990, 1999))
Beispiel #4
0
def gettext_lazy(st):
    return sk.deferred(gettext, st)
Beispiel #5
0
from boogie.models import F, Q, Sum, Max, Min  # noqa: E402
from django.conf import settings  # noqa: E402
from django.contrib.auth.models import AnonymousUser  # noqa: E402
from ej_clusters.enums import ClusterStatus  # noqa: E402
from ej_profiles.enums import Race, Gender  # noqa: E402
from ej_conversations.enums import Choice, RejectionReason  # noqa: E402

_export = {F, Q, Max, Min, Sum, sk}
_enums = {ClusterStatus, Choice, RejectionReason, Race, Gender}

#
# Create models, manager accessors and examples
#
settings.ALLOWED_HOSTS.append("testserver")

_first = lambda obj: deferred(lambda: obj.first())


def extract(obj):
    return obj._obj__


# Conversation app
from ej_conversations.models import (
    Conversation,
    Comment,
    Vote,
    FavoriteConversation,
    ConversationTag,
)  # noqa: E402
Beispiel #6
0
import sidekick as sk

models = sk.import_later('.models', package=__package__)
powers = sk.deferred(lambda: models.ConversationPowers.objects)


def promote_comment(comment, user=None):
    """
    Promotes a comment.

    If user is given, register that the given user contributed with the
    comment promotion.
    """
    conversation = comment.conversation
    if user:
        powers.incr_by(user, conversation, promote_actions=1)
    if comment.author != user:
        powers.incr_by(comment.author, conversation, promoted_comments=1)
    if not comment.is_promoted:
        comment.is_promoted = True
        comment.save(update_fields=['is_promoted'])
    models.CommentPromotion.objects.get_or_create(user=user, comment=comment)
Beispiel #7
0
from typing import Dict, List, Iterable

import pandas as pd
import sidekick as sk

from ..functions import regions
from ..types import PandasT

sqlite3 = sk.import_later("sqlite3")
IS_CODE_PATH = re.compile(r"[A-Z]{2}(-\w+)?")
PICKLE_EXTENSIONS = (".pkl", ".pickle", ".pkl.gz", ".pickle.gz")
SQL_EXTENSIONS = (".sql", ".sqlite")
CSV_EXTENSIONS = (".csv", ".csv.gz", ".csv.bz2")
HDF5_EXTENSIONS = (".hdf", ".hfd5")

db = sk.deferred(regions)


def find_data_path(package) -> Path:
    """
    Find the data folder for package.

    This assumes the package is installed as as symlink from the main
    repository folder.
    """
    try:
        mod = sys.modules[package]
    except KeyError:
        mod = importlib.import_module(package)
    return Path(mod.__file__).resolve().absolute().parent.parent / "data"
Beispiel #8
0
def lazy_stored_string(path):
    """
    A lazy string-like object that loads information from a file.
    """
    return sk.deferred(lazy_description, path)