# Buggy code
def requirement(self, package, formatted=False):
    if formatted and not package.source_type:
        req = "{}=={}".format(package.name, package.version)
        for h in package.hashes:
            hash_type = "sha256"
            if ":" in h:
                hash_type, h = h.split(":")

            req += " --hash {}:{}".format(hash_type, h)

        req += "\n"

        return req

    if package.source_type in ["file", "directory"]:
        if package.root_dir:
            req = os.path.join(package.root_dir, package.source_url)
        else:
            req = os.path.realpath(package.source_url)

        if package.develop and package.source_type == "directory":
            req = ["-e", req]

        return req

    if package.source_type == "git":
        return "git+{}@{}#egg={}".format(
            package.source_url, package.source_reference, package.name
        )

    return "{}=={}".format(package.name, package.version)


# Traceback (EnvCommandError)
C:\projects\fts\fact-extract>poetry add https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.1.0/en_core_web_sm-2.1.0.tar.gz#egg=en_core_web_sm -vvv
Using virtualenv: C:\Users\Dylan\AppData\Local\pypoetry\Cache\virtualenvs\fact-extract-LQupvckr-py3.7

Updating dependencies
Resolving dependencies...
1: fact: fact-extract is 0.0.0
1: derived: fact-extract
1: fact: fact-extract depends on click (^7.0)
1: fact: fact-extract depends on scrapy (^1.7)
1: fact: fact-extract depends on textacy (^0.8.0)
1: fact: fact-extract depends on en-core-web-sm (*)
1: fact: fact-extract depends on pytest (^3.0)
1: fact: fact-extract depends on black (^19.3-beta.0)
1: selecting fact-extract (0.0.0)
1: derived: black (^19.3-beta.0)
1: derived: pytest (^3.0)
1: derived: en-core-web-sm (*)
1: derived: textacy (^0.8.0)
1: derived: scrapy (^1.7)
1: derived: click (^7.0)
1: fact: black (19.3b0) depends on click (>=6.5)
1: fact: black (19.3b0) depends on attrs (>=18.1.0)
1: fact: black (19.3b0) depends on appdirs (*)
1: fact: black (19.3b0) depends on toml (>=0.9.4)
1: selecting black (19.3b0)
1: derived: toml (>=0.9.4)
1: derived: appdirs (*)
1: derived: attrs (>=18.1.0)
1: fact: pytest (3.10.1) depends on py (>=1.5.0)
1: fact: pytest (3.10.1) depends on six (>=1.10.0)
1: fact: pytest (3.10.1) depends on attrs (>=17.4.0)
1: fact: pytest (3.10.1) depends on more-itertools (>=4.0.0)
1: fact: pytest (3.10.1) depends on atomicwrites (>=1.0)
1: fact: pytest (3.10.1) depends on pluggy (>=0.7)
1: fact: pytest (3.10.1) depends on colorama (*)
1: selecting pytest (3.10.1)
1: derived: colorama (*)
1: derived: pluggy (>=0.7)
1: derived: atomicwrites (>=1.0)
1: derived: more-itertools (>=4.0.0)
1: derived: six (>=1.10.0)
1: derived: py (>=1.5.0)
1: fact: en-core-web-sm (2.1.0) depends on spacy (>=2.1.0)
1: selecting en-core-web-sm (2.1.0 https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.1.0/en_core_web_sm-2.1.0.tar.gz#egg=en_core_web_sm)
1: derived: spacy (>=2.1.0)
1: fact: textacy (0.8.0) depends on cachetools (>=2.0.0)
1: fact: textacy (0.8.0) depends on cytoolz (>=0.8.0)
1: fact: textacy (0.8.0) depends on jellyfish (>=0.6.0,<0.7.0)
1: fact: textacy (0.8.0) depends on joblib (>=0.13.0)
1: fact: textacy (0.8.0) depends on networkx (>=1.11)
1: fact: textacy (0.8.0) depends on numpy (>=1.9.0,<2.0.0)
1: fact: textacy (0.8.0) depends on pyemd (>=0.3.0)
1: fact: textacy (0.8.0) depends on pyphen (>=0.9.4)
1: fact: textacy (0.8.0) depends on requests (>=2.10.0)
1: fact: textacy (0.8.0) depends on scipy (>=0.17.0)
1: fact: textacy (0.8.0) depends on scikit-learn (>=0.18.0,<0.21.0)
1: fact: textacy (0.8.0) depends on spacy (>=2.0.12)
1: fact: textacy (0.8.0) depends on srsly (>=0.0.5)
1: fact: textacy (0.8.0) depends on tqdm (>=4.11.1)
1: selecting textacy (0.8.0)
1: derived: tqdm (>=4.11.1)
1: derived: srsly (>=0.0.5)
1: derived: scikit-learn (>=0.18.0,<0.21.0)
1: derived: scipy (>=0.17.0)
1: derived: requests (>=2.10.0)
1: derived: pyphen (>=0.9.4)
1: derived: pyemd (>=0.3.0)
1: derived: numpy (>=1.9.0,<2.0.0)
1: derived: networkx (>=1.11)
1: derived: joblib (>=0.13.0)
1: derived: jellyfish (>=0.6.0,<0.7.0)
1: derived: cytoolz (>=0.8.0)
1: derived: cachetools (>=2.0.0)
1: fact: scrapy (1.7.2) depends on w3lib (>=1.17.0)
1: fact: scrapy (1.7.2) depends on queuelib (*)
1: fact: scrapy (1.7.2) depends on lxml (*)
1: fact: scrapy (1.7.2) depends on pyOpenSSL (*)
1: fact: scrapy (1.7.2) depends on cssselect (>=0.9)
1: fact: scrapy (1.7.2) depends on six (>=1.5.2)
1: fact: scrapy (1.7.2) depends on parsel (>=1.5)
1: fact: scrapy (1.7.2) depends on PyDispatcher (>=2.0.5)
1: fact: scrapy (1.7.2) depends on service-identity (*)
1: fact: scrapy (1.7.2) depends on PyPyDispatcher (>=2.1.0)
1: fact: scrapy (1.7.2) depends on Twisted (>=13.1.0)
1: selecting scrapy (1.7.2)
1: derived: Twisted (>=13.1.0)
1: derived: PyPyDispatcher (>=2.1.0)
1: derived: service-identity (*)
1: derived: PyDispatcher (>=2.0.5)
1: derived: parsel (>=1.5)
1: derived: cssselect (>=0.9)
1: derived: pyOpenSSL (*)
1: derived: lxml (*)
1: derived: queuelib (*)
1: derived: w3lib (>=1.17.0)
1: selecting click (7.0)
1: selecting toml (0.10.0)
1: selecting appdirs (1.4.3)
1: selecting attrs (19.1.0)
1: selecting colorama (0.4.1)
1: fact: pluggy (0.12.0) depends on importlib-metadata (>=0.12)
1: selecting pluggy (0.12.0)
1: derived: importlib-metadata (>=0.12)
1: selecting atomicwrites (1.3.0)
1: selecting more-itertools (7.2.0)
1: selecting six (1.12.0)
1: selecting py (1.8.0)
1: fact: spacy (2.1.6) depends on numpy (>=1.15.0)
1: fact: spacy (2.1.6) depends on murmurhash (>=0.28.0,<1.1.0)
1: fact: spacy (2.1.6) depends on cymem (>=2.0.2,<2.1.0)
1: fact: spacy (2.1.6) depends on preshed (>=2.0.1,<2.1.0)
1: fact: spacy (2.1.6) depends on thinc (>=7.0.8,<7.1.0)
1: fact: spacy (2.1.6) depends on blis (>=0.2.2,<0.3.0)
1: fact: spacy (2.1.6) depends on plac (>=0.9.6,<1.0.0)
1: fact: spacy (2.1.6) depends on requests (>=2.13.0,<3.0.0)
1: fact: spacy (2.1.6) depends on wasabi (>=0.2.0,<1.1.0)
1: fact: spacy (2.1.6) depends on srsly (>=0.0.6,<1.1.0)
1: selecting spacy (2.1.6)
1: derived: srsly (>=0.0.6,<1.1.0)
1: derived: wasabi (>=0.2.0,<1.1.0)
1: derived: requests (>=2.13.0,<3.0.0)
1: derived: plac (>=0.9.6,<1.0.0)
1: derived: blis (>=0.2.2,<0.3.0)
1: derived: thinc (>=7.0.8,<7.1.0)
1: derived: preshed (>=2.0.1,<2.1.0)
1: derived: cymem (>=2.0.2,<2.1.0)
1: derived: murmurhash (>=0.28.0,<1.1.0)
1: derived: numpy (>=1.15.0)
1: selecting tqdm (4.32.2)
1: selecting srsly (0.0.7)
1: fact: scikit-learn (0.20.3) depends on numpy (>=1.8.2)
1: fact: scikit-learn (0.20.3) depends on scipy (>=0.13.3)
1: selecting scikit-learn (0.20.3)
1: fact: scipy (1.3.0) depends on numpy (>=1.13.3)
1: selecting scipy (1.3.0)
1: fact: requests (2.22.0) depends on chardet (>=3.0.2,<3.1.0)
1: fact: requests (2.22.0) depends on idna (>=2.5,<2.9)
1: fact: requests (2.22.0) depends on urllib3 (>=1.21.1,<1.25.0 || >1.25.0,<1.25.1 || >1.25.1,<1.26)
1: fact: requests (2.22.0) depends on certifi (>=2017.4.17)
1: selecting requests (2.22.0)
1: derived: certifi (>=2017.4.17)
1: derived: urllib3 (>=1.21.1,<1.25.0 || >1.25.0,<1.25.1 || >1.25.1,<1.26)
1: derived: idna (>=2.5,<2.9)
1: derived: chardet (>=3.0.2,<3.1.0)
1: selecting pyphen (0.9.5)
1: fact: pyemd (0.5.1) depends on numpy (>=1.9.0,<2.0.0)
1: selecting pyemd (0.5.1)
1: selecting numpy (1.16.4)
1: fact: networkx (2.3) depends on decorator (>=4.3.0)
1: selecting networkx (2.3)
1: derived: decorator (>=4.3.0)
1: selecting joblib (0.13.2)
1: selecting jellyfish (0.6.1)
1: fact: cytoolz (0.10.0) depends on toolz (>=0.8.0)
1: selecting cytoolz (0.10.0)
1: derived: toolz (>=0.8.0)
1: selecting cachetools (3.1.1)
1: fact: twisted (19.2.1) depends on zope.interface (>=4.4.2)
1: fact: twisted (19.2.1) depends on constantly (>=15.1)
1: fact: twisted (19.2.1) depends on incremental (>=16.10.1)
1: fact: twisted (19.2.1) depends on Automat (>=0.3.0)
1: fact: twisted (19.2.1) depends on hyperlink (>=17.1.1)
1: fact: twisted (19.2.1) depends on PyHamcrest (>=1.9.0)
1: fact: twisted (19.2.1) depends on attrs (>=17.4.0)
1: selecting twisted (19.2.1)
1: derived: PyHamcrest (>=1.9.0)
1: derived: hyperlink (>=17.1.1)
1: derived: Automat (>=0.3.0)
1: derived: incremental (>=16.10.1)
1: derived: constantly (>=15.1)
1: derived: zope.interface (>=4.4.2)
1: selecting pypydispatcher (2.1.2)
1: fact: service-identity (18.1.0) depends on attrs (>=16.0.0)
1: fact: service-identity (18.1.0) depends on pyasn1-modules (*)
1: fact: service-identity (18.1.0) depends on pyasn1 (*)
1: fact: service-identity (18.1.0) depends on cryptography (*)
1: selecting service-identity (18.1.0)
1: derived: cryptography (*)
1: derived: pyasn1 (*)
1: derived: pyasn1-modules (*)
1: selecting pydispatcher (2.0.5)
1: fact: parsel (1.5.1) depends on w3lib (>=1.19.0)
1: fact: parsel (1.5.1) depends on lxml (>=2.3)
1: fact: parsel (1.5.1) depends on six (>=1.5.2)
1: fact: parsel (1.5.1) depends on cssselect (>=0.9)
1: selecting parsel (1.5.1)
1: derived: lxml (>=2.3)
1: derived: w3lib (>=1.19.0)
1: selecting cssselect (1.0.3)
1: fact: pyopenssl (19.0.0) depends on cryptography (>=2.3)
1: fact: pyopenssl (19.0.0) depends on six (>=1.5.2)
1: selecting pyopenssl (19.0.0)
1: derived: cryptography (>=2.3)
1: selecting lxml (4.3.4)
1: selecting queuelib (1.5.0)
1: fact: w3lib (1.20.0) depends on six (>=1.4.1)
1: selecting w3lib (1.20.0)
PyPI: Invalid constraint (pathlib2 ; python_version == "3.4.*" or python_version < "3") found in importlib-metadata-0.18 dependencies, skipping
1: fact: importlib-metadata (0.18) depends on zipp (>=0.5)
1: selecting importlib-metadata (0.18)
1: derived: zipp (>=0.5)
1: selecting wasabi (0.2.2)
1: selecting plac (0.9.6)
1: fact: blis (0.2.4) depends on numpy (>=1.15.0)
1: selecting blis (0.2.4)
1: fact: thinc (7.0.8) depends on murmurhash (>=0.28.0,<1.1.0)
1: fact: thinc (7.0.8) depends on cymem (>=2.0.2,<2.1.0)
1: fact: thinc (7.0.8) depends on preshed (>=1.0.1,<2.1.0)
1: fact: thinc (7.0.8) depends on blis (>=0.2.1,<0.3.0)
1: fact: thinc (7.0.8) depends on wasabi (>=0.0.9,<1.1.0)
1: fact: thinc (7.0.8) depends on srsly (>=0.0.6,<1.1.0)
1: fact: thinc (7.0.8) depends on numpy (>=1.7.0)
1: fact: thinc (7.0.8) depends on plac (>=0.9.6,<1.0.0)
1: fact: thinc (7.0.8) depends on tqdm (>=4.10.0,<5.0.0)
1: selecting thinc (7.0.8)
1: fact: preshed (2.0.1) depends on cymem (>=2.0.2,<2.1.0)
1: selecting preshed (2.0.1)
1: selecting cymem (2.0.2)
1: selecting murmurhash (1.0.2)
1: selecting certifi (2019.6.16)
1: selecting urllib3 (1.25.3)
1: selecting idna (2.8)
1: selecting chardet (3.0.4)
1: selecting decorator (4.4.0)
1: selecting toolz (0.10.0)
1: fact: pyhamcrest (1.9.0) depends on six (*)
1: selecting pyhamcrest (1.9.0)
1: fact: hyperlink (19.0.0) depends on idna (>=2.5)
1: selecting hyperlink (19.0.0)
1: fact: automat (0.7.0) depends on attrs (>=16.1.0)
1: fact: automat (0.7.0) depends on six (*)
1: selecting automat (0.7.0)
1: selecting incremental (17.5.0)
1: selecting constantly (15.1.0)
1: selecting zope.interface (4.6.0)
1: fact: cryptography (2.7) depends on asn1crypto (>=0.21.0)
1: fact: cryptography (2.7) depends on six (>=1.4.1)
1: fact: cryptography (2.7) depends on cffi (>=1.8,<1.11.3 || >1.11.3)
1: selecting cryptography (2.7)
1: derived: cffi (>=1.8,<1.11.3 || >1.11.3)
1: derived: asn1crypto (>=0.21.0)
1: selecting pyasn1 (0.4.5)
1: fact: pyasn1-modules (0.2.5) depends on pyasn1 (>=0.4.1,<0.5.0)
1: selecting pyasn1-modules (0.2.5)
1: selecting zipp (0.5.2)
1: fact: cffi (1.12.3) depends on pycparser (*)
1: selecting cffi (1.12.3)
1: derived: pycparser (*)
1: selecting asn1crypto (0.24.0)
1: selecting pycparser (2.19)
1: Version solving took 2.410 seconds.
1: Tried 1 solutions.

Writing lock file


Package operations: 4 installs, 0 updates, 0 removals

- Installing en_core_web_sm (2.1.0 https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.1.0/en_core_web_sm-2.1.0.tar.gz#egg=en_core_web_sm)

[EnvCommandError]
Command ['C:\\Users\\Dylan\\AppData\\Local\\pypoetry\\Cache\\virtualenvs\\fact-extract-LQupvckr-py3.7\\Scripts\\python.exe', '-m', 'pip', 'install', '--no-deps', 'en-core-web-sm==2.1.0'] errored with the following return code 1, and output:
Collecting en-core-web-sm==2.1.0
Could not find a version that satisfies the requirement en-core-web-sm==2.1.0 (from versions: )
No matching distribution found for en-core-web-sm==2.1.0
You are using pip version 19.0.3, however version 19.2.2 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.


Traceback (most recent call last):
File "C:\Users\Dylan\.poetry\lib\poetry\_vendor\py3.7\clikit\console_application.py", line 132, in run
status_code = command.handle(parsed_args, io)
File "C:\Users\Dylan\.poetry\lib\poetry\_vendor\py3.7\clikit\api\command\command.py", line 119, in handle
status_code = self._do_handle(args, io)
File "C:\Users\Dylan\.poetry\lib\poetry\_vendor\py3.7\clikit\api\command\command.py", line 167, in _do_handle
return getattr(handler, handler_method)(args, io, self)
File "C:\Users\Dylan\.poetry\lib\poetry\_vendor\py3.7\cleo\commands\command.py", line 92, in wrap_handle
return self.handle()
File "C:\Users\Dylan\.poetry\lib\poetry\console\commands\add.py", line 149, in handle
status = installer.run()
File "C:\Users\Dylan\.poetry\lib\poetry\installation\installer.py", line 74, in run
self._do_install(local_repo)
File "C:\Users\Dylan\.poetry\lib\poetry\installation\installer.py", line 286, in _do_install
self._execute(op)
File "C:\Users\Dylan\.poetry\lib\poetry\installation\installer.py", line 302, in _execute
getattr(self, '_execute_{}'.format(method))(operation)
File "C:\Users\Dylan\.poetry\lib\poetry\installation\installer.py", line 327, in _execute_install
self._installer.install(operation.package)
File "C:\Users\Dylan\.poetry\lib\poetry\installation\pip_installer.py", line 88, in install
self.run(*args)
File "C:\Users\Dylan\.poetry\lib\poetry\installation\pip_installer.py", line 109, in run
return self._env.run('python', '-m', 'pip', *args, **kwargs)
File "C:\Users\Dylan\.poetry\lib\poetry\utils\env.py", line 875, in run
return super(VirtualEnv, self).run(bin, *args, **kwargs)
File "C:\Users\Dylan\.poetry\lib\poetry\utils\env.py", line 708, in run
raise EnvCommandError(e, input=input_)

# Fixed code
def requirement(self, package, formatted=False):
    if formatted and not package.source_type:
        req = "{}=={}".format(package.name, package.version)
        for h in package.hashes:
            hash_type = "sha256"
            if ":" in h:
                hash_type, h = h.split(":")

            req += " --hash {}:{}".format(hash_type, h)

        req += "\n"

        return req

    if package.source_type in ["file", "directory"]:
        if package.root_dir:
            req = os.path.join(package.root_dir, package.source_url)
        else:
            req = os.path.realpath(package.source_url)

        if package.develop and package.source_type == "directory":
            req = ["-e", req]

        return req

    if package.source_type == "git":
        return "git+{}@{}#egg={}".format(
            package.source_url, package.source_reference, package.name
        )

    if package.source_type == "url":
        return "{}#egg={}".format(package.source_url, package.name)

    return "{}=={}".format(package.name, package.version)