Finding locally compiled Raku modules

Richard Hainsworth

How can find modules that have been installed locally, and which I can use in a Raku program?

Assume that we have three distributions: Parent, Brother, Sister. Parent 'provides' Top.rakumod, while Brother and Sister provide 'Top::Son.rakumod' and 'Top::Daughter.rakumod', respectively. Brother and Sister have a 'depends': 'Top' in their META6.json.

Each distribution is in its own git repo. And each are installed by zef.

Suppose Top is set up as a class with an interface method, perhaps something like: multi method on-starting { ... }, which each sub-class has to implement, and which when run, provides the caller with information about the sub-class. So both Top::Brother and Top::Daughter implement on-starting. There could also be distributions Top::Aunt and so on, which are not locally installed. We need to find which are installed.

So, now we run an instance of Top (as defined in Parent). It needs to look for installed modules that match Top::*. The place to start (I think) is $*REPO, which is a linked list of repositories containing the modules that are installed. $*REPO also does the CompUnit::Repository role, which in turn has a 'need' method.

What I don't understand is how to manipulate $*REPO to get a list of all the candidate modules that match Top::*, along the whole of the linked list.

Once I have the list of candidates, I can use ^can to check it has a on-starting method, and then call that method.

If this is not the way to get to a result where Top finds out about locally installed modules, I'd appreciate some alternatives to the scheme I just laid out.

ugexe

CompUnit::Repository (CUR) has a candidates method for searching distributions, but it does not allow for searching by name prefix (since it also does fast lookups which require the full name to get its sha1 directory/lookup). For a CompUnit::Repository::FileSystem (CURFS) you can call .distribution to get the distribution is provides, and for CompUnit::Repository::Installation (CURI) you can call .installed to get all the distributions it provides:

raku -e '                                                                                        \
    say $*REPO.repo-chain                                                                        \
        .grep(CompUnit::Repository::FileSystem | CompUnit::Repository::Installation)             \ 
        .map({ $_ ~~ CompUnit::Repository::FileSystem ?? $_.distribution !! $_.installed.Slip }) \
        .grep(*.defined)                                                                         \
;'

If you want to match namespaces you would need to then grep on the distributions name or the name of its modules:

my @matches = @distributions.grep({ $_.meta<provides>.keys.first({.starts-with("Top::")}) });

This way of handling things can be seen in the Pluggable module (which I'd suggest using if you also want to load such code)

Of course you explicitly asked only for installed modules, but ignoring CURFS doesn't make any sense -- as an application developer it isn't supposed to matter where or how a module is loaded. If someone wants to use -I ./foo instead of installing it there isn't a good reason to ignore it. If you insist on doing this anyway it should be obvious how to change the example above to accommodate.

Once I have the list of candidates, I can use ^can to check it has a on-starting method, and then call that method.

Having a list of candidates doesn't let you do anything other than inspect the meta file or slurp the source code of various files. At the very least you would load whatever module you wanted to call e.g. .^can first, and there is going to be a few steps involved in that, which the distribution object can't be used directly to load with (you extract the full name from it and use that to load it) -- so again I'd suggest using Pluggable

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Virtualenv not finding imported modules

From Dev

Finding Modules in Joomla

From Dev

Use Haskell like Prelude modules in a module in raku

From Dev

Make locally compiled programs request password graphically

From Dev

Finding dependencies for a compiled C++ program

From Dev

Angular Jasmine test not finding modules

From Dev

Finding unused python modules in a directory

From Dev

Rails not finding classes within modules

From Dev

Jasmine/Karma not finding Angular modules

From Dev

babel react issues finding modules

From Dev

Locally installed versus globally installed NPM modules

From Dev

Why does npm install modules locally by default?

From Dev

Do Ansible modules run locally or on the remote host?

From Dev

Fetching both locally and globally installed nodejs modules

From Dev

Why does npm install modules locally by default?

From Dev

lambda not finding my node_modules

From Java

Ansible not finding custom python modules on remote server

From Dev

Finding modules when running python with virtualenvs, in launchd

From Dev

Finding Menu ids of existing Modules in Odoo?

From Dev

finding out the list of required modules by a module in racket

From Dev

Angular 2: Problems with imports not finding modules

From Dev

'Failed to load interface' error when loading compiled modules in ghci

From Dev

How to run a TypeScript app compiled into a single file with AMD modules?

From Dev

VMware Workstation: Error, modules must be compiled... - how to fix?

From Dev

VMware Workstation: Error, modules must be compiled... - how to fix?

From Dev

'Failed to load interface' error when loading compiled modules in ghci

From Dev

Loading kernel modules that were compiled for another kernel failed

From Dev

Configure built-in modules in cross-compiled linux

From Dev

Before you can run VMware several modules must be compiled

Related Related

  1. 1

    Virtualenv not finding imported modules

  2. 2

    Finding Modules in Joomla

  3. 3

    Use Haskell like Prelude modules in a module in raku

  4. 4

    Make locally compiled programs request password graphically

  5. 5

    Finding dependencies for a compiled C++ program

  6. 6

    Angular Jasmine test not finding modules

  7. 7

    Finding unused python modules in a directory

  8. 8

    Rails not finding classes within modules

  9. 9

    Jasmine/Karma not finding Angular modules

  10. 10

    babel react issues finding modules

  11. 11

    Locally installed versus globally installed NPM modules

  12. 12

    Why does npm install modules locally by default?

  13. 13

    Do Ansible modules run locally or on the remote host?

  14. 14

    Fetching both locally and globally installed nodejs modules

  15. 15

    Why does npm install modules locally by default?

  16. 16

    lambda not finding my node_modules

  17. 17

    Ansible not finding custom python modules on remote server

  18. 18

    Finding modules when running python with virtualenvs, in launchd

  19. 19

    Finding Menu ids of existing Modules in Odoo?

  20. 20

    finding out the list of required modules by a module in racket

  21. 21

    Angular 2: Problems with imports not finding modules

  22. 22

    'Failed to load interface' error when loading compiled modules in ghci

  23. 23

    How to run a TypeScript app compiled into a single file with AMD modules?

  24. 24

    VMware Workstation: Error, modules must be compiled... - how to fix?

  25. 25

    VMware Workstation: Error, modules must be compiled... - how to fix?

  26. 26

    'Failed to load interface' error when loading compiled modules in ghci

  27. 27

    Loading kernel modules that were compiled for another kernel failed

  28. 28

    Configure built-in modules in cross-compiled linux

  29. 29

    Before you can run VMware several modules must be compiled

HotTag

Archive