ci: format
This commit is contained in:
parent
427d03ec2d
commit
2a373b72dd
11 changed files with 93 additions and 23 deletions
|
|
@ -50,7 +50,10 @@ function M.handle_cache_command(cmd)
|
||||||
{ level = vim.log.levels.INFO, override = true }
|
{ level = vim.log.levels.INFO, override = true }
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
logger.log(("Unknown platform '%s'."):format(cmd.platform), { level = vim.log.levels.ERROR })
|
logger.log(
|
||||||
|
("Unknown platform '%s'."):format(cmd.platform),
|
||||||
|
{ level = vim.log.levels.ERROR }
|
||||||
|
)
|
||||||
end
|
end
|
||||||
elseif cmd.platform then
|
elseif cmd.platform then
|
||||||
if vim.tbl_contains(platforms, cmd.platform) then
|
if vim.tbl_contains(platforms, cmd.platform) then
|
||||||
|
|
@ -60,7 +63,10 @@ function M.handle_cache_command(cmd)
|
||||||
{ level = vim.log.levels.INFO, override = true }
|
{ level = vim.log.levels.INFO, override = true }
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
logger.log(("Unknown platform '%s'."):format(cmd.platform), { level = vim.log.levels.ERROR })
|
logger.log(
|
||||||
|
("Unknown platform '%s'."):format(cmd.platform),
|
||||||
|
{ level = vim.log.levels.ERROR }
|
||||||
|
)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
cache.clear_all()
|
cache.clear_all()
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,10 @@ local state = require('cp.state')
|
||||||
function M.login(platform)
|
function M.login(platform)
|
||||||
platform = platform or state.get_platform()
|
platform = platform or state.get_platform()
|
||||||
if not platform then
|
if not platform then
|
||||||
logger.log('No platform specified. Usage: :CP login <platform>', { level = vim.log.levels.ERROR })
|
logger.log(
|
||||||
|
'No platform specified. Usage: :CP login <platform>',
|
||||||
|
{ level = vim.log.levels.ERROR }
|
||||||
|
)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -32,7 +35,10 @@ end
|
||||||
function M.logout(platform)
|
function M.logout(platform)
|
||||||
platform = platform or state.get_platform()
|
platform = platform or state.get_platform()
|
||||||
if not platform then
|
if not platform then
|
||||||
logger.log('No platform specified. Usage: :CP logout <platform>', { level = vim.log.levels.ERROR })
|
logger.log(
|
||||||
|
'No platform specified. Usage: :CP logout <platform>',
|
||||||
|
{ level = vim.log.levels.ERROR }
|
||||||
|
)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
cache.load()
|
cache.load()
|
||||||
|
|
|
||||||
|
|
@ -43,13 +43,19 @@ function M.get_platform_contests(platform, refresh)
|
||||||
|
|
||||||
if refresh or vim.tbl_isempty(picker_contests) then
|
if refresh or vim.tbl_isempty(picker_contests) then
|
||||||
local display_name = constants.PLATFORM_DISPLAY_NAMES[platform]
|
local display_name = constants.PLATFORM_DISPLAY_NAMES[platform]
|
||||||
logger.log(('Fetching %s contests...'):format(display_name), { level = vim.log.levels.INFO, override = true, sync = true })
|
logger.log(
|
||||||
|
('Fetching %s contests...'):format(display_name),
|
||||||
|
{ level = vim.log.levels.INFO, override = true, sync = true }
|
||||||
|
)
|
||||||
|
|
||||||
local contests = scraper.scrape_contest_list(platform)
|
local contests = scraper.scrape_contest_list(platform)
|
||||||
cache.set_contest_summaries(platform, contests)
|
cache.set_contest_summaries(platform, contests)
|
||||||
picker_contests = cache.get_contest_summaries(platform)
|
picker_contests = cache.get_contest_summaries(platform)
|
||||||
|
|
||||||
logger.log(('Fetched %d %s contests.'):format(#picker_contests, display_name), { level = vim.log.levels.INFO, override = true })
|
logger.log(
|
||||||
|
('Fetched %d %s contests.'):format(#picker_contests, display_name),
|
||||||
|
{ level = vim.log.levels.INFO, override = true }
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
return picker_contests
|
return picker_contests
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,10 @@ function M.start(platform, contest_id, language)
|
||||||
|
|
||||||
local remaining = start_time - os.time()
|
local remaining = start_time - os.time()
|
||||||
if remaining <= 0 then
|
if remaining <= 0 then
|
||||||
logger.log('Contest has already started, setting up...', { level = vim.log.levels.INFO, override = true })
|
logger.log(
|
||||||
|
'Contest has already started, setting up...',
|
||||||
|
{ level = vim.log.levels.INFO, override = true }
|
||||||
|
)
|
||||||
require('cp.setup').setup_contest(platform, contest_id, nil, language)
|
require('cp.setup').setup_contest(platform, contest_id, nil, language)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,10 @@ local function apply_template(bufnr, lang_id, platform)
|
||||||
end
|
end
|
||||||
local path = vim.fn.expand(eff.template)
|
local path = vim.fn.expand(eff.template)
|
||||||
if vim.fn.filereadable(path) ~= 1 then
|
if vim.fn.filereadable(path) ~= 1 then
|
||||||
logger.log(('[cp.nvim] template not readable: %s'):format(path), { level = vim.log.levels.WARN })
|
logger.log(
|
||||||
|
('[cp.nvim] template not readable: %s'):format(path),
|
||||||
|
{ level = vim.log.levels.WARN }
|
||||||
|
)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local lines = vim.fn.readfile(path)
|
local lines = vim.fn.readfile(path)
|
||||||
|
|
@ -117,7 +120,10 @@ local function start_tests(platform, contest_id, problems)
|
||||||
scraper.scrape_all_tests(platform, contest_id, function(ev)
|
scraper.scrape_all_tests(platform, contest_id, function(ev)
|
||||||
local cached_tests = {}
|
local cached_tests = {}
|
||||||
if not ev.interactive and vim.tbl_isempty(ev.tests) then
|
if not ev.interactive and vim.tbl_isempty(ev.tests) then
|
||||||
logger.log(("No tests found for problem '%s'."):format(ev.problem_id), { level = vim.log.levels.WARN })
|
logger.log(
|
||||||
|
("No tests found for problem '%s'."):format(ev.problem_id),
|
||||||
|
{ level = vim.log.levels.WARN }
|
||||||
|
)
|
||||||
end
|
end
|
||||||
for i, t in ipairs(ev.tests) do
|
for i, t in ipairs(ev.tests) do
|
||||||
cached_tests[i] = { index = i, input = t.input, expected = t.expected }
|
cached_tests[i] = { index = i, input = t.input, expected = t.expected }
|
||||||
|
|
@ -144,7 +150,10 @@ local function start_tests(platform, contest_id, problems)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end, function()
|
end, function()
|
||||||
logger.log(('Loaded %d test%s.'):format(to_fetch, to_fetch == 1 and '' or 's'), { level = vim.log.levels.INFO, override = true })
|
logger.log(
|
||||||
|
('Loaded %d test%s.'):format(to_fetch, to_fetch == 1 and '' or 's'),
|
||||||
|
{ level = vim.log.levels.INFO, override = true }
|
||||||
|
)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -280,10 +289,20 @@ function M.setup_problem(problem_id, language)
|
||||||
|
|
||||||
if vim.fn.filereadable(source_file) == 1 then
|
if vim.fn.filereadable(source_file) == 1 then
|
||||||
local existing = cache.get_file_state(vim.fn.fnamemodify(source_file, ':p'))
|
local existing = cache.get_file_state(vim.fn.fnamemodify(source_file, ':p'))
|
||||||
if existing and (existing.platform ~= platform or existing.contest_id ~= (state.get_contest_id() or '') or existing.problem_id ~= problem_id) then
|
if
|
||||||
|
existing
|
||||||
|
and (
|
||||||
|
existing.platform ~= platform
|
||||||
|
or existing.contest_id ~= (state.get_contest_id() or '')
|
||||||
|
or existing.problem_id ~= problem_id
|
||||||
|
)
|
||||||
|
then
|
||||||
logger.log(
|
logger.log(
|
||||||
('File %q already exists for %s/%s %s.'):format(
|
('File %q already exists for %s/%s %s.'):format(
|
||||||
source_file, existing.platform, existing.contest_id, existing.problem_id
|
source_file,
|
||||||
|
existing.platform,
|
||||||
|
existing.contest_id,
|
||||||
|
existing.problem_id
|
||||||
),
|
),
|
||||||
{ level = vim.log.levels.ERROR }
|
{ level = vim.log.levels.ERROR }
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,10 @@ function M.submit(opts)
|
||||||
local problem_id = state.get_problem_id()
|
local problem_id = state.get_problem_id()
|
||||||
local language = (opts and opts.language) or state.get_language()
|
local language = (opts and opts.language) or state.get_language()
|
||||||
if not platform or not contest_id or not problem_id or not language then
|
if not platform or not contest_id or not problem_id or not language then
|
||||||
logger.log('No active problem. Use :CP <platform> <contest> first.', { level = vim.log.levels.ERROR })
|
logger.log(
|
||||||
|
'No active problem. Use :CP <platform> <contest> first.',
|
||||||
|
{ level = vim.log.levels.ERROR }
|
||||||
|
)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -311,7 +311,10 @@ setup_keybindings = function(buf)
|
||||||
end
|
end
|
||||||
|
|
||||||
if is_tracked then
|
if is_tracked then
|
||||||
logger.log('Test buffer closed unexpectedly. Exiting editor.', { level = vim.log.levels.WARN })
|
logger.log(
|
||||||
|
'Test buffer closed unexpectedly. Exiting editor.',
|
||||||
|
{ level = vim.log.levels.WARN }
|
||||||
|
)
|
||||||
M.toggle_edit()
|
M.toggle_edit()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
@ -368,7 +371,10 @@ function M.toggle_edit(test_index)
|
||||||
state.get_platform(), state.get_contest_id(), state.get_problem_id()
|
state.get_platform(), state.get_contest_id(), state.get_problem_id()
|
||||||
|
|
||||||
if not platform or not contest_id or not problem_id then
|
if not platform or not contest_id or not problem_id then
|
||||||
logger.log('No problem context. Run :CP <platform> <contest> first.', { level = vim.log.levels.ERROR })
|
logger.log(
|
||||||
|
'No problem context. Run :CP <platform> <contest> first.',
|
||||||
|
{ level = vim.log.levels.ERROR }
|
||||||
|
)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,10 @@ function M.toggle_interactive(interactor_cmd)
|
||||||
and contest_data.index_map
|
and contest_data.index_map
|
||||||
and not contest_data.problems[contest_data.index_map[problem_id]].interactive
|
and not contest_data.problems[contest_data.index_map[problem_id]].interactive
|
||||||
then
|
then
|
||||||
logger.log('This problem is not interactive. Use :CP {run,panel}.', { level = vim.log.levels.ERROR })
|
logger.log(
|
||||||
|
'This problem is not interactive. Use :CP {run,panel}.',
|
||||||
|
{ level = vim.log.levels.ERROR }
|
||||||
|
)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -383,7 +386,10 @@ function M.ensure_io_view()
|
||||||
and contest_data.index_map
|
and contest_data.index_map
|
||||||
and contest_data.problems[contest_data.index_map[problem_id]].interactive
|
and contest_data.problems[contest_data.index_map[problem_id]].interactive
|
||||||
then
|
then
|
||||||
logger.log('This problem is not interactive. Use :CP {run,panel}.', { level = vim.log.levels.ERROR })
|
logger.log(
|
||||||
|
'This problem is not interactive. Use :CP {run,panel}.',
|
||||||
|
{ level = vim.log.levels.ERROR }
|
||||||
|
)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -599,7 +605,10 @@ function M.run_io_view(test_indices_arg, debug, mode)
|
||||||
end
|
end
|
||||||
io_view_running = true
|
io_view_running = true
|
||||||
|
|
||||||
logger.log(('%s tests...'):format(debug and 'Debugging' or 'Running'), { level = vim.log.levels.INFO, override = true })
|
logger.log(
|
||||||
|
('%s tests...'):format(debug and 'Debugging' or 'Running'),
|
||||||
|
{ level = vim.log.levels.INFO, override = true }
|
||||||
|
)
|
||||||
|
|
||||||
mode = mode or 'combined'
|
mode = mode or 'combined'
|
||||||
|
|
||||||
|
|
@ -792,7 +801,10 @@ function M.toggle_panel(panel_opts)
|
||||||
and contest_data.index_map
|
and contest_data.index_map
|
||||||
and contest_data.problems[contest_data.index_map[state.get_problem_id()]].interactive
|
and contest_data.problems[contest_data.index_map[state.get_problem_id()]].interactive
|
||||||
then
|
then
|
||||||
logger.log('This is an interactive problem. Use :CP interact instead.', { level = vim.log.levels.WARN })
|
logger.log(
|
||||||
|
'This is an interactive problem. Use :CP interact instead.',
|
||||||
|
{ level = vim.log.levels.WARN }
|
||||||
|
)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -152,7 +152,10 @@ local function discover_nix_submit_cmd()
|
||||||
:wait()
|
:wait()
|
||||||
|
|
||||||
if result.code ~= 0 then
|
if result.code ~= 0 then
|
||||||
logger.log('nix build #submitEnv failed: ' .. (result.stderr or ''), { level = vim.log.levels.WARN })
|
logger.log(
|
||||||
|
'nix build #submitEnv failed: ' .. (result.stderr or ''),
|
||||||
|
{ level = vim.log.levels.WARN }
|
||||||
|
)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -216,7 +219,10 @@ local function discover_nix_python()
|
||||||
:wait()
|
:wait()
|
||||||
|
|
||||||
if result.code ~= 0 then
|
if result.code ~= 0 then
|
||||||
logger.log('nix build #pythonEnv failed: ' .. (result.stderr or ''), { level = vim.log.levels.WARN })
|
logger.log(
|
||||||
|
'nix build #pythonEnv failed: ' .. (result.stderr or ''),
|
||||||
|
{ level = vim.log.levels.WARN }
|
||||||
|
)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -367,7 +367,8 @@ def _submit_headless(
|
||||||
page.wait_for_timeout(BROWSER_SETTLE_DELAY)
|
page.wait_for_timeout(BROWSER_SETTLE_DELAY)
|
||||||
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=BROWSER_SUBMIT_NAV_TIMEOUT["atcoder"]
|
lambda url: "/submissions/me" in url,
|
||||||
|
timeout=BROWSER_SUBMIT_NAV_TIMEOUT["atcoder"],
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
submit_error = str(e)
|
submit_error = str(e)
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,9 @@ HTTP_TIMEOUT = 15.0
|
||||||
|
|
||||||
BROWSER_SESSION_TIMEOUT = 15000
|
BROWSER_SESSION_TIMEOUT = 15000
|
||||||
BROWSER_NAV_TIMEOUT = 10000
|
BROWSER_NAV_TIMEOUT = 10000
|
||||||
BROWSER_SUBMIT_NAV_TIMEOUT: defaultdict[str, int] = defaultdict(lambda: BROWSER_NAV_TIMEOUT)
|
BROWSER_SUBMIT_NAV_TIMEOUT: defaultdict[str, int] = defaultdict(
|
||||||
|
lambda: BROWSER_NAV_TIMEOUT
|
||||||
|
)
|
||||||
BROWSER_SUBMIT_NAV_TIMEOUT["codeforces"] = BROWSER_NAV_TIMEOUT * 2
|
BROWSER_SUBMIT_NAV_TIMEOUT["codeforces"] = BROWSER_NAV_TIMEOUT * 2
|
||||||
BROWSER_TURNSTILE_POLL = 5000
|
BROWSER_TURNSTILE_POLL = 5000
|
||||||
BROWSER_ELEMENT_WAIT = 10000
|
BROWSER_ELEMENT_WAIT = 10000
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue