Skip to content

Commit

Permalink
Fix some flake8 warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ronaldoussoren committed May 31, 2023
1 parent 7e3daca commit 4f53590
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
2 changes: 1 addition & 1 deletion modulegraph/find_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def find_needed_modules(
# first trim the path (of the head package),
# then convert directory name in package name,
# finally push into modulegraph.
for (dirpath, dirnames, filenames) in os.walk(path):
for dirpath, dirnames, filenames in os.walk(path):
if "__init__.py" in filenames and dirpath.startswith(path):
package = (
f
Expand Down
29 changes: 17 additions & 12 deletions modulegraph/modulegraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ def os_listdir(path):
"""
Deprecated name
"""
warnings.warn("Use zipio.listdir instead of os_listdir", DeprecationWarning)
warnings.warn(
"Use zipio.listdir instead of os_listdir", DeprecationWarning, stacklevel=2
)
return zipio.listdir(path)


Expand Down Expand Up @@ -387,14 +389,16 @@ def find_module(name, path=None):


def moduleInfoForPath(path):
for (ext, readmode, typ) in imp.get_suffixes():
for ext, readmode, typ in imp.get_suffixes():
if path.endswith(ext):
return os.path.basename(path)[: -len(ext)], readmode, typ
return None


def AddPackagePath(packagename, path):
warnings.warn("Use addPackagePath instead of AddPackagePath", DeprecationWarning)
warnings.warn(
"Use addPackagePath instead of AddPackagePath", DeprecationWarning, stacklevel=2
)

addPackagePath(packagename, path)

Expand All @@ -413,7 +417,9 @@ def addPackagePath(packagename, path):
# sys.modules at runtime by calling ReplacePackage("_xmlplus", "xml")
# before running ModuleGraph.
def ReplacePackage(oldname, newname):
warnings.warn("use replacePackage instead of ReplacePackage", DeprecationWarning)
warnings.warn(
"use replacePackage instead of ReplacePackage", DeprecationWarning, stacklevel=2
)
replacePackage(oldname, newname)


Expand Down Expand Up @@ -660,6 +666,7 @@ def __init__(self, *args, **kwds):
warnings.warn(
"This class will be removed in a future version of modulegraph",
DeprecationWarning,
stacklevel=2,
)
super(FlatPackage, *args, **kwds)

Expand All @@ -669,6 +676,7 @@ def __init__(self, *args, **kwds):
warnings.warn(
"This class will be removed in a future version of modulegraph",
DeprecationWarning,
stacklevel=2,
)
super(FlatPackage, *args, **kwds)

Expand Down Expand Up @@ -742,7 +750,6 @@ def in_tryexcept(self):
return self._in_tryexcept[-1]

def _process_import(self, name, fromlist, level):

if sys.version_info[0] == 2:
if name == "__future__" and "absolute_import" in (fromlist or ()):
self._level = 0
Expand Down Expand Up @@ -978,8 +985,8 @@ def getReferers(self, tonode, collapse_missing_modules=True):
if collapse_missing_modules:
for n in in_edges:
if isinstance(n, MissingModule):
for n in self.getReferers(n, False):
yield n
for r in self.getReferers(n, False):
yield r

else:
yield n
Expand Down Expand Up @@ -1828,7 +1835,6 @@ def _scan_bytecode_stores(
HAVE_ARGUMENT=_Bchr(dis.HAVE_ARGUMENT), # noqa: M511,B008
unpack=struct.unpack,
):

code = co.co_code
constants = co.co_consts
n = len(code)
Expand Down Expand Up @@ -1863,7 +1869,6 @@ def _scan_bytecode(
STORE_GLOBAL=_Bchr(dis.opname.index("STORE_GLOBAL")), # noqa: M511,B008
unpack=struct.unpack,
):

# Python >=2.5: LOAD_CONST flags, LOAD_CONST names, IMPORT_NAME name
# Python < 2.5: LOAD_CONST names, IMPORT_NAME name
extended_import = bool(sys.version_info[:2] >= (2, 5))
Expand Down Expand Up @@ -2101,15 +2106,15 @@ def edgevisitor(edge, data, head, tail):
yield "\t%s;\n" % (cpatt % item,)

# find all packages (subgraphs)
for (node, data, _outgoing, _incoming) in nodes:
for node, data, _outgoing, _incoming in nodes:
nodetoident[node] = getattr(data, "identifier", None)
if isinstance(data, Package):
packageidents[data.identifier] = node
inpackages[node] = {node}
packagenodes.add(node)

# create sets for subgraph, write out descriptions
for (node, data, outgoing, incoming) in nodes:
for node, data, outgoing, incoming in nodes:
# update edges
for edge in (describe_edge(e) for e in outgoing):
edges.append(edge)
Expand Down Expand Up @@ -2169,7 +2174,7 @@ def edgevisitor(edge, data, head, tail):
def do_graph(edges, tabs):
edgestr = tabs + '"%s" -> "%s" [%s];\n'
# describe edge
for (edge, data, head, tail) in edges:
for edge, data, head, tail in edges:
attribs = edgevisitor(edge, data, head, tail)
yield edgestr % (
head,
Expand Down
7 changes: 4 additions & 3 deletions modulegraph/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ def imp_walk(name):
raise ImportError if a name can not be found.
"""
warnings.warn("imp_walk will be removed in a future version", DeprecationWarning)
warnings.warn(
"imp_walk will be removed in a future version", DeprecationWarning, stacklevel=2
)

if name in sys.builtin_module_names:
yield name, (None, None, ("", "", imp.C_BUILTIN))
Expand Down Expand Up @@ -112,15 +114,14 @@ def imp_walk(name):
raise ImportError("No module named %s" % (name,))


cookie_re = re.compile(br"coding[:=]\s*([-\w.]+)")
cookie_re = re.compile(rb"coding[:=]\s*([-\w.]+)")
if sys.version_info[0] == 2:
default_encoding = "ascii"
else:
default_encoding = "utf-8"


def guess_encoding(fp):

for _i in range(2):
ln = fp.readline()

Expand Down

0 comments on commit 4f53590

Please sign in to comment.