diff --git a/plain-code/plain/code/cli.py b/plain-code/plain/code/cli.py index 69789df79b..16473d11e5 100644 --- a/plain-code/plain/code/cli.py +++ b/plain-code/plain/code/cli.py @@ -282,8 +282,13 @@ def _print_annotations_json(result: AnnotationResult) -> None: @click.argument("paths", nargs=-1) @click.option("--unsafe-fixes", is_flag=True, help="Apply ruff unsafe fixes") @click.option("--add-noqa", is_flag=True, help="Add noqa comments to suppress errors") +@click.option("--skip-oxc", is_flag=True, help="Skip oxlint and oxfmt") def fix( - ctx: click.Context, paths: tuple[str, ...], unsafe_fixes: bool, add_noqa: bool + ctx: click.Context, + paths: tuple[str, ...], + unsafe_fixes: bool, + add_noqa: bool, + skip_oxc: bool, ) -> None: """Fix formatting and linting issues""" if not paths: @@ -327,7 +332,7 @@ def fix( if result.returncode != 0: sys.exit(result.returncode) - if other_paths and config.get("oxc", {}).get("enabled", True): + if not skip_oxc and other_paths and config.get("oxc", {}).get("enabled", True): oxlint = OxcTool("oxlint") oxfmt = OxcTool("oxfmt") diff --git a/plain-code/plain/code/oxc.py b/plain-code/plain/code/oxc.py index 9e284bdb78..bfebe14c66 100644 --- a/plain-code/plain/code/oxc.py +++ b/plain-code/plain/code/oxc.py @@ -118,13 +118,21 @@ def detect_platform_slug(self) -> str: @staticmethod def get_latest_version() -> str: """Find the latest apps_v release tag via the GitHub API.""" - resp = httpx.get( - "https://api.github.com/repos/oxc-project/oxc/releases", - params={"per_page": 20}, - headers={"Accept": "application/vnd.github+json"}, - follow_redirects=True, - ) - resp.raise_for_status() + try: + resp = httpx.get( + "https://api.github.com/repos/oxc-project/oxc/releases", + params={"per_page": 20}, + headers={"Accept": "application/vnd.github+json"}, + follow_redirects=True, + ) + resp.raise_for_status() + except httpx.HTTPError as e: + raise click.ClickException( + "Couldn't reach github.com to look up the latest oxlint/oxfmt " + f"release ({e}). If this environment can't reach GitHub, pin a " + "version in pyproject.toml under [tool.plain.code.oxc], or pass " + "--skip-oxc." + ) from e for release in resp.json(): tag = release["tag_name"] if tag.startswith(TAG_PREFIX): @@ -143,21 +151,27 @@ def download(self, version: str = "") -> str: # Download into memory for extraction data = io.BytesIO() - with httpx.stream("GET", url, follow_redirects=True) as resp: - resp.raise_for_status() - total = int(resp.headers.get("Content-Length", 0)) - if total: - with click.progressbar( - length=total, - label=f"Downloading {self.name}", - width=0, - ) as bar: + try: + with httpx.stream("GET", url, follow_redirects=True) as resp: + resp.raise_for_status() + total = int(resp.headers.get("Content-Length", 0)) + if total: + with click.progressbar( + length=total, + label=f"Downloading {self.name}", + width=0, + ) as bar: + for chunk in resp.iter_bytes(chunk_size=1024 * 1024): + data.write(chunk) + bar.update(len(chunk)) + else: for chunk in resp.iter_bytes(chunk_size=1024 * 1024): data.write(chunk) - bar.update(len(chunk)) - else: - for chunk in resp.iter_bytes(chunk_size=1024 * 1024): - data.write(chunk) + except httpx.HTTPError as e: + raise click.ClickException( + f"Couldn't download {self.name} from github.com ({e}). If this " + "environment can't reach GitHub, pass --skip-oxc." + ) from e data.seek(0)