Packaging/Python: Difference between revisions
imported>Milahu add todo poetry2nix |
imported>Milahu add setup.py |
||
| Line 67: | Line 67: | ||
</syntaxHighlight> | </syntaxHighlight> | ||
to your derivation. | to your derivation. | ||
== setup.py == | |||
The <code>setup.py</code> file is required by <code>buildPythonPackage</code>, | |||
but it's missing in some packages | |||
setup.py example: | |||
<syntaxHighlight lang=python> | |||
from setuptools import setup | |||
with open('requirements.txt') as f: | |||
install_requires = f.read().splitlines() | |||
setup( | |||
name='someprogram', | |||
#packages=['someprogram'], | |||
version='0.1.0', | |||
#author='...', | |||
#description='...', | |||
install_requires=install_requires, | |||
scripts=[ | |||
'someprogram.py', | |||
], | |||
entry_points={ | |||
#'console_scripts': ['someprogram=some_module:main'] | |||
}, | |||
) | |||
</syntaxHighlight> | |||
In this example, <code>someprogram.py</code> would be installed as <code>$out/bin/someprogram.py</code> | |||
To rename the binary, for example to remove the <code>.py</code> file extension, you can use <code>postInstall</code> | |||
<syntaxHighlight lang=nix> | |||
buildPythonPackage { | |||
# ... | |||
postInstall = '' | |||
mv -v $out/bin/someprogram.py $out/bin/someprogram | |||
''; | |||
} | |||
</syntaxHighlight> | |||
=== requirements.txt === | |||
<code>requirements.txt</code> in it's simplest form is a list of python packages | |||
<pre> | |||
numpy | |||
Requests | |||
Pillow | |||
</pre> | |||
<code>buildPythonPackage</code> will check these dependencies, but you still must declare the nix dependencies in <code>buildInputs</code>, <code>propagatedBuildInputs</code>, <code>checkInputs</code>, ... | |||
== Automatic packaging == | == Automatic packaging == | ||