BAPCtools
BAPCtools copied to clipboard
[tools] Separate changing to contest directory and getting problems list
Copying part of the discussion from https://github.com/RagnarGrootKoerkamp/BAPCtools/pull/163#discussion_r748593896:
@RagnarGrootKoerkamp:
Really it would be cleaner to parse these after cding to the contest dir, but that probably introduces other problems
@mpsijm:
I've tried separating the
cd
ing to the contest dir before parsing the personal config file in f5ac03601745ae8935d89209356b8b5ba8862cd2. [...] Splitting off achange_directory()
function from theget_problems()
function already makes things slightly cleaner, but:
- Moving
change_directory()
outsiderun_parsed_args
means we'll have to duplicate this betweenmain()
andtest(args)
- This will also require changes in the behaviour of
new_{contest,problem}
, as the--contest
and--problem
flags are not valid for these commands
- Moving
change_directory()
outsiderun_parsed_args
means we'll have to duplicate this betweenmain()
andtest(args)
That's fine - duplicating some code for tests is OK with me.
- This will also require changes in the behavior of
new_{contest,problem}
, as the--contest
and--problem
flags are not valid for these commands
Right. Do you want to spend some more time on this for this PR? (I assume that's why it's draft for now.)
I'm not exactly sure myself yet how we should handle this. One possibility:
- parse args without reading any config files (only to find the subcommand)
- if new_{contest,problem}, handle that and exit
- if other subcommand, cd to contest directory
- parse args again, now with reading the required context
duplicating some code for tests is OK with me.
All right :slightly_smiling_face:
(I assume that's why it's draft for now.)
Correct :yum:
I'm not exactly sure myself yet how we should handle this. One possibility: [...]
Sounds good, but I don't like the fact that the arguments need to be parsed twice. I was thinking of something like the following (but I'll need to try this to see how it works out):
- In
main()
:- Read command line args (without passing the personal config as default values)
- Set
initial_cwd = os.getcwd()
-
cd
to to contest directory (this reads--contest
and--problem
only from the command line, but having them in a personal config file wouldn't make sense anyway :stuck_out_tongue:) - Read personal config
- Call
run_parsed_arguments
with combinedargs
object
- In
run_parsed_arguments(args)
:-
if action in ['new_contest', 'new_problem']:
check if--contest
and/or--problem
are set, and throw an error if so (onlynew_problem --contest
would be valid). Then,os.chdir(initial_pwd)
and continue with the action -
else:
continue processing theargs
as usual
-
Maybe 2.i should be checked before 1.iv, but that requires a bit more rewriting. I'll experiment with it for a bit :slightly_smiling_face:
@mpsijm what's the status here? I kinda forgot what this was about
If I remember correctly, this is mostly to make the parsing of the personal config file more consistent. It's mostly a code cleanup that doesn't really have high priority, but I would still like to finish it if I do have the time :stuck_out_tongue: