unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Help adding a python package: chia-blockchain
@ 2021-04-16  8:57 Vladilen Kozin
  2021-04-16 13:57 ` Vladilen Kozin
  2021-04-17  1:20 ` Leo Prikler
  0 siblings, 2 replies; 3+ messages in thread
From: Vladilen Kozin @ 2021-04-16  8:57 UTC (permalink / raw)
  To: guix-devel

Hi all.

Could a kind soul handhold me while I try to port a python package to
guix please. I am not a python programmer, so not on first name basis
with python ecosystem and new to guix - double trouble.

I've made some progress, but could use a bit of your help. Current
state of affairs is tracked in this repo:
https://github.com/vkz/ze-guix

Repo and package I'm trying to import:
https://github.com/Chia-Network/chia-blockchain

Both it and all of its dependencies are open source, most on pypi but
sadly some are only available there as binary wheels. Building from
source entirely maybe complicated since it very quickly escalates to
multiple build systems e.g. chiapos (proof of space lib) and chiavdf
are C++ and rely on cmake, clvm_rs (their homegrown lisp) is written
in Rust etc.

Conceptually, installation is very simple and basically relies on
binary wheels and amounts to:
- checkout repo,
- init and update submodule(s) - really only mozilla-ca,
- create virtual env and activate,
- upgrade to the latest pip to use binary wheels,
- install deps and the package with pip

You can see the steps I extracted from their install.sh here:
https://github.com/vkz/ze-guix/blob/master/packages/manual-install.log

Now, guix obviously heads and shoulders above virtualenv or at least
it should be, however trying to build from source escalates quickly as
I've mentioned. So, first question is if I could define a package by
"replicating" the above essentially binary-only steps but replace
virtualenv with e.g. guix profile or smth. This should be possible to
do in code - as a proper package with some rudimentary build system
that amounts to building everything inside a separate profile or maybe
just pulling binary wheels into a directory in store and then adding
that to whatever Python or pip expect and use as their PATH
equivalent. IMO doing something trivial like this should be easy. To
be sure this approach has security and "freedom" implications, but
this is orthogonal to having something that works installed quickly.
Building from source is very often involved borderline crazy. Could
someone kindly teach me how to do this "binary" only packaging.

Now, to building from source.

First step I tried was to `guix import pypi -r`. This fails because
not all deps have source pushed to pypi and only offer binary wheels.
IMO `guix import` has no business failing like this or even at all for
whatever reason. It is best effort tool to begin with that should
result in a template that I can fill in. If there are errors - skip
the dependency, report it, but please continue.

Since, recursive `guix import` failed me I had to manually track deps
and essentially call `guix import` for each one. Result you can see
here:
https://github.com/vkz/ze-guix/blob/master/packages/chia.scm

This won't build for several reasons. Not all deps are there, some
probably shouldn't be like win32 something or other. Another reason,
I'd have to figure out how to build the inputs that require cmake and
rust and python (some all at once). And this is where I could really
use help. Examples as mentioned earlier are these dependencies:
https://github.com/Chia-Network/chiapos
https://github.com/Chia-Network/clvm_rs
maybe others - it is a fairly big project and I've not even touched
NPM/node that they rely on for their GUI client. That's another scary
can of worms I'm not prepared to peek inside at this time.

Ok, so really two questions:
- how can I build a "binary" only python package that simply relies on
binary wheels e.g. from pypi,
- how to deal with multi-build systems e.g. python + cmake or python +
rust, maybe someone could think of a good educational (so, not too
convoluted) example of such package already in source tree.

Latter would probably go much faster and teach better if done as
pair-programming exercise, but that maybe a lot to ask. If you're up
for it, I'm game though.

Thank you
-- 
Best regards
Vlad Kozin


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

* Re: Help adding a python package: chia-blockchain
  2021-04-16  8:57 Help adding a python package: chia-blockchain Vladilen Kozin
