Skip to content
This repository was archived by the owner on Oct 7, 2022. It is now read-only.

Add cli option to include an override.nix file #109

Merged
merged 4 commits into from
Mar 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ env:
- EXAMPLE=rss2email
- EXAMPLE=scipy
- EXAMPLE=tornado
- EXAMPLE=connexion
# - EXAMPLE=vulnix
matrix:
exclude:
Expand Down
7 changes: 7 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,13 @@ dependency of ``execnet``::

This was you can add or remove any python package.

Including overrides
^^^^^^^^^^^^^^^^^^^

Additional to a autogenerated ``requirements_overrides.nix`` file you
can include additional overrides files via the ``-O`` command line
argument. These overrides will be included the same way as your
``requirements_overrides.nix``.

Creating default.nix for you project
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
12 changes: 7 additions & 5 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ stdenv, fetchurl, zip, makeWrapper, nix, nix-prefetch-scripts
{ stdenv, fetchurl, zip, makeWrapper, nix, nix-prefetch-git, nix-prefetch-hg
, pythonPackages
, src ? { outPath = ./.; name = "pypi2nix"; }
}:
Expand Down Expand Up @@ -26,7 +26,7 @@ in stdenv.mkDerivation rec {
];
buildInputs = [
pythonPackages.python pythonPackages.flake8
zip makeWrapper nix.out nix-prefetch-scripts
zip makeWrapper nix.out nix-prefetch-git nix-prefetch-hg
];
doCheck = true;
sourceRoot = ".";
Expand All @@ -48,8 +48,8 @@ in stdenv.mkDerivation rec {

patchPhase = ''
sed -i -e "s|default='nix-shell',|default='${nix.out}/bin/nix-shell',|" $out/pkgs/pypi2nix/cli.py
sed -i -e "s|nix-prefetch-git|${nix-prefetch-scripts}/bin/nix-prefetch-git|" $out/pkgs/pypi2nix/stage2.py
sed -i -e "s|nix-prefetch-hg|${nix-prefetch-scripts}/bin/nix-prefetch-hg|" $out/pkgs/pypi2nix/stage2.py
sed -i -e "s|nix-prefetch-git|${nix-prefetch-git}/bin/nix-prefetch-git|" $out/pkgs/pypi2nix/stage2.py
sed -i -e "s|nix-prefetch-hg|${nix-prefetch-hg}/bin/nix-prefetch-hg|" $out/pkgs/pypi2nix/stage2.py
'';

commonPhase = ''
Expand All @@ -69,7 +69,9 @@ in stdenv.mkDerivation rec {
'';

installPhase = commonPhase + ''
wrapProgram $out/bin/pypi2nix --prefix PYTHONPATH : "$PYTHONPATH"
wrapProgram $out/bin/pypi2nix \
--prefix PYTHONPATH : "$PYTHONPATH" \
--prefix PATH : "${nix-prefetch-git}/bin:${nix-prefetch-hg}/bin"
'';

shellHook = ''
Expand Down
83 changes: 54 additions & 29 deletions examples/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
OS := $(shell uname)
PYPI2NIX=./pypi2nix/bin/pypi2nix
NIX_PATH=nixpkgs=https://github.com/NixOS/nixpkgs-channels/archive/nixpkgs-unstable.tar.gz
NIX_BUILD=nix-build
NIX_SHELL=nix-shell


ifeq ($(OS), Darwin)
Expand All @@ -19,7 +21,8 @@ endif
scipy \
pillow \
tornado \
vulnix
vulnix \
connexion

all: \
awscli_and_requests \
Expand All @@ -31,7 +34,8 @@ all: \
scipy \
pillow \
tornado \
vulnix
vulnix \
connexion

clear: \
awscli_and_requests-clear \
Expand All @@ -44,21 +48,22 @@ clear: \
scipy-clear \
pillow-clear \
tornado-clear \
vulnix-clear
vulnix-clear \
connexion-clear


pypi2nix-clear:
rm -f pypi2nix

$(PYPI2NIX): pypi2nix-clear
echo "building pypi2nix ..."
nix-build ../release.nix -A build.x86_64-linux -o pypi2nix
$(NIX_BUILD) ../release.nix -A build.x86_64-linux -o pypi2nix

pillow: pillow.nix
echo "building and testing pillow..."
nix-build pillow.nix -o pillow -A interpreter --show-trace
$(NIX_BUILD) pillow.nix -o pillow -A interpreter --show-trace
./pillow/bin/python -c 'import PIL'
nix-shell pillow.nix -A interpreter --run "python -c 'import PIL'"
$(NIX_SHELL) pillow.nix -A interpreter --run "python -c 'import PIL'"

pillow.nix: pillow.txt $(PYPI2NIX)
echo "generating pillownix expressions ..."
Expand All @@ -82,9 +87,9 @@ pillow-clear:

empy: empy.nix
echo "building and testing empy ..."
nix-build empy.nix -o empy -A interpreter --show-trace
$(NIX_BUILD) empy.nix -o empy -A interpreter --show-trace
./empy/bin/python -c 'import em'
nix-shell empy.nix -A interpreter --run "python -c 'import em'"
$(NIX_SHELL) empy.nix -A interpreter --run "python -c 'import em'"

empy.nix: empy.txt $(PYPI2NIX)
echo "generating empy nix expressions ..."
Expand All @@ -107,11 +112,11 @@ empy-clear:

lektor: lektor.nix
echo "building and testing lektor ..."
nix-build lektor.nix -o lektor -A interpreter --show-trace
$(NIX_BUILD) lektor.nix -o lektor -A interpreter --show-trace
./lektor/bin/python -c 'import lektor'
./lektor/bin/lektor --help
nix-shell lektor.nix -A interpreter --run "python -c 'import lektor'"
nix-shell lektor.nix -A interpreter --run "lektor --help"
$(NIX_SHELL) lektor.nix -A interpreter --run "python -c 'import lektor'"
$(NIX_SHELL) lektor.nix -A interpreter --run "lektor --help"

lektor.nix: lektor.txt $(PYPI2NIX)
echo "generating lektor nix expressions ..."
Expand All @@ -136,11 +141,11 @@ lektor-clear:

rss2email: rss2email.nix
echo "building and testing rss2email ..."
nix-build rss2email.nix -o rss2email -A interpreter --show-trace
$(NIX_BUILD) rss2email.nix -o rss2email -A interpreter --show-trace
./rss2email/bin/python -c 'import rss2email'
./rss2email/bin/r2e --help
nix-build rss2email.nix -A interpreter --run "python -c 'import rss2email'"
nix-build rss2email.nix -A interpreter --run "r2e --help"
$(NIX_BUILD) rss2email.nix -A interpreter --run "python -c 'import rss2email'"
$(NIX_BUILD) rss2email.nix -A interpreter --run "r2e --help"

rss2email.nix: rss2email.txt $(PYPI2NIX)
echo "generating rss2email nix expressions ..."
Expand All @@ -163,12 +168,12 @@ rss2email-clear:

awscli_and_requests: awscli_and_requests.nix
echo "building and testing awscli and requests library ..."
nix-build awscli.nix -o awscli_and_requests -A interpreter --show-trace
$(NIX_BUILD) awscli.nix -o awscli_and_requests -A interpreter --show-trace
./awscli_and_requests/bin/python -c 'import awscli; import requests'
PAGER=none ./awscli_and_requests/bin/aws help
nix-shell awscli.nix -A interpreter --run "python -c 'import awscli'"
nix-shell awscli.nix -A interpreter --run "python -c 'import awscli; import requests'"
nix-shell awscli.nix -A interpreter --run "PAGER=none aws help"
$(NIX_SHELL) awscli.nix -A interpreter --run "python -c 'import awscli'"
$(NIX_SHELL) awscli.nix -A interpreter --run "python -c 'import awscli; import requests'"
$(NIX_SHELL) awscli.nix -A interpreter --run "PAGER=none aws help"

awscli_and_requests.nix: awscli_and_requests.txt $(PYPI2NIX)
echo "generating awscli and requests nix expressions ..."
Expand All @@ -190,8 +195,8 @@ awscli_and_requests-clear:
vulnix: vulnix-clear $(PYPI2NIX)
echo "building and testing vulnix..."
git clone https://github.com/garbas/vulnix vulnix-src
cd vulnix-src && nix-shell update.nix --argstr pypi2nix "./../$(PYPI2NIX)"
NIX_PATH=$(NIX_PATH) nix-build vulnix-src/default.nix --arg pkgs "import <nixpkgs> {}" -o vulnix
cd vulnix-src && $(NIX_SHELL) update.nix --argstr pypi2nix "./../$(PYPI2NIX)"
NIX_PATH=$(NIX_PATH) $(NIX_BUILD) vulnix-src/default.nix --arg pkgs "import <nixpkgs> {}" -o vulnix
./vulnix/bin/vulnix --help

vulnix-clear:
Expand All @@ -201,9 +206,9 @@ vulnix-clear:

scipy: scipy.nix
echo "building and testing scipy..."
nix-build scipy.nix -o scipy -A interpreter --show-trace
$(NIX_BUILD) scipy.nix -o scipy -A interpreter --show-trace
./scipy/bin/python -c 'import scipy'
nix-shell scipy.nix -A interpreter --run "python -c 'import scipy'"
$(NIX_SHELL) scipy.nix -A interpreter --run "python -c 'import scipy'"

scipy.nix: scipy.txt $(PYPI2NIX)
echo "generating scipy.nix expressions ..."
Expand All @@ -221,14 +226,14 @@ scipy-clear:

tornado: tornado.nix
echo "building and testing tornado..."
nix-build tornado.nix -o tornado -A interpreter --show-trace
$(NIX_BUILD) tornado.nix -o tornado -A interpreter --show-trace --fallback
./tornado/bin/python -c 'import tornado'
nix-shell tornado.nix -A interpreter --run "python -c 'import tornado'"
$(NIX_SHELL) tornado.nix -A interpreter --run "python -c 'import tornado'"
if ./string_in_file "69253c820df473407c562a227d0ba36df25018ab" tornado.nix ; then true ; else echo "ERROR: Revision '69253c820df473407c562a227d0ba36df25018ab' not found in tornado.nix!" ; exit 123 ; fi

tornado.nix: tornado.txt $(PYPI2NIX)
echo "generating tornado.nix expressions ..."
$(PYPI2NIX) -v --basename tornado -r tornado.txt -I $(NIX_PATH) -V "3.5"
$(PYPI2NIX) -v --basename tornado -r tornado.txt -I $(NIX_PATH) -V "3.5" -O 'https://raw.githubusercontent.com/garbas/nixpkgs-python/master/overrides.nix' -O 'git+https://github.com/garbas/nixpkgs-python.git#path=overrides.nix&rev=28ecf4bc8cf5e718862159eb1f324ddcf227dfef'

tornado.txt: tornado-clear
echo "-e git+git://github.com/tornadoweb/tornado.git@69253c820df473407c562a227d0ba36df25018ab#egg=tornado" > tornado.txt
Expand All @@ -242,9 +247,9 @@ tornado-clear:

ldap: ldap.nix
echo "building and testing ldap..."
nix-build ldap.nix -o ldap -A interpreter --show-trace
$(NIX_BUILD) ldap.nix -o ldap -A interpreter --show-trace
./ldap/bin/python -c 'import ldap'
nix-shell ldap.nix -A interpreter --run "python -c 'import ldap'"
$(NIX_SHELL) ldap.nix -A interpreter --run "python -c 'import ldap'"

ldap.nix: ldap.txt $(PYPI2NIX)
echo "generating ldap.nix expressions ..."
Expand All @@ -269,9 +274,9 @@ ldap-clear:

mercurial: mercurial.nix
echo "building and testing mercurial..."
nix-build mercurial.nix -o mercurial -A interpreter --show-trace -j 1
$(NIX_BUILD) mercurial.nix -o mercurial -A interpreter --show-trace -j 1
./mercurial/bin/python -c 'import flake8'
nix-shell mercurial.nix -A interpreter --run "python -c 'import flake8'"
$(NIX_SHELL) mercurial.nix -A interpreter --run "python -c 'import flake8'"
if ./string_in_file "a209fb6" mercurial.nix ; then true ; else echo "ERROR: Revision 'a209fb6' not found in tornado_generated.nix!"; exit 123; fi

mercurial.nix: mercurial.txt $(PYPI2NIX)
Expand All @@ -289,3 +294,23 @@ mercurial-clear:
rm -f mercurial.txt
rm -f mercurial.nix
rm -f mercurial_frozen.txt

connexion: connexion.nix
echo "building and testing connexion..."
$(NIX_BUILD) connexion.nix -o connexion -A interpreter --show-trace -j 1
./connexion/bin/python -c 'import connexion'
$(NIX_SHELL) connexion.nix -A interpreter --run "python -c 'import connexion'"

connexion.nix: connexion.txt $(PYPI2NIX)
echo "generating connexion.nix expressions ..."
$(PYPI2NIX) -v --basename connexion -r connexion.txt -I $(NIX_PATH) -V "2.7" -e vcversioner -O "git+https://github.com/garbas/nixpkgs-python.git#path=overrides.nix"


connexion.txt: connexion-clear
echo "connexion" > connexion.txt

connexion-clear:
rm -f connexion
rm -f connexion.txt
rm -f connexion.nix
rm -f connexion_frozen.txt
9 changes: 9 additions & 0 deletions examples/connexion_override.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{ pkgs, python }:

self: super: {

"jsonschema" = python.overrideDerivation super."jsonschema" (old: {
propagatedBuildInputs = old.propagatedBuildInputs ++ [self.vcversioner];
});

}
10 changes: 10 additions & 0 deletions src/pypi2nix/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import shutil
import tempfile

import pypi2nix.overrides
import pypi2nix.stage0
import pypi2nix.stage1
import pypi2nix.stage2
Expand Down Expand Up @@ -96,6 +97,13 @@
help=u'Extra Python dependencies needed before the installation'
u'to build wheels.'
)
@click.option('-O', '--overrides',
multiple=True,
required=False,
type=pypi2nix.overrides.OVERRIDES_URL,
help=u'Extra expressions that override generated expressions ' +
u'for specific packages',
)
def main(version,
verbose,
nix_shell,
Expand All @@ -110,6 +118,7 @@ def main(version,
buildout,
editable,
setup_requires,
overrides
):
"""SPECIFICATION should be requirements.txt (output of pip freeze).
"""
Expand Down Expand Up @@ -319,6 +328,7 @@ def handle_requirements_file(project_dir, requirements_file):
enable_tests=enable_tests,
python_version=pypi2nix.utils.PYTHON_VERSIONS[python_version],
current_dir=current_dir,
common_overrides=overrides,
)

click.echo('')
Expand Down
Loading