Resolvendo uma dependência com poetry dependency management
Tags: poetry, python, management, code
Published: 2020-07-06 20:50:48

Usando o [Poetry](https://python-poetry.org/) para gerenciar um pequeno projeto em Python, me deparo com o seguinte erro ao instalar uma dependência:

comando:
```shell
$ poetry add newspaper3k

Using version ^0.2.8 for newspaper3k

Updating dependencies
Resolving dependencies... (1.3s)

[ReadError]
file could not be opened successfully
```

Falhou ao instalar a dependência. 

Executei o mesmo comando acima passando `-vvv` para exibir as mensagens de *debug*, omiti parte do debug com `[...]` pra não ficar muito extenso:

```shell
$ poetry add newspaper3k -vvv
Using virtualenv: 

[...]
PyPI: 18 packages found for newspaper3k *
Using version ^0.2.8 for newspaper3k

Updating dependencies
Resolving dependencies...

[...]

PyPI: 1 packages found for newspaper3k >=0.2.8,<0.3.0

[...]

   1: selecting feedfinder2 (0.0.4)
PyPI: Getting info for feedparser (5.2.1) from PyPI
PyPI: No dependencies found, downloading archives
PyPI: Downloading sdist: feedparser-5.2.1.tar.bz2
   1: Version solving took 0.791 seconds.
   1: Tried 1 solutions.

[ReadError]
file could not be opened successfully

Traceback (most recent call last):

[...]

"/home/jhoonb/.poetry/lib/poetry/_vendor/py3.8/pkginfo/sdist.py", line 26, in _get_archive
    archive = tarfile.TarFile.open(fqn)
  File "/home/jhoonb/.asdf/installs/python/3.8.2/lib/python3.8/tarfile.py", line 1604, in open
    raise ReadError("file could not be opened successfully")
```

O instalador tentou baixar e abrir a seguinte *lib* `feedparser-5.2.1.tar.bz2`, não conseguiu e retornou erro *file could not be opened successfully*.

a *lib* [newspaper3k](https://github.com/codelucas/newspaper) depende de [feedparser](https://github.com/kurtmckee/feedparser/), mas por algum motivo quebrou na instalação.

Tentando instalar a dependência que quebrou via `poetry`:
```shell
$ poetry add feedparser -vvv 

[...]

PyPI: 12 packages found for feedparser *
Using version ^5.2.1 for feedparser

Updating dependencies
Resolving dependencies...

[...]

PyPI: 1 packages found for feedparser >=5.2.1,<6.0.0
PyPI: Getting info for feedparser (5.2.1) from PyPI
PyPI: No dependencies found, downloading archives
PyPI: Downloading sdist: feedparser-5.2.1.tar.bz2
   1: Version solving took 0.759 seconds.
   1: Tried 1 solutions.

[ReadError]
file could not be opened successfully

Traceback (most recent call last):
  File 

[...]


"/home/jhoonb/.asdf/installs/python/3.8.2/lib/python3.8/tarfile.py", line 1604, in open
    raise ReadError("file could not be opened successfully")
```
Não conseguimos instalar a *lib*. Mas tentando instalar pelo `pip` a instalação é concluída:

```shell
$ pip3 install feedparser      
pip3 install feedparser  
Collecting feedparser
  Using cached feedparser-5.2.1.tar.gz (252 kB)
Building wheels for collected packages: feedparser
  Building wheel for feedparser (setup.py) ... done
  Created wheel for feedparser: filename=feedparser-5.2.1-py3-none-any.whl size=44939 [...]
Successfully built feedparser
Installing collected packages: feedparser
Successfully installed feedparser-5.2.1
```
O problema deve ser no **poetry**, vamos tentar instalar essa dependência apontando para *github*, no *branch master*, porque por padrão o branch é *develop*:

```shell
$ poetry add git+https://github.com/kurtmckee/feedparser.git#master

Updating dependencies
Resolving dependencies... (14.3s)

Writing lock file


Package operations: 1 install, 0 updates, 0 removals

  - Installing feedparser (5.2.1 cf41851)
```
 
Instalado com sucesso! Agora vamos tentar instalar a *lib* `newspaper3k`:

```shell
$ poetry add newspaper3k                                           
Using version ^0.2.8 for newspaper3k

Updating dependencies
Resolving dependencies... (16.2s)

Writing lock file


Package operations: 23 installs, 0 updates, 0 removals

  - Installing certifi (2020.6.20)
  - Installing chardet (3.0.4)
  - Installing idna (2.10)
  - Installing urllib3 (1.25.9)
  - Installing requests (2.24.0)
  - Installing soupsieve (1.9.6)
  - Installing beautifulsoup4 (4.9.1)
  - Installing click (7.1.2)
  - Installing joblib (0.16.0)
  - Installing regex (2020.6.8)
  - Installing requests-file (1.5.1)
  - Installing tqdm (4.47.0)
  - Installing cssselect (1.1.0)
  - Installing feedfinder2 (0.0.4)
  - Installing jieba3k (0.35.1)
  - Installing lxml (4.5.1)
  - Installing nltk (3.5)
  - Installing pillow (7.2.0)
  - Installing python-dateutil (2.8.1)
  - Installing pyyaml (5.3.1)
  - Installing tinysegmenter (0.3)
  - Installing tldextract (2.2.2)
  - Installing newspaper3k (0.2.8)
```
Conseguimos instalar! Tivemos que adicionar a dependência `feedparser` diretamente em nosso projeto apontando para *git* em *branch master*.

Fica em aberto a questão do **poetry** não conseguir instalar a lib `newspaper3k` com a dependência diretamente. O `pip` conseguiu resolver o problema.