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 multiple load when running rougify -r ... #1566

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

jneen
Copy link
Member

@jneen jneen commented Jul 21, 2020

If the required file contains require 'rouge' (which should be unnecessary when using rougify but might be there for other purposes), we currently catastrophically load another copy of Rouge, which may be from a different version. This prevents that with a simple definition guard.

I know it looks hacky, but it's the only way to have proper reload semantics. Rouge.reload! continues to work with this, because the Rouge constant will be removed from the toplevel first.

(edit: accidentally pushed the wrong branch, this is 1 commit)

except through `reload!` which properly removes the previous version
first
@jneen jneen force-pushed the bugfix.multiple-load-warning branch from b6390b9 to 05840b6 Compare July 21, 2020 05:02
@pyrmont pyrmont self-assigned this Jul 23, 2020
@pyrmont pyrmont added the needs-review The PR needs to be reviewed label Jul 23, 2020
@jneen
Copy link
Member Author

jneen commented Jul 24, 2020

This is failing because ruby 2.3 and earlier do not support top-level return. Since 2.3 is end-of-lifed, I wonder if it's worth supporting? It'd be nice to have some numbers about what ruby versions rouge is being used on.

However, we can solve the same problem by using a require in ./bin/rougify instead of load.

@jneen
Copy link
Member Author

jneen commented Jul 24, 2020

Er.... hang on no we can't. That would still allow multiple versions of Rouge to be loaded in the same runtime.

Comment on lines +7 to +9
# Avoid multiple loads (top-level return will be possible when 2.4+ is the
# minimum supported version)
unless Object::const_defined?(:Rouge) && Rouge.const_defined?(:LIB_DIR)
Copy link
Contributor

Choose a reason for hiding this comment

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

@jneen According to these notes, this was the alternative approach before top-level return. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

@jneen How does this look to you?

@pyrmont pyrmont added author-action The PR has been reviewed but action by the author is needed and removed needs-review The PR needs to be reviewed labels Sep 8, 2020
@pyrmont pyrmont removed their assignment Dec 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author-action The PR has been reviewed but action by the author is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants