From d95c5793ae1eb49ab6f1e9de8d9729a5c1a0c0fe Mon Sep 17 00:00:00 2001 From: Sen Wu Date: Fri, 30 Mar 2018 22:55:48 -0700 Subject: [PATCH 1/3] fix postgresql password issue --- fonduer/async_annotations.py | 27 ++++++++++++--------------- fonduer/snorkel/models/meta.py | 11 +++++++---- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/fonduer/async_annotations.py b/fonduer/async_annotations.py index 8ac4df356..e189393a3 100644 --- a/fonduer/async_annotations.py +++ b/fonduer/async_annotations.py @@ -160,21 +160,18 @@ def copy_postgres(segment_file_blob, table_name, tsv_columns): separated by comma. e.g. "name, age, income" """ print('Copying %s to postgres' % table_name) - if _meta.DBPORT: - cmd = ('cat %s | psql -p %s %s -U %s -c "COPY %s(%s) ' - 'FROM STDIN" --set=ON_ERROR_STOP=true') % (segment_file_blob, - _meta.DBPORT, - _meta.DBNAME, - _meta.DBUSER, - table_name, - tsv_columns) - else: - cmd = ('cat %s | psql %s -U %s -c "COPY %s(%s) ' - 'FROM STDIN" --set=ON_ERROR_STOP=true') % (segment_file_blob, - _meta.DBNAME, - _meta.DBUSER, - table_name, - tsv_columns) + + username = "-U " + _meta.DBUSER if _meta.DBUSER is not None else "" + password = "PGPASSWORD=" + _meta.DBPWD if _meta.DBPWD is not None else "" + port = "-p " + str(_meta.DBPORT) if _meta.DBPORT is not None else "" + cmd = ('cat %s | %s psql %s %s %s -c "COPY %s(%s) ' + 'FROM STDIN" --set=ON_ERROR_STOP=true') % (segment_file_blob, + password, + _meta.DBNAME, + username, + port, + table_name, + tsv_columns) _out = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True) print(_out) diff --git a/fonduer/snorkel/models/meta.py b/fonduer/snorkel/models/meta.py index 86899e2f7..c39b9423d 100644 --- a/fonduer/snorkel/models/meta.py +++ b/fonduer/snorkel/models/meta.py @@ -45,6 +45,7 @@ class Meta(object): DBNAME = None DBUSER = None DBPORT = None + DBPWD = None Session = None engine = None Base = declarative_base(name='Base', cls=object) @@ -55,11 +56,13 @@ class Meta(object): def init(cls, conn_string=None): """Return the unique Meta class.""" if conn_string and not Meta.ready: + url = urlparse(conn_string) Meta.conn_string = conn_string - Meta.DBNAME = conn_string.split('/')[-1] - Meta.DBUSER = getpass.getuser() - Meta.DBPORT = urlparse(conn_string).port - Meta.postgres = conn_string.startswith('postgres') + Meta.DBNAME = url.path[1:] + Meta.DBUSER = url.username + Meta.DBPWD = url.password + Meta.DBPORT = url.port + Meta.postgres = url.scheme.startswith('postgres') # We initialize the engine within the models module because models' # schema can depend on which data types are supported by the engine Meta.ready = Meta.postgres From 01109154046dcbdd1deb99ef562076b3e216bf7a Mon Sep 17 00:00:00 2001 From: Luke Hsiao Date: Fri, 30 Mar 2018 23:08:51 -0700 Subject: [PATCH 2/3] Remove unused import --- fonduer/snorkel/models/meta.py | 1 - 1 file changed, 1 deletion(-) diff --git a/fonduer/snorkel/models/meta.py b/fonduer/snorkel/models/meta.py index c39b9423d..a8efdd2b0 100644 --- a/fonduer/snorkel/models/meta.py +++ b/fonduer/snorkel/models/meta.py @@ -1,6 +1,5 @@ from __future__ import absolute_import, division, print_function -import getpass import logging from builtins import object from urllib.parse import urlparse From 0d3feba3b430daee59cc544e0997fbfc4a8bec28 Mon Sep 17 00:00:00 2001 From: Luke Hsiao Date: Fri, 30 Mar 2018 23:33:19 -0700 Subject: [PATCH 3/3] Update docs and version --- CHANGELOG.rst | 11 ++++++++--- docs/dev/changelog.rst | 12 ++++++++++++ docs/dev/install.rst | 5 ----- fonduer/_version.py | 2 +- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 1bdbad5d5..82aaaa995 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,10 @@ -.. note:: - Fonduer is still under active development and APIs may still change - rapidly. +Version 0.1.6 +------------- + +* `@senwu`_: Fix support for providing a PostgreSQL username and password as + part of the connection string provided to Meta.init() + (`#40 `_) +* `@lukehsiao`_: Switch README from Markdown to reStructuredText Version 0.1.5 ------------- @@ -51,3 +55,4 @@ Version 0.1.2 For convenience, all username links for contributors can be listed here .. _@lukehsiao: https://github.com/lukehsiao +.. _@senwu: https://github.com/senwu diff --git a/docs/dev/changelog.rst b/docs/dev/changelog.rst index 2b0c4815e..1fbe424fe 100644 --- a/docs/dev/changelog.rst +++ b/docs/dev/changelog.rst @@ -1,4 +1,16 @@ Changelog ========= +We are following `Semantic Versioning 2.0.0`_ conventions. The maintainers will +create a git tag for each release and increment the version number found in +`fonduer/\_version.py`_ accordingly. We deploy tags to PyPI automatically using +Travis-CI. + +.. note:: + Fonduer is still under active development and APIs may still change + rapidly. + .. include:: ../../CHANGELOG.rst + +.. _Semantic Versioning 2.0.0: https://semver.org/ +.. _fonduer/\_version.py: https://github.com/HazyResearch/fonduer/blob/master/fonduer/_version.py diff --git a/docs/dev/install.rst b/docs/dev/install.rst index e1c93af5e..693dab910 100644 --- a/docs/dev/install.rst +++ b/docs/dev/install.rst @@ -1,11 +1,6 @@ Installation ============ -We are following `Semantic Versioning 2.0.0 `__ -conventions. The maintainers will create a git tag for each release and -increment the version number found in `fonduer/\_version.py`_ accordingly. We -deploy tags to PyPI automatically using Travis-CI. - To test changes in the package, you install it in `editable mode`_ locally in your virtualenv by running:: diff --git a/fonduer/_version.py b/fonduer/_version.py index 1276d0254..0a8da8825 100644 --- a/fonduer/_version.py +++ b/fonduer/_version.py @@ -1 +1 @@ -__version__ = "0.1.5" +__version__ = "0.1.6"