예제 #1
0
async def suggest_typeshed_update(update: Update,
                                  session: aiohttp.ClientSession,
                                  action_level: ActionLevel) -> None:
    if action_level <= ActionLevel.nothing:
        return
    title = f"[stubsabot] Bump {update.distribution} to {update.new_version_spec}"
    async with _repo_lock:
        branch_name = f"{BRANCH_PREFIX}/{normalize(update.distribution)}"
        subprocess.check_call(
            ["git", "checkout", "-B", branch_name, "origin/master"])
        with open(update.stub_path / "METADATA.toml", "rb") as f:
            meta = tomlkit.load(f)
        meta["version"] = update.new_version_spec
        with open(update.stub_path / "METADATA.toml", "w") as f:
            tomlkit.dump(meta, f)
        subprocess.check_call(["git", "commit", "--all", "-m", title])
        if action_level <= ActionLevel.local:
            return
        somewhat_safe_force_push(branch_name)
        if action_level <= ActionLevel.fork:
            return

    body = "\n".join(f"{k}: {v}" for k, v in update.links.items())
    body += """

If stubtest fails for this PR:
- Leave this PR open (as a reminder, and to prevent stubsabot from opening another PR)
- Fix stubtest failures in another PR, then close this PR
"""
    await create_or_update_pull_request(title=title,
                                        body=body,
                                        branch_name=branch_name,
                                        session=session)
예제 #2
0
async def suggest_typeshed_obsolete(obsolete: Obsolete,
                                    session: aiohttp.ClientSession,
                                    action_level: ActionLevel) -> None:
    if action_level <= ActionLevel.nothing:
        return
    title = f"[stubsabot] Mark {obsolete.distribution} as obsolete since {obsolete.obsolete_since_version}"
    async with _repo_lock:
        branch_name = f"{BRANCH_PREFIX}/{normalize(obsolete.distribution)}"
        subprocess.check_call(
            ["git", "checkout", "-B", branch_name, "origin/master"])
        with open(obsolete.stub_path / "METADATA.toml", "rb") as f:
            meta = tomlkit.load(f)
        obs_string = tomlkit.string(obsolete.obsolete_since_version)
        obs_string.comment(
            f"Released on {obsolete.obsolete_since_date.date().isoformat()}")
        meta["obsolete_since"] = obs_string
        with open(obsolete.stub_path / "METADATA.toml", "w") as f:
            tomlkit.dump(meta, f)
        subprocess.check_call(["git", "commit", "--all", "-m", title])
        if action_level <= ActionLevel.local:
            return
        somewhat_safe_force_push(branch_name)
        if action_level <= ActionLevel.fork:
            return

    body = "\n".join(f"{k}: {v}" for k, v in obsolete.links.items())
    await create_or_update_pull_request(title=title,
                                        body=body,
                                        branch_name=branch_name,
                                        session=session)
예제 #3
0
파일: core.py 프로젝트: danieleades/pdm
 def write_pyproject(self, show_message: bool = True) -> None:
     with atomic_open_for_write(
         self.pyproject_file.as_posix(), encoding="utf-8"
     ) as f:
         tomlkit.dump(self.pyproject, f)  # type: ignore
     if show_message:
         self.core.ui.echo(
             f"Changes are written to {termui.green('pyproject.toml')}."
         )
     self._pyproject = None
예제 #4
0
파일: core.py 프로젝트: danieleades/pdm
    def write_lockfile(
        self, toml_data: dict, show_message: bool = True, write: bool = True
    ) -> None:
        toml_data["metadata"].update(self.get_lock_metadata())

        if write:
            with atomic_open_for_write(self.lockfile_file) as fp:
                tomlkit.dump(toml_data, fp)  # type: ignore
            if show_message:
                self.core.ui.echo(f"Changes are written to {termui.green('pdm.lock')}.")
            self._lockfile = None
        else:
            self._lockfile = toml_data
예제 #5
0
    def _save_config(self) -> None:
        """Save the changed to config file."""
        self.config_file.parent.mkdir(parents=True, exist_ok=True)
        toml_data: Dict[str, Any] = {}
        for key, value in self._file_data.items():
            *parts, last = key.split(".")
            temp = toml_data
            for part in parts:
                if part not in temp:
                    temp[part] = {}
                temp = temp[part]
            temp[last] = value

        with self.config_file.open("w", encoding="utf-8") as fp:
            tomlkit.dump(toml_data, fp)  # type: ignore
예제 #6
0
def save(document: tomlkit.TOMLDocument, file_path: str | Path) -> None:
    """Save a TOML document to a given path"""
    settings_path = Path(file_path)
    with settings_path.open('w') as f:
        tomlkit.dump(document, f)
예제 #7
0
def test_dump_to_file_object():
    doc = {"foo": "bar"}
    fp = io.StringIO()
    dump(doc, fp)
    assert fp.getvalue() == 'foo = "bar"\n'