@ 2021-04-16 13:57 ` Vladilen Kozin
  2021-04-17  1:20 ` Leo Prikler
  1 sibling, 0 replies; 3+ messages in thread
From: Vladilen Kozin @ 2021-04-16 13:57 UTC (permalink / raw)
  To: guix-devel

Another "hilarious" consequence of attempting to side-step "the guix"
way. If I just follow the `pip install` steps I end up with some C++
dependency (blspy I believe) complaining that it can't find libstdc++.
Quick `locate` search unsurfaced it somewhere under /gnu/store, but of
course binaries (like binary wheels) pre-built this way are completely
oblivious to Linux machines (or I suppose Guix) that don't have the
usual /lib or /lib64 or whatever. So yeah, looks like its guix way or
no way. Like I mentioned earlier, could use some guidance in packaging
this.

On Fri, 16 Apr 2021 at 09:57, Vladilen Kozin <vladilen.kozin@gmail.com> wrote:
>
> Hi all.
>
> Could a kind soul handhold me while I try to port a python package to
> guix please. I am not a python programmer, so not on first name basis
> with python ecosystem and new to guix - double trouble.
>
> I've made some progress, but could use a bit of your help. Current
> state of affairs is tracked in this repo:
> https://github.com/vkz/ze-guix
>
> Repo and package I'm trying to import:
> https://github.com/Chia-Network/chia-blockchain
>
> Both it and all of its dependencies are open source, most on pypi but
> sadly some are only available there as binary wheels. Building from
> source entirely maybe complicated since it very quickly escalates to
> multiple build systems e.g. chiapos (proof of space lib) and chiavdf
> are C++ and rely on cmake, clvm_rs (their homegrown lisp) is written
> in Rust etc.
>
> Conceptually, installation is very simple and basically relies on
> binary wheels and amounts to:
> - checkout repo,
> - init and update submodule(s) - really only mozilla-ca,
> - create virtual env and activate,
> - upgrade to the latest pip to use binary wheels,
> - install deps and the package with pip
>
> You can see the steps I extracted from their install.sh here:
> https://github.com/vkz/ze-guix/blob/master/packages/manual-install.log
>
> Now, guix obviously heads and shoulders above virtualenv or at least
> it should be, however trying to build from source escalates quickly as
> I've mentioned. So, first question is if I could define a package by
> "replicating" the above essentially binary-only steps but replace
> virtualenv with e.g. guix profile or smth. This should be possible to
> do in code - as a proper package with some rudimentary build system
> that amounts to building everything inside a separate profile or maybe
> just pulling binary wheels into a directory in store and then adding
> that to whatever Python or pip expect and use as their PATH
> equivalent. IMO doing something trivial like this should be easy. To
> be sure this approach has security and "freedom" implications, but
> this is orthogonal to having something that works installed quickly.
> Building from source is very often involved borderline crazy. Could
> someone kindly teach me how to do this "binary" only packaging.
>
> Now, to building from source.
>
> First step I tried was to `guix import pypi -r`. This fails because
> not all deps have source pushed to pypi and only offer binary wheels.
> IMO `guix import` has no business failing like this or even at all for
> whatever reason. It is best effort tool to begin with that should
> result in a template that I can fill in. If there are errors - skip
> the dependency, report it, but please continue.
>
> Since, recursive `guix import` failed me I had to manually track deps
> and essentially call `guix import` for each one. Result you can see
> here:
> https://github.com/vkz/ze-guix/blob/master/packages/chia.scm
>
> This won't build for several reasons. Not all deps are there, some
> probably shouldn't be like win32 something or other. Another reason,
> I'd have to figure out how to build the inputs that require cmake and
> rust and python (some all at once). And this is where I could really
> use help. Examples as mentioned earlier are these dependencies:
> https://github.com/Chia-Network/chiapos
> https://github.com/Chia-Network/clvm_rs
> maybe others - it is a fairly big project and I've not even touched
> NPM/node that they rely on for their GUI client. That's another scary
> can of worms I'm not prepared to peek inside at this time.
>
> Ok, so really two questions:
> - how can I build a "binary" only python package that simply relies on
> binary wheels e.g. from pypi,
> - how to deal with multi-build systems e.g. python + cmake or python +
> rust, maybe someone could think of a good educational (so, not too
> convoluted) example of such package already in source tree.
>
> Latter would probably go much faster and teach better if done as
> pair-programming exercise, but that maybe a lot to ask. If you're up
> for it, I'm game though.
>
> Thank you
> --
> Best regards
> Vlad Kozin



