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

Maintenance (2024-03-02) #899

Merged
merged 26 commits into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
4e7a6e9
tests: remove legacy python file coding
jdknight Mar 2, 2024
075decb
refactor define processing from a mainline
jdknight Mar 2, 2024
f2ea993
tests: update expected line-count with test asset change
jdknight Mar 2, 2024
82bf0a6
builder: noqa on private member access of sphinx's writer doc cache
jdknight Mar 2, 2024
76a48d3
rework for-loops to ignore unused values
jdknight Mar 2, 2024
018e635
implicitly concatenated string
jdknight Mar 2, 2024
899eaab
use suppressible exception over try-except-pass
jdknight Mar 2, 2024
dd14921
remove various variable/function shadowing
jdknight Mar 2, 2024
c3e1074
remove superfluous else return
jdknight Mar 2, 2024
5b1502f
add exception chaining on various exceptions
jdknight Mar 2, 2024
fa3c849
add trailing commas (COM812)
jdknight Mar 2, 2024
23951db
remove unnecessary parenthesis
jdknight Mar 2, 2024
96c98c5
simplify verbose lines
jdknight Mar 2, 2024
82623a1
explicit stty paths for getpass override
jdknight Mar 2, 2024
13f9a84
suppress linter warning on aliased locale translation function
jdknight Mar 2, 2024
c334d8a
suppress linter subprocess warnings on non-input calls
jdknight Mar 2, 2024
0de7c90
suppress linter security warning on random call
jdknight Mar 2, 2024
de012bd
tests: explicit capture of builder init call
jdknight Mar 2, 2024
4ec94db
simplify various attribute set-exists checks
jdknight Mar 2, 2024
0ff0503
remove superfluous else return
jdknight Mar 2, 2024
f7ccc22
suppress xml recursion warnings for trusted svg/sites
jdknight Mar 2, 2024
1d29624
config: provide defaults for legacy search-mode handling
jdknight Mar 2, 2024
e922c1b
config: move publish-debug opts into except block
jdknight Mar 3, 2024
e3bf7b9
remove obsolete linter hints
jdknight Mar 3, 2024
85e01ca
various linter tweaks
jdknight Mar 3, 2024
4666d8c
tox: bump ruff version
jdknight Mar 3, 2024
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
4 changes: 2 additions & 2 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
select = [
lint.select = [
'ALL',
]

ignore = [
lint.ignore = [
# various translator/role/etc. definitions may not use all/any arguments
'ARG001',
'ARG002',
Expand Down
16 changes: 8 additions & 8 deletions sphinxcontrib/confluencebuilder/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class ConfluenceBuilder(Builder):
allow_parallel = True
default_translator_class = ConfluenceStorageFormatTranslator
name = 'confluence'
format = 'confluence_storage' # noqa: A003
format = 'confluence_storage'
supported_image_types = ConfluenceSupportedImages()
supported_linkcode = True
supported_remote_images = True
Expand Down Expand Up @@ -267,7 +267,7 @@ def prepare_writing(self, docnames):
# environment is performing any doctree caching, clear the entire
# cache
if getattr(self.env, '_write_doc_doctree_cache', None):
self.env._write_doc_doctree_cache = {}
self.env._write_doc_doctree_cache = {} # noqa: SLF001

# process the document structure of the root document, populating a
# publish order to ensure parent pages are created first (when using
Expand Down Expand Up @@ -374,7 +374,7 @@ def prepare_writing(self, docnames):
labels['search'] = 'search', '', ''

if self.domain_indices:
for indexname, _ in self.domain_indices.items():
for indexname in self.domain_indices:
anonlabels[indexname] = indexname, ''
labels[indexname] = indexname, '', ''

Expand Down Expand Up @@ -440,7 +440,7 @@ def write_doc(self, docname, doctree):

if ids:
for node in findall(doctree, nodes.reference):
if 'refid' in node and node['refid']:
if node.get('refid'):
top_ref = node['refid'] in ids

# allow a derived class to hint if this is a #top
Expand Down Expand Up @@ -719,7 +719,7 @@ def finish(self):

# build domain indexes
if self.domain_indices:
for indexname, indexdata in self.domain_indices.items():
for indexname in self.domain_indices:
self.info(f'generating index ({indexname})...',
nonl=(not self._verbose))

Expand Down Expand Up @@ -1129,9 +1129,9 @@ def _register_doctree_title_targets(self, docname, doctree):
if section_id > 0:
target = f'{target}.{section_id}'

for id_ in section_node['ids']:
id_ = f'{docname}#{id_}'
self.state.register_target(id_, target)
for raw_id in section_node['ids']:
full_id = f'{docname}#{raw_id}'
self.state.register_target(full_id, target)

def _top_ref_check(self, node):
"""
Expand Down
12 changes: 6 additions & 6 deletions sphinxcontrib/confluencebuilder/cmd/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ def build_main(args_parser):
logger.warn('unknown arguments: {}'.format(' '.join(unknown_args)))

defines = {}
for val in args.define:
try:
key, val = val.split('=', 1)
try:
for define in args.define:
key, val = define.split('=', 1)
defines[key] = val
except ValueError:
logger.error('invalid define provided in command line')
return 1
except ValueError:
logger.error('invalid define provided in command line')
return 1

work_dir = args.work_dir if args.work_dir else Path.cwd()
if args.output_dir:
Expand Down
2 changes: 1 addition & 1 deletion sphinxcontrib/confluencebuilder/cmd/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def report_main(args_parser):

# parse
print('parsing information...')
xml_data = ElementTree.fromstring(raw_data)
xml_data = ElementTree.fromstring(raw_data) # noqa: S314
info += ' parsed: yes\n'
root = ElementTree.ElementTree(xml_data)
for o in root.findall('typeId'):
Expand Down
16 changes: 9 additions & 7 deletions sphinxcontrib/confluencebuilder/cmd/wipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,8 @@ def wipe_main(args_parser):

if args.verbose:
print('-------------------------')
page_names = []
for p in legacy_pages:
page_names.append(publisher._name_cache[p])
name_cache = publisher._name_cache # noqa: SLF001
page_names = [name_cache[p] for p in legacy_pages]
sorted(page_names)
print('\n'.join(page_names))
print('-------------------------')
Expand Down Expand Up @@ -195,11 +194,14 @@ def ask_question(question, default='no'):

while True:
rsp = input(question + prompt).strip().lower()

if default is not None and rsp == '':
return default == 'yes'
elif rsp in ('y', 'yes'):

if rsp in ('y', 'yes'):
return True
elif rsp in ('n', 'no', 'q'): # q for 'quit'

if rsp in ('n', 'no', 'q'): # q for 'quit'
return False
else:
print("Please respond with 'y' or 'n'.\n")

print("Please respond with 'y' or 'n'.\n")
4 changes: 2 additions & 2 deletions sphinxcontrib/confluencebuilder/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
def docutils_findall(doctree, *args, **kwargs):
if docutils_version_info >= (0, 18, 1):
return doctree.findall(*args, **kwargs)
else:
return doctree.traverse(*args, **kwargs)

return doctree.traverse(*args, **kwargs)


# use sphinx's inline_all_toctrees which supports the `replace` argument;
Expand Down
4 changes: 2 additions & 2 deletions sphinxcontrib/confluencebuilder/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def legacy(new, orig):
legacy('confluence_root_homepage', 'confluence_master_homepage')
legacy('confluence_space_key', 'confluence_space_name')

if getattr(config, 'confluence_adv_aggressive_search') is True:
if getattr(config, 'confluence_cleanup_search_mode') is None:
if getattr(config, 'confluence_adv_aggressive_search', None) is True:
if getattr(config, 'confluence_cleanup_search_mode', None) is None:
config['confluence_cleanup_search_mode'] = 'search-aggressive'


Expand Down
3 changes: 1 addition & 2 deletions sphinxcontrib/confluencebuilder/config/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,15 +491,14 @@ def conf_translate(value):

# ##################################################################

opts = PublishDebug._member_names_ # pylint: disable=no-member

# confluence_publish_debug
try:
validator.conf('confluence_publish_debug').bool() # deprecated
except ConfluenceConfigError:
try:
validator.conf('confluence_publish_debug').enum(PublishDebug)
except ConfluenceConfigError as ex:
opts = PublishDebug._member_names_ # pylint: disable=no-member
opts_str = '\n - '.join(opts)
raise ConfluencePublishDebugConfigError(ex, opts_str) from ex

Expand Down
5 changes: 2 additions & 3 deletions sphinxcontrib/confluencebuilder/config/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from pathlib import Path
from sphinxcontrib.confluencebuilder.debug import PublishDebug
from sphinxcontrib.confluencebuilder.util import str2bool
import contextlib


# configures the default editor to publication
Expand Down Expand Up @@ -131,7 +132,5 @@ def apply_defaults(builder):
# if the parent page is an integer value in a string type, cast it to an
# integer; otherwise, assume it is a page name (string)
if conf.confluence_parent_page:
try:
with contextlib.suppress(ValueError):
conf.confluence_parent_page = int(conf.confluence_parent_page)
except ValueError:
pass
14 changes: 7 additions & 7 deletions sphinxcontrib/confluencebuilder/config/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,9 @@ def enum(self, etype):
if value is not None and not isinstance(value, etype):
try:
value = etype[value.lower()]
except (AttributeError, KeyError):
except (AttributeError, KeyError) as ex:
msg = f'{self.key} is not an enumeration ({etype.__name__})'
raise ConfluenceConfigError(msg)
raise ConfluenceConfigError(msg) from ex

return self

Expand Down Expand Up @@ -275,16 +275,16 @@ def float_(self, positive=False):
if isinstance(value, str):
try:
value = float(value)
except ValueError:
except ValueError as ex:
msg = f'{self.key} is not a float string'
raise ConfluenceConfigError(msg)
raise ConfluenceConfigError(msg) from ex
elif isinstance(value, int):
value = float(value)

if positive:
if not isinstance(value, float) or value <= 0:
msg = f'{self.key} is not a positive float'
raise ConfluenceConfigError()
raise ConfluenceConfigError
elif not isinstance(value, float) or value < 0:
msg = f'{self.key} is not a non-negative float'
raise ConfluenceConfigError(msg)
Expand Down Expand Up @@ -316,9 +316,9 @@ def int_(self, positive=False):
if isinstance(value, str):
try:
value = int(value)
except ValueError:
except ValueError as ex:
msg = f'{self.key} is not an integer string'
raise ConfluenceConfigError(msg)
raise ConfluenceConfigError(msg) from ex

if positive:
if not isinstance(value, int) or value <= 0:
Expand Down
49 changes: 30 additions & 19 deletions sphinxcontrib/confluencebuilder/directives.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def string_list(argument):

if argument:
for line in argument.splitlines():
for label in line.strip().split(' '):
label = label.strip()
for label_entry in line.strip().split(' '):
label = label_entry.strip()
if label:
data.append(label)

Expand Down Expand Up @@ -260,43 +260,55 @@ def run(self):
# if explicit server is provided, ensure both options are set
if 'server' in params or 'serverId' in params:
if 'server' not in params:
msg = ':server-name: required when server-id is ' \
'set; but none supplied'
msg = (
':server-name: required when server-id is set; '
'but none supplied'
)
raise self.error(msg)
if 'serverId' not in params:
msg = ':server-id: required when server-name is ' \
'set; but none supplied'
msg = (
':server-id: required when server-name is set; '
'but none supplied'
)
raise self.error(msg)
# if a server key is provided, fetch values from configuration
elif target_server:
config = self.state.document.settings.env.config
if not config.confluence_jira_servers:
msg = ':server: is set but no ' \
'confluence_jira_servers defined in config'
msg = (
':server: is set but no '
'confluence_jira_servers defined in config'
)
raise self.error(msg)
jira_servers = config['confluence_jira_servers']
if target_server not in jira_servers:
msg = ':server: is set but does not exist in ' \
'confluence_jira_servers config'
msg = (
':server: is set but does not exist in '
'confluence_jira_servers config'
)
raise self.error(msg)
jira_server_config = jira_servers[target_server]
if 'name' not in jira_server_config:
msg = ':server: is set but missing name entry in ' \
'confluence_jira_servers config'
msg = (
':server: is set but missing name entry in '
'confluence_jira_servers config'
)
raise self.error(msg)
params['server'] = jira_server_config['name']
if 'id' not in jira_server_config:
msg = ':server: is set but missing id entry in ' \
'confluence_jira_servers config'
msg = (
':server: is set but missing id entry in '
'confluence_jira_servers config'
)
raise self.error(msg)
params['serverId'] = jira_server_config['id']

if 'serverId' in params:
try:
UUID(params['serverId'], version=4)
except ValueError:
except ValueError as ex:
msg = 'server-id is not a valid uuid'
raise self.error(msg)
raise self.error(msg) from ex

return [node]

Expand Down Expand Up @@ -349,6 +361,5 @@ def kebab_case_to_camel_case(s):
Returns:
the converted string
"""
s = ''.join(list(map(lambda x: x.capitalize(), s.split('-'))))
s = s[0].lower() + s[1:]
return s
s = ''.join(x.capitalize() for x in s.split('-'))
return s[0].lower() + s[1:]
6 changes: 3 additions & 3 deletions sphinxcontrib/confluencebuilder/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def track_page_hash(self, docname):

return doc_hash

def track_last_page_id(self, docname, id):
def track_last_page_id(self, docname, page_id):
"""
track the last publish page identifier for a document

Expand All @@ -155,10 +155,10 @@ def track_last_page_id(self, docname, id):

Args:
docname: the name of the document
id: the page identifier
page_id: the page identifier
"""

self._active_pids[docname] = id
self._active_pids[docname] = page_id
self._cached_pids.pop(docname, None)

def load_cache(self):
Expand Down
13 changes: 5 additions & 8 deletions sphinxcontrib/confluencebuilder/intersphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ def build_intersphinx(builder):
def escape(string):
return re.sub("\\s+", ' ', string)

if builder.cloud:
pages_part = 'pages/{}/'
else:
pages_part = 'pages/viewpage.action?pageId={}'
pages_part_fmt = 'pages/'
pages_part_fmt += '{}/' if builder.cloud else 'viewpage.action?pageId={}'

inventory_db = builder.out_dir / INVENTORY_FILENAME
with inventory_db.open('wb') as f:
Expand Down Expand Up @@ -70,12 +68,11 @@ def escape(string):
else:
anchor = ''

uri = pages_part.format(page_id)
uri = pages_part_fmt.format(page_id)
if anchor:
uri += '#' + anchor
if dispname == name:
dispname = '-'
entry = f'{name} {domainname}:{typ} {prio} {uri} {dispname}\n'
display = '-' if dispname == name else dispname
entry = f'{name} {domainname}:{typ} {prio} {uri} {display}\n'
logger.verbose('(intersphinx) ' + entry.strip())
f.write(compressor.compress(entry.encode('utf-8')))

Expand Down
Loading