本文整理汇总了Python中nuitka.Utils.basename方法的典型用法代码示例。如果您正苦于以下问题:Python Utils.basename方法的具体用法?Python Utils.basename怎么用?Python Utils.basename使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nuitka.Utils
的用法示例。
在下文中一共展示了Utils.basename方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: isSameModulePath
# 需要导入模块: from nuitka import Utils [as 别名]
# 或者: from nuitka.Utils import basename [as 别名]
def isSameModulePath(path1, path2):
if Utils.basename(path1) == "__init__.py":
path1 = Utils.dirname(path1)
if Utils.basename(path2) == "__init__.py":
path2 = Utils.dirname(path2)
return Utils.abspath(path1) == Utils.abspath(path2)
示例2: isImportedPath
# 需要导入模块: from nuitka import Utils [as 别名]
# 或者: from nuitka.Utils import basename [as 别名]
def isImportedPath( module_relpath ):
module_name = Utils.basename( module_relpath )
if module_name.endswith( ".py" ):
module_name = module_name[:-3]
key = module_relpath, module_name
return key in imported_modules
示例3: getImportedModule
# 需要导入模块: from nuitka import Utils [as 别名]
# 或者: from nuitka.Utils import basename [as 别名]
def getImportedModule( module_relpath ):
module_name = Utils.basename( module_relpath )
if module_name.endswith( ".py" ):
module_name = module_name[:-3]
key = module_relpath, module_name
return imported_modules[ key ]
示例4: _consider
# 需要导入模块: from nuitka import Utils [as 别名]
# 或者: from nuitka.Utils import basename [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 basename [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: __init__
# 需要导入模块: from nuitka import Utils [as 别名]
# 或者: from nuitka.Utils import basename [as 别名]
def __init__(self, name, package_name, source_ref):
NodeBase.__init__(
self,
source_ref = source_ref
)
PythonModuleMixin.__init__(
self,
name = name,
package_name = package_name
)
assert Utils.basename(source_ref.getFilename()) != "<frozen>"
示例7: copyUsedDLLs
# 需要导入模块: from nuitka import Utils [as 别名]
# 或者: from nuitka.Utils import basename [as 别名]
def copyUsedDLLs(dist_dir, binary_filename, standalone_entry_points):
dll_map = []
for early_dll in detectUsedDLLs(standalone_entry_points):
dll_name = Utils.basename(early_dll)
target_path = Utils.joinpath(
dist_dir,
dll_name
)
# Check that if a DLL has the name name, if it's identical,
# happens at least for OSC and Fedora 20.
if Utils.isFile(target_path):
import filecmp
if filecmp.cmp(early_dll, target_path):
continue
else:
sys.exit("Error, conflicting DLLs for '%s'." % dll_name)
shutil.copy(
early_dll,
target_path
)
dll_map.append(
(early_dll, dll_name)
)
if Options.isShowInclusion():
info("Included used shared library '%s'.", early_dll)
if Utils.getOS() == "Darwin":
# For MacOS, the binary needs to be changed to reflect the DLL
# location in the dist folder.
fixupBinaryDLLPaths(binary_filename, dll_map)
if Utils.getOS() == "Linux":
# For Linux, the rpath of libraries may be an issue.
for _original_path, early_dll in dll_map:
removeSharedLibraryRPATH(
Utils.joinpath(dist_dir, early_dll)
)
for standalone_entry_point in standalone_entry_points[1:]:
removeSharedLibraryRPATH(
standalone_entry_point[0]
)
示例8: __init__
# 需要导入模块: from nuitka import Utils [as 别名]
# 或者: from nuitka.Utils import basename [as 别名]
def __init__(self, name, package_name, source_ref):
NodeBase.__init__(
self,
source_ref = source_ref
)
PythonModuleMixin.__init__(
self,
name = name,
package_name = package_name
)
assert Utils.basename(source_ref.getFilename()) != "<frozen>"
# That is too likely a bug.
assert name != "__main__"
示例9: _detectedSourceFile
# 需要导入模块: from nuitka import Utils [as 别名]
# 或者: from nuitka.Utils import basename [as 别名]
def _detectedSourceFile(filename, module_name, result, is_late):
if module_name in module_names:
return
if module_name == "collections.abc":
_detectedSourceFile(
filename = filename,
module_name = "_collections_abc",
result = result,
is_late = is_late
)
source_code = open(filename,"rb").read()
if Utils.python_version >= 300:
source_code = source_code.decode("utf-8")
filename = filename.decode("utf-8")
if module_name == "site":
source_code = """\
__file__ = (__nuitka_binary_dir + '%s%s') if '__nuitka_binary_dir' in dict(__builtins__ ) else '<frozen>';%s""" % (
os.path.sep,
os.path.basename(filename),
source_code
)
debug(
"Freezing module '%s' (from '%s').",
module_name,
filename
)
result.append(
(
module_name,
marshal.dumps(
compile(source_code, filename, "exec")
),
Utils.basename(filename) == "__init__.py",
filename,
is_late
)
)
module_names.add(module_name)
示例10: _consider
# 需要导入模块: from nuitka import Utils [as 别名]
# 或者: from nuitka.Utils import basename [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
}
)
示例11: buildModuleTree
# 需要导入模块: from nuitka import Utils [as 别名]
# 或者: from nuitka.Utils import basename [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,
#.........这里部分代码省略.........
示例12: detectBinaryDLLs
# 需要导入模块: from nuitka import Utils [as 别名]
# 或者: from nuitka.Utils import basename [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-"):
#.........这里部分代码省略.........
示例13: copyUsedDLLs
# 需要导入模块: from nuitka import Utils [as 别名]
# 或者: from nuitka.Utils import basename [as 别名]
def copyUsedDLLs(dist_dir, binary_filename, standalone_entry_points):
# This is terribly complex, because we check the list of used DLLs
# trying to avoid duplicates, and detecting errors with them not
# being binary identical, so we can report them. And then of course
# we also need to handle OS specifics, pylint: disable=R0912,R0914
dll_map = []
used_dlls = detectUsedDLLs(standalone_entry_points)
for dll_filename1, sources1 in tuple(iterItems(used_dlls)):
for dll_filename2, sources2 in tuple(iterItems(used_dlls)):
if dll_filename1 == dll_filename2:
continue
# Colliding basenames are an issue to us.
if Utils.basename(dll_filename1) != Utils.basename(dll_filename2):
continue
# May already have been removed earlier
if dll_filename1 not in used_dlls:
continue
if dll_filename2 not in used_dlls:
continue
dll_name = Utils.basename(dll_filename1)
if Options.isShowInclusion():
info(
"""Colliding DLL names for %s, checking identity of \
'%s' <-> '%s'.""" % (
dll_name,
dll_filename1,
dll_filename2,
)
)
# Check that if a DLL has the same name, if it's identical,
# happens at least for OSC and Fedora 20.
import filecmp
if filecmp.cmp(dll_filename1, dll_filename2):
del used_dlls[dll_filename2]
continue
sys.exit(
"""Error, conflicting DLLs for '%s' \
(%s used by %s different from %s used by %s).""" % (
dll_name,
dll_filename1,
", ".join(sources1),
dll_filename2,
", ".join(sources2)
)
)
for dll_filename, sources in iterItems(used_dlls):
dll_name = Utils.basename(dll_filename)
target_path = Utils.joinpath(
dist_dir,
dll_name
)
shutil.copy(
dll_filename,
target_path
)
dll_map.append(
(dll_filename, dll_name)
)
if Options.isShowInclusion():
info(
"Included used shared library '%s' (used by %s)." % (
dll_filename,
", ".join(sources)
)
)
if Utils.getOS() == "Darwin":
# For MacOS, the binary needs to be changed to reflect the DLL
# location in the dist folder.
fixupBinaryDLLPaths(binary_filename, dll_map)
if Utils.getOS() == "Linux":
# For Linux, the rpath of libraries may be an issue.
for _original_path, dll_filename in dll_map:
removeSharedLibraryRPATH(
Utils.joinpath(dist_dir, dll_filename)
)
for standalone_entry_point in standalone_entry_points[1:]:
removeSharedLibraryRPATH(
standalone_entry_point[0]
)
示例14: decideModuleTree
# 需要导入模块: from nuitka import Utils [as 别名]
# 或者: from nuitka.Utils import basename [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
#.........这里部分代码省略.........