def _add_scripts(self) -> List[Path]: added = [] entry_points = self.convert_entry_points() for scripts_path in self._env.script_dirs: if is_dir_writable(path=scripts_path, create=True): break else: self._io.write_error_line( " - Failed to find a suitable script installation directory for {}".format( self._poetry.file.parent ) ) return [] scripts = entry_points.get("console_scripts", []) for script in scripts: name, script = script.split(" = ") module, callable_ = script.split(":") callable_holder = callable_.split(".", 1)[0] script_file = scripts_path.joinpath(name) self._debug( " - Adding the <c2>{}</c2> script to <b>{}</b>".format( name, scripts_path ) ) with script_file.open("w", encoding="utf-8") as f: f.write( decode( SCRIPT_TEMPLATE.format( python=self._env.python, module=module, callable_holder=callable_holder, callable_=callable_, ) ) ) script_file.chmod(0o755) added.append(script_file) if WINDOWS: cmd_script = script_file.with_suffix(".cmd") cmd = WINDOWS_CMD_TEMPLATE.format(python=self._env.python, script=name) self._debug( " - Adding the <c2>{}</c2> script wrapper to <b>{}</b>".format( cmd_script.name, scripts_path ) ) with cmd_script.open("w", encoding="utf-8") as f: f.write(decode(cmd)) added.append(cmd_script) return added
def writable_candidates(self) -> List[Path]: if self._writable_candidates is not None: return self._writable_candidates self._writable_candidates = [] for candidate in self._candidates: if not is_dir_writable(path=candidate, create=True): continue self._writable_candidates.append(candidate) return self._writable_candidates