From 25fb55d311c24bda472b9166c5cd57cdc33bb823 Mon Sep 17 00:00:00 2001 From: James Knight Date: Fri, 11 Aug 2023 00:04:49 -0400 Subject: [PATCH 1/2] util: resolve relative file lists from source directory When a relative path publish list is provided in a configuration, look for the file from within the source directory (which is the expected location when this feature was introduced). This should prevent issues when invoking a Sphinx build from outside a project's source directory. Signed-off-by: James Knight --- sphinxcontrib/confluencebuilder/builder.py | 2 +- .../confluencebuilder/config/checks.py | 2 +- sphinxcontrib/confluencebuilder/util.py | 18 +++++++++++++----- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/sphinxcontrib/confluencebuilder/builder.py b/sphinxcontrib/confluencebuilder/builder.py index ada637ce..02b82961 100644 --- a/sphinxcontrib/confluencebuilder/builder.py +++ b/sphinxcontrib/confluencebuilder/builder.py @@ -191,7 +191,7 @@ def prepare_subset(option): if value is None: return None - value = handle_cli_file_subset(config, option, value) + value = handle_cli_file_subset(self, option, value) if value is None: return None diff --git a/sphinxcontrib/confluencebuilder/config/checks.py b/sphinxcontrib/confluencebuilder/config/checks.py index 102305b2..f134baf3 100644 --- a/sphinxcontrib/confluencebuilder/config/checks.py +++ b/sphinxcontrib/confluencebuilder/config/checks.py @@ -532,7 +532,7 @@ def validate_configuration(builder): # if provided a file via command line, treat as a list def conf_translate(value): - return handle_cli_file_subset(config, option, value) + return handle_cli_file_subset(builder, option, value) value = conf_translate(value) try: diff --git a/sphinxcontrib/confluencebuilder/util.py b/sphinxcontrib/confluencebuilder/util.py index dd2b0d14..e4d17584 100644 --- a/sphinxcontrib/confluencebuilder/util.py +++ b/sphinxcontrib/confluencebuilder/util.py @@ -303,7 +303,7 @@ def getpass2(prompt='Password: '): return getpass.getpass(prompt=prompt) -def handle_cli_file_subset(config, option, value): +def handle_cli_file_subset(builder, option, value): """ process a file subset entry based on a cli-provided value @@ -313,7 +313,7 @@ def handle_cli_file_subset(config, option, value): this is a string, it is most likely a list of files from the command line. Args: - config: the sphinx configuration + builder: the confluence builder option: the key associated to this configuration value value: the configuration value @@ -321,14 +321,22 @@ def handle_cli_file_subset(config, option, value): the resolved configuration value """ - if option in config['overrides'] and isinstance(value, str): + if option in builder.config['overrides'] and isinstance(value, str): if not value: # an empty command line subset is an "unset" request # (and not an empty list); if no values are detected, # return `None` return None - elif not os.path.isfile(value): - value = value.split(',') + else: + if os.path.isabs(value): + target_file = value + else: + target_file = os.path.join(builder.env.srcdir, value) + + if os.path.isfile(target_file): + value = target_file + else: + value = value.split(',') return value From 7f08fe20023c55f8033379d6da054d9fc291f40a Mon Sep 17 00:00:00 2001 From: James Knight Date: Fri, 11 Aug 2023 00:05:12 -0400 Subject: [PATCH 2/2] tests: verify accepting relative publish list files Adding tests which not only check a publish list provided from an absolute path, but also a relative path based on a project's source directory. Signed-off-by: James Knight --- tests/unit-tests/test_config_publish_list.py | 27 ++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/tests/unit-tests/test_config_publish_list.py b/tests/unit-tests/test_config_publish_list.py index 3c72fef8..b1084051 100644 --- a/tests/unit-tests/test_config_publish_list.py +++ b/tests/unit-tests/test_config_publish_list.py @@ -67,7 +67,7 @@ def test_config_publishlist_allow_list_cli_empty(self): call('folder/page-b', ANY), ], any_order=True) - def test_config_publishlist_allow_list_file_default(self): + def test_config_publishlist_allow_list_file_default_abs(self): publish_list = os.path.join(self.dataset, 'publish-list-default') config = dict(self.config) @@ -81,6 +81,18 @@ def test_config_publishlist_allow_list_file_default(self): call('folder/page-b', ANY), ], any_order=True) + def test_config_publishlist_allow_list_file_default_relative(self): + config = dict(self.config) + config['confluence_publish_allowlist'] = 'publish-list-default' + + with patch.object(ConfluenceBuilder, 'publish_doc') as mm: + self.build(self.dataset, config=config) + + mm.assert_has_calls([ + call('page-a', ANY), + call('folder/page-b', ANY), + ], any_order=True) + def test_config_publishlist_allow_list_file_empty(self): publish_list = os.path.join(self.dataset, 'publish-list-empty') @@ -186,7 +198,7 @@ def test_config_publishlist_deny_list_cli_empty(self): call('folder/page-b', ANY), ], any_order=True) - def test_config_publishlist_deny_list_file_default(self): + def test_config_publishlist_deny_list_file_default_abs(self): publish_list = os.path.join(self.dataset, 'publish-list-default') config = dict(self.config) @@ -199,6 +211,17 @@ def test_config_publishlist_deny_list_file_default(self): call('index', ANY), ], any_order=True) + def test_config_publishlist_deny_list_file_default_relative(self): + config = dict(self.config) + config['confluence_publish_denylist'] = 'publish-list-default' + + with patch.object(ConfluenceBuilder, 'publish_doc') as mm: + self.build(self.dataset, config=config) + + mm.assert_has_calls([ + call('index', ANY), + ], any_order=True) + def test_config_publishlist_deny_list_file_empty(self): publish_list = os.path.join(self.dataset, 'publish-list-empty')