-- 
Best regards
Vlad Kozin


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

* Re: Help adding a python package: chia-blockchain
  2021-04-16  8:57 Help adding a python package: chia-blockchain Vladilen Kozin
  2021-04-16 13:57 ` Vladilen Kozin
@ 2021-04-17  1:20 ` Leo Prikler
  1 sibling, 0 replies; 3+ messages in thread
From: Leo Prikler @ 2021-04-17  1:20 UTC (permalink / raw)
  To: Vladilen Kozin, guix-devel

Hi Vladilen,

Am Freitag, den 16.04.2021, 09:57 +0100 schrieb Vladilen Kozin:
> Hi all.
> 
> Could a kind soul handhold me while I try to port a python package to
> guix please. I am not a python programmer, so not on first name basis
> with python ecosystem and new to guix - double trouble.
> 
> I've made some progress, but could use a bit of your help. Current
> state of affairs is tracked in this repo:
> https://github.com/vkz/ze-guix

Some comments on what you've written so far:

;; wtf? surely we don't need that on Linux
Probably not, yeah.  If you want to, you can substitute* references to
that package away.
;; can we just skip these since this is only for testing?
Yes, but you'll have to disable tests :)

Otherwise mostly LGTM.

> Repo and package I'm trying to import:
> https://github.com/Chia-Network/chia-blockchain
> 
> Both it and all of its dependencies are open source, most on pypi but
> sadly some are only available there as binary wheels. Building from
> source entirely maybe complicated since it very quickly escalates to
> multiple build systems e.g. chiapos (proof of space lib) and chiavdf
> are C++ and rely on cmake, clvm_rs (their homegrown lisp) is written
> in Rust etc.
They have thought about writing a Lisp implementation in Rust, but has
anyone thought about writing a Rust compiler in Lisp?  Perhaps it could
even output shared objects, that'd be nice.  Jokes aside, let's
continue.

> Conceptually, installation is very simple and basically relies on
> binary wheels and amounts to:
> - checkout repo,
> - init and update submodule(s) - really only mozilla-ca,
> - create virtual env and activate,
> - upgrade to the latest pip to use binary wheels,
> - install deps and the package with pip
> 
> You can see the steps I extracted from their install.sh here:
> https://github.com/vkz/ze-guix/blob/master/packages/manual-install.log
> 
> Now, guix obviously heads and shoulders above virtualenv or at least
> it should be, however trying to build from source escalates quickly
> as
> I've mentioned. So, first question is if I could define a package by
> "replicating" the above essentially binary-only steps but replace
> virtualenv with e.g. guix profile or smth. This should be possible to
> do in code - as a proper package with some rudimentary build system
> that amounts to building everything inside a separate profile or
> maybe
> just pulling binary wheels into a directory in store and then adding
> that to whatever Python or pip expect and use as their PATH
> equivalent. IMO doing something trivial like this should be easy. To
> be sure this approach has security and "freedom" implications, but
> this is orthogonal to having something that works installed quickly.
> Building from source is very often involved borderline crazy. Could
> someone kindly teach me how to do this "binary" only packaging.
We have copy-build-system and a tool called patchelf.  Some folks, who
don't care as much about freedom as we do might even go ahead and
implement a patchelf-build-system, but that's a little besides the
point.  If you feel like fiddling around in those binaries will be
quicker than mixing build systems, that's pretty much the approach you
would take, but it's not an easy one.

