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

Add sphinx factory class #3656

Merged
merged 10 commits into from
Apr 23, 2017
Merged

Conversation

tk0miya
Copy link
Member

@tk0miya tk0miya commented Apr 22, 2017

As a refactoring, I'd like to introduce a factory class of sphinx components:

  • builders
  • translators
  • domains
  • source parsers

This is a first step of refactoring. I will continue to improve this to whole of components.

I believe this brings our application class simple.

At present, the factory class is only used to make application class simple. Hopefully, I'd like to give the factory object to setup() function of each extensions. I think it is much simpler.

@tk0miya tk0miya added this to the 1.6 milestone Apr 22, 2017
@tk0miya tk0miya self-assigned this Apr 22, 2017
@tk0miya tk0miya requested a review from shimizukawa April 22, 2017 11:36
@tk0miya
Copy link
Member Author

tk0miya commented Apr 22, 2017

I know this is still WIP. But this is very large refactoring. So I'd like to merge this into master branch and improve step by step.
I believe this does not harms anything our code.
@shimizukawa What do you think?

Copy link
Member

@shimizukawa shimizukawa left a comment

Choose a reason for hiding this comment

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

IMO, the factory class seems having 2 responsibilities; factory and registry.

} # type: Dict[unicode, unicode]


class SphinxFactory(object):
Copy link
Member

Choose a reason for hiding this comment

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

I feel the name of Factory is not good.
IMO, this factory class seems having 2 responsibilities; factory and registry.

  1. registry for builders, domains, source_parsers and translators.
  2. adding object to registry.
  3. getting object from registry.
  4. having loading extension mechanism.
  5. creating instance of builders, domains and translators.

I think 4 and 5 are the responsibility of factory, but 1,2, 3 are registry.

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed, it is not good naming.
question: do you mean splitting the feature to two classes?

Copy link
Member Author

Choose a reason for hiding this comment

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

As a result of discussion, I finally renamed it to SphinxComponentRegistry.

def get_translator_class(self, *args):
# type: (Any) -> nodes.NodeVisitor
"""Return a class of translator."""
return self.app.factory.get_translator_class(self)
Copy link
Member

Choose a reason for hiding this comment

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

In this case, it seems that app.factoryworks as a registry for internal mechanism.
So every internal mechanism should access to app.registry instead of app.factory if my understanding is correct.
It means that app.factory has two responsibility; factory and registry.

BTW (not important) I feel that this reference is deep. IMHO, principle of least knowledge (A.K.A. The Law of Demeter) is good practice.

@tk0miya tk0miya merged commit 6169506 into sphinx-doc:master Apr 23, 2017
@tk0miya
Copy link
Member Author

tk0miya commented Apr 23, 2017

Merged. Thank you for reviewing!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants