Skip to content

Module listing discovery (wildcard glob) #5343

Open

Description

@parsonsmatt

Now that cabal has common stanzas, the only thing keeping me using hpack is that hpack will, by default, autodiscover all of your modules and stuff them into exposed-modules (you can disable this by explicitly defining that stanza). This feature is really convenient to me.

Mimicing that behavior seems like it might be against the Cabal philosophy, as it's implicit -- "If exposed-modules is not defined, collect all modules not listed in other-modules and make them exposed-modules."

A middle ground solution that provides convenience with a degree of explicitness is glob patterns for the module listings. Consider this syntax:

exposed-modules: *

This would find all modules in the source directory and add them as exposed-modules. Kinda like hpack's autodiscovery, but we're explicitly writing "please find all the modules for me."

You could also write:

exposed-modules:
    Control.Monad.*

which would only collect modules under the Control.Monad namespace into exposed-modules -- any other modules would need to be either explicitly added to exposed-modules or other-modules.

Activity

  1. 23Skidoo commented on May 24, 2018

    @23Skidoo
    Member

    It'd be also convenient to be able to specify module names to be treated as exceptions from auto-exposing with glob patterns: other-modules: Control.Monad.Internal.*.

  2. gbaz commented on May 24, 2018

    @gbaz
    Collaborator

    Right. I'd think we'd want some logic relating the two. Explicit always takes precedence over glob. So other-modules explicit takes precedence over glob in exposed-modules, and exposed-modules explicit takes precedence over glob in other-modules. If both are globs or both are explicit, I'd suggest an error, rather than trying to be too clever and pick a potentially nonobvious direction to resolve the ambiguity?

  3. gbaz commented on May 24, 2018

    @gbaz
    Collaborator

    I also don't know if there are interaction effects with backpack that we'd have to worry about -- i.e is it genuinely always the case that given a glob we can simply scan a file-listing without inspecting any contents to determine what it expands to?

  4. parsonsmatt commented on May 24, 2018

    @parsonsmatt
    CollaboratorAuthor

    Yeah, given the following modules:

    Foo
    Foo.Bar
    Baz
    Baz.Internal
    

    I'd expect the following:

    exposed-modules: *
    -- other-modules: [] -- no other-modules clause
    
    -- expands to:
    
    exposed-modules:
        Foo
        Foo.Bar
        Baz
        Baz.Internal
    
    exposed-modules:
        Foo
        Foo.*
     other-modules:
        Baz.*
    
    -- expands to:
    
    exposed-modules:
        Foo
        Foo.Bar
    other-modules:    
        Baz.Internal
    

    and a warning/error that module Baz is not in either listing, as happens now

    exposed-modules:
        *
    other-modules:
        Baz.Internal
    
    -- expands to:
    
    exposed-modules:
        Foo
        Foo.Bar
        Baz
    other-modules:
        Baz.Internal
    

    Because the explicit other-modules overrides the * globbing.

    exposed-modules:
        Foo
    other-modules:
        *
    
    -- expands to:
    exposed-modules:
        Foo
    other-modules:
        Foo.Bar
        Baz
        Baz.Internal
    

    For the same reason as above.

    I have no idea how this would interact with Backpack 🤔

  5. cdepillabout commented on May 2, 2019

    @cdepillabout
    Contributor

    It would be really nice to get this change into cabal.

    This is the sole reason we are still using hpack at work.

  6. domenkozar commented on Aug 5, 2019

    @domenkozar
    Collaborator

    I'd be happy to chip in to get this one done. It's the last annoyance I have that hpack fixed :)

  7. phadej commented on Aug 5, 2019

    @phadej
    Collaborator
  8. domenkozar commented on Aug 5, 2019

    @domenkozar
    Collaborator

    What if glob would be allowed for local development but rejected by hackage. For hackage sdist could substitute glob with the actual files.

    You kind of lose git repository to hackage mapping, but that was never the thing with revisions anyway.

  9. hasufell commented on Aug 6, 2019

    @hasufell
    Member

    You kind of lose git repository to hackage mapping, but that was never the thing with revisions anyway.

    Yep, revisions are already a wart (knowing that they are a sad necessary fix), break freeze files if you don't freeze the index, cause problems for distributions, are infrastructure specific, ...

    Let's not take this as an argument of good design to allow more semi-defined behavior.

    I feel like hpack is exactly what fills the gap here and careful maintainers commit both the hpack and the .cabal files to their repository. Is this really cabals job? If not hpack, then it sounds more like an IDE feature.

  10. phadej commented on Aug 10, 2019

    @phadej
    Collaborator

    FWIW, I released https://hackage.haskell.org/package/cabal-fmt-0.1 which in addition to (opinionatedly) formatting your .cabal file can expand exposed-modules, e.g.

      hs-source-files: src
      -- cabal-fmt: expand src
      exposed-modules:
        Foo
        Foo.Bar

    i.e. in the case when new modules are added, I run cabal-fmt --inplace my.cabal and exposed-modules are re-populated.

    The functionality is bare-bones, let's see what will be needed. In one project, I simply moved non exposed-modules into other hs-source-dirs (actually other-modules, and main-is: Main.hs is in other dir now).

  11. chshersh commented on Aug 15, 2019

    @chshersh
    Member

    cabal-fmt looks helpful and useful. However, the UX of calling command to discover modules is not the same as automatic support of modules discovery by the build tool. In that case, I might as well write the module name manually.

    hpack showed the benefits of such package configuration features like metadata deduplication and automatic module discovery. And if you can reduce duplication of stanza information within a single package using common stanzas, a lot of people are still using hpack because they found the automatic module discovery feature handy. For me, the drawbacks of using hpack outweigh the benefits of its features, and I'm not using it in my projects. However, this particular feature of the module listing discovery is very useful. It makes Haskell development experience smoother, more pleasant and more beginner-friendly, which is very important for Haskell.

    As a maintainer of multiple open-source Haskell libraries and applications, I welcome every contribution. And I want various people to be able to contribute to my projects with as little hassle as possible. That's why I support both build tools cabal and stack. And I find the number of configuration files required for a single Haskell repository too big to my taste:

    package-name.cabal
    cabal.project
    cabal.project.local
    stack.yaml
    stack.yaml.lock
    package.yaml
    

    and there could be more, the list is not exhaustive

    I think that reducing the number of configuration files required for a project, and the number of tools and formats people need to know to develop Haskell projects while preserving the same features is a goal worth trying to achieve. It seems to me that this particular minor (in terms of implementation) feature of module listing discovery can push cabal much further and helps already fractured community to become closer to the consensus of package development.

  12. phadej commented on Aug 15, 2019

    @phadej
    Collaborator

    It seems to me that this particular minor (in terms of implementation) feature of module listing discovery can push ...

    I'll be happy to see a PR.

    My experience on Cabal and cabal-install (and downstream tooling using Cabal as a library) says very opposite. This change is not minor, as .cabal file interpretation becomes file-system state / tarball dependent. (The extra-source-files is different, at least for now, as those are only interesting for sdist command).

    EDIT: note the fact that hpack "works" is because there is clear stage separation. package.yaml is compiled to pkgname.cabal, and pkgname.cabal is used as input to actual build tooling. Blurring the boundary, requiring to .cabal files to be interpreted before further consumption it tricky.

  13. 23 remaining items

  14. philderbeast commented on Mar 31, 2022

    @philderbeast
    Collaborator

    Hpack can be used as a library.

    @hasufell that is how hpack-dhall works.

  15. hdgarrood commented on Nov 16, 2022

    @hdgarrood
    Contributor

    So it seems like the design where globs are permitted in exposed-modules and expanded during cabal sdist is promising and solves all of the problems we are aware of but is blocked on exact printing for cabal files? Is that an accurate summary of where this issue is?

    I’d still really really like to see this happen; in my mind the evidence that people generally just don’t want to explicitly list out every module in their project is extremely strong:

    • the existence of various tools like hpack (including the stack integration), autopack, and cabal-auto-expose (which seems to be the same idea as autopack)
    • the 👍/👎ratio on this issue
    • the fact that few other languages/build systems require you to do this
  16. gbaz commented on Nov 17, 2022

    @gbaz
    Collaborator

    @hdgarrood is this you volunteering to work on exactprint? :-)

  17. hdgarrood commented on Nov 17, 2022

    @hdgarrood
    Contributor

    Probably not, sorry! I think the best I can do is bug some of my colleagues about it :(

  18. Mikolaj commented on Dec 15, 2022

    @Mikolaj
    Member

    Please do bug them. :) There's quite a bit of design discussion in the github project about it (or scattered among the tickets listed there), so it should be ready to actually implement.

  19. Martinsos commented on Mar 9, 2023

    @Martinsos
    Collaborator

    It would be awesome to see this implemented -> in a bigger projects, when moving modules around and refactoring, updating exposed-modules becomes so much of a pain that it deters me a bit from even doing changes in the code. I will be looking at autopack now, but it would be great if cabal supported this natively -> it is weird having to explain to junior devs why they need to do this in cabal when in popular languages this is not needed.

    @Mikolaj design discussion that is scattered -> how hard would be to gather that in one spot, to make it easier for somebody to contribute?

  20. Mikolaj commented on Mar 9, 2023

    @Mikolaj
    Member

    @Mikolaj design discussion that is scattered -> how hard would be to gather that in one spot, to make it easier for somebody to contribute?

    That, and making a summary of what similar components are ready and what needs to be done, would likely be a major part of the work needed for the whole task, including coding.

  21. domenkozar commented on Feb 19, 2024

    @domenkozar
    Collaborator
  22. michaelpj commented on Jun 8, 2024

    @michaelpj
    Collaborator

    So it seems like the design where globs are permitted in exposed-modules and expanded during cabal sdist is promising and solves all of the problems we are aware of but is blocked on exact printing for cabal files?

    I'm interested as to whether this is the only thing we'd accept or whether we would also be okay with Domen's suggestion:

    What if glob would be allowed for local development but rejected by hackage.

    Hackage already has higher standards than cabal for what cabal files it will accept. It would be quite reasonable for it to reject module wildcards. It also cleaves the userbase at a natural fault line:

    1. People who publish libraries on Hackage will need to have explicit module listings, probably also during development, like today
    2. People who work on large industrial applications that are not published on Hackage will never need to have explicit module listings.

    I guess the objection would be that this (probably?) requires support for module wildcards in Cabal-the-library and not just cabal-install? On the other hand, it doesn't rely on exact-printing, which is perpetually just out of reach...

  23. Ericson2314 commented on Nov 29, 2024

    @Ericson2314
    Collaborator

    I think it would be good to put in Cabal the library for a different reason, which is an alternative implementation.

    Instead of doing the globing ourselves, we could have GHC simply tell Cabal about all the modules it found. (We can get this from ghc -M today, even).

    Nevermind backpack, there are things like Happy / Alex too where we end up getting autogenerated modules. Globbing would have to reproduce all that logic, but GHC knows what libraries is is going to build.


    I would also like a version where we can say if different source directories for exposed or hidden modules. This works with either the we-glob or GHC-tells-us approach (since we can see where the modules are located). I think it's good practice to put different sorts of things in different directories anyways, and this sidesteps the question of exactly what sorts of globs we want, and what the priority order between different glob stanzas would be, since directories are trivially disjoint (and nesting source dirs should already be an error, right?).

  24. hasufell commented on Nov 30, 2024

    @hasufell
    Member

    Instead of doing the globing ourselves, we could have GHC simply tell Cabal about all the modules it found. (We can get this from ghc -M today, even).

    I don't think this is a good suggestion.

    First: we want less entanglement between GHC and Cabal.

    Second: I doubt that even works properly with cabal conditionals around hs-source-dirs and the like.

  25. Ericson2314 commented on Nov 30, 2024

    @Ericson2314
    Collaborator

    First: we want less entanglement between GHC and Cabal.

    Yes, but is entirely a matter of opinion whether this is more or less entanglement. The installed .conf file already contains information which is computed with GHC's aid, after all.

    Second: I doubt that even works properly with cabal conditionals around hs-source-dirs and the like.

    Hmm? If you have conditional source dirs, then you get conditional which modules are provided. That is true with globs too.

  26. devnchill commented on Mar 11, 2026

    @devnchill

    guys and update ?

  27. added
    re: globbing
    on May 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions