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

Fix #8: Incremental building not working #14

Closed
Closed
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
7 changes: 5 additions & 2 deletions sphinxcontrib/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,15 @@ def download_images(app, env):
.format(src, dst))


def configure_backend(app):
def configure_backend(app, main_config):
global DEFAULT_CONFIG

config = copy.deepcopy(DEFAULT_CONFIG)
config.update(app.config.images_config)
app.config.images_config = config
Comment on lines +268 to 273

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would probably use the main_config directly since it's provided, but I'm not sure if there is a good reason why the hook has both app and the config though.

Suggested change
def configure_backend(app, main_config):
global DEFAULT_CONFIG
config = copy.deepcopy(DEFAULT_CONFIG)
config.update(app.config.images_config)
app.config.images_config = config
def check_config(app, config):
'''Ensure all config values are defined'''
merged = copy.deepcopy(DEFAULT_CONFIG)
merged.update(config.images_config)
config.images_config = merged


def builder_init(app):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still configuring the backend and probably shouldn't be renamed

Suggested change
def builder_init(app):
def configure_backend(app):

config = app.config.images_config
ensuredir(os.path.join(app.env.srcdir, config['cache_path']))

# html builder
Expand Down Expand Up @@ -346,7 +348,8 @@ def setup(app):
global DEFAULT_CONFIG

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This global declaration isn't needed, and it might be good to remove it while you're editing this file

app.require_sphinx('1.0')
app.add_config_value('images_config', DEFAULT_CONFIG, 'env')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this isn't actually needed because the configuration will be merged anyways, it might make sense to just pass a dict which also wouldn't break when copying it.

Suggested change
app.add_config_value('images_config', DEFAULT_CONFIG, 'env')
app.add_config_value('images_config', {}, 'env')

app.connect('builder-inited', configure_backend)
app.connect('config-inited', configure_backend)
app.connect('builder-inited', builder_init)
Comment on lines +351 to +352

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the suggestions above:

Suggested change
app.connect('config-inited', configure_backend)
app.connect('builder-inited', builder_init)
app.connect('config-inited', check_config)
app.connect('builder-inited', configure_backend)

app.connect('env-updated', download_images)
app.connect('env-updated', install_backend_static_files)

Expand Down