unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Stefan Israelsson Tampe <stefan.itampe@gmail.com>
To: david larsson <david.larsson@selfhosted.xyz>
Cc: "Stefan Israelsson Tampe <stefan.itampe@gmail.com>" <guile-user@gnu.org>
Subject: Re: python-on-guile
Date: Mon, 10 Feb 2020 21:11:58 +0100	[thread overview]
Message-ID: <CAGua6m3qCk0zR7XWzNcGAWrj9Uy_kecNxhmUyYeHysjVrcPC+w@mail.gmail.com> (raw)
In-Reply-To: <98c0afcebc4b6a584e7a576250b31256@selfhosted.xyz>

I have now added the bytes constructor that was not working.

To compile from source please try use the git repository at:

https://gitlab.com/python-on-guile/python-on-guile/

see readme for how to compile and what dependencies you have.

Regards
Stefan

On Mon, Feb 10, 2020 at 1:14 PM david larsson <david.larsson@selfhosted.xyz>
wrote:

> On 2020-02-09 21:36, Stefan Israelsson Tampe wrote:
> > in sys that is
> >
> > On Sun, Feb 9, 2020 at 9:36 PM Stefan Israelsson Tampe
> > <stefan.itampe@gmail.com> wrote:
> >
> >> OKey, I changed the values from immutable lists to lists.
> >>
>
> Great!
>
> >> On Sun, Feb 9, 2020 at 9:27 PM Stefan Israelsson Tampe
> >> <stefan.itampe@gmail.com> wrote:
> >>
> >> Note that a lot of things are untested because I'm alone on the
> >> development.
>
> Ok, I understand.
>
> I haven't been able to build a recent version, but if you can share some
> updated instructions, then I could perhaps help out with some occasional
> testing. I have only managed to build from the old commit fc0d7a9 by
> updating the current python-on-guile guix package locally.
>
> >>
> >> netlib is not included, you can test to add the python module file
> >> to a (language python module) directory
>
> What's been working for me so far is only (load "path/to/file.py") and
> (load-compiled "path/to/file.go").
>
> (use-modules (a b c)) did not work for me, except to load modules
> already shipped with python-on-guile repo; (language python module
> python) etc.
>
> >>
> >> I have recently added much more of the python stdlib aka 3.7 but not
> >> all.
> >>
> >> Not sure what you mean by .scm file and .py fle when it comes to
> >> base64
> >> using that module in scheme gives
> >> scheme@(guile-user)> (b64decode (b64encode "abc"))
> >> $2 = b'abc'
> >> scheme@(guile-user)> (b64decode (b64encode #(1 2 3)))
> >> $3 = b'\x01\x02\x03'
> >>
> >> Which return a bytevector if you want a string back you need to
> >> interpret the bytevector back to a string
>
> Im getting weird results when trying to output the base64 representation
> of a string, take btest.py:
>    #import sys
>    import base64
>    def mybmethod(x):
>        mybytes = bytes(x, "utf-8")
>        encodedbytes = base64.b64encode(mybytes)
>        myb64string = str(encodedbytes, "utf-8")
>        return myb64string
>        #print(myb64string)
>    #mybmethod(sys.argv[1])
>
> and assume btest.scm using it with:
>    (add-to-load-path (dirname (current-filename)))
>    (use-modules (language python module python))
>    (load "btest.py")
>    (define-public (mybmethodscm cmdline)
>      (display (mybmethod (cadr cmdline))))
>
> With this it will not work to run the scheme file with
>    guile -e mybmethodscm btest.scm dfasdf
>
> The error I got indicated that btest.py uses the bytes procedure from
> within python-on-guile instead of from the python3 base64 lib:
>
> -------------------
>
> In
> /home/user1/VirtualHome/src/code_guile/python-on-guile-test/btest.scm:
>      18:11  4 (mybmethodscm _)
> In btest.py:
>     10:584  3 (_ "dfasdf" . _)
> In oop/pf-objects.scm:
>     584:15  2 (create-object _ _)
>     567:11  1 (the-create-object _ _)
> In language/python/bytes.scm:
>       99:6  0 Exception thrown while printing backtrace:
> Unbound slot in object Error while printing exception.
>
> language/python/bytes.scm:99:6: Wrong number of arguments to #<procedure
> 7f2bab5d4560 at language/python/bytes.scm:92:0 (self) | (self s)>
>
> -------------------
>
> For a moment though, I could run:
>
>     guile -e mybmethodscm btest.scm dfasdf | rev | base64 -d | rev
>     # gives: dfasdf
>
> which was also strange.
>
> >>
> >> modules are a bit difficult as I use the guile module system and the
> >> python modules are different.
> >> So nested modules needs some work. The best is to test and see.
>
> Ok, got it!
>
> >>
> >> I will look into the sys thingies
> >>
> >> Regards
> >> Stefan
> >>
> >> On Sun, Feb 9, 2020 at 8:40 PM david larsson
> >> <david.larsson@selfhosted.xyz> wrote:
> >> Thanks for your explanations, but unfortunately I still can't figure
> >> out
> >> how to use this except in the simplest of cases.
> >>
> >> I am using the guix package python-on-guile 0.1.0-3.00a51a2 - maybe
> >> thats outdated?
> >>
> >> The simple things I have managed to do, are like:
> >>
> >> (add-to-load-path (dirname (current-filename)))
> >> (load-compiled python-test.go)
> >>
> >> where python-test.go is compiled with:
> >>
> >> guild compile python-test.py --output=python-test.go
> >> --from=python
> >>
> >> and contains simple things, like:
> >>
> >> f(s):
> >> a = s + 1
> >> return a
> >>
> >> but if I add statements to python-test.py like:
> >>
> >> import netaddr
> >> def myfun(a)
> >> <something using netaddr>
> >>
> >> (netaddr is a module installed via: pip3 install --user netaddr)
> >>
> >> I receive an error about not finding the module.
> >>
> >> I am able to add only the modules which exist in the python-on-guile
> >>
> >> repo, like:
> >>
> >> import sys
> >> import base64
> >>
> >> but Im getting errors, for example Im not able to use things from
> >> sys,
> >> like:
> >>
> >> sys.path.append(<somepath>)
> >> sys.path.insert(0, <somepath>)
> >>
> >> I was able to use some things from base64 but I only received weird
> >> results when converting between bytevectors and strings between the
> >> .scm
> >> file and .py file. What works fine using python3 python-test.py do
> >> not
> >> usually work when passing either a bytevector or string to the same
> >> go-compiled file from the .scm file using the python-code. Not sure
> >> whether there's a problem using python3 vs python2 here?
> >>
> >> Essentially, what Im looking for is how to proceed if I want to use
> >> modules installed via the pip package manager from guile, and what
> >> paths
> >> and imports I need to make, and how I might need to wrap them
> >> correctly
> >> in the scheme and python files to invoke a pip package procedure
> >> from
> >> guile.
> >>
> >> Best regards,
> >> David
> >>
> >> On 2020-02-09 18:59, Stefan Israelsson Tampe wrote:
> >>> I'm the author of that lib.
> >>>
> >>> 1)
> >>>
> >>> The main bindings are reachable through (language python module
> >>> python)
> >>>
> >>> So you could now go ahead and do
> >>>> (use-modules (language python module python))
> >>>> ;L python
> >>>
> >>> And you will get a python shell that works quite ok for one liners
> >>>
> >>> 2)
> >>>
> >>> If you write a module and place it in a/b/c.py
> >>> you can use the classes and functions theirin by
> >>>
> >>> (use-modules (a b c))
> >>>
> >>> 3)
> >>> you can load a .py file as (i hope this work)
> >>> (load "a.py")
> >>>
> >>> 4)
> >>> If you place a module in (language python module a.py) you can
> >> import
> >>> ir as a usual mode as
> >>>> from a import *
> >>>
> >>> The documentation is for the macro framework that enables you to
> >> work
> >>> with python classes and idioms like python iteration.
> >>>
> >>> Hope this helps
> >>> /Stefan
> >>>
> >>> On Sun, Feb 9, 2020 at 6:31 PM david larsson
> >>> <david.larsson@selfhosted.xyz> wrote:
> >>>
> >>>> Hi everyone,
> >>>> I am trying to wrap my head around how to use the python-on-guile
> >>>> library, but Im struggling. Does anyone have example code that
> >> might
> >>>>
> >>>> help, and which isn't too advanced?
> >>>>
> >>>> All tips and suggestions appreciated!
> >>>>
> >>>> Best regards,
> >>>> David
>
>


  parent reply	other threads:[~2020-02-10 20:11 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-09 17:30 python-on-guile david larsson
2020-02-09 17:59 ` python-on-guile Stefan Israelsson Tampe
2020-02-09 19:39   ` python-on-guile david larsson
     [not found]     ` <CAGua6m1aQuwGu4ZRRk9r1Ytao_QjftzCQK5+tb_B4axh-Y3aWg@mail.gmail.com>
     [not found]       ` <CAGua6m1VFHsaid+CGUN==3AvXqZTZUO8xbOSh3r4xNVTAik79g@mail.gmail.com>
     [not found]         ` <CAGua6m3vTY=hk8QaEoKUvFwPsm7N-uatMV1KyvgdAyKS4Gjh9g@mail.gmail.com>
2020-02-10 12:13           ` python-on-guile david larsson
2020-02-10 14:40             ` python-on-guile Stefan Israelsson Tampe
2020-02-10 14:46             ` python-on-guile Stefan Israelsson Tampe
2020-02-10 20:11             ` Stefan Israelsson Tampe [this message]
2020-02-11  7:17               ` python-on-guile david larsson
2020-02-11 10:44                 ` python-on-guile Stefan Israelsson Tampe
2020-02-11 20:57                 ` python-on-guile Stefan Israelsson Tampe
2020-02-12  9:18                   ` python-on-guile david larsson
2020-02-12  9:59                     ` python-on-guile Stefan Israelsson Tampe
2020-02-12 15:26                       ` python-on-guile david larsson
     [not found]                         ` <CAGua6m2SP2RZ1Ok5bG2xmoHGanmRUrfaG34yY7P8=AWs0fXw2g@mail.gmail.com>
2020-02-12 19:47                           ` python-on-guile david larsson
     [not found]                             ` <CAGua6m1rcNZT_15LN=dWRb66E93UyLDFfdkaJjmyWYerWE9Jpg@mail.gmail.com>
     [not found]                               ` <46dbd813788cc3d1dc0b994106c8a528@selfhosted.xyz>
     [not found]                                 ` <CAGua6m12ytkdDcHj+PEx615qCzaXPB4P+u-DCqWQexuRo28BWA@mail.gmail.com>
2020-02-13  7:30                                   ` python-on-guile david larsson
     [not found]                                     ` <CAGua6m2+hEpGf8Z+CfyO+-mKH4sQF-mVb7YS1=+88hF2bRkjPw@mail.gmail.com>
2020-02-18 10:45                                       ` python-on-guile david larsson
     [not found]                                         ` <CAGua6m0d=L9b9MEMYekX0tL0PO3k+ZR+LP=7YYQojzr0VYdkmw@mail.gmail.com>
2020-02-19  7:30                                           ` python-on-guile david larsson
  -- strict thread matches above, loose matches on Subject: below --
2021-04-23 15:00 Python-on-guile Mikael Djurfeldt
2021-04-23 20:35 ` Python-on-guile Zelphir Kaltstahl
2021-04-23 20:41 ` Python-on-guile Linus Björnstam
2021-04-23 21:04 ` Python-on-guile Matt Wette
2021-04-24  9:43   ` Python-on-guile Mikael Djurfeldt
2021-04-24 10:04 ` Python-on-guile Mikael Djurfeldt
2021-04-24 11:26   ` Python-on-guile Stefan Israelsson Tampe
2021-04-24 12:59     ` Python-on-guile Stefan Israelsson Tampe
2021-04-24 14:41       ` Python-on-guile Stefan Israelsson Tampe
2021-04-24 15:19         ` Python-on-guile Stefan Israelsson Tampe
2021-04-25  8:20           ` Python-on-guile Mikael Djurfeldt
2021-04-25 10:21             ` Python-on-guile Stefan Israelsson Tampe
2021-04-25  8:46           ` Python-on-guile Stefan Israelsson Tampe
2021-04-25 10:54       ` Python-on-guile Dr. Arne Babenhauserheide
2021-04-25 11:54         ` Python-on-guile Vivien Kraus via General Guile related discussions
2021-04-25 10:18 ` Python-on-guile Stefan Israelsson Tampe
2021-04-27 12:29 ` Python-on-guile Nala Ginrut
2019-07-09 17:15 python-on-guile Stefan Israelsson Tampe
2019-06-14 18:06 python-on-guile Stefan Israelsson Tampe
2019-06-22 21:07 ` python-on-guile Arne Babenhauserheide
2019-06-26 18:45 ` python-on-guile Nala Ginrut

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAGua6m3qCk0zR7XWzNcGAWrj9Uy_kecNxhmUyYeHysjVrcPC+w@mail.gmail.com \
    --to=stefan.itampe@gmail.com \
    --cc=david.larsson@selfhosted.xyz \
    --cc=guile-user@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).