all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Make a simple guile script to a package - source local file
@ 2023-10-23 18:01 Théo Tyburn
  2023-10-26 14:18 ` Tomas Volf
  0 siblings, 1 reply; 10+ messages in thread
From: Théo Tyburn @ 2023-10-23 18:01 UTC (permalink / raw)
  To: help-guix

Hi,

I have some guile CLI scripts and I would like to make them accessible
in $PATH by putting each of them in a package.

Is there a simple way to do this without having to make a git
repository ? What I would like is something like this:

> (package
>   (name "script1")
>   (version "0.0.0")
>   (source (LOCAL-DIR "/path/to/scripts/"))
>   (build-system trivial-build-system))

and then copy the guile script to /bin using the trivial build-system.

I guess what I'm looking for is a function like LOCAL-DIR. It would be
similar to git-checkout but wouldn't require git. Is there such
a thing ?

Cheers,

Théo


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

* Re: Make a simple guile script to a package - source local file
  2023-10-23 18:01 Make a simple guile script to a package - source local file Théo Tyburn
@ 2023-10-26 14:18 ` Tomas Volf
  2023-10-29  8:44   ` Théo Tyburn
  2024-01-19 21:28   ` Théo Tyburn
  0 siblings, 2 replies; 10+ messages in thread
From: Tomas Volf @ 2023-10-26 14:18 UTC (permalink / raw)
  To: Théo Tyburn; +Cc: help-guix

[-- Attachment #1: Type: text/plain, Size: 1120 bytes --]

On 2023-10-23 18:01:12 +0000, Théo Tyburn wrote:
> Hi,
> 
> I have some guile CLI scripts and I would like to make them accessible
> in $PATH by putting each of them in a package.
> 
> Is there a simple way to do this without having to make a git
> repository ? What I would like is something like this:
> 
> > (package
> >   (name "script1")
> >   (version "0.0.0")
> >   (source (LOCAL-DIR "/path/to/scripts/"))
> >   (build-system trivial-build-system))
> 
> and then copy the guile script to /bin using the trivial build-system.
> 
> I guess what I'm looking for is a function like LOCAL-DIR. It would be
> similar to git-checkout but wouldn't require git. Is there such
> a thing ?

I believe you are looking for (source (local-file ..)), example can be found in
this excellent blog post:

https://guix.gnu.org/en/blog/2023/from-development-environments-to-continuous-integrationthe-ultimate-guide-to-software-development-with-guix/

> 
> Cheers,
> 
> Théo
>

)t.

-- 
There are only two hard things in Computer Science:
cache invalidation, naming things and off-by-one errors.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: Make a simple guile script to a package - source local file
  2023-10-26 14:18 ` Tomas Volf
@ 2023-10-29  8:44   ` Théo Tyburn
  2024-01-19 21:28   ` Théo Tyburn
  1 sibling, 0 replies; 10+ messages in thread
From: Théo Tyburn @ 2023-10-29  8:44 UTC (permalink / raw)
  To: Tomas Volf; +Cc: help-guix


Tomas Volf <wolf@wolfsden.cz> writes:

> I believe you are looking for (source (local-file ..)), example can be found in
> this excellent blog post:
>
> https://guix.gnu.org/en/blog/2023/from-development-environments-to-continuous-integrationthe-ultimate-guide-to-software-development-with-guix/

That's exactly what I needed, thanks!


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

* Re: Make a simple guile script to a package - source local file
  2023-10-26 14:18 ` Tomas Volf
  2023-10-29  8:44   ` Théo Tyburn
@ 2024-01-19 21:28   ` Théo Tyburn
  2024-01-19 21:46     ` Felix Lechner via
  2024-01-19 22:44     ` Richard Sent
  1 sibling, 2 replies; 10+ messages in thread
From: Théo Tyburn @ 2024-01-19 21:28 UTC (permalink / raw)
  To: Tomas Volf; +Cc: help-guix


Hi again,

Now I want to package a python script that has some dependencies on
python packages.

How do I go about packaging it to make the script available from the command line
without polluting the environment with the dependencies ? I am looking
for a similar effect to running `guix shell python python-a python-b
python-c -- my_script.py` but without re-entering the profile env all
the time. Probably I could achieve this by making a profile and launch
my script from a bash file that sources the profile beforehand, but this
seems tedious. I would like to automate all this, in guile.

Any hints ? 

Tomas Volf <wolf@wolfsden.cz> writes:

