当前位置: 首页>>代码示例>>Python>>正文


Python path.abspath方法代码示例

本文整理汇总了Python中os.path.abspath方法的典型用法代码示例。如果您正苦于以下问题:Python path.abspath方法的具体用法?Python path.abspath怎么用?Python path.abspath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在os.path的用法示例。


在下文中一共展示了path.abspath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_referenceSourceExistsNonWriteable

# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import abspath [as 别名]
def test_referenceSourceExistsNonWriteable(self, mock_is_writeable, mock_os, mock_debug, mock_path, mock_execute, mock_getstatusoutput):
      # Reference sources exists but cannot be written
      # The reference repo is set nevertheless but not updated
      mock_path.exists.side_effect = lambda x: True
      mock_is_writeable.side_effect = lambda x: False
      mock_os.path.join.side_effect = join
      mock_getstatusoutput.side_effect = allow_directory_creation
      mock_git_clone = MagicMock(return_value=None)
      mock_git_fetch = MagicMock(return_value=None)
      mock_execute.side_effect = lambda x, **k: allow_git_clone(x, mock_git_clone, mock_git_fetch, *k)
      spec = OrderedDict({"source": "https://github.com/alisw/AliRoot"})
      referenceSources = "sw/MIRROR"
      reference = abspath(referenceSources) + "/aliroot"
      mock_os.makedirs.reset_mock()
      mock_git_clone.reset_mock()
      mock_git_fetch.reset_mock()
      updateReferenceRepoSpec(referenceSources=referenceSources, p="AliRoot", spec=spec, fetch=True)
      mock_os.makedirs.assert_called_with('%s/sw/MIRROR' % getcwd())
      self.assertEqual(mock_git_fetch.call_count, 0, "Expected no calls to git fetch (called %d times instead)" % mock_git_fetch.call_count)
      self.assertEqual(mock_git_clone.call_count, 0, "Expected no calls to git clone (called %d times instead)" % mock_git_clone.call_count)
      self.assertEqual(spec.get("reference"), reference)
      self.assertEqual(True, call('Updating references.') in mock_debug.mock_calls) 
开发者ID:alisw,项目名称:alibuild,代码行数:24,代码来源:test_workarea.py

示例2: test_pep8

# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import abspath [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) 
开发者ID:HTTP-APIs,项目名称:hydrus,代码行数:21,代码来源:test_pep8.py

示例3: test_referenceSourceExistsWriteable

# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import abspath [as 别名]
def test_referenceSourceExistsWriteable(self, mock_is_writeable, mock_os, mock_debug, mock_path, mock_execute, mock_getstatusoutput):
      # Reference sources exists and can be written
      # The reference repo is set nevertheless but not updated
      mock_path.exists.side_effect = lambda x: True
      mock_is_writeable.side_effect = lambda x: True
      mock_os.path.join.side_effect = join
      mock_getstatusoutput.side_effect = allow_directory_creation
      mock_git_clone = MagicMock(return_value=None)
      mock_git_fetch = MagicMock(return_value=None)
      mock_execute.side_effect = lambda x, **k: allow_git_clone(x, mock_git_clone, mock_git_fetch, *k)
      spec = OrderedDict({"source": "https://github.com/alisw/AliRoot"})
      referenceSources = "sw/MIRROR"
      reference = abspath(referenceSources) + "/aliroot"
      mock_os.makedirs.reset_mock()
      mock_git_clone.reset_mock()
      mock_git_fetch.reset_mock()
      updateReferenceRepoSpec(referenceSources=referenceSources, p="AliRoot", spec=spec, fetch=True)
      mock_os.makedirs.assert_called_with('%s/sw/MIRROR' % getcwd())
      self.assertEqual(mock_git_fetch.call_count, 1, "Expected one call to git fetch (called %d times instead)" % mock_git_fetch.call_count)
      self.assertEqual(mock_git_clone.call_count, 0, "Expected no calls to git clone (called %d times instead)" % mock_git_clone.call_count)
      self.assertEqual(spec.get("reference"), reference)
      self.assertEqual(True, call('Updating references.') in mock_debug.mock_calls) 
开发者ID:alisw,项目名称:alibuild,代码行数:24,代码来源:test_workarea.py

示例4: test_referenceBasedirExistsWriteable

# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import abspath [as 别名]
def test_referenceBasedirExistsWriteable(self, mock_is_writeable, mock_os, mock_debug, mock_path, mock_execute, mock_getstatusoutput):
      """
      The referenceSources directory exists and it's writeable
      Reference sources are already there
      """
      mock_path.exists.side_effect = lambda x: True
      mock_is_writeable.side_effect = lambda x: True
      mock_os.path.join.side_effect = join
      mock_getstatusoutput.side_effect = allow_directory_creation
      mock_git_clone = MagicMock(return_value=None)
      mock_git_fetch = MagicMock(return_value=None)
      mock_execute.side_effect = lambda x, **k: allow_git_clone(x, mock_git_clone, mock_git_fetch, *k)
      spec = OrderedDict({"source": "https://github.com/alisw/AliRoot"})
      referenceSources = "sw/MIRROR"
      reference = abspath(referenceSources) + "/aliroot"
      mock_os.makedirs.reset_mock()
      mock_git_clone.reset_mock()
      mock_git_fetch.reset_mock()
      updateReferenceRepo(referenceSources=referenceSources, p="AliRoot", spec=spec)
      mock_os.makedirs.assert_called_with('%s/sw/MIRROR' % getcwd())
      self.assertEqual(mock_git_fetch.call_count, 1, "Expected one call to git fetch (called %d times instead)" % mock_git_fetch.call_count) 
开发者ID:alisw,项目名称:alibuild,代码行数:23,代码来源:test_workarea.py

示例5: test_referenceBasedirNotExistsWriteable

# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import abspath [as 别名]
def test_referenceBasedirNotExistsWriteable(self, mock_is_writeable, mock_os, mock_debug, mock_path, mock_execute, mock_getstatusoutput):
      """
      The referenceSources directory exists and it's writeable
      Reference sources are not already there
      """
      mock_path.exists.side_effect = reference_sources_do_not_exists
      mock_is_writeable.side_effect = lambda x: False # not writeable
      mock_os.path.join.side_effect = join
      mock_os.makedirs.side_effect = lambda x: True
      mock_getstatusoutput.side_effect = allow_directory_creation
      mock_git_clone = MagicMock(return_value=None)
      mock_git_fetch = MagicMock(return_value=None)
      mock_execute.side_effect = lambda x, **k: allow_git_clone(x, mock_git_clone, mock_git_fetch, *k)
      spec = OrderedDict({"source": "https://github.com/alisw/AliRoot"})
      referenceSources = "sw/MIRROR"
      reference = abspath(referenceSources) + "/aliroot"
      mock_os.makedirs.reset_mock()
      mock_git_clone.reset_mock()
      mock_git_fetch.reset_mock()
      updateReferenceRepo(referenceSources=referenceSources, p="AliRoot", spec=spec)
      mock_path.exists.assert_called_with('%s/sw/MIRROR/aliroot' % getcwd())
      mock_os.makedirs.assert_called_with('%s/sw/MIRROR' % getcwd())
      self.assertEqual(mock_git_clone.call_count, 0, "Expected no calls to git clone (called %d times instead)" % mock_git_clone.call_count) 
开发者ID:alisw,项目名称:alibuild,代码行数:25,代码来源:test_workarea.py

示例6: test_referenceSourceNotExistsWriteable

# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import abspath [as 别名]
def test_referenceSourceNotExistsWriteable(self, mock_is_writeable, mock_os, mock_debug, mock_path, mock_execute, mock_getstatusoutput):
      """
      The referenceSources directory does not exist and it's writeable
      Reference sources are not already there
      """
      mock_path.exists.side_effect = reference_sources_do_not_exists
      mock_is_writeable.side_effect = lambda x: True  # is writeable
      mock_os.path.join.side_effect = join
      mock_os.makedirs.side_effect = lambda x: True
      mock_getstatusoutput.side_effect = allow_directory_creation
      mock_git_clone = MagicMock(return_value=None)
      mock_git_fetch = MagicMock(return_value=None)
      mock_execute.side_effect = lambda x, **k: allow_git_clone(x, mock_git_clone, mock_git_fetch, *k)
      spec = OrderedDict({"source": "https://github.com/alisw/AliRoot"})
      referenceSources = "sw/MIRROR"
      reference = abspath(referenceSources) + "/aliroot"
      mock_os.makedirs.reset_mock()
      mock_git_clone.reset_mock()
      mock_git_fetch.reset_mock()
      updateReferenceRepo(referenceSources=referenceSources, p="AliRoot", spec=spec)
      mock_path.exists.assert_called_with('%s/sw/MIRROR/aliroot' % getcwd())
      mock_os.makedirs.assert_called_with('%s/sw/MIRROR' % getcwd())
      self.assertEqual(mock_git_clone.call_count, 1, "Expected only one call to git clone (called %d times instead)" % mock_git_clone.call_count) 
开发者ID:alisw,项目名称:alibuild,代码行数:25,代码来源:test_workarea.py

示例7: all_handlers

# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import abspath [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 
开发者ID:awslabs,项目名称:aws-ops-automator,代码行数:26,代码来源:__init__.py

