dry-analyst-73584
01/27/2022, 7:29 PMpymongo==3.7.1
and it's being imported as import pymongo
in a bunch of places, but for some reason when I run tests I'm getting
ImportError while importing test module '/private/var/folders/yv/1kp6r8h57p91lxsszfdppwsw0000gn/T/process-executionGbSusG/test/python/foursquare_test/mongo/lib/handles_test.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
test/python/foursquare_test/mongo/lib/handles_test.py:10: in <module>
from foursquare.mongo import mongo_ops
src/python/foursquare/mongo/mongo_ops.py:13: in <module>
import pymongo
E ImportError: No module named pymongo
It seems to be specific to that mongo_ops.py
file. Everything that depends on mongo_ops.py fails with the import error. But every other file that has import pymongo
is working fine. I can fix it by editing the BUILD file:
python_sources(
dependencies = [
"3rdparty/python:pymongo",
],
)
But it seems extremely odd that I would need to.high-yak-85899
01/27/2022, 7:30 PMrequests
dry-analyst-73584
01/27/2022, 7:31 PMhigh-yak-85899
01/27/2022, 7:32 PMrefined-addition-53644
01/27/2022, 7:35 PM./pants dependencies src/python/foursquare/mongo/mongo_ops.py
bitter-ability-32190
01/27/2022, 7:37 PMhigh-yak-85899
01/27/2022, 7:41 PMdry-analyst-73584
01/27/2022, 7:42 PMimport pymongo
and they work just fine, but this one doesn't.import pymongo
import pymongo.errors
from pymongo.thing import SomeThingElse
Which was gross, so I fixed it to only have import pymongo
I thought maybe it had cached some bad state, but I've been running it with --no-pantsd
and --no-local-cache
to check and that didn't fix it either.bitter-ability-32190
01/27/2022, 7:47 PMdry-analyst-73584
01/27/2022, 7:53 PMpython_sources()
# coding=utf-8
# Copyright 2014 Foursquare Labs Inc. All Rights Reserved.
from __future__ import absolute_import, division, print_function
import datetime
import logging
import os
import shlex
import shutil
import socket
import subprocess
import urllib2
import xmlrpclib
import argparse
import motor
import pymongo
import supervisor.supervisord
import supervisor.xmlrpc
from tornado import gen
import tornado.ioloop
import tornado.web
import toro
And are working just fine.bitter-ability-32190
01/27/2022, 7:59 PMpants
specifically for pymongo
I can reproduce on main
.import pymongo
and are working fine:
• I assume some tests are importing those files and not failing to import
• Do you know if any file in those passing tests directly or indirectly import either bson
or gridfs
?dry-analyst-73584
01/27/2022, 8:07 PMbitter-ability-32190
01/27/2022, 8:09 PMhigh-yak-85899
01/27/2022, 8:11 PMmodule_mappings
on my own locally?dry-analyst-73584
01/27/2022, 8:11 PMbitter-ability-32190
01/27/2022, 8:12 PMrequests
isn't in Pants' default list, so it isn't the same issue 😕import pymongo
.
The linked PR is Pants' list of "these packages map to these modules". It's used for cases like pyyaml
where the package name is pyyaml
but the module name is yaml
.
Before the PR, pants
though the pymongo
package only contained the modules bson
and gridfs
. So if you imported those (directly or indirectly) pymongo
would be in your tests' env.
If you didn't import either of those (and just imported pymongo
) Pants wouldn't know where pymongo
came from.dry-analyst-73584
01/27/2022, 8:17 PMhappy-kitchen-89482
01/27/2022, 8:17 PMbitter-ability-32190
01/27/2022, 8:21 PMhappy-kitchen-89482
01/27/2022, 8:47 PMhigh-yak-85899
01/27/2022, 8:48 PMdry-analyst-73584
01/27/2022, 8:49 PMdependencies=["pymongo"]
also workedhappy-kitchen-89482
01/27/2022, 8:53 PMdry-analyst-73584
01/27/2022, 8:54 PMhigh-yak-85899
01/27/2022, 8:55 PMpython_requirements()
is defined so it applies to all files. Certainly not a fix for all modules and doesn't help in the case where you make your own python_requirement
much closer to the target that consumes it.dry-analyst-73584
01/27/2022, 8:58 PMhappy-kitchen-89482
01/28/2022, 1:01 AMbitter-ability-32190
01/28/2022, 1:09 AMdry-analyst-73584
01/28/2022, 5:39 PMhappy-kitchen-89482
01/28/2022, 5:43 PM