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

Use singleton-like Meta class to store global state #36

Merged
merged 9 commits into from
Mar 30, 2018
Merged

Conversation

lukehsiao
Copy link
Contributor

Closes #34.

@lukehsiao lukehsiao added the enhancement New feature or request label Mar 30, 2018
@lukehsiao lukehsiao added this to the v0.1.5 milestone Mar 30, 2018
@lukehsiao lukehsiao self-assigned this Mar 30, 2018
@lukehsiao lukehsiao requested a review from senwu March 30, 2018 07:02
We cannot conditionally initialize the database tables in the context
classes because snorkel_postgres is only initialized after the imports.
Because we won't support sqlite (see #35), just initialize the context
based on using postgres.
@lukehsiao
Copy link
Contributor Author

This release is NOT backwards compatable with v0.1.4. Specifically, in order
to initialize a session with postgresql, you no longer do

os.environ['SNORKELDB'] = 'postgres://localhost:5432/' + DBNAME
from fonduer import SnorkelSession       
session = SnorkelSession()

which had the side-effects of manipulating your database tables on import (or creating a snorkel.db file if you forgot to set the environment variable). Now, you use the Meta class to initialize your session:

from fonduer import Meta       
session = Meta.init("postgres://localhost:5432/" + DBNAME).SnorkelSession()

No side-effects occur until Meta is initialized.

@lukehsiao lukehsiao changed the title Use singleton-like Meta to store global state Use singleton-like Meta class to store global state Mar 30, 2018
def test_e2e(caplog):
"""Run an end-to-end test on 20 documents of the hardware domain."""
caplog.set_level(logging.INFO)
PARALLEL = 2
max_docs = 12

session = SnorkelSession()
session = Meta.init('postgres://localhost:5432/' + DB).SnorkelSession()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we update the name here (FonduerSession)?

@@ -29,6 +25,7 @@ def test_parse_structure(caplog):
"""
caplog.set_level(logging.INFO)
logger = logging.getLogger(__name__)
session = Meta.init('postgres://localhost:5432/' + ATTRIBUTE).SnorkelSession()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here.

@@ -77,7 +74,7 @@ def test_parse_document_md(caplog):
This tests both the structural and visual parse of the document.
"""
logger = logging.getLogger(__name__)
session = SnorkelSession()
session = Meta.init('postgres://localhost:5432/' + ATTRIBUTE).SnorkelSession()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here.

@@ -126,7 +123,7 @@ def test_parse_document_diseases(caplog):
"""
caplog.set_level(logging.INFO)
logger = logging.getLogger(__name__)
session = SnorkelSession()
session = Meta.init('postgres://localhost:5432/' + ATTRIBUTE).SnorkelSession()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here.

docs/index.rst Outdated
dev/tests
:maxdepth: 2
:caption: Developer Documentation

Copy link
Collaborator

Choose a reason for hiding this comment

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

remove the extra spaces

@lukehsiao lukehsiao merged commit 793df54 into master Mar 30, 2018
@lukehsiao lukehsiao deleted the singleton branch March 30, 2018 21:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants