cslmath / Champlain-Saint-Lambert-webwork-repo

A library of WeBWorK problems contributed by the Champlain Saint-Lambert math department
3 stars 4 forks source link

Can we use pointers in pg files in the CPL? #31

Open maharper opened 3 years ago

maharper commented 3 years ago

The OPL uses links or pointers in (many) pg files. That is file name.pg is only a pointer or link to master file.pg.

Can we do this in the CPL? If so, does it play nicely with saved set defs and with template assignments?

It would allow us to fully resolve #30 fix typos "Lorentz" -> "Lorenz"

maharper commented 3 years ago

Yes, we can use redirection links in problems locally. The basic structure is:

DOCUMENT();
includePGproblem("path/to/MH21-redirect-to.pg");
ENDDOCUMENT();

The main concern is that the path to the good problem, path/to/MH21-redirect-to.pg in this case, starts from the course templates directory. This means the redirection or pointer would not survive moving the good file (for example from CPL-Contrib to CPL or from CPL to OPL) although I suppose multiple, chained redirections may be possible.

The redirections in the OPL are called pointers and most seem to be like the attached file. MH21-redirect-from-1.pg.txt.

Remaining TODO:

gabindu commented 3 years ago

Personally, I'd recommend against this, as there are just too many moving pieces which might break at any given moment...

Also, linked problem files are problematic (da-dum-tss) when a teacher decides to edit a local copy for whatever reason. (In the particular case of #30, that's less of an issue, as this would actually point out that this file wasn't the one to use in the first place - but I've already run into this problem on occasion with linked problem files in the OPL.)

Relatedly, I wonder what happens to random seeds with linked files - is the seed correctly passed on to the linked file? When the link is used to replace an incorrect file name, this might not be an issue - but when a link is used to create a second version of the same problem, this needs to be verified, otherwise this could lead to completely identical problems on the same assignment.

By the way: A different solution to this whole situation (but which probably would also suffer from the same random seed issue) would be using symlinks or (better) hard links on a file system basis, which would avoid at least some WebWork-centric issues. On a *nix system, ln source target creates a new file "target" which is in fact using the same data as the file source: Editing either will change the same content, and deleting either has no effect on the other. In particular, the files can even be moved around freely - as long as they stay on the same file system. (In fact, both "files" point to the same inode in the file system, so are for all matters in fact the same file, but with two different names.)

All this being said, hard links (and I believe symlinks as well) are unfortunately not preserved by git - so that's probably not a great solution either.

maharper commented 3 years ago

I was just thinking this morning that links might be another solution and we already use links in the CPL in a couple of cases. They are fiddly to get to work properly with git as you say, I had some issues and had to be careful to make sure my local CPL git worked with symlinks (Windows).

In this particular case I don'think there is much possibility of things breaking as the problems are already in the CPL and won't be moving. I will however check if the pointer ca be relative to the file location (using ./redirect-to.pg instead of full/path/from/template-dir/redirect-to.pg) as that would solve any relocation problems.

maharper commented 3 years ago

Relatedly, I wonder what happens to random seeds with linked files - is the seed correctly passed on to the linked file? When the link is used to replace an incorrect file name, this might not be an issue - but when a link is used to create a second version of the same problem, this needs to be verified, otherwise this could lead to completely identical problems on the same assignment.

I am a.s. that this is not a problem. You can add two copies of the same pg file to a homework set and the two questions in the homework set are assigned different seeds. I don't see any reason why it would be any different if one question was a pointer to the pg used by a second question.