"""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_outputfromtypingimportTYPE_CHECKINGfrompackaging.versionimportInvalidVersion,VersionifTYPE_CHECKING:fromharp.configimportConfigurationBuilderas_ConfigurationBuilderROOT_DIR:str=os.path.dirname(os.path.dirname(os.path.abspath(__file__)))defget_relative_path(path:str)->str:""" Returns the relative path of the given path from the root directory. :param path: The path to get the relative path of. :return: The relative path. """returnos.path.relpath(path,ROOT_DIR)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.8.1"__hardcoded_version__=__version____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: skipasyncdefarun(builder:"_ConfigurationBuilder"):fromharp.config.adapters.hypercornimportHypercornAdaptersystem=awaitbuilder.abuild_system()server=HypercornAdapter(system)try:returnawaitserver.serve()finally:awaitsystem.dispose()
[docs]defrun(builder:"_ConfigurationBuilder"):""" Run the default server using provided configuration. :param builder: Config :return: """importasyncioreturnasyncio.run(arun(builder))