Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support relative publish list #838

Merged
merged 2 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sphinxcontrib/confluencebuilder/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion sphinxcontrib/confluencebuilder/config/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
18 changes: 13 additions & 5 deletions sphinxcontrib/confluencebuilder/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -313,22 +313,30 @@ 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

Returns:
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

Expand Down
27 changes: 25 additions & 2 deletions tests/unit-tests/test_config_publish_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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')

Expand Down Expand Up @@ -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)
Expand All @@ -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')

Expand Down