"""The Core (:mod:`harp`) package is the root namespace of the Harp framework.It mostly contains a reference to the :class:`Config` class, because it's the only object you need to start using Harpusing the python API (you don't *need* to use this API, configuration files should be enough for most use cases, butif you want to, this is the starting point).For convenience, the :func:`run` function is also available, which is a simple way to start the default serverimplementation for your configuration object.Example usage:.. code-block:: python from harp import Config, run config = Config() config.add_defaults() if __name__ == "__main__": run(config)You can find more information about how configuration works in the :mod:`harp.config` module.Contents--------"""importosfromsubprocessimportcheck_outputfrompackaging.versionimportInvalidVersion,VersionROOT_DIR=os.path.dirname(os.path.dirname(os.path.abspath(__file__)))def_parse_version(version:str,/,*,default=None)->Version:try:returnVersion(version)exceptInvalidVersion:if"-"inversion:return_parse_version(version.rsplit("-",1)[0],default=default)returndefault# last release__title__="Core"__version__="0.5.1"__revision__=__version__# we can't commit the not yet known revision# override with version.txt if available (after docker build for example)ifos.path.exists(os.path.join(ROOT_DIR,"version.txt")):withopen(os.path.join(ROOT_DIR,"version.txt"))asf:__version__=f.read().strip()__parsed_version__=_parse_version(__version__)# override with current development version/revision if available (disabled in CI, for docs)ifnotos.environ.get("CI",False)andos.path.exists(os.path.join(ROOT_DIR,".git")):__revision__=check_output(["git","rev-parse","HEAD"],cwd=ROOT_DIR).decode("utf-8").strip()try:__version__=(check_output(["git","describe","--tags","--always","--dirty"],cwd=ROOT_DIR).decode("utf-8").strip())__parsed_version__=_parse_version(__version__,default=__parsed_version__)exceptException:__version__=__revision__[:7]from._loggingimportget_logger# noqa: E402, isort: skipfromharp.configimportConfig# noqa: E402, isort: skip
[docs]defrun(config:Config):""" Run the default server using provided configuration. :param config: Config :return: """importasynciofromharp.config.adapters.hypercornimportHypercornAdapterfromharp.config.factories.kernel_factoryimportKernelFactoryfactory=KernelFactory(config)server=HypercornAdapter(factory)returnasyncio.run(server.serve())