diff --git a/python/sqlcommenter-python/README.md b/python/sqlcommenter-python/README.md index 0572abb1..5ddbbff2 100644 --- a/python/sqlcommenter-python/README.md +++ b/python/sqlcommenter-python/README.md @@ -26,7 +26,7 @@ Add the provided Django middleware to your Django project's settings. All querie ```python MIDDLEWARE = [ - 'sqlcommenter.django.middleware.SqlCommenter', + 'google.cloud.sqlcommenter.django.middleware.SqlCommenter', ... ] ``` @@ -41,7 +41,7 @@ which when viewed say on Postgresql logs, produces If you want the opencensus attributes included, you must set the ``SQLCOMMENTER_WITH_OPENCENSUS`` setting to ``True`` and include ``'opencensus.ext.django.middleware.OpencensusMiddleware'`` before -``'sqlcommenter.django.middleware.SqlCommenter',`` in your ``MIDDLEWARE`` +``'google.cloud.sqlcommenter.django.middleware.SqlCommenter',`` in your ``MIDDLEWARE`` setting. ### SQLAlchemy @@ -50,7 +50,7 @@ Attach the provided event listener to the `before_cursor_execute` event of the d ```python import sqlalchemy -from sqlcommenter.sqlalchemy.executor import BeforeExecuteFactory +from google.cloud.sqlcommenter.sqlalchemy.executor import BeforeExecuteFactory engine = sqlalchemy.create_engine(...) listener = BeforeExecuteFactory(with_db_driver=True, with_db_framework=True, with_opencensus=True) @@ -72,7 +72,7 @@ Use the provided cursor factory to generate database cursors. All queries execut ```python import psycopg2 -from sqlcommenter.psycopg2.extension import CommenterCursorFactory +from google.cloud.sqlcommenter.psycopg2.extension import CommenterCursorFactory cursor_factory = CommenterCursorFactory( with_db_driver=True, with_dbapi_level=True, with_dbapi_threadsafety=True, diff --git a/python/sqlcommenter-python/google/__init__.py b/python/sqlcommenter-python/google/__init__.py new file mode 100644 index 00000000..79c6a2fa --- /dev/null +++ b/python/sqlcommenter-python/google/__init__.py @@ -0,0 +1,15 @@ +#!/usr/bin/python +# +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. diff --git a/python/sqlcommenter-python/google/cloud/__init__.py b/python/sqlcommenter-python/google/cloud/__init__.py new file mode 100644 index 00000000..79c6a2fa --- /dev/null +++ b/python/sqlcommenter-python/google/cloud/__init__.py @@ -0,0 +1,15 @@ +#!/usr/bin/python +# +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. diff --git a/python/sqlcommenter-python/sqlcommenter/__init__.py b/python/sqlcommenter-python/google/cloud/sqlcommenter/__init__.py similarity index 100% rename from python/sqlcommenter-python/sqlcommenter/__init__.py rename to python/sqlcommenter-python/google/cloud/sqlcommenter/__init__.py diff --git a/python/sqlcommenter-python/sqlcommenter/django/__init__.py b/python/sqlcommenter-python/google/cloud/sqlcommenter/django/__init__.py similarity index 99% rename from python/sqlcommenter-python/sqlcommenter/django/__init__.py rename to python/sqlcommenter-python/google/cloud/sqlcommenter/django/__init__.py index fc9ebfb4..f80e041f 100644 --- a/python/sqlcommenter-python/sqlcommenter/django/__init__.py +++ b/python/sqlcommenter-python/google/cloud/sqlcommenter/django/__init__.py @@ -13,4 +13,3 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - diff --git a/python/sqlcommenter-python/sqlcommenter/django/middleware.py b/python/sqlcommenter-python/google/cloud/sqlcommenter/django/middleware.py similarity index 96% rename from python/sqlcommenter-python/sqlcommenter/django/middleware.py rename to python/sqlcommenter-python/google/cloud/sqlcommenter/django/middleware.py index 8322b4e6..ce21fdf0 100644 --- a/python/sqlcommenter-python/sqlcommenter/django/middleware.py +++ b/python/sqlcommenter-python/google/cloud/sqlcommenter/django/middleware.py @@ -17,9 +17,8 @@ import django from django.db import connection from django.db.backends.utils import CursorDebugWrapper - -from sqlcommenter import generate_sql_comment -from sqlcommenter.opencensus import get_opencensus_values +from google.cloud.sqlcommenter import generate_sql_comment +from google.cloud.sqlcommenter.opencensus import get_opencensus_values django_version = django.get_version() diff --git a/python/sqlcommenter-python/sqlcommenter/flask.py b/python/sqlcommenter-python/google/cloud/sqlcommenter/flask.py similarity index 100% rename from python/sqlcommenter-python/sqlcommenter/flask.py rename to python/sqlcommenter-python/google/cloud/sqlcommenter/flask.py diff --git a/python/sqlcommenter-python/sqlcommenter/opencensus.py b/python/sqlcommenter-python/google/cloud/sqlcommenter/opencensus.py similarity index 100% rename from python/sqlcommenter-python/sqlcommenter/opencensus.py rename to python/sqlcommenter-python/google/cloud/sqlcommenter/opencensus.py diff --git a/python/sqlcommenter-python/sqlcommenter/psycopg2/__init__.py b/python/sqlcommenter-python/google/cloud/sqlcommenter/psycopg2/__init__.py similarity index 99% rename from python/sqlcommenter-python/sqlcommenter/psycopg2/__init__.py rename to python/sqlcommenter-python/google/cloud/sqlcommenter/psycopg2/__init__.py index fc9ebfb4..f80e041f 100644 --- a/python/sqlcommenter-python/sqlcommenter/psycopg2/__init__.py +++ b/python/sqlcommenter-python/google/cloud/sqlcommenter/psycopg2/__init__.py @@ -13,4 +13,3 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - diff --git a/python/sqlcommenter-python/sqlcommenter/psycopg2/extension.py b/python/sqlcommenter-python/google/cloud/sqlcommenter/psycopg2/extension.py similarity index 93% rename from python/sqlcommenter-python/sqlcommenter/psycopg2/extension.py rename to python/sqlcommenter-python/google/cloud/sqlcommenter/psycopg2/extension.py index 5d84cb02..940fd931 100644 --- a/python/sqlcommenter-python/sqlcommenter/psycopg2/extension.py +++ b/python/sqlcommenter-python/google/cloud/sqlcommenter/psycopg2/extension.py @@ -16,10 +16,9 @@ import psycopg2 import psycopg2.extensions - -from sqlcommenter import generate_sql_comment -from sqlcommenter.flask import get_flask_info -from sqlcommenter.opencensus import get_opencensus_values +from google.cloud.sqlcommenter import generate_sql_comment +from google.cloud.sqlcommenter.flask import get_flask_info +from google.cloud.sqlcommenter.opencensus import get_opencensus_values # This integration extends psycopg2.extensions.cursor diff --git a/python/sqlcommenter-python/sqlcommenter/sqlalchemy/__init__.py b/python/sqlcommenter-python/google/cloud/sqlcommenter/sqlalchemy/__init__.py similarity index 99% rename from python/sqlcommenter-python/sqlcommenter/sqlalchemy/__init__.py rename to python/sqlcommenter-python/google/cloud/sqlcommenter/sqlalchemy/__init__.py index fc9ebfb4..f80e041f 100644 --- a/python/sqlcommenter-python/sqlcommenter/sqlalchemy/__init__.py +++ b/python/sqlcommenter-python/google/cloud/sqlcommenter/sqlalchemy/__init__.py @@ -13,4 +13,3 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - diff --git a/python/sqlcommenter-python/sqlcommenter/sqlalchemy/executor.py b/python/sqlcommenter-python/google/cloud/sqlcommenter/sqlalchemy/executor.py similarity index 93% rename from python/sqlcommenter-python/sqlcommenter/sqlalchemy/executor.py rename to python/sqlcommenter-python/google/cloud/sqlcommenter/sqlalchemy/executor.py index c3c03105..c72886ea 100644 --- a/python/sqlcommenter-python/sqlcommenter/sqlalchemy/executor.py +++ b/python/sqlcommenter-python/google/cloud/sqlcommenter/sqlalchemy/executor.py @@ -19,10 +19,9 @@ from __future__ import absolute_import import sqlalchemy - -from sqlcommenter import generate_sql_comment -from sqlcommenter.flask import get_flask_info -from sqlcommenter.opencensus import get_opencensus_values +from google.cloud.sqlcommenter import generate_sql_comment +from google.cloud.sqlcommenter.flask import get_flask_info +from google.cloud.sqlcommenter.opencensus import get_opencensus_values def BeforeExecuteFactory( diff --git a/python/sqlcommenter-python/setup.py b/python/sqlcommenter-python/setup.py index 46401e2b..2c778cd2 100644 --- a/python/sqlcommenter-python/setup.py +++ b/python/sqlcommenter-python/setup.py @@ -17,7 +17,7 @@ from setuptools import find_packages, setup setup( - name='sqlcommenter', + name='google.cloud.sqlcommenter', version='0.1', author='Google Developers', author_email='sqlcommenter@googlegroups.com', diff --git a/python/sqlcommenter-python/tests/__init__.py b/python/sqlcommenter-python/tests/__init__.py index fc9ebfb4..f80e041f 100644 --- a/python/sqlcommenter-python/tests/__init__.py +++ b/python/sqlcommenter-python/tests/__init__.py @@ -13,4 +13,3 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - diff --git a/python/sqlcommenter-python/tests/django/__init__.py b/python/sqlcommenter-python/tests/django/__init__.py index fc9ebfb4..f80e041f 100644 --- a/python/sqlcommenter-python/tests/django/__init__.py +++ b/python/sqlcommenter-python/tests/django/__init__.py @@ -13,4 +13,3 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - diff --git a/python/sqlcommenter-python/tests/django/tests.py b/python/sqlcommenter-python/tests/django/tests.py index b2e85c7e..674af9a0 100644 --- a/python/sqlcommenter-python/tests/django/tests.py +++ b/python/sqlcommenter-python/tests/django/tests.py @@ -19,8 +19,7 @@ from django.http import HttpRequest from django.test import TestCase, override_settings from django.urls import resolve, reverse - -from sqlcommenter.django.middleware import SqlCommenter +from google.cloud.sqlcommenter.django.middleware import SqlCommenter from ..opencensus_mock import mock_opencensus_tracer from . import views diff --git a/python/sqlcommenter-python/tests/flask/__init__.py b/python/sqlcommenter-python/tests/flask/__init__.py index fc9ebfb4..f80e041f 100644 --- a/python/sqlcommenter-python/tests/flask/__init__.py +++ b/python/sqlcommenter-python/tests/flask/__init__.py @@ -13,4 +13,3 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - diff --git a/python/sqlcommenter-python/tests/flask/app.py b/python/sqlcommenter-python/tests/flask/app.py index 94706dae..b431945e 100644 --- a/python/sqlcommenter-python/tests/flask/app.py +++ b/python/sqlcommenter-python/tests/flask/app.py @@ -15,8 +15,7 @@ # limitations under the License. from flask import Flask - -from sqlcommenter.flask import get_flask_info +from google.cloud.sqlcommenter.flask import get_flask_info app = Flask(__name__) diff --git a/python/sqlcommenter-python/tests/flask/tests.py b/python/sqlcommenter-python/tests/flask/tests.py index fcf98772..5daebe3d 100644 --- a/python/sqlcommenter-python/tests/flask/tests.py +++ b/python/sqlcommenter-python/tests/flask/tests.py @@ -18,8 +18,7 @@ import flask import pytest - -from sqlcommenter.flask import get_flask_info +from google.cloud.sqlcommenter.flask import get_flask_info from .app import app diff --git a/python/sqlcommenter-python/tests/generic/__init__.py b/python/sqlcommenter-python/tests/generic/__init__.py index fc9ebfb4..f80e041f 100644 --- a/python/sqlcommenter-python/tests/generic/__init__.py +++ b/python/sqlcommenter-python/tests/generic/__init__.py @@ -13,4 +13,3 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - diff --git a/python/sqlcommenter-python/tests/generic/test_generate_sql_comment.py b/python/sqlcommenter-python/tests/generic/test_generate_sql_comment.py index bd045d52..32572fe4 100644 --- a/python/sqlcommenter-python/tests/generic/test_generate_sql_comment.py +++ b/python/sqlcommenter-python/tests/generic/test_generate_sql_comment.py @@ -16,7 +16,7 @@ from unittest import TestCase -from sqlcommenter import generate_sql_comment +from google.cloud.sqlcommenter import generate_sql_comment class GenerateSqlCommentTests(TestCase): diff --git a/python/sqlcommenter-python/tests/generic/test_opencensus.py b/python/sqlcommenter-python/tests/generic/test_opencensus.py index 81e37e94..21097d8e 100644 --- a/python/sqlcommenter-python/tests/generic/test_opencensus.py +++ b/python/sqlcommenter-python/tests/generic/test_opencensus.py @@ -17,8 +17,7 @@ from unittest import TestCase import six - -from sqlcommenter.opencensus import get_opencensus_values +from google.cloud.sqlcommenter.opencensus import get_opencensus_values from ..compat import mock from ..opencensus_mock import mock_opencensus_tracer @@ -26,7 +25,7 @@ class OpenCensusTests(TestCase): def test_not_installed(self): - with mock.patch('sqlcommenter.opencensus.execution_context', new=None): + with mock.patch('google.cloud.sqlcommenter.opencensus.execution_context', new=None): with six.assertRaisesRegex(self, ImportError, 'opencensus is not installed'): get_opencensus_values() diff --git a/python/sqlcommenter-python/tests/psycopg2/__init__.py b/python/sqlcommenter-python/tests/psycopg2/__init__.py index fc9ebfb4..f80e041f 100644 --- a/python/sqlcommenter-python/tests/psycopg2/__init__.py +++ b/python/sqlcommenter-python/tests/psycopg2/__init__.py @@ -13,4 +13,3 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - diff --git a/python/sqlcommenter-python/tests/psycopg2/tests.py b/python/sqlcommenter-python/tests/psycopg2/tests.py index 16f3af91..dfcb58da 100644 --- a/python/sqlcommenter-python/tests/psycopg2/tests.py +++ b/python/sqlcommenter-python/tests/psycopg2/tests.py @@ -18,9 +18,8 @@ import psycopg2.extensions from forbiddenfruit import curse - -from sqlcommenter import url_quote -from sqlcommenter.psycopg2.extension import CommenterCursorFactory +from google.cloud.sqlcommenter import url_quote +from google.cloud.sqlcommenter.psycopg2.extension import CommenterCursorFactory from ..compat import mock from ..opencensus_mock import mock_opencensus_tracer @@ -89,27 +88,27 @@ class FlaskTests(Psycopg2TestCase): 'route': '/', } - @mock.patch('sqlcommenter.psycopg2.extension.get_flask_info', return_value=flask_info) + @mock.patch('google.cloud.sqlcommenter.psycopg2.extension.get_flask_info', return_value=flask_info) def test_all_data(self, get_info): self.assertSQL( "SELECT 1; /*controller='c',framework='flask',route='/'*/", ) - @mock.patch('sqlcommenter.psycopg2.extension.get_flask_info', return_value=flask_info) + @mock.patch('google.cloud.sqlcommenter.psycopg2.extension.get_flask_info', return_value=flask_info) def test_framework_disabled(self, get_info): self.assertSQL( "SELECT 1; /*controller='c',route='/'*/", with_framework=False, ) - @mock.patch('sqlcommenter.psycopg2.extension.get_flask_info', return_value=flask_info) + @mock.patch('google.cloud.sqlcommenter.psycopg2.extension.get_flask_info', return_value=flask_info) def test_controller_disabled(self, get_info): self.assertSQL( "SELECT 1; /*framework='flask',route='/'*/", with_controller=False, ) - @mock.patch('sqlcommenter.psycopg2.extension.get_flask_info', return_value=flask_info) + @mock.patch('google.cloud.sqlcommenter.psycopg2.extension.get_flask_info', return_value=flask_info) def test_route_disabled(self, get_info): self.assertSQL( "SELECT 1; /*controller='c',framework='flask'*/", diff --git a/python/sqlcommenter-python/tests/sqlalchemy/__init__.py b/python/sqlcommenter-python/tests/sqlalchemy/__init__.py index fc9ebfb4..f80e041f 100644 --- a/python/sqlcommenter-python/tests/sqlalchemy/__init__.py +++ b/python/sqlcommenter-python/tests/sqlalchemy/__init__.py @@ -13,4 +13,3 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - diff --git a/python/sqlcommenter-python/tests/sqlalchemy/tests.py b/python/sqlcommenter-python/tests/sqlalchemy/tests.py index 75f0e839..ae7239f2 100644 --- a/python/sqlcommenter-python/tests/sqlalchemy/tests.py +++ b/python/sqlcommenter-python/tests/sqlalchemy/tests.py @@ -17,8 +17,7 @@ from unittest import TestCase import sqlalchemy - -from sqlcommenter.sqlalchemy.executor import BeforeExecuteFactory +from google.cloud.sqlcommenter.sqlalchemy.executor import BeforeExecuteFactory from ..compat import mock from ..opencensus_mock import mock_opencensus_tracer @@ -78,27 +77,27 @@ class FlaskTests(SQLAlchemyTestCase): 'route': '/', } - @mock.patch('sqlcommenter.sqlalchemy.executor.get_flask_info', return_value=flask_info) + @mock.patch('google.cloud.sqlcommenter.sqlalchemy.executor.get_flask_info', return_value=flask_info) def test_all_data(self, get_info): self.assertSQL( "SELECT 1; /*controller='c',framework='flask',route='/'*/", ) - @mock.patch('sqlcommenter.sqlalchemy.executor.get_flask_info', return_value=flask_info) + @mock.patch('google.cloud.sqlcommenter.sqlalchemy.executor.get_flask_info', return_value=flask_info) def test_framework_disabled(self, get_info): self.assertSQL( "SELECT 1; /*controller='c',route='/'*/", with_framework=False, ) - @mock.patch('sqlcommenter.sqlalchemy.executor.get_flask_info', return_value=flask_info) + @mock.patch('google.cloud.sqlcommenter.sqlalchemy.executor.get_flask_info', return_value=flask_info) def test_controller_disabled(self, get_info): self.assertSQL( "SELECT 1; /*framework='flask',route='/'*/", with_controller=False, ) - @mock.patch('sqlcommenter.sqlalchemy.executor.get_flask_info', return_value=flask_info) + @mock.patch('google.cloud.sqlcommenter.sqlalchemy.executor.get_flask_info', return_value=flask_info) def test_route_disabled(self, get_info): self.assertSQL( "SELECT 1; /*controller='c',framework='flask'*/", diff --git a/python/sqlcommenter-python/tests/tests.py b/python/sqlcommenter-python/tests/tests.py index 1b58ae1c..94a49781 100644 --- a/python/sqlcommenter-python/tests/tests.py +++ b/python/sqlcommenter-python/tests/tests.py @@ -14,25 +14,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -#!/usr/bin/python -# -# Copyright 2019 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - from unittest import TestCase -from sqlcommenter import generate_sql_comment +from google.cloud.sqlcommenter import generate_sql_comment from .opencensus_mock import mock_opencensus_tracer