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

Commit 004966c

Browse files
committed
adding -e option (used the same as in requirements files)
1 parent f9d0084 commit 004966c

File tree

4 files changed

+38
-47
lines changed

4 files changed

+38
-47
lines changed

examples/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ rss2email.nix: rss2email.txt $(PYPI2NIX)
9393
@$(PYPI2NIX) -r rss2email.txt -V "3.4" -I $(NIX_PATH)
9494

9595
rss2email.txt: rss2email-clear
96-
@echo "https://github.com/wking/rss2email/archive/master.zip" > rss2email.txt
96+
@echo "https://github.com/wking/rss2email/archive/master.zip#egg=rss2email" > rss2email.txt
9797

9898
rss2email-clear:
9999
@rm -f rss2email

src/pypi2nix/cli.py

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import click
2-
import functools
32
import hashlib
43
import os
5-
import random
6-
import string
7-
import tempfile
84
import shutil
5+
import tempfile
96

107
import pypi2nix.stage1
118
import pypi2nix.stage2
@@ -55,7 +52,8 @@
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',
@@ -64,11 +62,13 @@
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+
)
7272
def 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
)

src/pypi2nix/stage2.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def process_metadata(wheel):
8080

8181

8282
def download_file(url, filename, chunk_size=1024):
83-
r = requests.get(url, stream=True)
83+
r = requests.get(url, stream=True, timeout=3)
8484
r.raise_for_status() # TODO: handle this nicer
8585

8686
with open(filename, 'wb') as fd:
@@ -134,7 +134,7 @@ def process_wheel(cache_dir, wheel, sources, index=INDEX_URL):
134134
release['url'] = sources[wheel['name']]
135135
release['hash_type'] = 'sha256'
136136

137-
r = requests.get(release['url'], stream=True)
137+
r = requests.get(release['url'], stream=True, timeout=3)
138138
r.raise_for_status() # TODO: handle this nicer
139139

140140
chunk_size=1024
@@ -148,7 +148,7 @@ def process_wheel(cache_dir, wheel, sources, index=INDEX_URL):
148148

149149
else:
150150
url = "{}/{}/json".format(index, wheel['name'])
151-
r = requests.get(url)
151+
r = requests.get(url, timeout=3)
152152
r.raise_for_status() # TODO: handle this nicer
153153
wheel_data = r.json()
154154

src/pypi2nix/stage3.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,14 @@ def main(packages_metadata,
121121
enable_tests,
122122
python_version,
123123
top_level,
124+
project_dir,
124125
):
125126
'''Create Nix expressions.
126127
'''
127128

128-
project_folder = os.path.dirname(requirements_files[0])
129-
130-
default_file = os.path.join(project_folder, '{}.nix'.format(requirements_name))
131-
generated_file = os.path.join(project_folder, '{}_generated.nix'.format(requirements_name))
132-
overrides_file = os.path.join(project_folder, '{}_override.nix'.format(requirements_name))
129+
default_file = os.path.join(project_dir, '{}.nix'.format(requirements_name))
130+
generated_file = os.path.join(project_dir, '{}_generated.nix'.format(requirements_name))
131+
overrides_file = os.path.join(project_dir, '{}_override.nix'.format(requirements_name))
133132

134133
version_file = os.path.join(os.path.dirname(__file__), 'VERSION')
135134
with open(version_file) as f:
@@ -172,8 +171,8 @@ def main(packages_metadata,
172171
extra_build_inputs=extra_build_inputs
173172
and "with pkgs; [ %s ]" % (' '.join(extra_build_inputs))
174173
or "[]",
175-
generated_file='.' + generated_file[len(project_folder):],
176-
overrides_file='.' + overrides_file[len(project_folder):],
174+
generated_file='.' + generated_file[len(project_dir):],
175+
overrides_file='.' + overrides_file[len(project_dir):],
177176
enable_tests=str(enable_tests).lower(),
178177
)
179178

0 commit comments

Comments
 (0)