ci: format

This commit is contained in:
Barrett Ruth 2026-03-04 19:03:54 -05:00
parent 9272a9660e
commit 574e6b3a79
Signed by: barrett
GPG key ID: A6C96C9349D2FC81
7 changed files with 196 additions and 907 deletions

View file

@ -26,6 +26,20 @@
ps.requests 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 = mkSubmitEnv =
pkgs: pkgs:
pkgs.buildFHSEnv { pkgs.buildFHSEnv {
@ -44,19 +58,24 @@
glib glib
gtk3 gtk3
libdrm libdrm
libGL
libxkbcommon libxkbcommon
mesa mesa
libGL
nspr nspr
nss nss
pango pango
xorg.libX11 libx11
xorg.libXcomposite libxcomposite
xorg.libXdamage libxdamage
xorg.libXext libxext
xorg.libXfixes libxfixes
xorg.libXrandr libxrandr
xorg.libxcb libxcb
at-spi2-core
expat
libgbm
systemdLibs
zlib
]; ];
runScript = "${pkgs.uv}/bin/uv"; runScript = "${pkgs.uv}/bin/uv";
}; };
@ -100,15 +119,19 @@
submitEnv = mkSubmitEnv (pkgsFor system); submitEnv = mkSubmitEnv (pkgsFor system);
}); });
formatter = eachSystem (system: (pkgsFor system).nixfmt-tree);
devShells = eachSystem (system: { devShells = eachSystem (system: {
default = (pkgsFor system).mkShell { default = (pkgsFor system).mkShell {
packages = with (pkgsFor system); [ packages = with (pkgsFor system); [
uv uv
python312 (mkDevPythonEnv (pkgsFor system))
prettier prettier
ruff
stylua stylua
selene selene
lua-language-server lua-language-server
ty
]; ];
}; };
}); });

View file

@ -278,7 +278,16 @@ function M.scrape_all_tests(platform, contest_id, callback)
}) })
end end
function M.submit(platform, contest_id, problem_id, language, source_code, credentials, on_status, callback) function M.submit(
platform,
contest_id,
problem_id,
language,
source_code,
credentials,
on_status,
callback
)
local done = false local done = false
run_scraper(platform, 'submit', { contest_id, problem_id, language }, { run_scraper(platform, 'submit', { contest_id, problem_id, language }, {
ndjson = true, ndjson = true,
@ -286,15 +295,22 @@ function M.submit(platform, contest_id, problem_id, language, source_code, crede
env_extra = { CP_CREDENTIALS = vim.json.encode(credentials) }, env_extra = { CP_CREDENTIALS = vim.json.encode(credentials) },
on_event = function(ev) on_event = function(ev)
if ev.status ~= nil then if ev.status ~= nil then
if type(on_status) == 'function' then on_status(ev.status) end if type(on_status) == 'function' then
on_status(ev.status)
end
elseif ev.success ~= nil then elseif ev.success ~= nil then
done = true done = true
if type(callback) == 'function' then callback(ev) end if type(callback) == 'function' then
callback(ev)
end
end end
end, end,
on_exit = function(proc) on_exit = function(proc)
if not done and type(callback) == 'function' then if not done and type(callback) == 'function' then
callback({ success = false, error = 'submit process exited (code=' .. tostring(proc.code) .. ')' }) callback({
success = false,
error = 'submit process exited (code=' .. tostring(proc.code) .. ')',
})
end end
end, end,
}) })

View file

@ -7,7 +7,7 @@ requires-python = ">=3.11"
dependencies = [ dependencies = [
"backoff>=2.2.1", "backoff>=2.2.1",
"beautifulsoup4>=4.13.5", "beautifulsoup4>=4.13.5",
"camoufox[geoip]", "scrapling[fetchers]>=0.4",
"curl-cffi>=0.13.0", "curl-cffi>=0.13.0",
"httpx>=0.28.1", "httpx>=0.28.1",
"ndjson>=0.3.1", "ndjson>=0.3.1",

View file

@ -235,7 +235,7 @@ def _extract_samples(html: str) -> list[TestCase]:
return cases return cases
_TURNSTILE_JS = '() => { const el = document.querySelector(\'[name="cf-turnstile-response"]\'); return el && el.value.length > 0; }' _TURNSTILE_JS = "() => { const el = document.querySelector('[name=\"cf-turnstile-response\"]'); return el && el.value.length > 0; }"
def _solve_turnstile(page) -> None: def _solve_turnstile(page) -> None:
@ -358,9 +358,7 @@ def _submit_headless(
finally: finally:
os.unlink(tmp_path) os.unlink(tmp_path)
page.locator('button[type="submit"]').click() page.locator('button[type="submit"]').click()
page.wait_for_url( page.wait_for_url(lambda url: "/submissions/me" in url, timeout=60000)
lambda url: "/submissions/me" in url, timeout=60000
)
except Exception as e: except Exception as e:
submit_error = str(e) submit_error = str(e)
@ -561,7 +559,12 @@ class AtcoderScraper(BaseScraper):
credentials: dict[str, str], credentials: dict[str, str],
) -> SubmitResult: ) -> SubmitResult:
return await asyncio.to_thread( return await asyncio.to_thread(
_submit_headless, contest_id, problem_id, source_code, language_id, credentials _submit_headless,
contest_id,
problem_id,
source_code,
language_id,
credentials,
) )

View file

@ -1,7 +1,7 @@
LANGUAGE_IDS = { LANGUAGE_IDS = {
"atcoder": { "atcoder": {
"cpp": "5028", "cpp": "6017",
"python": "5078", "python": "6082",
}, },
"codeforces": { "codeforces": {
"cpp": "89", "cpp": "89",

View file

@ -4,8 +4,10 @@ set -eu
nix develop --command stylua --check . nix develop --command stylua --check .
git ls-files '*.lua' | xargs nix develop --command selene --display-style quiet git ls-files '*.lua' | xargs nix develop --command selene --display-style quiet
nix develop --command prettier --check . nix develop --command prettier --check .
nix fmt
git diff --exit-code -- '*.nix'
nix develop --command lua-language-server --check . --checklevel=Warning nix develop --command lua-language-server --check . --checklevel=Warning
nix develop --command uvx ruff format --check . nix develop --command ruff format --check .
nix develop --command uvx ruff check . nix develop --command ruff check .
nix develop --command uvx ty check . nix develop --command ty check .
nix develop --command uv run pytest tests/ -v nix develop --command python -m pytest tests/ -v

1009
uv.lock generated

File diff suppressed because it is too large Load diff