How to use the pathlib2.Path function in pathlib2

To help you get started, we’ve selected a few pathlib2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github schwa / punic / testing / test_example_projects.py View on Github external
def test_local_1():
    with example_work_directory('local_1'):

        assert(Path('Cartfile.resolved').exists() == False)
        output = runner.check_run('punic resolve')
        assert(Path('Cartfile.resolved').open().read() == 'local "A" "."\n')

        # TODO: This should NOT be created by a resolve.
        # assert(Path('Carthage/Checkouts').exists() == False)
        output = runner.check_run('punic fetch')
        assert(Path('Carthage/Checkouts').is_dir() == True)

        # TODO: This should NOT be created by a fetch.
        # assert(Path('Carthage/Build').exists() == False)
        output = runner.check_run('punic build')
        assert(Path('Carthage/Build/Mac/A.framework').exists() == True)
        assert(Path('Carthage/Build/Mac/A.dSYM').exists() == True)
github tribe29 / checkmk / tests / unit / cmk / utils / test_man_pages.py View on Github external
def test_man_page_path_only_shipped():
    assert man_pages.man_page_path("if64") == Path(cmk_path()) / "checkman" / "if64"
    assert man_pages.man_page_path("not_existant") is None
github syslog-ng / syslog-ng / tests / python_functional / src / setup / unit_testcase.py View on Github external
def get_temp_dir(self):
        testcase_name = calculate_testcase_name(self.testcase_context)
        testcase_subdir = "{}_{}".format(self.__get_current_date(), testcase_name)
        temp_dir = Path("/tmp", testcase_subdir)
        temp_dir.mkdir()
        self.__registered_dirs.append(temp_dir)
        return temp_dir
github parklab / PaSDqc / src / mappable_positions.py View on Github external
def lookup_map_file(build, chrom):

    chrom = to_hg19_format(chrom)

    path = pathlib2.Path("db/")
    map_file = sorted(path.glob('{}.{}.map.bed'.format(build, chrom)))[0]

    if not map_file:
        raise IOError("Uh oh, there's no map file matching {} and {}".format(build, chrom))

    return map_file
github onicagroup / runway / runway / module / __init__.py View on Github external
path (Union[str, Path]): Path to the module.
            options (Dict[str, Dict[str, Any]]): Everything in the module
                definition merged with applicable values from the deployment
                definition.

        """
        options = options or {}
        super(RunwayModuleNpm, self).__init__(context, path, options)
        del self.options  # remove the attr set by the parent class

        # potential future state of RunwayModule attributes in a future release
        self._raw_path = Path(options.pop('path')) if options.get('path') else None
        self.environments = options.pop('environments', {})
        self.options = options.pop('options', {})
        self.parameters = options.pop('parameters', {})
        self.path = path if isinstance(self.path, Path) else Path(self.path)
        self.name = options.get('name', self.path.name)

        for k, v in options.items():
            setattr(self, k, v)

        self.check_for_npm()  # fail fast
        warn_on_boto_env_vars(self.context.env_vars)
github allegroai / trains-agent / trains_agent / helper / package / conda_api.py View on Github external
This means environment have to be deleted using 'conda env remove'.
        If necessary, conda can be fooled into deleting a partially-deleted environment by creating an empty file
        in '\conda-meta\history' (value found in 'conda.gateways.disk.test.PREFIX_MAGIC_FILE').
        Otherwise, it complains that said directory is not a conda environment.

        See: https://github.com/conda/conda/issues/7682
        """
        try:
            self._run_command(("env", "remove", "-p", self.path))
        except Exception:
            pass
        rm_tree(self.path)
        # if we failed removing the path, change it's name
        if is_windows_platform() and Path(self.path).exists():
            try:
                Path(self.path).rename(Path(self.path).as_posix() + '_' + str(time()))
            except Exception:
                pass
github Azure / batch-shipyard / shipyard.py View on Github external
def ensure_pathlib_conf(conf):
        # type: (Any) -> pathlib.Path
        """Ensure conf object is a pathlib object
        :param str or pathlib.Path or None conf: conf object
        :rtype: pathlib.Path or None
        :return: conf object as pathlib
        """
        if conf is not None and not isinstance(conf, pathlib.Path):
            conf = pathlib.Path(conf)
        return conf
github Azure / batch-shipyard / convoy / crypto.py View on Github external
def generate_ssh_keypair(export_path, prefix=None):
    # type: (str, str) -> tuple
    """Generate an ssh keypair for use with user logins
    :param str export_path: keypair export path
    :param str prefix: key prefix
    :rtype: tuple
    :return: (private key filename, public key filename)
    """
    if util.is_none_or_empty(prefix):
        prefix = _SSH_KEY_PREFIX
    privkey = pathlib.Path(export_path, prefix)
    pubkey = pathlib.Path(export_path, prefix + '.pub')
    if privkey.exists():
        old = pathlib.Path(export_path, prefix + '.old')
        if old.exists():
            old.unlink()
        privkey.rename(old)
    if pubkey.exists():
        old = pathlib.Path(export_path, prefix + '.pub.old')
        if old.exists():
            old.unlink()
        pubkey.rename(old)
    logger.info('generating ssh key pair to path: {}'.format(export_path))
    subprocess.check_call(
        ['ssh-keygen', '-f', str(privkey), '-t', 'rsa', '-N', ''''''])
    return (privkey, pubkey)