> [[PGP Signed Part:Undecided]]
> On 2023-10-23 18:01:12 +0000, Théo Tyburn wrote:
>> Hi,
>> 
>> I have some guile CLI scripts and I would like to make them accessible
>> in $PATH by putting each of them in a package.
>> 
>> Is there a simple way to do this without having to make a git
>> repository ? What I would like is something like this:
>> 
>> > (package
>> >   (name "script1")
>> >   (version "0.0.0")
>> >   (source (LOCAL-DIR "/path/to/scripts/"))
>> >   (build-system trivial-build-system))
>> 
>> and then copy the guile script to /bin using the trivial build-system.
>> 
>> I guess what I'm looking for is a function like LOCAL-DIR. It would be
>> similar to git-checkout but wouldn't require git. Is there such
>> a thing ?
>
> I believe you are looking for (source (local-file ..)), example can be found in
> this excellent blog post:
>
> https://guix.gnu.org/en/blog/2023/from-development-environments-to-continuous-integrationthe-ultimate-guide-to-software-development-with-guix/
>
>> 
>> Cheers,
>> 
>> Théo
>>
>
> )t.



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

* Re: Make a simple guile script to a package - source local file
  2024-01-19 21:28   ` Théo Tyburn
@ 2024-01-19 21:46     ` Felix Lechner via
  2024-01-20 17:19       ` Théo Tyburn
  2024-01-19 22:44     ` Richard Sent
  1 sibling, 1 reply; 10+ messages in thread
From: Felix Lechner via @ 2024-01-19 21:46 UTC (permalink / raw)
  To: Théo Tyburn, Tomas Volf; +Cc: help-guix

Hi Théo,

On Fri, Jan 19 2024, Théo Tyburn wrote:

> How do I go about packaging it to make the script available from the command line
> without polluting the environment with the dependencies ?

The best way is wrap-program, or my forthcoming wrap-executable.

Kind regards
Felix


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

* Re: Make a simple guile script to a package - source local file
  2024-01-19 21:28   ` Théo Tyburn
  2024-01-19 21:46     ` Felix Lechner via
@ 2024-01-19 22:44     ` Richard Sent
  2024-01-20 12:32       ` Théo Tyburn
  1 sibling, 1 reply; 10+ messages in thread
From: Richard Sent @ 2024-01-19 22:44 UTC (permalink / raw)
  To: Théo Tyburn; +Cc: Tomas Volf, help-guix

Théo Tyburn <theo.tyburn@posteo.net> writes:

> Hi again,
>
> Now I want to package a python script that has some dependencies on
> python packages.
>
> How do I go about packaging it to make the script available from the command line
> without polluting the environment with the dependencies ? I am looking
> for a similar effect to running `guix shell python python-a python-b
> python-c -- my_script.py` but without re-entering the profile env all
> the time. Probably I could achieve this by making a profile and launch
> my script from a bash file that sources the profile beforehand, but this
> seems tedious. I would like to automate all this, in guile.
>

Depending on what you mean by polluting or re-entering the profile
information all the time this might not be what you want. When I write
scripts that rely on specific dependencies I don't want to permanently
install, I write the shebang like this:

--8<---------------cut here---------------start------------->8---
#!/usr/bin/env -S guix shell ruby ruby-colorize password-store -- ruby
--8<---------------cut here---------------end--------------->8---

This relies on /usr/bin/env supporting -S, which to my understanding
isn't POSIX but instead a coreutils extension. Pretty sure --container
would work here but I've not tried it.

-- 
Take it easy,
Richard Sent
Making my computer weirder one commit at a time.


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

* Re: Make a simple guile script to a package - source local file
  2024-01-19 22:44     ` Richard Sent
@ 2024-01-20 12:32       ` Théo Tyburn
  2024-01-20 13:29         ` Tomas Volf
  0 siblings, 1 reply; 10+ messages in thread
From: Théo Tyburn @ 2024-01-20 12:32 UTC (permalink / raw)
  To: Richard Sent; +Cc: Tomas Volf, help-guix

Richard Sent <richard@freakingpenguin.com> writes:

> Depending on what you mean by polluting or re-entering the profile
> information all the time this might not be what you want. When I write
> scripts that rely on specific dependencies I don't want to permanently
> install, I write the shebang like this:
>
> --8<---------------cut here---------------start------------->8---
> #!/usr/bin/env -S guix shell ruby ruby-colorize password-store -- ruby
> --8<---------------cut here---------------end--------------->8---

This is a really nice trick !

Unfortunately you either have to reevaluate the profile at each
run or create a profile and do something like

#!/usr/bin/env -S guix shell -p
  ${GUIX_EXTRA_PROFILES}/python-pydbus/python-pydbus -- python3

> This relies on /usr/bin/env supporting -S, which to my understanding
> isn't POSIX but instead a coreutils extension. Pretty sure --container
> would work here but I've not tried it.

Also as you mentioned, I fear I will not be able to directly
distribute this to people not running guix.

But thanks for the hint :)


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

* Re: Make a simple guile script to a package - source local file
  2024-01-20 12:32       ` Théo Tyburn
