Skip to content

Conversation

@alcarney
Copy link
Member

Unless esbonio finds a sphinx-build command to use from the user's config it will attempt to guess something reasonable. During this process it generates a default build directory to use, in a subfolder of platformdirs.user_cache_dir() so that it does not interfere with the user's files.

Up until now, the moment a user sets their own sphinx-build command this behavior is lost, which can lead to issues on some systems.

This PR introduces a ${defaultBuildDir} placeholder value that the user can use to provide their own build flags, while maintaining the default choice of build directory provided by esbonio.

Closes #865

Unless esbonio finds a `sphinx-build` command to use from the
user's config it will attempt to guess something reasonable. During
this process it generates a default build directory to use, in a
subfolder of `platformdirs.user_cache_dir()` so that it does not
interfere with the user's files.

Up until now, the moment a user sets their own `sphinx-build` command
this behavior is lost, which can lead to issues on some systems
(see swyddfa#865).

This commit introduces a `${defaultBuildDir}` placeholder value that
the user can use to provide their own build flags, while maintaining
the default choice of build dir provided by esbonio.
Backslashes in Windows filepaths can cause issues

```python
>>> import re
>>> VARIABLE = re.compile(r"\$\{(\w+)\}")
>>> VARIABLE.sub('\\path\\to\\cache', '${defaultBuildDir}/doctrees')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python3.12/re/__init__.py", line 334, in _compile_template
    return _sre.template(pattern, _parser.parse_template(repl, pattern))
                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.12/re/_parser.py", line 1075, in parse_template
    raise s.error('bad escape %s' % this, len(this)) from None
re.error: bad escape \p at position 0
```

Calling `re.escape` on the replacement ensures that characters like
backslashes are escaped correctly

```python
>>> VARIABLE.sub(re.escape('\\path\\to\\cache'), '${defaultBuildDir}/doctrees')
'\\path\\to\\cache/doctrees'
>>>
```
When `manager.get_client` is called many times in quick
succession (such as on server restart with N files open) this can fool
the `SphinxManager` into creating multiple client instances for a
given configuration scope.

By storing a ``None`` at the relevant scope we allow the SphinxManager
to detect that the scope has already been handled, preventing the
spawning of duplicated client instances.

This should, finally, fix the flaky test issue (swyddfa#859)
@alcarney alcarney merged commit c89ec6b into swyddfa:develop Sep 29, 2024
11 checks passed
@alcarney alcarney deleted the build-dir branch September 29, 2024 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot clear docs/_build directory due to locked database files

1 participant