cp.nvim/flake.nix
Barrett Ruth c194f12eee
feat(atcoder): extract submit helpers; add live status notifications (#294)
## Problem

`_submit_sync` was a 170-line nested closure with `_solve_turnstile` and
the browser-install block further nested inside it. Status events went
to
stderr, which `run_scraper()` silently discards, leaving the user with a
10–30s silent hang after credential entry. The NDJSON spawn path also
lacked stdin support, so submit had no streaming path at all.

## Solution

Extract `_TURNSTILE_JS`, `_solve_turnstile`, `_ensure_browser`, and
`_submit_headless` to module level in `atcoder.py`; status events
(`installing_browser`, `checking_login`, `logging_in`, `submitting`) now
print to stdout as NDJSON. Add stdin pipe support to the NDJSON spawn
path in `scraper.lua` and switch `M.submit` to streaming with an
`on_status` callback. Wire `on_status` in `submit.lua` to fire
`vim.notify` for each phase transition.
2026-03-04 19:27:29 -05:00

139 lines
3.4 KiB
Nix

{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
systems.url = "github:nix-systems/default-linux";
};
outputs =
{
self,
nixpkgs,
systems,
}:
let
eachSystem = nixpkgs.lib.genAttrs (import systems);
pkgsFor = system: nixpkgs.legacyPackages.${system};
mkPythonEnv =
pkgs:
pkgs.python312.withPackages (ps: [
ps.backoff
ps.beautifulsoup4
ps.curl-cffi
ps.httpx
ps.ndjson
ps.pydantic
ps.requests
]);
mkDevPythonEnv =
pkgs:
pkgs.python312.withPackages (ps: [
ps.backoff
ps.beautifulsoup4
ps.curl-cffi
ps.httpx
ps.ndjson
ps.pydantic
ps.requests
ps.pytest
ps.pytest-mock
]);
mkSubmitEnv =
pkgs:
pkgs.buildFHSEnv {
name = "cp-nvim-submit";
targetPkgs =
pkgs: with pkgs; [
uv
alsa-lib
at-spi2-atk
cairo
cups
dbus
fontconfig
freetype
gdk-pixbuf
glib
gtk3
libdrm
libxkbcommon
mesa
libGL
nspr
nss
pango
libx11
libxcomposite
libxdamage
libxext
libxfixes
libxrandr
libxcb
at-spi2-core
expat
libgbm
systemdLibs
zlib
];
runScript = "${pkgs.uv}/bin/uv";
};
mkPlugin =
pkgs:
let
pythonEnv = mkPythonEnv pkgs;
submitEnv = mkSubmitEnv pkgs;
in
pkgs.vimUtils.buildVimPlugin {
pname = "cp-nvim";
version = "0-unstable-${self.shortRev or self.dirtyShortRev or "dev"}";
src = self;
postPatch = ''
substituteInPlace lua/cp/utils.lua \
--replace-fail "local _nix_python = nil" \
"local _nix_python = '${pythonEnv.interpreter}'"
substituteInPlace lua/cp/utils.lua \
--replace-fail "local _nix_submit_cmd = nil" \
"local _nix_submit_cmd = '${submitEnv}/bin/cp-nvim-submit'"
'';
nvimSkipModule = [
"cp.pickers.telescope"
"cp.version"
];
passthru = { inherit pythonEnv submitEnv; };
meta.description = "Competitive programming plugin for Neovim";
};
in
{
overlays.default = final: prev: {
vimPlugins = prev.vimPlugins // {
cp-nvim = mkPlugin final;
};
};
packages = eachSystem (system: {
default = mkPlugin (pkgsFor system);
pythonEnv = mkPythonEnv (pkgsFor system);
submitEnv = mkSubmitEnv (pkgsFor system);
});
formatter = eachSystem (system: (pkgsFor system).nixfmt-tree);
devShells = eachSystem (system: {
default = (pkgsFor system).mkShell {
packages = with (pkgsFor system); [
uv
(mkDevPythonEnv (pkgsFor system))
prettier
ruff
stylua
selene
lua-language-server
ty
];
};
});
};
}