How to use the pathlib2.Path.cwd 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 / punic / repository.py View on Github external
cartfile_private_path = self.path / 'Cartfile.private'

            if cartfile_path.exists():
                cartfile.read(cartfile_path)
                specifications += cartfile.specifications

            if cartfile_private_path.exists():
                cartfile.read(cartfile_private_path)
                if set(specifications).intersection(cartfile.specifications):
                    raise PunicRepresentableError(
                        "Specifications in your Cartfile.private conflict with specifications within your Cartfile.")
                specifications += cartfile.specifications

            if not specifications:
                raise PunicRepresentableError(
                    "No specifications found in {} or {}".format(cartfile_path.relative_to(Path.cwd()), cartfile_private_path.relative_to(Path.cwd())))

        else:
            self.check_work_directory()

            try:
                parsed_revision = self.rev_parse(revision)
            except:
                print("FAILED") # JIWTODO
                return []

            result = runner.run('git show "{}:Cartfile"'.format(parsed_revision), cwd=self.path)
            if result.return_code != 0:
                specifications = []
            else:
                data = result.stdout
                cartfile = Cartfile(use_ssh=self.config.use_ssh, overrides=config.repo_overrides)
github nodepy / nodepy / nodepy / context.py View on Github external
def __init__(self, maindir=None, config=None, parent=None, isolate=True, inherit=True):
    if not config and not parent:
      filename = os.path.expanduser(os.getenv('NODEPY_CONFIG', '~/.nodepy/config'))
      config = Config(filename, {})
    if not maindir and not parent:
      maindir = pathlib.Path.cwd()
    self.parent = parent
    self.isolate = isolate
    self.inherit = inherit
    self._config = config
    self._maindir = maindir
    self.require = Require(self, self.maindir)
    self.extensions = [extensions.ImportSyntax(), extensions.NamespaceSyntax()]
    self.resolver = resolver.StdResolver([], [loader.PythonLoader()]) #, loader.PackageRootLoader()])
    self.resolvers = []
    self.pathaugmentors = [base.ZipPathAugmentor()]
    self.modules = {}
    self.packages = {}
    self.module_stack = []
    self.main_module = None
    self.localimport = localimport.localimport([])
    self.tracer = None
github MultiChain / multichain / depends / v8_data_lib.py View on Github external
def process_bin_files(platform):
    cwd = Path.cwd()
    obj_names = []
    for f in chain(cwd.glob("*.bin"), cwd.glob("*.dat")):
        obj_names.append(process_bin_file(f, platform))
    os.chdir("obj")
    _arch, _obj_suffix, lib_pattern = get_bin_type(platform)
    ar = "x86_64-w64-mingw32-ar" if platform == "win32" else "ar"
    cmd = [ar, "rvs", lib_pattern.format("v8_data")]
    cmd += obj_names
    logger.info(' '.join(cmd))
    call(cmd)
github allegroai / trains / trains / backend_interface / task / repo / detectors.py View on Github external
def _normalize_root(root):
        """
        Get the absolute location of the parent folder (where .git resides)
        """
        root_parts = list(reversed(Path(root).parts))
        cwd_abs = list(reversed(Path.cwd().parts))
        count = len(cwd_abs)
        for i, p in enumerate(cwd_abs):
            if i >= len(root_parts):
                break
            if p == root_parts[i]:
                count -= 1
        cwd_abs.reverse()
        root_abs_path = Path().joinpath(*cwd_abs[:count])
        return str(root_abs_path)
github allegroai / trains / trains / backend_interface / task / repo / scriptinfo.py View on Github external
def _get_entry_point(cls, repo_root, script_path):
        repo_root = Path(repo_root).absolute()

        try:
            # Use os.path.relpath as it calculates up dir movements (../)
            entry_point = os.path.relpath(str(script_path), str(Path.cwd()))
        except ValueError:
            # Working directory not under repository root
            entry_point = script_path.relative_to(repo_root)

        return Path(entry_point).as_posix()
github MultiChain / multichain / builder / v8_data_lib.py View on Github external
def process_bin_files(platform):
    cwd = Path.cwd()
    obj_names = []
    for f in chain(cwd.glob("*.bin"), cwd.glob("*.dat")):
        obj_names.append(process_bin_file(f, platform))
    os.chdir("obj")
    _arch, _obj_suffix, lib_pattern = get_bin_type(platform)
    cmd = ["ar", "rvs", lib_pattern.format("v8_data")]
    cmd += obj_names
    logger.info(' '.join(cmd))
    call(cmd)
github allegroai / trains / trains / backend_interface / task / repo / scriptinfo.py View on Github external
def _get_working_dir(cls, repo_root):
        repo_root = Path(repo_root).absolute()

        try:
            return Path.cwd().relative_to(repo_root).as_posix()
        except ValueError:
            # Working directory not under repository root
            return os.path.curdir
github schwa / punic / punic / __init__.py View on Github external
def __init__(self, root_path=None):

        global current_session

        if not current_session:
            current_session = self

        if not root_path:
            root_path = Path.cwd()

        self.config = config

        root_project_identifier = ProjectIdentifier(overrides=None, project_name=self.config.root_path.name)

        self.all_repositories = {root_project_identifier: Repository(punic=self, identifier=root_project_identifier, repo_path=self.config.root_path),}

        self.root_project = self._repository_for_identifier(root_project_identifier)