Zulip Chat Archive

Stream: general

Topic: Diagnosing cyclic imports


Eric Wieser (Nov 12 2020 at 11:48):

Is there a tool that will show me the full import cycle / graph?

Eric Wieser (Nov 12 2020 at 11:50):

Ah, found leanproject import-graph, which seems to run quite slowly on mathlib

Kevin Lacker (Nov 12 2020 at 16:34):

i found grep to be the most useful tool here (or the similar ack)

Eric Wieser (Dec 02 2020 at 18:58):

Running into cyclic import issues again in https://github.com/leanprover-community/mathlib/pull/5187 :(

Eric Wieser (Dec 02 2020 at 19:14):

It would be really handy if lean could print the full cycle when this happens

Eric Wieser (Dec 02 2020 at 19:18):

I get the feeling mathlibtools.leanproject import-graph doesn't work when cyclic imports are present either

Eric Wieser (Dec 02 2020 at 19:36):

For some reason even if I revert to a working build and run py -3.8 -m mathlibtools.leanproject import-graph --to data.fintype.basic bad.graphml, I get a file with a single node in it

Johan Commelin (Dec 02 2020 at 19:46):

Eric Wieser said:

It would be really handy if lean could print the full cycle when this happens

note that tsort will print cycles. So if you use the bash functions that I posted last time, it might be easy to get the full cycle.

Eric Wieser (Dec 02 2020 at 19:55):

Eric Wieser said:

For some reason even if I revert to a working build and run py -3.8 -m mathlibtools.leanproject import-graph --to data.fintype.basic bad.graphml, I get a file with a single node in it

I just tried this again from python - the exception on these lines is being thrown byPath(r"C:/projects/mathlib/src").relative_to("src"). I think this is a mathlibtools bug, although perhaps I have an outdated version

Eric Wieser (Dec 02 2020 at 20:00):

Updated to mathlibtools == 1.0.0, but still have the problem. Can someone check if import-graph works for them?

Eric Wieser (Dec 03 2020 at 11:16):

leanprover-community/mathlib-tools#88 fixes it for me. cc @Patrick Massot, since you just looked at another mathlibtools thread.

Patrick Massot (Dec 03 2020 at 11:46):

Thanks!

Bolton Bailey (Aug 19 2021 at 18:25):

Hey, I'm also wanting lean to show me where the cycle is that I've introduced. Is there a good way of doing this / where can I get @Johan Commelin 's bash functions that make this easier?

Yaël Dillies (Aug 19 2021 at 18:29):

Doing it by hand is usually not too hard if the files concerned do not have transitive imports. A rough knowledge of the library's organisation also helps.

Bolton Bailey (Aug 19 2021 at 18:36):

Yeah, ok, after focusing and clicking for about a minute I found the cycle, thanks for the advice.

Bolton Bailey (Aug 19 2021 at 18:38):

It is true that you sort of have to have a working knowledge of how imports in mathlib tend to work though, so I would support the error message printing the cycle.

Yaël Dillies (Aug 19 2021 at 18:48):

Yeah absolutely! Would be a great addition.

Bolton Bailey (Aug 19 2021 at 18:52):

Hehe, I am now trying to reconstruct what I did to find the cycle and I can't find it.

Yaël Dillies (Aug 19 2021 at 18:53):

Importing wrongly once will likely create many cycles, so it's probably hard to find the "meaningful" one.

Bolton Bailey (Aug 19 2021 at 18:56):

Ok, found it again, crisis averted


Last updated: Dec 20 2023 at 11:08 UTC