示例8: test_x_zip_feature_na20_chain

# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import abspath [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)) 
开发者ID:pyscf,项目名称:pyscf,代码行数:18,代码来源:test_0091_tddft_x_zip_na20.py

示例9: test_vna_lih

# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import abspath [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) 
开发者ID:pyscf,项目名称:pyscf,代码行数:21,代码来源:test_0004_vna.py

示例10: cached_path

# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import abspath [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") 
开发者ID:ConvLab,项目名称:ConvLab,代码行数:20,代码来源:mdbt.py

示例11: register_module

# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import abspath [as 别名]
def register_module(new_path):
    """ register_module(new_path): adds a directory to sys.path.
    Do nothing if it does not exist or if it's already in sys.path.
    """
    if not os.path.exists(new_path):
        return

    new_path = os.path.abspath(new_path)
    if platform.system() == 'Windows':
        new_path = new_path.lower()
    for x in sys.path:
        x = os.path.abspath(x)
        if platform.system() == 'Windows':
            x = x.lower()
        if new_path in (x, x + os.sep):
            return
    sys.path.insert(0, new_path) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:19,代码来源:lib_util.py

示例12: __init__

# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import abspath [as 别名]
def __init__(self, path=None, expanduser=False):
        """ Initialize and return a local Path instance.

        Path can be relative to the current directory.
        If path is None it defaults to the current working directory.
        If expanduser is True, tilde-expansion is performed.
        Note that Path instances always carry an absolute path.
        Note also that passing in a local path object will simply return
        the exact same path object. Use new() to get a new copy.
        """
        if path is None:
            self.strpath = py.error.checked_call(os.getcwd)
        else:
            try:
                path = fspath(path)
            except TypeError:
                raise ValueError("can only pass None, Path instances "
                                 "or non-empty strings to LocalPath")
            if expanduser:
                path = os.path.expanduser(path)
            self.strpath = abspath(path) 
开发者ID:pytest-dev,项目名称:py,代码行数:23,代码来源:local.py

示例13: process_paths

# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import abspath [as 别名]
def process_paths(options, candidates=None, error=True):
    """Process files and log errors."""
    errors = check_path(options, rootdir=CURDIR, candidates=candidates)

    if options.format in ['pycodestyle', 'pep8']:
        pattern = "%(filename)s:%(lnum)s:%(col)s: %(text)s"
    elif options.format == 'pylint':
        pattern = "%(filename)s:%(lnum)s: [%(type)s] %(text)s"
    else:  # 'parsable'
        pattern = "%(filename)s:%(lnum)s:%(col)s: [%(type)s] %(text)s"

    for er in errors:
        if options.abspath:
            er._info['filename'] = op.abspath(er.filename)
        LOGGER.warning(pattern, er._info)

    if error:
        sys.exit(int(bool(errors)))

    return errors 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:22,代码来源:main.py

示例14: _walk_moler_python_files

# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import abspath [as 别名]
def _walk_moler_python_files(path, *args):
    """
    Walk thru directory with commands and search for python source code (except __init__.py)
    Yield relative filepath to parameter path

    :param path: relative path do directory with commands
    :type path:
    :rtype: str
    """
    repo_path = abspath(join(path, '..', '..'))

    observer = "event" if "events" in split(path) else "command"
    print("Processing {}s test from path: '{}'".format(observer, path))

    for (dirpath, _, filenames) in walk(path):
        for filename in filenames:
            if filename.endswith('__init__.py'):
                continue
            if filename.endswith('.py'):
                abs_path = join(dirpath, filename)
                in_moler_path = relpath(abs_path, repo_path)
                yield in_moler_path 
开发者ID:nokia,项目名称:moler,代码行数:24,代码来源:cmds_events_doc.py

示例15: protect

# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import abspath [as 别名]
def protect(protect_args=None):
    global c
    flags = ''
    option_end = False
    if not protect_args:
        protect_args = argv[1:]
    for arg in protect_args:
        if arg == '--':
            option_end = True
        elif (arg.startswith("-") and not option_end):
            flags = flags + arg[arg.rfind('-') + 1:]
        elif arg in c.invalid:
            pprint('"." and ".." may not be protected')
        else:
            path = abspath(expv(expu(arg)))
            evalpath = dirname(path) + "/." + basename(path) + c.suffix
            if not exists(path):
                pprint("Warning: " + path + " does not exist")
            with open(evalpath, "w") as f:
                question = input("Question for " + path + ": ")
                answer = input("Answer: ")
                f.write(question + "\n" + answer + "\n" + flags.upper()) 
开发者ID:alanzchen,项目名称:rm-protection,代码行数:24,代码来源:protect.py


注:本文中的os.path.abspath方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。