-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use module names rather than file names for output #25
base: master
Are you sure you want to change the base?
Conversation
Thanks a lot, Jason. Is there no way for SerAPI to give us this information? I'm wary of adding code that I don't understand fully, and that (I think?) duplicates something that Coq already does internally. Maybe @ejgallego can help? Emilio, we'd like to name the files produced by Alectryon based on their module path; can SerAPI tell us what the module path of the current file is? Thanks! |
# will result in confusing names if the path starts with '..', so | ||
# in that case we use the absolute path | ||
fpath = os.path.relpath(os.path.normpath(fpath), '.') | ||
if fpath.startswith('..' + os.sep) and not os.path.abspath(fpath): # do we need the second conjunct ever? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this branch ever be taken? That is, when does not os.path.abspath(fpath)
return True?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the not os.path.abspath(fpath)
is redundant because paths starting with ../
should never be absolute (absolute means that it starts with a mount point/drive letter or else starts with /
, I think). But the branch is certainly taken, for example if you invoke the script on ../foo.v
alectryon/cli.py
Outdated
return lambda contents, fname, output, output_directory: \ | ||
write_output(ext, contents, fname, output, output_directory) | ||
return lambda contents, fname, fpath, output, output_directory, coq_args_Q, coq_args_R: \ | ||
write_output(ext, contents, fname, fpath, output, output_directory, coq_args_Q, coq_args_R) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this transformation only happen for Coq files? Presumably reST file don't need the renaming, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that files should either be module-named or else laid out in a directory hirerachy. Are all non-coq files flat? (And what about .v.rst?).
Yes it can as the logic is already there, I'm not sure if exposed in the protocol, but should be very easy to add. So IUUC you want the function at https://github.com/coq/coq/blob/ea62d1e19f2ba565ea3a18ba3709a06af5c845ac/sysinit/coqargs.ml#L459 exposed in the API? Should be a matter of just wrapping it. Note that there has been a lot of work in providing a better setup for Coq libraries and theories, including a single, queryable API for loadpaths etc... , but it is still not finished, but that doesn't mean we forgot about it and other requests. |
In particular a terrible pitfall current tooling for Coq has is that it has several copies of code managing A fix for this is already started at coq/coq#14059 , but indeed note that I strongly discourage people doing tooling having their own logic for loadpaths, instead they should aim to use the existing code and the new library as soon as it is available. I say this because it is extremely likely that there will big changes in how libs are managed in Coq in the short term, so any code you write for that today will not work soon unless you indeed use the API we aim to provide in In particular, it is not safe to make any assumptions on paths [which are opaque on the new library] and on mappings w.r.t. paths <-> dirmaps. |
Coq's library handling code contains an API to map "logical" paths to "physical" paths and vice-versa, we provide a helper query ```lisp (Query () (LogicalPath file)) ``` which exposes this resolution for users, as requested in cpitclaudel/alectryon#25 Note that the plan for 8.14 is to expose the fully principled API that will be introduced at coq/coq#14059.
Added , c.f. https://github.com/ejgallego/coq-serapi/pull/236/files [Note the function was already there but unused, I got side-tracked sadly but indeed there were plans to expose it] |
@cpitclaudel do you want me to update this PR with your feedback, or shall we abandon it in favor of rocq-archive/coq-serapi#236? (I imagine it'd be easy for you to code something up using that?)
I'm not sure what to make of this, given that I maintain https://github.com/JasonGross/coq-tools to be compatible with Coq all the way back to 8.5. (I dropped 8.4 when it got too hard to build on newer versions of Linux.) Are people's developments going to suddenly start breaking? Or are you just saying that the edge cases are going to change behavior? |
Hard to know yet, the proposal is not even in CEP form. So indeed the current model will be "V1 library model" and I think it will keep working for a while, for users of the new features, coq-tools would indeed require likely a lot of work. So it is more about additional features than about the existing model which will be preserved, but indeed some stuff such as concrete file location may change. Easy example: we will stop installing everything under IMHO we should try to avoid placing duplicate logic inside tooling, but rather take the painful but correct path which it is to have the tooling use the right upstream libraries instead. Updated SerAPI protocol will hopefully come with direct Python bindings so for Coq tools it should be a matter of using the Python API I hope. Tradeoffs are subtle here tho, a typical example is parsing. Many people have tried to re-implement Coq's parser (with not the best results IMO), where in most cases the right solution indeed is to use Coq's parser, however Coq parsing API is not good for all use cases so YMMV. For now my idea is to support Python, OCaml, and JavaScript/TypeScript users in direct API form, rest are on their own with the serialized RPC . Reimplementing any kind of logic separately IMHO leads to inevitable bitrot, as either:
|
As for this PR I guess the best tradeoff is to keep the Python code in a compat module, and use it if SerAPI < supported version, otherwise use the SerAPI tool. This kind of "polyfill" pattern could be useful for some other features IMHO. |
Now that I have hijacked the thread and we are talking about what the protocol can/should do I'd like to do a very brief update on what is the status w.r.t. things Alectryon needs: the short story is that after analyzing what is missing for Alectryon, unfortunately to implement/provide that properly does require deep changes in the way we handle documents internally in Coq; a presentation of what is going on should hopefully happen soon. |
My solution to this was to run |
That's an easy case, if you are already running IMVHO this is poorly managed by current Coq implementation, new document managers should make this much better but still parsing is tied to execution so if you need a truly isolated parsing phase you are out of luck and will have to write your own :( |
I think I prefer that solution in the long term. While we wait for that we could work on this PR, but I think it would work very nicely as well to just monkey-patch things on your side. WDYT? |
We could, but that's more maintenance and more debugging. I prefer to take a dependency on a more recent SerAPI. |
Got it, thanks a lot for the update! |
You can easily translate between these two, I think, as long as each of the cutoffs is between codepoints. (basically you split the bytestring at positions reported by Coq, then encode each sub-bytestring and compute cumulative sums over the lengths of the resulting (sub)strings). But indeed this is a case where sercomp is pretty nice. |
Sounds good, let me then review my org file to see what more patches I have pending for Alectryon and I'll make a SerAPI release this week. |
And much faster than |
I think the bigger problem is that I'm trying to be compatible with both python 2 and python 3, and they handle strings in different ways. |
That's software archeology: Python 2 has been EOL for 10 years and unsupported for since last year :) |
I'm happy to just depend on my fork of alectryon until the better long term fix happens, assuming it'll happen in the not-too-distant future. |
Coq's library handling code contains an API to map "logical" paths to "physical" paths and vice-versa, we provide a helper query ```lisp (Query () (LogicalPath file)) ``` which exposes this resolution for users, as requested in cpitclaudel/alectryon#25 Note that the plan for 8.14 is to expose the fully principled API that will be introduced at coq/coq#14059.
458fba8
to
ebfdc34
Compare
5d75901
to
d7ec2b4
Compare
CHANGES: - [serapi] New query `(Query () (LogicalPath file))` which will return the logical path for a particular `.v` file (@ejgallego, see also cpitclaudel/alectryon#25) - [serapi] new `(SaveDoc opts)` command supporting saving of .vo files even when from interactive mode; note that using `--topfile` is required (fixes rocq-archive/coq-serapi#238, @ejgallego, reported by Jason Gross) - [sertop] we don't link the OCaml `num` library anymore, this could have some impact on plugins (@ejgallego) - [nix] Added Nix support (rocq-archive/coq-serapi#249, fixes rocq-archive/coq-serapi#248, @Zimmi48, reported by @nyraghu) - [serapi] Fix COQPATH support: interpret paths as absolute (rocq-archive/coq-serapi#249, @Zimmi48) - [serlib] Ignore `env` parameter in certain exceptions (rocq-archive/coq-serapi#254, fixes rocq-archive/coq-serapi#250, @ejgallego, reported by @cpitclaudel) - [sertop] New option `--omit_env` that will disable the serialization of Coq's super heavy global environments (rocq-archive/coq-serapi#254 @ejgallego) - [build] Test OCaml 4.12 (ejgallego/coq-serapi#257 @ejgallego) - [sertop] Async mode was not working due to passing `-no-glob` to workers
@JasonGross Any chance you can update your fork? It is lagging behind and we need newer alectryon features for HoTT. |
@cpitclaudel What is the status of the more principled fix here? |
5a1e613
to
59e380b
Compare
@Alizter I've rebased. |
59e380b
to
6d9557d
Compare
6d9557d
to
2eefbdf
Compare
Sorry, I missed this message because my Coq filter was too aggressive (looks like I missed a lot of stuff) :/
It seems that it got merged! So we should probably use that. But, re-reading #14 , it seems that what |
Where is the implementation of |
It's described here: https://github.com/xavierleroy/coq2html?tab=readme-ov-file#html-generation It's completely trivial; it just prepends its argument to the name of each generated file: |
Ah, yes, it looks like |
Fixes #14
Code adjusted from
https://github.com/JasonGross/coq-tools/blob/9b81719a2172e4301126378e5aebf83e3f2b43e6/import_util.py#L99-L111