Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions plain-code/plain/code/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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")

Expand Down
54 changes: 34 additions & 20 deletions plain-code/plain/code/oxc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)

Expand Down
Loading