Python os.path.abspath() Examples
The following are 30
code examples of os.path.abspath().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
os.path
, or try the search function
.
Example #1
Source File: test_pep8.py From hydrus with MIT License | 8 votes |
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)
Example #2
Source File: test_workarea.py From alibuild with GNU General Public License v3.0 | 7 votes |
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)
Example #3
Source File: test_workarea.py From alibuild with GNU General Public License v3.0 | 6 votes |
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)
Example #4
Source File: protect.py From rm-protection with MIT License | 6 votes |
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())
Example #5
Source File: __init__.py From aws-ops-automator with Apache License 2.0 | 6 votes |
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
Example #6
Source File: test_workarea.py From alibuild with GNU General Public License v3.0 | 6 votes |
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)
Example #7
Source File: test_workarea.py From alibuild with GNU General Public License v3.0 | 6 votes |
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)
Example #8
Source File: test_workarea.py From alibuild with GNU General Public License v3.0 | 6 votes |
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)
Example #9
Source File: cmds_events_doc.py From moler with BSD 3-Clause "New" or "Revised" License | 6 votes |
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
Example #10
Source File: main.py From linter-pylama with MIT License | 6 votes |
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
Example #11
Source File: local.py From py with MIT License | 6 votes |
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)
Example #12
Source File: lib_util.py From misp42splunk with GNU Lesser General Public License v3.0 | 6 votes |
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)
Example #13
Source File: test_0091_tddft_x_zip_na20.py From pyscf with Apache License 2.0 | 6 votes |
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))
Example #14
Source File: lib_util.py From misp42splunk with GNU Lesser General Public License v3.0 | 6 votes |
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)
Example #15
Source File: test_0004_vna.py From pyscf with Apache License 2.0 | 6 votes |
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)
Example #16
Source File: mdbt.py From ConvLab with MIT License | 6 votes |
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")
Example #17
Source File: wrappers.py From adversarial-policies with MIT License | 5 votes |
def __init__(self, env, directory, single_video=True): """ :param env: (gym.Env) the wrapped environment. :param directory: the output directory. :param single_video: (bool) if True, generates a single video file, with episodes concatenated. If False, a new video file is created for each episode. Usually a single video file is what is desired. However, if one is searching for an interesting episode (perhaps by looking at the metadata), saving to different files can be useful. """ super(VideoWrapper, self).__init__(env) self.episode_id = 0 self.video_recorder = None self.single_video = single_video self.directory = osp.abspath(directory) # Make sure to not put multiple different runs in the same directory, # if the directory already exists error_msg = ( "You're trying to use the same directory twice, " "this would result in files being overwritten" ) assert not os.path.exists(self.directory), error_msg os.makedirs(self.directory, exist_ok=True)
Example #18
Source File: log.py From misp42splunk with GNU Lesser General Public License v3.0 | 5 votes |
def __init__(self, namespace=None, default_level=logging.INFO): self._loggers = {} self._default_level = default_level if namespace is None: namespace = cutil.get_appname_from_path(op.abspath(__file__)) if namespace: namespace = namespace.lower() self._namespace = namespace
Example #19
Source File: ca_certs_locater.py From misp42splunk with GNU Lesser General Public License v3.0 | 5 votes |
def _read_httplib2_default_certs(): import httplib2 # import error should not happen here, and will be well handled by outer called httplib_dir = os.path.dirname(os.path.abspath(httplib2.__file__)) ca_certs_path = os.path.join(httplib_dir, HTTPLIB2_CA_CERT_FILE_NAME) return _read_pem_file(ca_certs_path)
Example #20
Source File: utilities.py From lnd_grpc with MIT License | 5 votes |
def get_lnd_dir(): """ :return: default LND directory based on detected OS platform """ lnd_dir = None _platform = platform.system() home_dir = str(Path.home()) if _platform == "Darwin": lnd_dir = home_dir + "/Library/Application Support/Lnd/" elif _platform == "Linux": lnd_dir = home_dir + "/.lnd/" elif _platform == "Windows": lnd_dir = path.abspath(environ.get("LOCALAPPDATA") + "Lnd/") return lnd_dir
Example #21
Source File: test_environment.py From me-ica with GNU Lesser General Public License v2.1 | 5 votes |
def test_user_dir(): if USER_KEY in env: del env[USER_KEY] home_dir = nibe.get_home_dir() if os.name == "posix": exp = pjoin(home_dir, '.nipy') else: exp = pjoin(home_dir, '_nipy') assert_equal(exp, nibe.get_nipy_user_dir()) env[USER_KEY] = '/a/path' assert_equal(abspath('/a/path'), nibe.get_nipy_user_dir())
Example #22
Source File: config2.py From TFFRCNN with MIT License | 5 votes |
def get_output_dir(imdb, net): """Return the directory where experimental artifacts are placed. A canonical path is built using the name from an imdb and a network (if not None). """ path = osp.abspath(osp.join(__C.ROOT_DIR, 'output', __C.EXP_DIR, imdb.name)) if net is None: return path else: return osp.join(path, net)
Example #23
Source File: ta_conf_manager.py From misp42splunk with GNU Lesser General Public License v3.0 | 5 votes |
def __init__(self, conf_file, splunkd_uri, session_key, appname=None): if appname is None: appname = utils.get_appname_from_path(op.abspath(__file__)) self._conf_file = conf.conf_file2name(conf_file) self._conf_mgr = conf.ConfManager(splunkd_uri, session_key, app_name=appname) self._cred_mgr = cred.CredentialManager( splunkd_uri, session_key, app=appname, owner="nobody", realm=appname) self._keys = None
Example #24
Source File: generate_emoji_html.py From apple-emoji-linux with Apache License 2.0 | 5 votes |
def _get_dir_infos( image_dirs, exts=None, prefixes=None, titles=None, default_ext=_default_ext, default_prefix=_default_prefix): """Return a list of DirInfos for the image_dirs. When defined, exts, prefixes, and titles should be the same length as image_dirs. Titles default to using the last segments of the image_dirs, exts and prefixes default to the corresponding default values.""" count = len(image_dirs) if not titles: titles = [None] * count elif len(titles) != count: raise ValueError('have %d image dirs but %d titles' % ( count, len(titles))) if not exts: exts = [default_ext] * count elif len(exts) != count: raise ValueError('have %d image dirs but %d extensions' % ( count, len(exts))) if not prefixes: prefixes = [default_prefix] * count elif len(prefixes) != count: raise ValueError('have %d image dirs but %d prefixes' % ( count, len(prefixes))) infos = [] for i in range(count): image_dir = image_dirs[i] title = titles[i] or path.basename(path.abspath(image_dir)) ext = exts[i] or default_ext prefix = prefixes[i] or default_prefix filemap = _get_image_data(image_dir, ext, prefix) infos.append(DirInfo(image_dir, title, filemap)) return infos
Example #25
Source File: ca_certs_locater.py From misp42splunk with GNU Lesser General Public License v3.0 | 5 votes |
def _read_httplib2_default_certs(): import httplib2 # import error should not happen here, and will be well handled by outer called httplib_dir = os.path.dirname(os.path.abspath(httplib2.__file__)) ca_certs_path = os.path.join(httplib_dir, HTTPLIB2_CA_CERT_FILE_NAME) return _read_pem_file(ca_certs_path)
Example #26
Source File: ta_conf_manager.py From misp42splunk with GNU Lesser General Public License v3.0 | 5 votes |
def __init__(self, conf_file, splunkd_uri, session_key, appname=None): if appname is None: appname = utils.get_appname_from_path(op.abspath(__file__)) self._conf_file = conf.conf_file2name(conf_file) self._conf_mgr = conf.ConfManager(splunkd_uri, session_key, app_name=appname) self._cred_mgr = cred.CredentialManager( splunkd_uri, session_key, app=appname, owner="nobody", realm=appname) self._keys = None
Example #27
Source File: log.py From misp42splunk with GNU Lesser General Public License v3.0 | 5 votes |
def __init__(self, namespace=None, default_level=logging.INFO): self._loggers = {} self._default_level = default_level if namespace is None: namespace = cutil.get_appname_from_path(op.abspath(__file__)) if namespace: namespace = namespace.lower() self._namespace = namespace
Example #28
Source File: lib_util.py From misp42splunk with GNU Lesser General Public License v3.0 | 5 votes |
def get_app_root_dir(): """Return the root dir of app""" return op.dirname(op.dirname(op.abspath(get_main_file())))
Example #29
Source File: versions.py From codimension with GNU General Public License v3.0 | 5 votes |
def getCodimensionVersion(): """Provides the IDE version""" from .globals import GlobalData import sys return GlobalData().version, abspath(sys.argv[0])
Example #30
Source File: lib_util.py From misp42splunk with GNU Lesser General Public License v3.0 | 5 votes |
def get_app_root_dir(): """Return the root dir of app""" return op.dirname(op.dirname(op.abspath(get_main_file())))