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

Commit f64e34f

Browse files
committed
adding ldap example to test -N/--extra-env option
fixes #97
1 parent e1f25c1 commit f64e34f

File tree

4 files changed

+67
-4
lines changed

4 files changed

+67
-4
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ os:
77
env:
88
- EXAMPLE=awscli_and_requests
99
- EXAMPLE=empy
10+
- EXAMPLE=ldap
1011
- EXAMPLE=lektor
1112
- EXAMPLE=rss2email
1213
- EXAMPLE=scipy

examples/Makefile

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,26 @@ endif
1515
all: \
1616
awscli_and_requests \
1717
empy \
18+
ldap \
1819
lektor \
1920
rss2email \
2021
scipy \
2122
sentry \
22-
vulnix \
23-
tornado
23+
tornado \
24+
vulnix
2425

2526
clear: \
2627
awscli_and_requests-clear \
2728
empy-clear \
29+
ldap_clear \
2830
lektor-clear \
2931
pypi2nix-clear \
3032
rss2email-clear \
3133
scipy-clear \
3234
sentry-clear \
33-
vulnix-clear \
34-
tornado-clear
35+
tornado-clear \
36+
vulnix-clear
37+
3538

3639
pypi2nix-clear:
3740
@rm -f ../result
@@ -238,3 +241,32 @@ tornado-clear:
238241
@rm -f tornado.nix
239242
@rm -f tornado_generated.nix
240243
@rm -f tornado_frozen.txt
244+
245+
246+
ldap: ldap.nix
247+
@echo "building and testing ldap..."
248+
@nix-build ldap.nix -o ldap -A interpreter --show-trace
249+
@./ldap/bin/python -c 'import ldap'
250+
@nix-shell ldap.nix -A interpreter --run "python -c 'import ldap'"
251+
252+
ldap.nix: ldap.txt $(PYPI2NIX)
253+
@echo "generating ldap.nix expressions ..."
254+
@$(PYPI2NIX) \
255+
-v \
256+
--basename ldap \
257+
-N "NIX_CFLAGS_COMPILE=\"-I\$${pkgs.cyrus_sasl.dev}/include/sasl \$$NIX_CFLAGS_COMPILE\"" \
258+
-E "openldap cyrus_sasl openssl" \
259+
--setup-requires "six packaging appdirs" \
260+
-r ldap.txt \
261+
-I $(NIX_PATH) \
262+
-V "2.7"
263+
264+
ldap.txt: ldap-clear
265+
@echo "python-ldap" > ldap.txt
266+
267+
ldap-clear:
268+
@rm -f ldap
269+
@rm -f ldap.txt
270+
@rm -f ldap.nix
271+
@rm -f ldap_generated.nix
272+
@rm -f ldap_frozen.txt

examples/ldap_override.nix

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{ pkgs, python }:
2+
3+
self: super: {
4+
5+
"python-ldap" = python.overrideDerivation super."python-ldap" (old: {
6+
NIX_CFLAGS_COMPILE = "-I${pkgs.cyrus_sasl.dev}/include/sasl";
7+
});
8+
9+
}

src/pypi2nix/stage1.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,27 @@ def main(verbose,
2727
a user provided requirements.txt.
2828
"""
2929

30+
31+
if extra_env:
32+
nix_instantiate = 'nix-instantiate'
33+
if os.path.exists(nix_shell):
34+
nix_instantiate = \
35+
os.path.abspath(os.path.join(
36+
os.path.dirname(nix_path),
37+
nix_instantiate
38+
))
39+
command_env = '%s --eval --expr \'let pkgs = import <nixpkgs> {}; in "%s"\'' % (
40+
41+
nix_instantiate,
42+
extra_env.replace('"', '\\"')
43+
)
44+
returncode, output = pypi2nix.utils.cmd(command_env, verbose != 0)
45+
if returncode != 0:
46+
if verbose == 0:
47+
click.echo(output)
48+
raise click.ClickException('Failed to interpret extra_env')
49+
extra_env = output.split('\n')[-2].strip()[1:-1]
50+
3051
command = '{nix_shell} {nix_file} {options} {nix_path} --show-trace --pure --run exit'.format( # noqa
3152
nix_shell=nix_shell,
3253
nix_file=os.path.join(os.path.dirname(__file__), 'pip.nix'),

0 commit comments

Comments
 (0)