本文整理汇总了Python中os.path.dirname方法的典型用法代码示例。如果您正苦于以下问题:Python path.dirname方法的具体用法?Python path.dirname怎么用?Python path.dirname使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类os.path
的用法示例。
在下文中一共展示了path.dirname方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_pep8
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import dirname [as 别名]
def test_pep8(self):
"""Test method to check PEP8 compliance over the entire project."""
self.file_structure = dirname(dirname(abspath(__file__)))
print("Testing for PEP8 compliance of python files in {}".format(
self.file_structure))
style = pep8.StyleGuide()
style.options.max_line_length = 100 # Set this to desired maximum line length
filenames = []
# Set this to desired folder location
for root, _, files in os.walk(self.file_structure):
python_files = [f for f in files if f.endswith(
'.py') and "examples" not in root]
for file in python_files:
if len(root.split('samples')) != 2: # Ignore samples directory
filename = '{0}/{1}'.format(root, file)
filenames.append(filename)
check = style.check_files(filenames)
self.assertEqual(check.total_errors, 0, 'PEP8 style errors: %d' %
check.total_errors)
示例2: import_helper
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import dirname [as 别名]
def import_helper():
from os.path import dirname
import imp
possible_libs = ["_alf_grammar.win32",
"_alf_grammar.ntoarm",
"_alf_grammar.ntox86",
"_alf_grammar.linux"]
found_lib = False
for i in possible_libs:
fp = None
try:
fp, pathname, description = imp.find_module(i, [dirname(__file__)])
_mod = imp.load_module("_alf_grammar", fp, pathname, description)
found_lib = True
break
except ImportError:
pass
finally:
if fp:
fp.close()
if not found_lib:
raise ImportError("Failed to load _alf_grammar module")
return _mod
示例3: has_system_site_packages
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import dirname [as 别名]
def has_system_site_packages(interpreter):
# TODO: unit-test
system_site_packages = check_output((
interpreter,
'-c',
# stolen directly from virtualenv's site.py
"""\
import site, os.path
print(
0
if os.path.exists(
os.path.join(os.path.dirname(site.__file__), 'no-global-site-packages.txt')
) else
1
)"""
))
system_site_packages = int(system_site_packages)
assert system_site_packages in (0, 1)
return bool(system_site_packages)
示例4: compile_bundle_entry
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import dirname [as 别名]
def compile_bundle_entry(self, spec, entry):
"""
Handler for each entry for the bundle method of the compile
process. This copies the source file or directory into the
build directory.
"""
modname, source, target, modpath = entry
bundled_modpath = {modname: modpath}
bundled_target = {modname: target}
export_module_name = []
if isfile(source):
export_module_name.append(modname)
copy_target = join(spec[BUILD_DIR], target)
if not exists(dirname(copy_target)):
makedirs(dirname(copy_target))
shutil.copy(source, copy_target)
elif isdir(source):
copy_target = join(spec[BUILD_DIR], modname)
shutil.copytree(source, copy_target)
return bundled_modpath, bundled_target, export_module_name
示例5: test_existing_removed
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import dirname [as 别名]
def test_existing_removed(self):
# force an existing file
target = self.registry.records[('app', 'nothing.js')]
os.mkdir(dirname(target))
with open(target, 'w'):
pass
with pretty_logging(stream=mocks.StringIO()) as stream:
self.registry.process_package('app')
log = stream.getvalue()
self.assertIn(
"package 'app' has declared 3 entry points for the "
"'calmjs.artifacts' registry for artifact construction", log
)
log = stream.getvalue()
self.assertIn("removing existing export target at ", log)
self.assertFalse(exists(target))
示例6: get_jmod_path
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import dirname [as 别名]
def get_jmod_path(self, respect_stripping=True, alt_module_info_name=None):
"""
Gets the path to the .jmod file corresponding to this module descriptor.
:param bool respect_stripping: Specifies whether or not to return a path
to a stripped .jmod file if this module is based on a dist
"""
if respect_stripping and self.dist is not None:
assert alt_module_info_name is None, 'alternate modules not supported for stripped dist ' + self.dist.name
return join(dirname(self.dist.path), self.name + '.jmod')
if self.dist is not None:
qualifier = '_' + alt_module_info_name if alt_module_info_name else ''
return join(dirname(self.dist.original_path()), self.name + qualifier + '.jmod')
if self.jarpath:
return join(dirname(self.jarpath), self.name + '.jmod')
assert self.jdk, self.name
p = join(self.jdk.home, 'jmods', self.name + '.jmod')
assert exists(p), p
return p
示例7: all_handlers
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import dirname [as 别名]
def all_handlers():
global __actions
if __actions is None:
__actions = []
current = abspath(os.getcwd())
while True:
if isdir(os.path.join(current, "handlers")):
break
parent = dirname(current)
if parent == current:
# at top level
raise Exception("Could not find handlers directory")
else:
current = parent
for f in listdir(os.path.join(current, "handlers")):
if isfile(join(current, "handlers", f)) and f.endswith("_{}.py".format(HANDLER.lower())):
module_name = HANDLERS_MODULE_NAME.format(f[0:-len(".py")])
m = _get_module(module_name)
cls = _get_handler_class(m)
if cls is not None:
handler_name = cls[0]
__actions.append(handler_name)
return __actions
示例8: test_x_zip_feature_na20_chain
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import dirname [as 别名]
def test_x_zip_feature_na20_chain(self):
""" This a test for compression of the eigenvectos at higher energies """
dname = dirname(abspath(__file__))
siesd = dname+'/sodium_20'
x = td_c(label='siesta', cd=siesd,x_zip=True, x_zip_emax=0.25,x_zip_eps=0.05,jcutoff=7,xc_code='RPA',nr=128, fermi_energy=-0.0913346431431985)
eps = 0.005
ww = np.arange(0.0, 0.5, eps/2.0)+1j*eps
data = np.array([ww.real*27.2114, -x.comp_polariz_inter_ave(ww).imag])
fname = 'na20_chain.tddft_iter_rpa.omega.inter.ave.x_zip.txt'
np.savetxt(fname, data.T, fmt=['%f','%f'])
#print(__file__, fname)
data_ref = np.loadtxt(dname+'/'+fname+'-ref')
#print(' x.rf0_ncalls ', x.rf0_ncalls)
#print(' x.matvec_ncalls ', x.matvec_ncalls)
self.assertTrue(np.allclose(data_ref,data.T, rtol=1.0e-1, atol=1e-06))
示例9: test_vna_lih
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import dirname [as 别名]
def test_vna_lih(self):
dname = dirname(abspath(__file__))
n = nao(label='lih', cd=dname)
m = 200
dvec,midv = 2*(n.atom2coord[1] - n.atom2coord[0])/m, (n.atom2coord[1] + n.atom2coord[0])/2.0
vgrid = np.tensordot(np.array(range(-m,m+1)), dvec, axes=0) + midv
sgrid = np.array(range(-m,m+1)) * np.sqrt((dvec*dvec).sum())
#vgrid = np.array([[-1.517908564663352e+00, 1.180550033093826e+00,0.000000000000000e+00]])
vna = n.vna(vgrid)
#for v,r in zip(vna,vgrid):
# print("%23.15e %23.15e %23.15e %23.15e"%(r[0], r[1], r[2], v))
#print(vna.shape, sgrid.shape)
np.savetxt('vna_lih_0004.txt', np.row_stack((sgrid, vna)).T)
ref = np.loadtxt(dname+'/vna_lih_0004.txt-ref')
for r,d in zip(ref[:,1],vna): self.assertAlmostEqual(r,d)
示例10: cached_path
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import dirname [as 别名]
def cached_path(file_path, cached_dir=None):
if not cached_dir:
cached_dir = str(Path(Path.home() / '.tatk') / "cache")
return allennlp_cached_path(file_path, cached_dir)
# DATA_PATH = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))), 'data/mdbt')
# VALIDATION_URL = os.path.join(DATA_PATH, "data/validate.json")
# WORD_VECTORS_URL = os.path.join(DATA_PATH, "word-vectors/paragram_300_sl999.txt")
# TRAINING_URL = os.path.join(DATA_PATH, "data/train.json")
# ONTOLOGY_URL = os.path.join(DATA_PATH, "data/ontology.json")
# TESTING_URL = os.path.join(DATA_PATH, "data/test.json")
# MODEL_URL = os.path.join(DATA_PATH, "models/model-1")
# GRAPH_URL = os.path.join(DATA_PATH, "graphs/graph-1")
# RESULTS_URL = os.path.join(DATA_PATH, "results/log-1.txt")
# KB_URL = os.path.join(DATA_PATH, "data/") # TODO: yaoqin
# TRAIN_MODEL_URL = os.path.join(DATA_PATH, "train_models/model-1")
# TRAIN_GRAPH_URL = os.path.join(DATA_PATH, "train_graph/graph-1")
示例11: getParentDomain
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import dirname [as 别名]
def getParentDomain(domain):
"""Get parent domain of given domain.
E.g. getParentDomain("www.hdfgroup.org") returns "hdfgroup.org"
Return None if the given domain is already a top-level domain.
"""
if domain.endswith(DOMAIN_SUFFIX):
n = len(DOMAIN_SUFFIX) - 1
domain = domain[:-n]
bucket = getBucketForDomain(domain)
domain_path = getPathForDomain(domain)
if len(domain_path) > 1 and domain_path[-1] == '/':
domain_path = domain_path[:-1]
dirname = op.dirname(domain_path)
if bucket:
parent = bucket + dirname
else:
parent = dirname
if not parent:
parent = None
return parent
示例12: _read_default_settings
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import dirname [as 别名]
def _read_default_settings():
cur_dir = op.dirname(op.abspath(__file__))
setting_file = op.join(cur_dir,"../../","splunktalib", "setting.conf")
parser = configparser.ConfigParser()
parser.read(setting_file)
settings = {}
keys = ("process_size", "thread_min_size", "thread_max_size",
"task_queue_size")
for option in keys:
try:
settings[option] = parser.get("global", option)
except configparser.NoOptionError:
settings[option] = -1
try:
settings[option] = int(settings[option])
except ValueError:
settings[option] = -1
log.logger.debug("settings: %s", settings)
return settings
示例13: probably_a_local_import
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import dirname [as 别名]
def probably_a_local_import(self, imp_name):
"""
Like the corresponding method in the base class, but this also
supports Cython modules.
"""
if imp_name.startswith(u"."):
# Relative imports are certainly not local imports.
return False
imp_name = imp_name.split(u".", 1)[0]
base_path = dirname(self.filename)
base_path = join(base_path, imp_name)
# If there is no __init__.py next to the file its not in a package
# so can't be a relative import.
if not exists(join(dirname(base_path), "__init__.py")):
return False
for ext in [".py", sep, ".pyc", ".so", ".sl", ".pyd", ".pyx"]:
if exists(base_path + ext):
return True
return False
示例14: read
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import dirname [as 别名]
def read(fname):
"""Read filename"""
return open(os.path.join(os.path.dirname(__file__), fname)).read()
示例15: _get_version
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import dirname [as 别名]
def _get_version():
from os.path import abspath, dirname, join
filename = join(dirname(abspath(__file__)), 'VERSION')
print('Reading version from {}'.format(filename))
version = open(filename).read().strip()
print('Version: {}'.format(version))
return version