"""  # noqa

# =============================================================================
# Directory constants
# =============================================================================

THIS_DIR = os.path.dirname(os.path.abspath(__file__))  # tools
SETUP_PY_DIR = os.path.abspath(join(THIS_DIR, os.pardir))
PROJECT_BASE_DIR = os.path.abspath(join(THIS_DIR, os.pardir, os.pardir))

DSTBASEDIR = LINUX_DEFAULT_CAMCOPS_DIR

TMPDIR = tempfile.mkdtemp()
log.info("Temporary working directory: " + TMPDIR)
WRKDIR = join(TMPDIR, "debian")
RPMTOPDIR = join(TMPDIR, "rpmbuild")

SRCSERVERDIR = join(PROJECT_BASE_DIR, "server")
DOCROOTDIR = join(PROJECT_BASE_DIR, "documentation")
PACKAGEDIR = join(SRCSERVERDIR, "packagebuild")

DSTDOCDIR = join("/usr/share/doc", PACKAGE_DEB_NAME)
WRKDOCDIR = workpath(WRKDIR, DSTDOCDIR)

WRKBASEDIR = workpath(WRKDIR, DSTBASEDIR)

DEBDIR = join(WRKDIR, "DEBIAN")
# ... where Debian package control information lives
DEBOVERRIDEDIR = workpath(WRKDIR, "/usr/share/lintian/overrides")
Exemple #2
0
    permitted_values_ok,
)
from camcops_server.cc_modules.cc_sqlalchemy import Base

log = BraceStyleAdapter(logging.getLogger(__name__))

# =============================================================================
# 1. Explore the metaclass system in detail
# =============================================================================

MODIFY_CLASS = True

if __name__ == "__main__":
    # Before classes are even declared:
    main_only_quicksetup_rootlogger()
    log.info("Module starting to load.")


def add_multiple_fields(
    cls: Type,
    first: int,
    last: int,
    prefix: str,
    coltype: Type,
    colkwargs: Dict[str, Any] = None,
) -> None:
    colkwargs = {} if colkwargs is None else colkwargs  # type: Dict[str, Any]
    for n in range(first, last + 1):
        nstr = str(n)
        colname = prefix + nstr
        setattr(cls, colname, Column(colname, coltype, **colkwargs))
Exemple #3
0
        query_times_df = DataFrame.from_records(query_times_arr)
        log.debug("query_times_df:\n{!r}", query_times_df)

        timelines = drug_timelines(
            drug_events_df=drug_events_df,
            event_lasts_for=event_lasts_for,
            patient_colname=DEFAULT_PATIENT_COLNAME,
            event_datetime_colname=DEFAULT_DRUG_EVENT_DATETIME_COLNAME)
        log.debug("timelines: {!r}", timelines)

        cumulative = cumulative_time_on_drug(
            drug_events_df=drug_events_df,
            event_lasts_for_timedelta=event_lasts_for,
            query_times_df=query_times_df,
            patient_colname=DEFAULT_PATIENT_COLNAME,
            event_datetime_colname=DEFAULT_DRUG_EVENT_DATETIME_COLNAME,
            start_colname=DEFAULT_START_DATETIME_COLNAME,
            when_colname=DEFAULT_QUERY_DATETIME_COLNAME)
        log.debug("cumulative:\n{}", cumulative)


# =============================================================================
# main
# =============================================================================

if __name__ == "__main__":
    main_only_quicksetup_rootlogger(level=logging.DEBUG)
    log.info("Running unit tests")
    unittest.main(argv=[sys.argv[0]])
    sys.exit(0)
- ensure that all models are loaded;
- provide log message around some of the slow imports.

"""

# SET UP LOGGING BEFORE WE IMPORT CAMCOPS MODULES, allowing them to log during
# imports (see e.g. cc_plot).
# Currently sets up colour logging even if under WSGI environment. This is fine
# for gunicorn from the command line; I'm less clear about whether the disk
# logs look polluted by ANSI codes; needs checking.
import logging
from cardinal_pythonlib.logs import BraceStyleAdapter

log = BraceStyleAdapter(logging.getLogger(__name__))
log.info("Imports starting")

# Main imports

import os  # nopep8
import platform  # nopep8
import subprocess  # nopep8
import tempfile  # nopep8
from typing import Any, Dict, List, Optional, TYPE_CHECKING  # nopep8
import unittest  # nopep8

import cherrypy  # nopep8
try:
    from gunicorn.app.base import BaseApplication
except ImportError:
    BaseApplication = None  # e.g. on Windows: "ImportError: no module named 'fcntl'".  # noqa