From 7a39a30e1cc63c423d7c91d1f5f61720f009109c Mon Sep 17 00:00:00 2001 From: James Knight Date: Sun, 24 Jul 2022 13:42:20 -0400 Subject: [PATCH 1/5] do not pass env argument into deprecated builders Changes to the builder to move towards passing an environment into the builder [1] can cause some legacy builder types to fail to load [2]. For example: Traceback (most recent call last): File "/home/runner/work/confluencebuilder/confluencebuilder/.tox/py38-sphinx51/lib/python3.8/site-packages/sphinx/registry.py", line 162, in create_builder return self.builders[name](app, env) TypeError: __init__() takes 2 positional arguments but 3 were given The fallback case for preparing deprecated builders should avoid setting `env`. [1]: 6ef22d261303ec07890305b300135c34952ca327 [2]: https://github.com/sphinx-contrib/confluencebuilder/pull/691 Signed-off-by: James Knight --- sphinx/registry.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sphinx/registry.py b/sphinx/registry.py index 561fba69b7..b4893e02cf 100644 --- a/sphinx/registry.py +++ b/sphinx/registry.py @@ -166,7 +166,7 @@ def create_builder(self, app: "Sphinx", name: str, f"'env'argument. Report this bug to the developers of your custom builder, " f"this is likely not a issue with Sphinx. The 'env' argument will be required " f"from Sphinx 7.", RemovedInSphinx70Warning, stacklevel=2) - builder = self.builders[name](app, env=...) # type: ignore[arg-type] + builder = self.builders[name](app) if env is not None: builder.set_environment(env) return builder From c83c83c4cdac9cfc047850844b3853ad9899e280 Mon Sep 17 00:00:00 2001 From: James Knight Date: Sun, 24 Jul 2022 13:42:39 -0400 Subject: [PATCH 2/5] always default create optional environment for deprecated builders Builder implementation would originally always create an optional environment instance, which an extended builder's implementation could reference in their own `__init__` call. However, with the change [1] to support an `env` argument, there is no longer a guarantee that `self.env` will exist. This commit changes this to restore the creating of `self.env` if `env` if not passed in. [1]: 6ef22d261303ec07890305b300135c34952ca327 Signed-off-by: James Knight --- sphinx/builders/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sphinx/builders/__init__.py b/sphinx/builders/__init__.py index 62a369a912..013dcbddcc 100644 --- a/sphinx/builders/__init__.py +++ b/sphinx/builders/__init__.py @@ -89,10 +89,11 @@ def __init__(self, app: "Sphinx", env: BuildEnvironment = None) -> None: self.env: BuildEnvironment = env self.env.set_versioning_method(self.versioning_method, self.versioning_compare) - elif env is not Ellipsis: + else: # ... is passed by SphinxComponentRegistry.create_builder to not show two warnings. warnings.warn("The 'env' argument to Builder will be required from Sphinx 7.", RemovedInSphinx70Warning, stacklevel=2) + self.env = Optional[BuildEnvironment] # type: ignore[assignment] self.events: EventManager = app.events self.config: Config = app.config self.tags: Tags = app.tags From 10e632b7136b164fcd01557fa1b59151003b459c Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Date: Mon, 25 Jul 2022 22:55:12 +0100 Subject: [PATCH 3/5] Update sphinx/builders/__init__.py --- sphinx/builders/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sphinx/builders/__init__.py b/sphinx/builders/__init__.py index 013dcbddcc..3517c51fc5 100644 --- a/sphinx/builders/__init__.py +++ b/sphinx/builders/__init__.py @@ -93,7 +93,7 @@ def __init__(self, app: "Sphinx", env: BuildEnvironment = None) -> None: # ... is passed by SphinxComponentRegistry.create_builder to not show two warnings. warnings.warn("The 'env' argument to Builder will be required from Sphinx 7.", RemovedInSphinx70Warning, stacklevel=2) - self.env = Optional[BuildEnvironment] # type: ignore[assignment] + self.env: Optional[BuildEnvironment] = None # type: ignore[assignment] self.events: EventManager = app.events self.config: Config = app.config self.tags: Tags = app.tags From a2b9e3d56c0b93845b05c429f889d3733a77e952 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Date: Mon, 25 Jul 2022 23:02:13 +0100 Subject: [PATCH 4/5] Update sphinx/builders/__init__.py --- sphinx/builders/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sphinx/builders/__init__.py b/sphinx/builders/__init__.py index 3517c51fc5..ed9a2e9ea0 100644 --- a/sphinx/builders/__init__.py +++ b/sphinx/builders/__init__.py @@ -93,7 +93,7 @@ def __init__(self, app: "Sphinx", env: BuildEnvironment = None) -> None: # ... is passed by SphinxComponentRegistry.create_builder to not show two warnings. warnings.warn("The 'env' argument to Builder will be required from Sphinx 7.", RemovedInSphinx70Warning, stacklevel=2) - self.env: Optional[BuildEnvironment] = None # type: ignore[assignment] + self.env = None # type: ignore[assignment] self.events: EventManager = app.events self.config: Config = app.config self.tags: Tags = app.tags From e3de9f7945ed7ff759e81832837201f44e0f3aae Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Date: Mon, 25 Jul 2022 23:05:37 +0100 Subject: [PATCH 5/5] Update sphinx/builders/__init__.py --- sphinx/builders/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sphinx/builders/__init__.py b/sphinx/builders/__init__.py index ed9a2e9ea0..2aede5c246 100644 --- a/sphinx/builders/__init__.py +++ b/sphinx/builders/__init__.py @@ -93,7 +93,7 @@ def __init__(self, app: "Sphinx", env: BuildEnvironment = None) -> None: # ... is passed by SphinxComponentRegistry.create_builder to not show two warnings. warnings.warn("The 'env' argument to Builder will be required from Sphinx 7.", RemovedInSphinx70Warning, stacklevel=2) - self.env = None # type: ignore[assignment] + self.env = None self.events: EventManager = app.events self.config: Config = app.config self.tags: Tags = app.tags