Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
else:
contents = []
for child in directory.children:
if child.ext == '.py':
contents.append(read_file(child.path, package))
elif child.is_package:
if package is not None:
sub_package_name = '%s.%s' % (package.name, child.name)
sub_package = Package(
filename=child.path, name=sub_package_name, parent=package
)
else:
sub_package = Package(filename=child.path, name=child.name)
read_directory(child.path, sub_package)
contents.append(sub_package)
return contents
if package is not None:
contents = package.contents
else:
contents = []
for child in directory.children:
# If the child is a Python file then parse it.
if child.ext == '.py':
contents.append(self.read_file(child.path, package))
# If the child is a sub-package then recurse!
elif child.is_package:
if package is not None:
sub_package_name = '%s.%s' % (package.name, child.name)
sub_package = Package(
filename = child.path,
name = sub_package_name,
parent = package
)
else:
sub_package = Package(filename=child.path, name=child.name)
self.read_directory(child.path, sub_package)
contents.append(sub_package)
return contents
raise ValueError("%s is NOT a directory." % filename)
if package is not None:
contents = package.contents
else:
contents = []
for child in directory.children:
if child.ext == '.py':
contents.append(read_file(child.path, package))
elif child.is_package:
if package is not None:
sub_package_name = '%s.%s' % (package.name, child.name)
sub_package = Package(
filename=child.path, name=sub_package_name, parent=package
)
else:
sub_package = Package(filename=child.path, name=child.name)
read_directory(child.path, sub_package)
contents.append(sub_package)
return contents
# If the child is a Python file then parse it.
if child.ext == '.py':
contents.append(self.read_file(child.path, package))
# If the child is a sub-package then recurse!
elif child.is_package:
if package is not None:
sub_package_name = '%s.%s' % (package.name, child.name)
sub_package = Package(
filename = child.path,
name = sub_package_name,
parent = package
)
else:
sub_package = Package(filename=child.path, name=child.name)
self.read_directory(child.path, sub_package)
contents.append(sub_package)
return contents