If you just were spend a little bit of effort reading the documentations you’d see that music21 uses the Krumhansl-Schmuckler algorithm for key detection with the Krumhansl-Kessler weights.
Basically this algorithm assigns to each chromatic step of a key a weight, representing how often we expect to find this particular note in this key. Each key will thus shift this set of weights. The algorithm then determines for each note the total duration of this note within the piece.
The key is then determined as the one where this set of durations and the theoretical weights have the highest correlation.
So basically it tries to math the key by how often we expect certain notes vs how often we actually have them.
Having minor and major then works by having different sets of weights for minor scales and major scales, and using the one that matches best.
This can of course easily extended to work with church modes, but it will lead to quite a few problems:
- A mode is a feature of really old music and not the same as a key, which is a feature of more modern music. This is important as many concepts of modern music do not fit well with modes. So inherently this might make little sense.
- You’d need to come up with weights for these modes, which would require a lot of research in modal music that might in fact not produce a resonable result
- This algorithm is not particularly stable in the first place, adding lots of additional options will increase the chance of "accidental" matches and wrong classifications. It might just work well with two keys, but with two keys and 7 modes this would probably not produce usable results.
But if you like, try to extend the code. This stuff is defined here:
Add weights for church modes and stuff, and see if you get anything usable. The code itself states that the Krumhansl-Schmuckler weights have a tendency to output the dominant as tonic, so I doubt it. But feel free to try :)