@ 2024-01-20 13:29         ` Tomas Volf
  2024-01-20 18:05           ` Théo Tyburn
  0 siblings, 1 reply; 10+ messages in thread
From: Tomas Volf @ 2024-01-20 13:29 UTC (permalink / raw)
  To: Théo Tyburn; +Cc: Richard Sent, help-guix

[-- Attachment #1: Type: text/plain, Size: 2371 bytes --]

On 2024-01-20 12:32:08 +0000, Théo Tyburn wrote:
> Richard Sent <richard@freakingpenguin.com> writes:
> 
> > Depending on what you mean by polluting or re-entering the profile
> > information all the time this might not be what you want. When I write
> > scripts that rely on specific dependencies I don't want to permanently
> > install, I write the shebang like this:
> >
> > --8<---------------cut here---------------start------------->8---
> > #!/usr/bin/env -S guix shell ruby ruby-colorize password-store -- ruby
> > --8<---------------cut here---------------end--------------->8---
> 
> This is a really nice trick !
> 
> Unfortunately you either have to reevaluate the profile at each
> run or create a profile and do something like
> 
> #!/usr/bin/env -S guix shell -p
>   ${GUIX_EXTRA_PROFILES}/python-pydbus/python-pydbus -- python3

It is work nothing that guix shell does cache the profiles, so it is pretty
fast:

    $ time -p guix shell vim -- true
    The following derivation will be built:
      /gnu/store/4mlf31h32244xzcni9w43f95k8n8xf1h-profile.drv
    
    applying 3 grafts for tcsh-6.24.01 ...
    applying 7 grafts for vim-9.0.2001 ...
    building CA certificate bundle...
    listing Emacs sub-directories...
    building fonts directory...
    building directory of Info manuals...
    building profile with 1 package...
    real 2.28
    user 1.24
    sys 0.09
    $ time -p guix shell vim -- true
    real 0.11
    user 0.14
    sys 0.01
    $ time -p guix shell vim -- true
    real 0.11
    user 0.13
    sys 0.02

> 
> > This relies on /usr/bin/env supporting -S, which to my understanding
> > isn't POSIX but instead a coreutils extension. Pretty sure --container
> > would work here but I've not tried it.
> 
> Also as you mentioned, I fear I will not be able to directly
> distribute this to people not running guix.
> 
> But thanks for the hint :)

I am using (for guile scripts) something like:

  #!/bin/sh
  exec guix shell ... -- guile -e main -s "$0" "$@"

So if the language allows you to treat the first non-shebang line as a shell
script, you can suddenly get by with POSIX env (which is handy on alpine linux).

Have a nice day,
Tomas Volf

-- 
There are only two hard things in Computer Science:
cache invalidation, naming things and off-by-one errors.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: Make a simple guile script to a package - source local file
  2024-01-19 21:46     ` Felix Lechner via
@ 2024-01-20 17:19       ` Théo Tyburn
  0 siblings, 0 replies; 10+ messages in thread
From: Théo Tyburn @ 2024-01-20 17:19 UTC (permalink / raw)
  To: Felix Lechner; +Cc: Tomas Volf, help-guix

Hi Felix,

Felix Lechner <felix.lechner@lease-up.com> writes:

> Hi Théo,
>
> On Fri, Jan 19 2024, Théo Tyburn wrote:
>
>> How do I go about packaging it to make the script available from the command line
>> without polluting the environment with the dependencies ?
>
> The best way is wrap-program, or my forthcoming wrap-executable.
>
> Kind regards
> Felix


This is what I was looking for, thanks !

If someone is interested, here is my function to wrap a python script in a package:

