Repository: jazzband/pip-tools

Issue:
Unnamed editable dependency raises AttributeError on second run
An editable dependency without a name raises an AttributeError when pip-compile is run the second time without the --upgrade flag.

##### Environment Versions

1. CentOS 7
1. Python version: Python 3.5.2
1. pip version:  pip 9.0.1
1. pip-tools version: pip-compile, version 1.8.1

##### Steps to replicate
foo.in:

```
-e .
```
run:

```
pip-compile foo.in
pip-compile foo.in
```

##### Expected result

```
#
# This file is autogenerated by pip-compile
# To update, run:
#
#    pip-compile --output-file foo.txt foo.in
#
-e file:///home/eric/projects/foo
```
(Well, not really the *hoped for* result due to #204.)
##### Actual result

```
Traceback (most recent call last):
  File "/home/eric/projects/foo/.env/bin/pip-compile", line 11, in <module>
    sys.exit(cli())
  File "/home/eric/projects/foo/.env/lib64/python3.5/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/home/eric/projects/foo/.env/lib64/python3.5/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/home/eric/projects/foo/.env/lib64/python3.5/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/eric/projects/foo/.env/lib64/python3.5/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/home/eric/projects/foo/.env/lib64/python3.5/site-packages/piptools/scripts/compile.py", line 139, in cli
    key = key_from_req(ireq.req)
  File "/home/eric/projects/foo/.env/lib64/python3.5/site-packages/piptools/utils.py", line 41, in key_from_req
    key = req.name
AttributeError: 'NoneType' object has no attribute 'name'
```
I think this could be fixed in compile.py (around line 138) by waiting to see if `is_pinned_requirement` returns True before trying to get the key. Something like...

```
        for ireq in ireqs:

            if is_pinned_requirement(ireq):
                key = key_from_req(ireq.req)
                existing_pins[key] = ireq
```


Discussion:
Thanks I have reproduced. It only happens on second compile run, when an output requirement already exists.

Resolving patch:
diff --git a/piptools/scripts/compile.py b/piptools/scripts/compile.py
--- a/piptools/scripts/compile.py
+++ b/piptools/scripts/compile.py
@@ -132,13 +132,8 @@ def cli(verbose, dry_run, pre, rebuild, find_links, index_url, extra_index_url,
     # Proxy with a LocalRequirementsRepository if --upgrade is not specified
     # (= default invocation)
     if not (upgrade or upgrade_packages) and os.path.exists(dst_file):
-        existing_pins = {}
         ireqs = parse_requirements(dst_file, finder=repository.finder, session=repository.session, options=pip_options)
-        for ireq in ireqs:
-            key = key_from_req(ireq.req)
-
-            if is_pinned_requirement(ireq):
-                existing_pins[key] = ireq
+        existing_pins = {key_from_req(ireq.req): ireq for ireq in ireqs if is_pinned_requirement(ireq)}
         repository = LocalRequirementsRepository(existing_pins, repository)
 
     log.debug('Using indexes:')


Test patch: