Skip to content

Commit

Permalink
Merge pull request #1124 from strictdoc-project/stanislaw/configure_host
Browse files Browse the repository at this point in the history
strictdoc.toml: fix how the "port" parameter is recognized
  • Loading branch information
stanislaw committed Apr 24, 2023
2 parents d379945 + a4d88e5 commit 6662cf8
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 16 deletions.
19 changes: 19 additions & 0 deletions docs/sphinx/source/strictdoc_01_user_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1490,6 +1490,25 @@ This option specifies a project title.
[project]
title = "StrictDoc Documentation"
Server configuration
~~~~~~~~~~~~~~~~~~~~

Host and port
^^^^^^^^^^^^^

By default, StrictDoc runs the server on ``127.0.0.1:5111``.

Use the ``[server]`` section to configure the host and port as follows.

.. code-block:: yaml
[project]
title = 'Test project with a host "localhost" and a port 5000'
[server]
host = "localhost"
port = 5000
Command-line interface options
------------------------------

Expand Down
2 changes: 1 addition & 1 deletion strictdoc/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from strictdoc.core.environment import SDocRuntimeEnvironment

__version__ = "0.0.39"
__version__ = "0.0.40"


environment = SDocRuntimeEnvironment(__file__)
28 changes: 16 additions & 12 deletions strictdoc/cli/cli_arg_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,7 @@ def check_excel_parser(parser):
command_parser_server.add_argument(
"--no-reload", dest="reload", action="store_false"
)
command_parser_server.add_argument(
"--port", default=5111, type=IntRange(1024, 65000)
)
command_parser_server.add_argument("--port", type=IntRange(1024, 65000))

# Command – Version
command_subparsers.add_parser(
Expand Down Expand Up @@ -294,16 +292,15 @@ def __init__(
input_path: str,
output_path: Optional[str],
reload: bool,
port: int,
port: Optional[int],
):
assert os.path.exists(input_path)
assert isinstance(port, int)
self.environment: SDocRuntimeEnvironment = environment
abs_input_path = os.path.abspath(input_path)
self.input_path: str = abs_input_path
self.output_path: Optional[str] = output_path
self.reload: bool = reload
self.port = port
self.port: Optional[int] = port


class ExportMode(Enum):
Expand Down Expand Up @@ -348,11 +345,6 @@ def __init__( # pylint: disable=too-many-arguments
# FIXME: This does not belong here.
self._server_port: Optional[int] = None

def configure_for_server(self, server_port: int):
assert isinstance(server_port, int)
self.is_running_on_server = True
self._server_port = server_port

@property
def server_port(self) -> int:
assert self._server_port is not None
Expand All @@ -377,7 +369,19 @@ def get_static_files_path(self):
def get_extra_static_files_path(self):
return self.environment.get_extra_static_files_path()

def integrate_project_config(self, project_config: ProjectConfig):
def integrate_configs(
self,
*,
project_config: ProjectConfig,
server_config: Optional[ServerCommandConfig],
):
server_port = project_config.server_port
if server_config is not None:
self.is_running_on_server = True
if server_config.port is not None:
server_port = server_config.port
self._server_port = server_port

if self.project_title is None:
self.project_title = project_config.project_title
self.dir_for_sdoc_assets = project_config.dir_for_sdoc_assets
Expand Down
4 changes: 3 additions & 1 deletion strictdoc/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ def _main(parallelizer):
path_to_config_dir=config.input_paths[0]
)
)
config.integrate_project_config(project_config)
config.integrate_configs(
project_config=project_config, server_config=None
)
parallelization_value = (
"Disabled" if config.no_parallelization else "Enabled"
)
Expand Down
5 changes: 3 additions & 2 deletions strictdoc/server/routers/main_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,9 @@ def create_main_router(
enable_mathjax=False,
experimental_enable_file_traceability=False,
)
export_config.integrate_project_config(project_config)
export_config.configure_for_server(server_port=server_config.port)
export_config.integrate_configs(
project_config=project_config, server_config=server_config
)
export_action = ExportAction(
project_config=project_config,
config=export_config,
Expand Down

0 comments on commit 6662cf8

Please sign in to comment.