> Now, to building from source.
> 
> First step I tried was to `guix import pypi -r`. This fails because
> not all deps have source pushed to pypi and only offer binary wheels.
> IMO `guix import` has no business failing like this or even at all
> for
> whatever reason. It is best effort tool to begin with that should
> result in a template that I can fill in. If there are errors - skip
> the dependency, report it, but please continue.
I don't think this works as a general statement.  While UX probably
could be improved in certain scenarios, sometimes an error really is an
error and stopping is the right decision.

> Since, recursive `guix import` failed me I had to manually track deps
> and essentially call `guix import` for each one. Result you can see
> here:
> https://github.com/vkz/ze-guix/blob/master/packages/chia.scm
> 
> This won't build for several reasons. Not all deps are there, some
> probably shouldn't be like win32 something or other. Another reason,
> I'd have to figure out how to build the inputs that require cmake and
> rust and python (some all at once). And this is where I could really
> use help. Examples as mentioned earlier are these dependencies:
> https://github.com/Chia-Network/chiapos
> https://github.com/Chia-Network/clvm_rs
> maybe others - it is a fairly big project and I've not even touched
> NPM/node that they rely on for their GUI client. That's another scary
> can of worms I'm not prepared to peek inside at this time.
This indeed sounds like a very daunting project.  Rest assured, even
the most advanced packagers usually shy away from such beasts.  (And
those who don't typically sacrifice part of their sanity.)

Now in principle, mixing build systems is *easy*.  Starting from
(arguments), you add:
- #:modules, that list both build systems, usually prefixed (e.g. gnu:
and cmake:)
- #:imported-modules, that hold the module closure for both (this can
be achieved by listing ,@%gnu-build-system-modules ,@%cmake-build-
system-modules and some others, for example)
- #:phases, that call the right procedures in the correct order.

A fairly simple package, that uses two build systems, is emacs-howm. 
After wip-emacs is merged, you have even more examples of emacs
packages mixing build systems for trivial stuff, since that's how I
chose to implement ELPA directories.  I'm getting sidetracked again.

Once you start seeing this pattern, you'll notice it in other packages
as well.  To search for packages, that use cmake in combination with
something else, grepping for cmake: is a good idea.  Likewise with
cargo: for Rust packages.

> Ok, so really two questions:
> - how can I build a "binary" only python package that simply relies
> on
> binary wheels e.g. from pypi,
By using a clever mix of "cp" and "patchelf" or their lisp equivalents.

> - how to deal with multi-build systems e.g. python + cmake or python
> +
> rust, maybe someone could think of a good educational (so, not too
> convoluted) example of such package already in source tree.
You can't get much shorter than emacs-howm.

> Latter would probably go much faster and teach better if done as
> pair-programming exercise, but that maybe a lot to ask. If you're up
> for it, I'm game though.
I'm sorry, it's rather late and I should probably go to bed, but as far
as contributing packages with huge dependency chains goes, there seem
to be somewhat regular meetups done; perhaps someone else has more
appropriate info for you.  Lastly, if the dependencies themselves have
a use other than being a dependency for what you're trying to package,
you could garner some interest by sending one of them, that already
builds fine, to guix-patches.  Though perhaps that "if" is a little too
big to be applicable here.

In any case, have fun mixing build systems and don't get too
discouraged by the huge load of work that's ahead of you.

Regards,
Leo




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

end of thread, other threads:[~2021-04-17  1:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-04-16  8:57 Help adding a python package: chia-blockchain Vladilen Kozin
2021-04-16 13:57 ` Vladilen Kozin
2021-04-17  1:20 ` Leo Prikler

Code repositories for project(s) associated with this public inbox

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

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).