mic92 / pythonix Goto Github PK
View Code? Open in Web Editor NEWEval nix code from python
License: MIT License
Eval nix code from python
License: MIT License
I am trying to use pythonix to import some local files and run some unit tests. However, it doesn't seem to parse relative paths properly. All of these methods work in the Nix REPL.
>>>import nix
>>> nix.eval('with import ./math.nix; isEven 2')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
nix.NixError: not an absolute path: '././math.nix'
>>> nix.eval('with import (./. + "math.nix"); isEven 2')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
nix.NixError: not an absolute path: '././.'
>>> nix.eval('with import (builtins.toString ./math.nix); isEven 2')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
nix.NixError: not an absolute path: '././math.nix'
Is it possible with pythonix to view a derivation similar to "nix show-derivation ..."? I have tried nix.eval("with import {}; python3Packages.numpy") and ran into errors. Maybe this is not the correct way to view a derivation output? My end goal is that I want to create an adjacency matrix of runtime vs test vs build time python dependencies. But I have plans to use all the derivations to gather statistics. Right now the big limitation for me is how to extract this from nix.
Currently in Nixpkgs python3 is python38, and python3Packages.pythonix
is built correctly, but python37Packages.pythonix
and python39Packages.pythonix
both install nix.so
in lib/python3.8/site-packages
, thus a dependent package python39Packages.nixpkgs
fails to import nix
: NixOS/nixpkgs#107623 (comment)
I don't know whether the root cause of this issue is in pythonix (in how it uses meson), meson (which seems most likely to me), or Nixpkgs.
I wanted to open an issue to judge what you think about exposing the nix expression AST in pythonix
. This package is already great for evaluating expressions and working with the results in python. I would like to add a PR for AST support because this would enable a whole set of tooling to be easily made. For example
I have already found that the AST is exposed at https://github.com/NixOS/nix/blob/master/src/libexpr/nixexpr.hh . I will need to have knowledge of interfacing C++ with python for my future job (without using cython) and I think this is a doable project that could provide a lot of benefit.
Steps to reproduce:
nix-shell -p 'python3.withPackages(ps: with ps; [ python3Packages.pythonix ])'
Error:
../src/python-to-nix.cc: In function ‘nix::Value* pythonnix::pythonToNixValue(nix::EvalState&, PyObject*)’:
../src/python-to-nix.cc:85:41: error: invalid conversion from ‘const char*’ to ‘char*’ [-fpermissive]
char *utf8 = PyUnicode_AsUTF8AndSize(obj, &size);
~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
Or is that a packaging issue?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.