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_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 #4
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 #5
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 #6
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 #7
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 #8
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 #9
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 #10
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 #11
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 #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: 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 #14
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 #15
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 #16
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 #17
Source File: options.py From godot-mono-builds with MIT License | 5 votes |
def base_opts_from_args(args): from os.path import abspath return BaseOpts( verbose_make = args.verbose_make, jobs = args.jobs, configure_dir = abspath(args.configure_dir), install_dir = abspath(args.install_dir), mono_source_root = abspath(args.mono_sources), mxe_prefix = args.mxe_prefix )
Example #18
Source File: options.py From godot-mono-builds with MIT License | 5 votes |
def android_opts_from_args(args): return AndroidOpts( **vars(runtime_opts_from_args(args)), android_toolchains_prefix = abspath(args.toolchains_prefix), android_sdk_root = abspath(args.android_sdk), android_ndk_root = abspath(args.android_ndk), android_api_version = args.android_api_version, android_cmake_version = args.android_cmake_version )
Example #19
Source File: options.py From godot-mono-builds with MIT License | 5 votes |
def ios_opts_from_args(args): return iOSOpts( **vars(runtime_opts_from_args(args)), ios_toolchain_path = abspath(args.ios_toolchain), ios_sdk_path = abspath(args.ios_sdk) if args.ios_sdk else '', ios_version_min = args.ios_version_min, osx_toolchain_path = abspath(args.osx_toolchain), osx_sdk_path = abspath(args.osx_sdk) if args.ios_sdk else '', osx_triple_abi = args.osx_triple_abi )
Example #20
Source File: config.py From Collaborative-Learning-for-Weakly-Supervised-Object-Detection with MIT License | 5 votes |
def get_output_dir(imdb, weights_filename): """Return the directory where experimental artifacts are placed. If the directory does not exist, it is created. A canonical path is built using the name from an imdb and a network (if not None). """ outdir = osp.abspath(osp.join(__C.ROOT_DIR, 'output', __C.EXP_DIR, imdb.name)) if weights_filename is None: weights_filename = 'default' outdir = osp.join(outdir, weights_filename) if not os.path.exists(outdir): os.makedirs(outdir) return outdir
Example #21
Source File: config.py From Collaborative-Learning-for-Weakly-Supervised-Object-Detection with MIT License | 5 votes |
def get_output_tb_dir(imdb, weights_filename): """Return the directory where tensorflow summaries are placed. If the directory does not exist, it is created. A canonical path is built using the name from an imdb and a network (if not None). """ outdir = osp.abspath(osp.join(__C.ROOT_DIR, 'tensorboard', __C.EXP_DIR, imdb.name)) if weights_filename is None: weights_filename = 'default' outdir = osp.join(outdir, weights_filename) if not os.path.exists(outdir): os.makedirs(outdir) return outdir
Example #22
Source File: imdb.py From Collaborative-Learning-for-Weakly-Supervised-Object-Detection with MIT License | 5 votes |
def cache_path(self): cache_path = osp.abspath(osp.join(cfg.DATA_DIR, 'cache')) if not os.path.exists(cache_path): os.makedirs(cache_path) return cache_path
Example #23
Source File: setup.py From BiblioPixelAnimations with MIT License | 5 votes |
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
Example #24
Source File: create_long_description.py From NiBetaSeries with MIT License | 5 votes |
def read(*names, **kwargs): return io.open( join(abspath(*names)), encoding=kwargs.get('encoding', 'utf8') ).read()
Example #25
Source File: setup.py From python-rest-api with BSD 2-Clause "Simplified" License | 5 votes |
def get_description(): working_directory = path.abspath(path.dirname(__file__)) readme_path = path.join(working_directory, 'README.md') with open(readme_path, encoding='utf-8') as f: return (f.read(), 'text/markdown')
Example #26
Source File: test_tmpdirs.py From delocate with BSD 2-Clause "Simplified" License | 5 votes |
def test_given_directory(): # Test InGivenDirectory cwd = getcwd() with InGivenDirectory() as tmpdir: assert_equal(tmpdir, abspath(cwd)) assert_equal(tmpdir, abspath(getcwd())) with InGivenDirectory(MY_DIR) as tmpdir: assert_equal(tmpdir, MY_DIR) assert_equal(realpath(MY_DIR), realpath(abspath(getcwd()))) # We were deleting the Given directory! Check not so now. assert_true(isfile(MY_PATH))
Example #27
Source File: run.py From find_forks with MIT License | 5 votes |
def main(): """Main function to run as shell script.""" loader = unittest.TestLoader() suite = loader.discover(path.abspath(path.dirname(__file__)), pattern='test_*.py') runner = unittest.TextTestRunner(buffer=True) runner.run(suite)
Example #28
Source File: config.py From cascade-rcnn_Pytorch with MIT License | 5 votes |
def get_output_dir(imdb, weights_filename): """Return the directory where experimental artifacts are placed. If the directory does not exist, it is created. A canonical path is built using the name from an imdb and a network (if not None). """ outdir = osp.abspath(osp.join(__C.ROOT_DIR, 'output', __C.EXP_DIR, imdb.name)) if weights_filename is None: weights_filename = 'default' outdir = osp.join(outdir, weights_filename) if not os.path.exists(outdir): os.makedirs(outdir) return outdir
Example #29
Source File: config.py From cascade-rcnn_Pytorch with MIT License | 5 votes |
def get_output_tb_dir(imdb, weights_filename): """Return the directory where tensorflow summaries are placed. If the directory does not exist, it is created. A canonical path is built using the name from an imdb and a network (if not None). """ outdir = osp.abspath(osp.join(__C.ROOT_DIR, 'tensorboard', __C.EXP_DIR, imdb.name)) if weights_filename is None: weights_filename = 'default' outdir = osp.join(outdir, weights_filename) if not os.path.exists(outdir): os.makedirs(outdir) return outdir
Example #30
Source File: imdb.py From cascade-rcnn_Pytorch with MIT License | 5 votes |
def cache_path(self): cache_path = osp.abspath(osp.join(cfg.DATA_DIR, 'cache')) if not os.path.exists(cache_path): os.makedirs(cache_path) return cache_path