unofficial mirror of help-guix@gnu.org 
 help / color / mirror / Atom feed
* Import package and generate use-module
@ 2021-04-24  9:26 phodina via
  2021-04-24 13:54 ` Ekaitz Zarraga
  0 siblings, 1 reply; 2+ messages in thread
From: phodina via @ 2021-04-24  9:26 UTC (permalink / raw)
  To: help-guix@gnu.org

I'm making a package for octoprint which is imported from PyPI. guix import -r octoprint generates the template to build the package.

However, I'm missing the :#use-module ... in order to build the package when I add (define-module (python-octoprint). Given the fact there are tens of inputs doing it manually seems tedious and writing a script to parse the package definition seems like reinventing the wheel as I'm certainly not the first person to run into this issue.

So is there a way to automate also this part?

Let me give you context:If I look at Guix package repository gnu/packages/python-xyz.scm I see there definitions of packages:

(define-public python-numpy
  (package
    (name "python-numpy")
...

If I have another package that depends on python-numpy I just provide the name in e.g. inputs and I don't have to import it with #:use-module within this file.

However, when I run guix import pypi PKG I get package definition and when I run guix build -f python-octoprint.scm I get this error:

/tmp/python-octoprint.scm:275:6: In procedure propagated-inputs:
error: python-flask: unbound variable
hint: Did you forget `(use-modules (gnu packages python-web))'?

Of course writing down all the unbound variables by hand is tedious and error-prone. And since guix gives a hint is there a way to write the dependency into the file?

And the question in general is: When I find out that the program is not packaged and I want to write the package definition and then verify it installs and runs correctly, what steps should I take?

guix pull pypi PKG > PKG.scm
# Add 'define-module'
??
guix build -f PKG.scm

Note: Doesn't matter if it's python or rust program. I'm interested in the workflow

Kind regards
Petr Hodina

Sent with [ProtonMail](https://protonmail.com) Secure Email.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Import package and generate use-module
  2021-04-24  9:26 Import package and generate use-module phodina via
@ 2021-04-24 13:54 ` Ekaitz Zarraga
  0 siblings, 0 replies; 2+ messages in thread
From: Ekaitz Zarraga @ 2021-04-24 13:54 UTC (permalink / raw)
  To: phodina; +Cc: help-guix@gnu.org

Hi,

‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Saturday, April 24, 2021 11:26 AM, phodina via <help-guix@gnu.org> wrote:

> I'm making a package for octoprint which is imported from PyPI. guix import -r octoprint generates the template to build the package.
>
> However, I'm missing the :#use-module ... in order to build the package when I add (define-module (python-octoprint). Given the fact there are tens of inputs doing it manually seems tedious and writing a script to parse the package definition seems like reinventing the wheel as I'm certainly not the first person to run into this issue.
>
> So is there a way to automate also this part?
>
> Let me give you context:If I look at Guix package repository gnu/packages/python-xyz.scm I see there definitions of packages:
>
> (define-public python-numpy
> (package
> (name "python-numpy")
> ...
>
> If I have another package that depends on python-numpy I just provide the name in e.g. inputs and I don't have to import it with #:use-module within this file.
>
> However, when I run guix import pypi PKG I get package definition and when I run guix build -f python-octoprint.scm I get this error:
>
> /tmp/python-octoprint.scm:275:6: In procedure propagated-inputs:
> error: python-flask: unbound variable
> hint: Did you forget `(use-modules (gnu packages python-web))'?
>
> Of course writing down all the unbound variables by hand is tedious and error-prone. And since guix gives a hint is there a way to write the dependency into the file?
>
> And the question in general is: When I find out that the program is not packaged and I want to write the package definition and then verify it installs and runs correctly, what steps should I take?
>
> guix pull pypi PKG > PKG.scm
>
> Add 'define-module'
>
> ====================
>
> ??
> guix build -f PKG.scm
>
> Note: Doesn't matter if it's python or rust program. I'm interested in the workflow
>
> Kind regards
> Petr Hodina
>
> Sent with ProtonMail Secure Email.

I'm not sure if I understand it correctly.

What I understand is you need to add the define-module like in
any guile file, but you don't need to import every single
variable in the module you are importing. You just import the
whole module and every `define-public` from the module will
be available.

See for instance this:

https://gitlab.com/ekaitz-zarraga/guix-packages/-/blob/master/electronics.scm#L7

That import provides *all* the public variables from the `python`
module, not only one.

The case of `python-numpy` you describe works because variables
share module scope, so they don't need to import other vars in
the same file: they can already see them.

In your case you are pretty much fine importing a couple of
modules: python-web for flask, and probably python-science or
so.

The lazy approach is:
I try to `guix build` if there's a missing module add it with
#:use-modules, as shown in the example.
Rinse and repeat.

The direct approach is to use tools like `guix show` to check
the module where your inputs are described and import them.

For example:

```
$ guix show python-flask
 name: python-flask
version: 1.1.2
outputs: out
systems: x86_64-linux i686-linux
dependencies: python-click@7.1.2 [...]
location: gnu/packages/python-web.scm:2946:2
homepage: https://www.palletsprojects.com/p/flask/
license: Modified BSD
[...]
```

So now you know it is defined in `python-web`, as it says
in the `location` field. Now, you can add the `#:use-modules`
form that includes `python-web` to your module definition.

If other of your inputs is located in the same module you
*don't* need to import it again, because it will be already
known by that import.

So the point here to clarify is:
Use modules don't import PACKAGES, they import THE WHOLE
FILE, with all the (public) packages it contains. So it's
not as tedious as you suggested.[^1]

I hope this helps.

Best,
Ekaitz

[^1]: you can actually choose specific variables to import,
exclude some or use a prefix for the imported ones.
But our normal usage is just to import the whole file. See:
https://www.gnu.org/software/guile/manual/html_node/Creating-Guile-Modules.html
and:
https://www.gnu.org/software/guile/manual/html_node/Using-Guile-Modules.html


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-04-24 13:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-24  9:26 Import package and generate use-module phodina via
2021-04-24 13:54 ` Ekaitz Zarraga

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).