#+BEGIN_SRC scheme
(define*-public (python-script-package name source-dir source-file #:key (inputs '()))
  (package
   (name name)
   (version "")
   (source (local-file (string-append source-dir "/" source-file) #:recursive? #t))
   (build-system copy-build-system)
   (inputs (cons python inputs))
   (arguments (list #:install-plan #~'((#$source-file #$(string-append "bin/" name)))
					#:phases
					`(modify-phases %standard-phases
					   (add-after 'strip 'wrap-python-scripts
						 (lambda* (#:key outputs #:allow-other-keys)
						   ;; Make sure program runs with the correct PYTHONPATH.
						   (wrap-program (search-input-file outputs (string-append "bin/" ,name))
							 `("GUIX_PYTHONPATH" ":"
							   prefix (,(getenv "GUIX_PYTHONPATH")))))))))
   
   (home-page "")
   (synopsis "")
   (description "")
   (license license:lgpl3+)))
#+END_SRC

It works like a charm with my guix home declaration :)

Happy hacking !


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

* Re: Make a simple guile script to a package - source local file
  2024-01-20 13:29         ` Tomas Volf
@ 2024-01-20 18:05           ` Théo Tyburn
  0 siblings, 0 replies; 10+ messages in thread
From: Théo Tyburn @ 2024-01-20 18:05 UTC (permalink / raw)
  To: Tomas Volf; +Cc: Richard Sent, help-guix


Tomas Volf <~@wolfsden.cz> writes:

> [[PGP Signed Part:Undecided]]
> On 2024-01-20 12:32:08 +0000, Théo Tyburn wrote:
>> Richard Sent <richard@freakingpenguin.com> writes:
>> 
>> > Depending on what you mean by polluting or re-entering the profile
>> > information all the time this might not be what you want. When I write
>> > scripts that rely on specific dependencies I don't want to permanently
>> > install, I write the shebang like this:
>> >
>> > --8<---------------cut here---------------start------------->8---
>> > #!/usr/bin/env -S guix shell ruby ruby-colorize password-store -- ruby
>> > --8<---------------cut here---------------end--------------->8---
>> 
>> This is a really nice trick !
>> 
>> Unfortunately you either have to reevaluate the profile at each
>> run or create a profile and do something like
>> 
>> #!/usr/bin/env -S guix shell -p
>>   ${GUIX_EXTRA_PROFILES}/python-pydbus/python-pydbus -- python3
>
> It is work nothing that guix shell does cache the profiles, so it is pretty
> fast:
>
>     $ time -p guix shell vim -- true
>     The following derivation will be built:
>       /gnu/store/4mlf31h32244xzcni9w43f95k8n8xf1h-profile.drv
>     
>     applying 3 grafts for tcsh-6.24.01 ...
>     applying 7 grafts for vim-9.0.2001 ...
>     building CA certificate bundle...
>     listing Emacs sub-directories...
>     building fonts directory...
>     building directory of Info manuals...
>     building profile with 1 package...
>     real 2.28
>     user 1.24
>     sys 0.09
>     $ time -p guix shell vim -- true
>     real 0.11
>     user 0.14
>     sys 0.01
>     $ time -p guix shell vim -- true
>     real 0.11
>     user 0.13
>     sys 0.02

Sure it is faster on the second run. Although it is even faster to
activate a profile. At least for me. Maybe this is getting slowed down
because I have some personal guile in $GUILE_LOAD_PATH ? I get something
like this even after having run the command already:

$ time -p guix shell vim -- true
real 1.52
user 2.06
sys 0.15

>> > This relies on /usr/bin/env supporting -S, which to my understanding
>> > isn't POSIX but instead a coreutils extension. Pretty sure --container
>> > would work here but I've not tried it.
>> 
>> Also as you mentioned, I fear I will not be able to directly
>> distribute this to people not running guix.
>> 
>> But thanks for the hint :)
>
> I am using (for guile scripts) something like:
>
>   #!/bin/sh
>   exec guix shell ... -- guile -e main -s "$0" "$@"
>
> So if the language allows you to treat the first non-shebang line as a shell
> script, you can suddenly get by with POSIX env (which is handy on alpine linux).

Interesting. Also good to know, thanks


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

end of thread, other threads:[~2024-01-20 18:15 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-23 18:01 Make a simple guile script to a package - source local file Théo Tyburn
2023-10-26 14:18 ` Tomas Volf
2023-10-29  8:44   ` Théo Tyburn
2024-01-19 21:28   ` Théo Tyburn
2024-01-19 21:46     ` Felix Lechner via
2024-01-20 17:19       ` Théo Tyburn
2024-01-19 22:44     ` Richard Sent
2024-01-20 12:32       ` Théo Tyburn
2024-01-20 13:29         ` Tomas Volf
2024-01-20 18:05           ` Théo Tyburn

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.