From 6e0bafea6fb5d9cde3ef689439c832b4febfd36f Mon Sep 17 00:00:00 2001 From: Mojtaba Komeili Date: Tue, 30 Aug 2022 16:46:26 -0400 Subject: [PATCH 1/9] adding the new function name --- .../providers/mturk/utils/script_utils.py | 41 +++++++++++++------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/mephisto/abstractions/providers/mturk/utils/script_utils.py b/mephisto/abstractions/providers/mturk/utils/script_utils.py index 6de93c5e0..131b4657b 100644 --- a/mephisto/abstractions/providers/mturk/utils/script_utils.py +++ b/mephisto/abstractions/providers/mturk/utils/script_utils.py @@ -11,22 +11,24 @@ from mephisto.data_model.requester import Requester from mephisto.data_model.unit import Unit from tqdm import tqdm # type: ignore +from mephisto.utils.logger_core import get_logger + +logging = get_logger(name=__name__) if TYPE_CHECKING: from mephisto.abstractions.database import MephistoDB -def direct_soft_block_mturk_workers( +def direct_assign_qual_mturk_workers( db: "MephistoDB", worker_list: List[str], - soft_block_qual_name: str, + qual_name: str, requester_name: Optional[str] = None, ): """ - Directly assign the soft blocking MTurk qualification that Mephisto - associates with soft_block_qual_name to all of the MTurk worker ids - in worker_list. If requester_name is not provided, it will use the - most recently registered mturk requester in the database. + Directly assign MTurk qualification that Mephisto associates with qual_name + to all of the MTurk worker ids in worker_list. If requester_name is not provided, + it will use the most recently registered mturk requester in the database. """ reqs = db.find_requesters(requester_name=requester_name, provider_type="mturk") requester = reqs[-1] @@ -35,21 +37,19 @@ def direct_soft_block_mturk_workers( requester, MTurkRequester ), "Can only direct soft block mturk workers from mturk requester" - mturk_qual_details = requester.datastore.get_qualification_mapping( - soft_block_qual_name - ) + mturk_qual_details = requester.datastore.get_qualification_mapping(qual_name) if mturk_qual_details is not None: # Overrule the requester, as this qualification already exists requester = Requester.get(db, mturk_qual_details["requester_id"]) qualification_id = mturk_qual_details["mturk_qualification_id"] else: qualification_id = requester._create_new_mturk_qualification( - soft_block_qual_name + qual_name ) assert isinstance( requester, MTurkRequester - ), "Can only direct soft block mturk workers from mturk requester" + ), "Can only direct assign qualification (soft block) mturk workers from mturk requester" mturk_client = requester._get_client(requester._requester_name) for worker_id in tqdm(worker_list): try: @@ -57,10 +57,27 @@ def direct_soft_block_mturk_workers( mturk_client, worker_id, qualification_id, value=1 ) except Exception as e: - print( + logger.exception( f'Failed to give worker with ID: "{worker_id}" qualification with error: {e}. Skipping.' ) +def direct_soft_block_mturk_workers( + db: "MephistoDB", + worker_list: List[str], + soft_block_qual_name: str, + requester_name: Optional[str] = None, +): + """ + Directly assign the soft blocking MTurk qualification that Mephisto + associates with soft_block_qual_name to all of the MTurk worker ids + in worker_list. If requester_name is not provided, it will use the + most recently registered mturk requester in the database. + """ + direct_assign_qual_mturk_workers(db=db, + worker_list=worker_list, + qual_name=soft_block_qual_name, + requester_name=requester_name) + def get_mturk_ids_from_unit_id(db, unit_id: str) -> Dict[str, Optional[str]]: """ From de64aff30d1635044d06fbb155d11ea580a51817 Mon Sep 17 00:00:00 2001 From: Mojtaba <11262163+mojtaba-komeili@users.noreply.github.com> Date: Tue, 30 Aug 2022 17:18:40 -0400 Subject: [PATCH 2/9] pre-commit install While retrying this step, realized that we need `pip install pre-commit` if it is not already installed. --- CONTRIBUTING.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 91861bda6..1ef299b00 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -12,7 +12,7 @@ We actively welcome your pull requests. 3. If you've changed APIs, update the documentation. 4. Ensure the test suite passes. 5. Make sure your code lints. - * This can be done by running `pre-commit install`. This will check the if your code is formatted correctly on each commit. + * This can be done by running `pip install pre-commit; pre-commit install`. This will check the if your code is formatted correctly on each commit. * Make sure that pre-commit is installed by following the steps in [this website](https://pre-commit.com/). 6. If you haven't already, complete the Contributor License Agreement ("CLA"). @@ -80,4 +80,4 @@ By contributing to Mephisto, you agree that your contributions will be licensed under the LICENSE file in the root directory of this source tree. ## Dependencies -To add a python dependency you need to add the dependency as well as its version number to the pyproject.toml file. \ No newline at end of file +To add a python dependency you need to add the dependency as well as its version number to the pyproject.toml file. From 278e88af18ef75b39fa1dfa5d3d6c06a797945fc Mon Sep 17 00:00:00 2001 From: Mojtaba Date: Tue, 30 Aug 2022 14:21:37 -0700 Subject: [PATCH 3/9] lint --- .../providers/mturk/utils/script_utils.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/mephisto/abstractions/providers/mturk/utils/script_utils.py b/mephisto/abstractions/providers/mturk/utils/script_utils.py index 131b4657b..7836b2119 100644 --- a/mephisto/abstractions/providers/mturk/utils/script_utils.py +++ b/mephisto/abstractions/providers/mturk/utils/script_utils.py @@ -43,9 +43,7 @@ def direct_assign_qual_mturk_workers( requester = Requester.get(db, mturk_qual_details["requester_id"]) qualification_id = mturk_qual_details["mturk_qualification_id"] else: - qualification_id = requester._create_new_mturk_qualification( - qual_name - ) + qualification_id = requester._create_new_mturk_qualification(qual_name) assert isinstance( requester, MTurkRequester @@ -57,10 +55,11 @@ def direct_assign_qual_mturk_workers( mturk_client, worker_id, qualification_id, value=1 ) except Exception as e: - logger.exception( + logging.exception( f'Failed to give worker with ID: "{worker_id}" qualification with error: {e}. Skipping.' ) + def direct_soft_block_mturk_workers( db: "MephistoDB", worker_list: List[str], @@ -73,10 +72,12 @@ def direct_soft_block_mturk_workers( in worker_list. If requester_name is not provided, it will use the most recently registered mturk requester in the database. """ - direct_assign_qual_mturk_workers(db=db, + direct_assign_qual_mturk_workers( + db=db, worker_list=worker_list, qual_name=soft_block_qual_name, - requester_name=requester_name) + requester_name=requester_name, + ) def get_mturk_ids_from_unit_id(db, unit_id: str) -> Dict[str, Optional[str]]: From 4f935bf21133b9cbe2d745483a4dc72e7f6f5b34 Mon Sep 17 00:00:00 2001 From: Jack Urbanek Date: Wed, 31 Aug 2022 16:45:00 -0400 Subject: [PATCH 4/9] Removing threadsafety as we already lock connections behind threads --- mephisto/abstractions/databases/local_database.py | 2 +- mephisto/abstractions/providers/mock/mock_datastore.py | 2 +- mephisto/abstractions/providers/mturk/mturk_datastore.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mephisto/abstractions/databases/local_database.py b/mephisto/abstractions/databases/local_database.py index 182e29687..3c3e35069 100644 --- a/mephisto/abstractions/databases/local_database.py +++ b/mephisto/abstractions/databases/local_database.py @@ -254,7 +254,7 @@ def _get_connection(self) -> Connection: curr_thread = threading.get_ident() if curr_thread not in self.conn or self.conn[curr_thread] is None: try: - conn = sqlite3.connect(self.db_path) + conn = sqlite3.connect(self.db_path, check_same_thread=False) conn.row_factory = StringIDRow self.conn[curr_thread] = conn except sqlite3.Error as e: diff --git a/mephisto/abstractions/providers/mock/mock_datastore.py b/mephisto/abstractions/providers/mock/mock_datastore.py index 05d456525..e28503eb6 100644 --- a/mephisto/abstractions/providers/mock/mock_datastore.py +++ b/mephisto/abstractions/providers/mock/mock_datastore.py @@ -54,7 +54,7 @@ def _get_connection(self) -> sqlite3.Connection: """ curr_thread = threading.get_ident() if curr_thread not in self.conn or self.conn[curr_thread] is None: - conn = sqlite3.connect(self.db_path) + conn = sqlite3.connect(self.db_path, check_same_thread=False) conn.row_factory = sqlite3.Row self.conn[curr_thread] = conn return self.conn[curr_thread] diff --git a/mephisto/abstractions/providers/mturk/mturk_datastore.py b/mephisto/abstractions/providers/mturk/mturk_datastore.py index 801a9fb9e..d874127af 100644 --- a/mephisto/abstractions/providers/mturk/mturk_datastore.py +++ b/mephisto/abstractions/providers/mturk/mturk_datastore.py @@ -92,7 +92,7 @@ def _get_connection(self) -> sqlite3.Connection: """ curr_thread = threading.get_ident() if curr_thread not in self.conn or self.conn[curr_thread] is None: - conn = sqlite3.connect(self.db_path) + conn = sqlite3.connect(self.db_path, check_same_thread=False) conn.row_factory = sqlite3.Row self.conn[curr_thread] = conn return self.conn[curr_thread] From 78fcafdffb8bd72c171e1237a67a28b1b5e39a53 Mon Sep 17 00:00:00 2001 From: Jack Urbanek Date: Thu, 1 Sep 2022 11:38:19 -0400 Subject: [PATCH 5/9] testing cypress fix --- .github/workflows/cypress-end-to-end-tests.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/cypress-end-to-end-tests.yml b/.github/workflows/cypress-end-to-end-tests.yml index 383d0956d..699df68e8 100644 --- a/.github/workflows/cypress-end-to-end-tests.yml +++ b/.github/workflows/cypress-end-to-end-tests.yml @@ -71,7 +71,7 @@ jobs: uses: actions/setup-python@v2 - name: 🪨 Setup Node - uses: actions/setup-node@v1 + uses: actions/setup-node@v3 with: node-version: 16 @@ -116,7 +116,7 @@ jobs: uses: actions/setup-python@v2 - name: 🪨 Setup Node - uses: actions/setup-node@v1 + uses: actions/setup-node@v3 with: node-version: 16 @@ -161,7 +161,7 @@ jobs: uses: actions/setup-python@v2 - name: 🪨 Setup Node - uses: actions/setup-node@v1 + uses: actions/setup-node@v3 with: node-version: 16 @@ -205,7 +205,7 @@ jobs: uses: actions/setup-python@v2 - name: 🪨 Setup Node - uses: actions/setup-node@v1 + uses: actions/setup-node@v3 with: node-version: 16 @@ -251,7 +251,7 @@ jobs: uses: actions/setup-python@v2 - name: 🪨 Setup Node - uses: actions/setup-node@v1 + uses: actions/setup-node@v3 with: node-version: 16 @@ -295,7 +295,7 @@ jobs: uses: actions/setup-python@v2 - name: 🪨 Setup Node - uses: actions/setup-node@v1 + uses: actions/setup-node@v3 with: node-version: 16 From 99ebf5394deb3d5429dae5f86c3712a98f80c8b3 Mon Sep 17 00:00:00 2001 From: Jack Urbanek Date: Thu, 1 Sep 2022 11:55:01 -0400 Subject: [PATCH 6/9] testing cypress fix --- .github/workflows/cypress-end-to-end-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cypress-end-to-end-tests.yml b/.github/workflows/cypress-end-to-end-tests.yml index 699df68e8..b314083ae 100644 --- a/.github/workflows/cypress-end-to-end-tests.yml +++ b/.github/workflows/cypress-end-to-end-tests.yml @@ -253,7 +253,7 @@ jobs: - name: 🪨 Setup Node uses: actions/setup-node@v3 with: - node-version: 16 + node-version: 16.16.0 - name: 🤖 Install Mephisto run: pip install -e . From 9dac9bcffbd90582d222acb06be1b1d3c85e975b Mon Sep 17 00:00:00 2001 From: Jack Urbanek Date: Thu, 1 Sep 2022 12:02:01 -0400 Subject: [PATCH 7/9] testing cypress fix --- .github/workflows/cypress-end-to-end-tests.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/cypress-end-to-end-tests.yml b/.github/workflows/cypress-end-to-end-tests.yml index b314083ae..5816894b4 100644 --- a/.github/workflows/cypress-end-to-end-tests.yml +++ b/.github/workflows/cypress-end-to-end-tests.yml @@ -73,7 +73,7 @@ jobs: - name: 🪨 Setup Node uses: actions/setup-node@v3 with: - node-version: 16 + node-version: 16.16.0 - name: 🤖 Install Mephisto run: pip install -e . @@ -118,7 +118,7 @@ jobs: - name: 🪨 Setup Node uses: actions/setup-node@v3 with: - node-version: 16 + node-version: 16.16.0 - name: 🤖 Install Mephisto run: pip install -e . @@ -163,7 +163,7 @@ jobs: - name: 🪨 Setup Node uses: actions/setup-node@v3 with: - node-version: 16 + node-version: 16.16.0 - name: 🤖 Install Mephisto run: pip install -e . @@ -207,7 +207,7 @@ jobs: - name: 🪨 Setup Node uses: actions/setup-node@v3 with: - node-version: 16 + node-version: 16.16.0 - name: 🤖 Install Mephisto run: | @@ -297,7 +297,7 @@ jobs: - name: 🪨 Setup Node uses: actions/setup-node@v3 with: - node-version: 16 + node-version: 16.16.0 - name: 🤖 Install Mephisto run: | From a8d9bf9940a3b3704598ec31b1dbfc52b4917bf5 Mon Sep 17 00:00:00 2001 From: Mojtaba Komeili Date: Tue, 30 Aug 2022 16:46:26 -0400 Subject: [PATCH 8/9] adding the new function name --- .../providers/mturk/utils/script_utils.py | 41 +++++++++++++------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/mephisto/abstractions/providers/mturk/utils/script_utils.py b/mephisto/abstractions/providers/mturk/utils/script_utils.py index 6de93c5e0..131b4657b 100644 --- a/mephisto/abstractions/providers/mturk/utils/script_utils.py +++ b/mephisto/abstractions/providers/mturk/utils/script_utils.py @@ -11,22 +11,24 @@ from mephisto.data_model.requester import Requester from mephisto.data_model.unit import Unit from tqdm import tqdm # type: ignore +from mephisto.utils.logger_core import get_logger + +logging = get_logger(name=__name__) if TYPE_CHECKING: from mephisto.abstractions.database import MephistoDB -def direct_soft_block_mturk_workers( +def direct_assign_qual_mturk_workers( db: "MephistoDB", worker_list: List[str], - soft_block_qual_name: str, + qual_name: str, requester_name: Optional[str] = None, ): """ - Directly assign the soft blocking MTurk qualification that Mephisto - associates with soft_block_qual_name to all of the MTurk worker ids - in worker_list. If requester_name is not provided, it will use the - most recently registered mturk requester in the database. + Directly assign MTurk qualification that Mephisto associates with qual_name + to all of the MTurk worker ids in worker_list. If requester_name is not provided, + it will use the most recently registered mturk requester in the database. """ reqs = db.find_requesters(requester_name=requester_name, provider_type="mturk") requester = reqs[-1] @@ -35,21 +37,19 @@ def direct_soft_block_mturk_workers( requester, MTurkRequester ), "Can only direct soft block mturk workers from mturk requester" - mturk_qual_details = requester.datastore.get_qualification_mapping( - soft_block_qual_name - ) + mturk_qual_details = requester.datastore.get_qualification_mapping(qual_name) if mturk_qual_details is not None: # Overrule the requester, as this qualification already exists requester = Requester.get(db, mturk_qual_details["requester_id"]) qualification_id = mturk_qual_details["mturk_qualification_id"] else: qualification_id = requester._create_new_mturk_qualification( - soft_block_qual_name + qual_name ) assert isinstance( requester, MTurkRequester - ), "Can only direct soft block mturk workers from mturk requester" + ), "Can only direct assign qualification (soft block) mturk workers from mturk requester" mturk_client = requester._get_client(requester._requester_name) for worker_id in tqdm(worker_list): try: @@ -57,10 +57,27 @@ def direct_soft_block_mturk_workers( mturk_client, worker_id, qualification_id, value=1 ) except Exception as e: - print( + logger.exception( f'Failed to give worker with ID: "{worker_id}" qualification with error: {e}. Skipping.' ) +def direct_soft_block_mturk_workers( + db: "MephistoDB", + worker_list: List[str], + soft_block_qual_name: str, + requester_name: Optional[str] = None, +): + """ + Directly assign the soft blocking MTurk qualification that Mephisto + associates with soft_block_qual_name to all of the MTurk worker ids + in worker_list. If requester_name is not provided, it will use the + most recently registered mturk requester in the database. + """ + direct_assign_qual_mturk_workers(db=db, + worker_list=worker_list, + qual_name=soft_block_qual_name, + requester_name=requester_name) + def get_mturk_ids_from_unit_id(db, unit_id: str) -> Dict[str, Optional[str]]: """ From bc4a1f72c4cb3d500f7eb47e4cba4c3d3d9a68c0 Mon Sep 17 00:00:00 2001 From: Mojtaba Date: Tue, 30 Aug 2022 14:21:37 -0700 Subject: [PATCH 9/9] lint --- .../providers/mturk/utils/script_utils.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/mephisto/abstractions/providers/mturk/utils/script_utils.py b/mephisto/abstractions/providers/mturk/utils/script_utils.py index 131b4657b..7836b2119 100644 --- a/mephisto/abstractions/providers/mturk/utils/script_utils.py +++ b/mephisto/abstractions/providers/mturk/utils/script_utils.py @@ -43,9 +43,7 @@ def direct_assign_qual_mturk_workers( requester = Requester.get(db, mturk_qual_details["requester_id"]) qualification_id = mturk_qual_details["mturk_qualification_id"] else: - qualification_id = requester._create_new_mturk_qualification( - qual_name - ) + qualification_id = requester._create_new_mturk_qualification(qual_name) assert isinstance( requester, MTurkRequester @@ -57,10 +55,11 @@ def direct_assign_qual_mturk_workers( mturk_client, worker_id, qualification_id, value=1 ) except Exception as e: - logger.exception( + logging.exception( f'Failed to give worker with ID: "{worker_id}" qualification with error: {e}. Skipping.' ) + def direct_soft_block_mturk_workers( db: "MephistoDB", worker_list: List[str], @@ -73,10 +72,12 @@ def direct_soft_block_mturk_workers( in worker_list. If requester_name is not provided, it will use the most recently registered mturk requester in the database. """ - direct_assign_qual_mturk_workers(db=db, + direct_assign_qual_mturk_workers( + db=db, worker_list=worker_list, qual_name=soft_block_qual_name, - requester_name=requester_name) + requester_name=requester_name, + ) def get_mturk_ids_from_unit_id(db, unit_id: str) -> Dict[str, Optional[str]]: