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.
This commit is contained in:
parent
1bc0aa41b6
commit
c194f12eee
11 changed files with 863 additions and 116 deletions
67
flake.nix
67
flake.nix
|
|
@ -26,10 +26,65 @@
|
|||
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";
|
||||
|
|
@ -39,12 +94,15 @@
|
|||
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; };
|
||||
passthru = { inherit pythonEnv submitEnv; };
|
||||
meta.description = "Competitive programming plugin for Neovim";
|
||||
};
|
||||
in
|
||||
|
|
@ -58,17 +116,22 @@
|
|||
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
|
||||
python312
|
||||
(mkDevPythonEnv (pkgsFor system))
|
||||
prettier
|
||||
ruff
|
||||
stylua
|
||||
selene
|
||||
lua-language-server
|
||||
ty
|
||||
];
|
||||
};
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue