Packaging/Python: Difference between revisions

imported>Milahu
m Automatic packaging: add github stars, sort
imported>Jooooscha
Clearify section about setup.py
Line 148: Line 148:
reference: [https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/interpreters/python/fetchpypi.nix fetchPypi implementation]
reference: [https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/interpreters/python/fetchpypi.nix fetchPypi implementation]


== setup.py ==
== Fix Missing <code>setup.py</code> ==


The <code>setup.py</code> file is required for <code>buildPythonPackage</code>,
The <code>setup.py</code> file is required for <code>buildPythonPackage</code>,
but it's missing in some packages
but it's missing in some packages.
If you get the following error, you need to one of the workarounds below.


<pre>
<pre>
Line 166: Line 167:


If both <code>setup.py</code> and <code>pyproject.toml</code> are missing,
If both <code>setup.py</code> and <code>pyproject.toml</code> are missing,
you have to add one of these files, for example:
you have to add one of these files.
For example, you can create the <code>setup.py</code> in the <code>preBuild</code> phase.


<syntaxHighlight lang=nix>
<syntaxHighlight lang=nix>
buildPythonPackage {
buildPythonPackage {
   preBuild = ''
   preBuild = ''
     cat >setup.py <<'EOF'
     cat > setup.py << EOF
    from setuptools import setup
    setup(
      name='someprogram',
      # ...
    )
    EOF
  '';
}
</syntaxHighlight>
 
setup.py example:
 
<syntaxHighlight lang=python>
from setuptools import setup
from setuptools import setup


Line 205: Line 194:
   },
   },
)
)
    EOF
  '';
}
</syntaxHighlight>
</syntaxHighlight>
More info about the <code>setup.py</code> can be found [https://docs.python.org/3/distutils/setupscript.html here].


<code>scripts</code> is useful for self-contained python scripts with no local imports.
<code>scripts</code> is useful for self-contained python scripts with no local imports.