Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_complete(self):
directory = resource_filename(
__name__, os.path.join("testdata", "distributions")
)
for filename in os.listdir(directory):
if filename.startswith("complete"):
data = distributiondata.get_data(os.path.join(directory, filename))
self.assertEqual(data, COMPLETE)
data["_source_download"] = False
data["_setuptools"] = None # Mark as unknown, in case no sdist is found.
data["_has_sdist"] = False
for download in urls:
if download["packagetype"] == "sdist":
# Found a source distribution. Download and analyze it.
data["_has_sdist"] = True
tempdir = tempfile.gettempdir()
filename = download["url"].split("/")[-1]
tmp = os.path.join(tempdir, filename)
logging.debug("Downloading %s to verify distribution" % filename)
try:
with open(tmp, "wb") as outfile:
outfile.write(urllib.urlopen(download["url"]).read())
ddata = distributiondata.get_data(tmp)
except Exception:
# Clean up the file
os.unlink(tmp)
raise
# Combine them, with the PyPI data winning:
ddata.update(data)
data = ddata
data["_source_download"] = True
break
return data
def run(mode, argument):
logging.info("-" * 30)
logging.info("Checking " + argument)
if mode == "directory":
data = projectdata.get_data(os.path.abspath(argument))
logging.info("Found " + data.get("name", "nothing"))
elif mode == "file":
data = distributiondata.get_data(os.path.abspath(argument))
logging.info("Found " + data.get("name", "nothing"))
else:
# It's probably a package name
data = pypidata.get_data(argument)
logging.info("Found " + data.get("name", "nothing"))
rating = ratings.rate(data)
logging.info("-" * 30)
for problem in rating[1]:
# XXX It would be nice with a * pointlist instead, but that requires
# that we know how wide the terminal is and nice word-breaks, so that's
# for later.
logging.info(problem)
if rating[1]:
logging.info("-" * 30)