本文整理汇总了Python中nuitka.Utils.isDir方法的典型用法代码示例。如果您正苦于以下问题:Python Utils.isDir方法的具体用法?Python Utils.isDir怎么用?Python Utils.isDir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nuitka.Utils
的用法示例。
在下文中一共展示了Utils.isDir方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: considerImplicitImports
# 需要导入模块: from nuitka import Utils [as 别名]
# 或者: from nuitka.Utils import isDir [as 别名]
def considerImplicitImports(self, signal_change):
for module_name, module_package in self.getImplicitImports():
_module_package, _module_name, module_filename = \
Importing.findModule(
source_ref = self.source_ref,
module_name = module_name,
parent_package = module_package,
level = -1,
warn = True
)
if module_filename is None:
sys.exit(
"Error, implicit module '%s' expected by '%s' not found" % (
module_name,
self.getFullName()
)
)
elif Utils.isDir(module_filename):
module_kind = "py"
elif module_filename.endswith(".py"):
module_kind = "py"
elif module_filename.endswith(".so"):
module_kind = "shlib"
elif module_filename.endswith(".pyd"):
module_kind = "shlib"
else:
assert False, module_filename
from nuitka.tree import Recursion
decision, reason = Recursion.decideRecursion(
module_filename = module_filename,
module_name = module_name,
module_package = module_package,
module_kind = module_kind
)
assert decision or reason == "Module is frozen."
if decision:
module_relpath = Utils.relpath(module_filename)
imported_module, added_flag = Recursion.recurseTo(
module_package = module_package,
module_filename = module_filename,
module_relpath = module_relpath,
module_kind = module_kind,
reason = reason
)
from nuitka.ModuleRegistry import addUsedModule
addUsedModule(imported_module)
if added_flag:
signal_change(
"new_code",
imported_module.getSourceReference(),
"Recursed to module."
)
示例2: checkPluginPath
# 需要导入模块: from nuitka import Utils [as 别名]
# 或者: from nuitka.Utils import isDir [as 别名]
def checkPluginPath(plugin_filename, module_package):
debug(
"Checking top level plugin path %s %s",
plugin_filename,
module_package
)
plugin_info = considerFilename(
module_package = module_package,
module_filename = plugin_filename
)
if plugin_info is not None:
# File or package makes a difference, handle that
if Utils.isFile(plugin_info[0]) or \
Importing.isPackageDir(plugin_info[0]):
_checkPluginPath(plugin_filename, module_package)
elif Utils.isDir(plugin_info[0]):
for sub_path, sub_filename in Utils.listDir(plugin_info[0]):
assert sub_filename != "__init__.py"
if Importing.isPackageDir(sub_path) or \
sub_path.endswith(".py"):
_checkPluginPath(sub_path, None)
else:
warning("Failed to include module from '%s'.", plugin_info[0])
else:
warning("Failed to recurse to directory '%s'.", plugin_filename)
示例3: checkPluginPath
# 需要导入模块: from nuitka import Utils [as 别名]
# 或者: from nuitka.Utils import isDir [as 别名]
def checkPluginPath( plugin_filename, module_package ):
plugin_info = considerFilename(
module_package = module_package,
module_filename = plugin_filename
)
if plugin_info is not None:
# File or package, handle that.
if Utils.isFile( plugin_info[0] ) or Importing.isPackageDir( plugin_info[0] ):
_checkPluginPath( plugin_filename, module_package )
elif Utils.isDir( plugin_info[0] ):
for sub_path, sub_filename in Utils.listDir( plugin_info[0] ):
assert sub_filename != "__init__.py"
if Importing.isPackageDir( sub_path ) or sub_path.endswith( ".py" ):
_checkPluginPath( sub_path, None )
else:
warning( "Failed to include module from '%s'.", plugin_info[0] )
示例4: _consider
# 需要导入模块: from nuitka import Utils [as 别名]
# 或者: from nuitka.Utils import isDir [as 别名]
def _consider( self, constraint_collection, module_filename, module_package ):
assert module_package is None or ( type( module_package ) is str and module_package != "" )
module_filename = Utils.normpath( module_filename )
if Utils.isDir( module_filename ):
module_name = Utils.basename( module_filename )
elif module_filename.endswith( ".py" ):
module_name = Utils.basename( module_filename )[:-3]
else:
module_name = None
if module_name is not None:
decision = self._decide( module_filename, module_name, module_package )
if decision:
module_relpath = Utils.relpath( module_filename )
return self._recurseTo(
constraint_collection = constraint_collection,
module_package = module_package,
module_filename = module_filename,
module_relpath = module_relpath
)
elif decision is None:
if module_package is None:
module_fullpath = module_name
else:
module_fullpath = module_package + "." + module_name
if module_filename not in self._warned_about:
self._warned_about.add( module_filename )
warning( # long message, but shall be like it, pylint: disable=C0301
"""\
Not recursing to '%(full_path)s' (%(filename)s), please specify \
--recurse-none (do not warn), \
--recurse-all (recurse to all), \
--recurse-not-to=%(full_path)s (ignore it), \
--recurse-to=%(full_path)s (recurse to it) to change.""" % {
"full_path" : module_fullpath,
"filename" : module_filename
}
)
示例5: considerFilename
# 需要导入模块: from nuitka import Utils [as 别名]
# 或者: from nuitka.Utils import isDir [as 别名]
def considerFilename( module_filename, module_package ):
assert module_package is None or ( type( module_package ) is str and module_package != "" )
module_filename = Utils.normpath( module_filename )
if Utils.isDir( module_filename ):
module_filename = Utils.abspath( module_filename )
module_name = Utils.basename( module_filename )
module_relpath = Utils.relpath( module_filename )
return module_filename, module_relpath, module_name
elif module_filename.endswith( ".py" ):
module_name = Utils.basename( module_filename )[:-3]
module_relpath = Utils.relpath( module_filename )
return module_filename, module_relpath, module_name
else:
return None
示例6: _checkPluginPath
# 需要导入模块: from nuitka import Utils [as 别名]
# 或者: from nuitka.Utils import isDir [as 别名]
def _checkPluginPath(plugin_filename, module_package):
debug(
"Checking detail plugin path %s %s",
plugin_filename,
module_package
)
plugin_info = considerFilename(
module_package = module_package,
module_filename = plugin_filename
)
if plugin_info is not None:
module, is_added = recurseTo(
module_filename = plugin_info[0],
module_relpath = plugin_info[1],
module_package = module_package,
module_kind = "py",
reason = "Lives in plugin directory."
)
if module:
if not is_added:
warning(
"Recursed to %s '%s' at '%s' twice.",
"package" if module.isPythonPackage() else "module",
module.getName(),
plugin_info[0]
)
if not isSameModulePath(module.getFilename(), plugin_info[0]):
warning(
"Duplicate ignored '%s'.",
plugin_info[1]
)
return
debug(
"Recursed to %s %s %s",
module.getName(),
module.getPackage(),
module
)
if module.isPythonPackage():
package_filename = module.getFilename()
if Utils.isDir(package_filename):
# Must be a namespace package.
assert Utils.python_version >= 330
package_dir = package_filename
# Only include it, if it contains actual modules, which will
# recurse to this one and find it again.
useful = False
else:
package_dir = Utils.dirname(package_filename)
# Real packages will always be included.
useful = True
debug(
"Package directory %s",
package_dir
)
for sub_path, sub_filename in Utils.listDir(package_dir):
if sub_filename in ("__init__.py", "__pycache__"):
continue
assert sub_path != plugin_filename
if Importing.isPackageDir(sub_path) or \
sub_path.endswith(".py"):
_checkPluginPath(sub_path, module.getFullName())
else:
# Modules should always be included.
useful = True
if useful:
ModuleRegistry.addRootModule(module)
else:
warning( "Failed to include module from '%s'.", plugin_info[0] )
示例7: _consider
# 需要导入模块: from nuitka import Utils [as 别名]
# 或者: from nuitka.Utils import isDir [as 别名]
def _consider(self, constraint_collection, module_filename, module_package):
assert module_package is None or \
(type(module_package) is str and module_package != "")
module_filename = Utils.normpath(module_filename)
if Utils.isDir(module_filename):
module_name = Utils.basename(module_filename)
module_kind = "py"
elif module_filename.endswith(".py"):
module_name = Utils.basename(module_filename)[:-3]
module_kind = "py"
elif module_filename.endswith(".so"):
module_kind = "shlib"
module_name = Utils.basename(module_filename)[:-3]
elif module_filename.endswith(".pyd"):
module_kind = "shlib"
module_name = Utils.basename(module_filename)[:-4]
else:
module_kind = None
module_name = None
if module_kind is not None:
from nuitka.tree import Recursion
decision, reason = Recursion.decideRecursion(
module_filename = module_filename,
module_name = module_name,
module_package = module_package,
module_kind = module_kind
)
if decision:
module_relpath = Utils.relpath(module_filename)
imported_module, added_flag = Recursion.recurseTo(
module_package = module_package,
module_filename = module_filename,
module_relpath = module_relpath,
module_kind = module_kind,
reason = reason
)
if added_flag:
constraint_collection.signalChange(
"new_code",
imported_module.getSourceReference(),
"Recursed to module."
)
return imported_module
elif decision is None and module_kind == "py":
if module_package is None:
module_fullpath = module_name
else:
module_fullpath = module_package + "." + module_name
if module_filename not in self._warned_about and \
module_fullpath not in getModuleWhiteList():
self._warned_about.add(module_filename)
warning(
"""\
Not recursing to '%(full_path)s' (%(filename)s), please specify \
--recurse-none (do not warn), \
--recurse-all (recurse to all), \
--recurse-not-to=%(full_path)s (ignore it), \
--recurse-to=%(full_path)s (recurse to it) to change.""" % {
"full_path" : module_fullpath,
"filename" : module_filename
}
)
示例8: buildModuleTree
# 需要导入模块: from nuitka import Utils [as 别名]
# 或者: from nuitka.Utils import isDir [as 别名]
def buildModuleTree( filename, package, is_top, is_main ):
# Many variables, branches, due to the many cases, pylint: disable=R0912
assert package is None or type( package ) is str
if is_main and Utils.isDir( filename ):
source_filename = Utils.joinpath( filename, "__main__.py" )
if not Utils.isFile( source_filename ):
sys.stderr.write(
"%s: can't find '__main__' module in '%s'\n" % (
Utils.basename( sys.argv[0] ),
filename
)
)
sys.exit( 2 )
filename = source_filename
main_added = True
else:
main_added = False
if Utils.isFile( filename ):
source_filename = filename
source_ref = SourceCodeReferences.fromFilename(
filename = filename,
future_spec = FutureSpec()
)
if is_main:
module_name = "__main__"
else:
module_name = Utils.basename( filename )
if module_name.endswith( ".py" ):
module_name = module_name[:-3]
if "." in module_name:
sys.stderr.write(
"Error, '%s' is not a proper python module name.\n" % (
module_name
)
)
sys.exit( 2 )
if is_main:
result = PythonMainModule(
source_ref = source_ref,
main_added = main_added
)
else:
result = PythonModule(
name = module_name,
package = package,
source_ref = source_ref
)
elif Utils.isDir( filename ) and Utils.isFile( Utils.joinpath( filename, "__init__.py" ) ):
source_filename = Utils.joinpath( filename, "__init__.py" )
if is_top:
source_ref = SourceCodeReferences.fromFilename(
filename = Utils.abspath( source_filename ),
future_spec = FutureSpec()
)
package_name = Utils.splitpath( filename )[-1]
else:
source_ref = SourceCodeReferences.fromFilename(
filename = Utils.abspath( source_filename ),
future_spec = FutureSpec()
)
package_name = Utils.basename( filename )
result = PythonPackage(
name = package_name,
package = package,
source_ref = source_ref
)
else:
sys.stderr.write(
"%s: can't open file '%s'.\n" % (
Utils.basename( sys.argv[0] ),
filename
)
)
sys.exit( 2 )
if not Options.shallHaveStatementLines():
source_ref = source_ref.atInternal()
source_code = readSourceCodeFromFilename( source_filename )
module_body = buildParseTree(
provider = result,
source_code = source_code,
source_ref = source_ref,
#.........这里部分代码省略.........
示例9: detectBinaryDLLs
# 需要导入模块: from nuitka import Utils [as 别名]
# 或者: from nuitka.Utils import isDir [as 别名]
def detectBinaryDLLs(binary_filename, package_name):
result = set()
if Utils.getOS() in ("Linux", "NetBSD"):
# Ask "ldd" about the libraries being used by the created binary, these
# are the ones that interest us.
process = subprocess.Popen(
args = [
"ldd",
binary_filename
],
stdout = subprocess.PIPE,
stderr = subprocess.PIPE
)
stdout, _stderr = process.communicate()
for line in stdout.split(b"\n"):
if not line:
continue
if b"=>" not in line:
continue
part = line.split(b" => ", 2)[1]
if b"(" in part:
filename = part[:part.rfind(b"(")-1]
else:
filename = part
if not filename:
continue
if Utils.python_version >= 300:
filename = filename.decode("utf-8")
result.add(filename)
elif Utils.getOS() == "Windows":
depends_exe = getDependsExePath()
env = os.environ.copy()
path = env.get("PATH","").split(";")
path += sys.path
if package_name is not None:
for element in sys.path:
candidate = Utils.joinpath(element, package_name)
if Utils.isDir(candidate):
path.append(candidate)
env["PATH"] = ";".join(path)
subprocess.call(
(
depends_exe,
"-c",
"-ot%s" % binary_filename + ".depends",
"-f1",
"-pa1",
"-ps1",
binary_filename
),
env = env,
)
inside = False
for line in open(binary_filename + ".depends"):
if "| Module Dependency Tree |" in line:
inside = True
continue
if not inside:
continue
if "| Module List |" in line:
break
if "]" not in line:
continue
# Skip missing DLLs, apparently not needed anyway.
if "?" in line[:line.find("]")]:
continue
dll_filename = line[line.find("]")+2:-1]
assert Utils.isFile(dll_filename), dll_filename
# The executable itself is of course excempted.
if Utils.normcase(dll_filename) == \
Utils.normcase(Utils.abspath(binary_filename)):
continue
dll_name = Utils.basename(dll_filename).upper()
# Win API can be assumed.
if dll_name.startswith("API-MS-WIN-") or dll_name.startswith("EXT-MS-WIN-"):
#.........这里部分代码省略.........
示例10: getDependsExePath
# 需要导入模块: from nuitka import Utils [as 别名]
# 或者: from nuitka.Utils import isDir [as 别名]
def getDependsExePath():
if Utils.getArchitecture() == "x86":
depends_url = "http://dependencywalker.com/depends22_x86.zip"
else:
depends_url = "http://dependencywalker.com/depends22_x64.zip"
import urllib
if "APPDATA" not in os.environ:
sys.exit("Error, standalone mode cannot find 'APPDATA' environment.")
nuitka_app_dir = os.path.join(os.environ["APPDATA"],"nuitka")
if not Utils.isDir(nuitka_app_dir):
os.makedirs(nuitka_app_dir)
nuitka_depends_zip = os.path.join(
nuitka_app_dir,
os.path.basename(depends_url)
)
if not Utils.isFile(nuitka_depends_zip):
print("""\
Nuitka will make use of Dependency Walker (http://dependencywalker.com) tool
to analyse the dependencies of Python extension modules. Is it OK to download
and put it in APPDATA (no installer needed, cached, one time question)."""
)
reply = Utils.get_input("Proceed and download? [Yes]/No ")
if reply.lower() in ("no", "n"):
sys.exit("Nuitka does not work in --standalone on Windows without.")
info("Downloading", depends_url)
Utils.urlretrieve(
depends_url,
nuitka_depends_zip
)
nuitka_depends_dir = os.path.join(
nuitka_app_dir,
Utils.getArchitecture()
)
if not Utils.isDir(nuitka_depends_dir):
os.makedirs(nuitka_depends_dir)
depends_exe = os.path.join(
nuitka_depends_dir,
"depends.exe"
)
if not Utils.isFile(depends_exe):
info("Extracting", depends_exe)
import zipfile
depends_zip = zipfile.ZipFile(nuitka_depends_zip)
depends_zip.extractall(nuitka_depends_dir)
assert Utils.isFile(depends_exe)
return depends_exe
示例11: getDependsExePath
# 需要导入模块: from nuitka import Utils [as 别名]
# 或者: from nuitka.Utils import isDir [as 别名]
def getDependsExePath():
""" Return the path of depends.exe (for Windows).
Will prompt the user to download if not already cached in AppData
directory for Nuitka.
"""
if Utils.getArchitecture() == "x86":
depends_url = "http://dependencywalker.com/depends22_x86.zip"
else:
depends_url = "http://dependencywalker.com/depends22_x64.zip"
if "APPDATA" not in os.environ:
sys.exit("Error, standalone mode cannot find 'APPDATA' environment.")
nuitka_app_dir = os.path.join(os.environ["APPDATA"], "nuitka")
if not Utils.isDir(nuitka_app_dir):
os.makedirs(nuitka_app_dir)
nuitka_depends_zip = os.path.join(
nuitka_app_dir,
os.path.basename(depends_url)
)
if not Utils.isFile(nuitka_depends_zip):
Tracing.printLine("""\
Nuitka will make use of Dependency Walker (http://dependencywalker.com) tool
to analyze the dependencies of Python extension modules. Is it OK to download
and put it in APPDATA (no installer needed, cached, one time question).""")
reply = raw_input("Proceed and download? [Yes]/No ")
if reply.lower() in ("no", "n"):
sys.exit("Nuitka does not work in --standalone on Windows without.")
info("Downloading '%s'" % depends_url)
urlretrieve(
depends_url,
nuitka_depends_zip
)
nuitka_depends_dir = os.path.join(
nuitka_app_dir,
Utils.getArchitecture()
)
if not Utils.isDir(nuitka_depends_dir):
os.makedirs(nuitka_depends_dir)
depends_exe = os.path.join(
nuitka_depends_dir,
"depends.exe"
)
if not Utils.isFile(depends_exe):
info("Extracting to '%s'" % depends_exe)
import zipfile
try:
depends_zip = zipfile.ZipFile(nuitka_depends_zip)
depends_zip.extractall(nuitka_depends_dir)
except Exception: # Catching anything zip throws, pylint:disable=W0703
info("Problem with the downloaded zip file, deleting it.")
Utils.deleteFile(depends_exe, must_exist = False)
Utils.deleteFile(nuitka_depends_zip, must_exist = True)
sys.exit(
"Error, need '%s' as extracted from '%s'." % (
depends_exe,
depends_url
)
)
assert Utils.isFile(depends_exe)
return depends_exe
示例12: decideModuleTree
# 需要导入模块: from nuitka import Utils [as 别名]
# 或者: from nuitka.Utils import isDir [as 别名]
def decideModuleTree(filename, package, is_shlib, is_top, is_main):
# Many variables, branches, due to the many cases, pylint: disable=R0912
assert package is None or type( package ) is str
if is_main and Utils.isDir( filename ):
source_filename = Utils.joinpath( filename, "__main__.py" )
if not Utils.isFile( source_filename ):
sys.stderr.write(
"%s: can't find '__main__' module in '%s'\n" % (
Utils.basename( sys.argv[0] ),
filename
)
)
sys.exit( 2 )
filename = source_filename
main_added = True
else:
main_added = False
if Utils.isFile( filename ):
source_filename = filename
source_ref = SourceCodeReferences.fromFilename(
filename = filename,
future_spec = FutureSpec()
)
if is_main:
module_name = "__main__"
else:
module_name = Utils.basename( filename )
if module_name.endswith( ".py" ):
module_name = module_name[:-3]
if is_shlib:
module_name = module_name.split(".")[0]
if "." in module_name:
sys.stderr.write(
"Error, '%s' is not a proper python module name.\n" % (
module_name
)
)
sys.exit( 2 )
if is_shlib:
result = PythonShlibModule(
name = module_name,
source_ref = source_ref,
package_name = package,
)
elif is_main:
result = PythonMainModule(
source_ref = source_ref,
main_added = main_added
)
else:
result = PythonModule(
name = module_name,
package_name = package,
source_ref = source_ref
)
elif Importing.isPackageDir(filename):
if is_top:
package_name = Utils.splitpath(filename)[-1]
else:
package_name = Utils.basename(filename)
source_filename = Utils.joinpath(filename, "__init__.py")
if not Utils.isFile( source_filename ):
assert Utils.python_version >= 330, source_filename
source_ref, result = createNamespacePackage(
package_name = package_name,
module_relpath = filename
)
source_filename = None
else:
source_ref = SourceCodeReferences.fromFilename(
filename = Utils.abspath( source_filename ),
future_spec = FutureSpec()
)
result = PythonPackage(
name = package_name,
package_name = package,
source_ref = source_ref
)
else:
sys.stderr.write(
"%s: can't open file '%s'.\n" % (
Utils.basename( sys.argv[0] ),
filename
#.........这里部分代码省略.........