11import click
2- import functools
32import hashlib
43import os
5- import random
6- import string
7- import tempfile
84import shutil
5+ import tempfile
96
107import pypi2nix .stage1
118import pypi2nix .stage2
5552 required = False ,
5653 default = None ,
5754 multiple = True ,
58- type = click .Path (exists = True , resolve_path = True ),
55+ type = click .Path (exists = True , file_okay = True , dir_okay = False ,
56+ resolve_path = True ),
5957 help = u'pip requirements.txt file' ,
6058 )
6159@click .option ('-b' , '--buildout' ,
6462 type = click .Path (exists = True ),
6563 help = u'zc.buildout configuration file' ,
6664 )
67- @click .argument ('specification' ,
68- nargs = - 1 ,
69- required = False ,
70- default = None ,
71- )
65+ @click .option ('-e' , '--editable' ,
66+ required = False ,
67+ default = None ,
68+ multiple = True ,
69+ type = str ,
70+ help = u'location/url to editable locations' ,
71+ )
7272def main (nix_path ,
7373 basename ,
7474 cache_dir ,
@@ -77,47 +77,37 @@ def main(nix_path,
7777 python_version ,
7878 requirements ,
7979 buildout ,
80- specification ,
80+ editable ,
8181 ):
8282 """SPECIFICATION should be requirements.txt (output of pip freeze).
8383 """
8484
85- # A user should specify only one of following options:
86- # * --requirements
87- # * --buildout
88- # * specifications
89- if functools .reduce (
90- lambda x , y : x + (y and 1 or 0 ),
91- [requirements , buildout , specification != tuple ()], 0 ) != 1 :
92- raise click .exceptions .UsageError (
93- "Only one of following options must be specified:\n "
94- " * -r/--requirements{}\n "
95- " * -b/--buildout{}\n "
96- " * SPECIFICATION{}\n " .format (
97- pypi2nix .utils .pretty_option (requirements ),
98- pypi2nix .utils .pretty_option (buildout ),
99- pypi2nix .utils .pretty_option (specification ),
100- ))
101-
10285 # temporary pypi2nix folder and make sure it exists
10386 tmp_dir = os .path .join (tempfile .gettempdir (), 'pypi2nix' )
10487 if not os .path .exists (tmp_dir ):
10588 os .makedirs (tmp_dir )
10689
107- if buildout :
108- raise click .exceptions .ClickException (
109- u'Not yet implemented!' )
90+ requirements_files = []
91+
92+ if requirements :
93+ requirements_files += requirements
11094
111- elif specification :
95+ if buildout :
11296 raise click .exceptions .ClickException (
11397 u'Not yet implemented!' )
11498
115- elif requirements :
116- requirements_files = requirements
117- requirements_name = os .path .splitext (os .path .basename (requirements [0 ]))[0 ]
99+ if editable :
100+ editable_file = os .path .join (tmp_dir , 'editable.txt' )
101+ with open (editable_file , 'w+' ) as f :
102+ for item in editable :
103+ f .write ('-e %s\n ' % item )
104+ requirements_files .append (editable_file )
118105
106+ project_dir = os .getcwd ()
119107 if basename :
120108 requirements_name = basename
109+ else :
110+ requirements_name = os .path .join (project_dir , 'requirements' )
121111
122112 if extra_build_inputs :
123113 extra_build_inputs = extra_build_inputs .split (' ' )
@@ -158,7 +148,8 @@ def main(nix_path,
158148
159149 click .echo ('Extracting metadata ...' )
160150
161- packages_metadata = pypi2nix .stage2 .main (wheels , requirements_files , cache_dir )
151+ packages_metadata = pypi2nix .stage2 .main (
152+ wheels , requirements_files , cache_dir )
162153
163154 click .echo ('Generating Nix expressions ...' )
164155
@@ -170,4 +161,5 @@ def main(nix_path,
170161 enable_tests = enable_tests ,
171162 python_version = pypi2nix .utils .PYTHON_VERSIONS [python_version ],
172163 top_level = top_level ,
164+ project_dir = project_dir ,
173165 )
0 commit comments