Skip to content

Commit 4d29359

Browse files
committed
Dependencies auto-install
1 parent 903bd41 commit 4d29359

File tree

2 files changed

+37
-18
lines changed

2 files changed

+37
-18
lines changed

README.md

+16-16
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,26 @@
88

99
- [Python 3.6+](https://www.python.org/downloads/)
1010

11-
##### Python dependencies
11+
🇪🇸 *Las dependencias de Python se instalarán automáticamente la primera vez que ejecutes el programa.*
1212

13-
🇪🇸 Ejecuta el siguiente comando. A veces el comando de dependencias para Python3 es `pip3` en vez de `pip`.
13+
También puedes instalarlas manualmente con el siguiente comando:
1414

15-
🇬🇧 Run the following command. Sometimes dependencies command for Python3 is `pip3` instead of `pip`.
15+
```shell
16+
pip install --user -r dependencies.txt
17+
```
18+
19+
A veces el comando para Python3 es `pip3` en lugar de `pip`.
20+
21+
🇬🇧 *Python dependencies will be installed automatically the first time you run the program.*
22+
23+
Dependencies can also be installed manually with the following command:
1624

1725
```shell
1826
pip install --user -r dependencies.txt
1927
```
2028

29+
Sometimes dependencies command for Python3 is `pip3` instead of `pip`.
30+
2131
*Instalará / Will install:*
2232

2333
- (EPUB/MOBI format) [Kindle Comic Converter](https://github.com/ciromattia/kcc)
@@ -26,27 +36,17 @@ pip install --user -r dependencies.txt
2636
- [colorama](https://pypi.org/project/colorama/)
2737
- [img2pdf](https://pypi.org/project/img2pdf/)
2838

29-
(*Opcional*) Puedes usar `virtualenv` para evitar conflictos con otras versiones de Python:
30-
31-
```bash
32-
sudo pip install virtualenv
33-
virtualenv env
34-
. env/bin/activate # Bash/Tcsh console
35-
#. env/bin/activate.fish # Fish console
36-
pip install -r dependencies.txt
37-
```
38-
3939
#### MOBI / Kindle
4040

41-
Para convertir un manga al formato MOBI (Kindle) necesitarás la dependencia [KindleGen](https://www.amazon.com/gp/feature.html?ie=UTF8&docId=1000765211).
41+
Para convertir un manga al formato MOBI (Kindle) necesitarás instalar [KindleGen](https://www.amazon.com/gp/feature.html?ie=UTF8&docId=1000765211).
4242

4343
En las últimas versiones de Mac OS X es posible que la anterior versión no funcione, así que necesitarás instalar [Kindle Previewer 3](https://www.amazon.com/gp/feature.html?ie=UTF8&docId=1003018611) y añadir el ejecutable `kindlegen` a tu PATH ejecutando el siguiente comando después de instalarlo: `cp /Applications/Kindle\ Previewer\ 3.app/Contents/MacOS/lib/fc/bin/kindlegen /usr/local/bin/kindlegen`
4444

4545
Puedes enviar tus capítulos directamente al Kindle con la aplicación [SendToKindle](https://www.amazon.com/gp/sendtokindle).
4646

4747
#### PDF
4848

49-
En la conversión a PDF algunas imágenes pueden dar el error `Exception: Refusing to work on images with alpha channel`. Para corregir esto se debe eliminar la transparencia de estas imágenes. Puedes añadir la opción `--remove-alpha` para hacerlo automáticamente. Para que funcione debes instalar [Wand + ImageMagick](http://docs.wand-py.org/en/0.5.9/guide/install.html).
49+
En la conversión a PDF algunas imágenes pueden dar el error `Exception: Refusing to work on images with alpha channel`. Para corregir esto se debe eliminar la transparencia de estas imágenes. Puedes añadir la opción `--remove-alpha` para hacerlo automáticamente. Para que funcione debes instalar [Wand + ImageMagick](http://docs.wand-py.org/en/0.6.1/guide/install.html).
5050

5151
### 🇪🇸 Uso
5252

@@ -65,7 +65,7 @@ uso: manga.py [-h] [--chapters CHAPTERS] [--directory DIRECTORY] [--single]
6565
parámetros posicionales:
6666
 manga                 título del manga a descargar
6767
68-
optional arguments:
68+
parámetros opcionales:
6969
 -h, --help           muestra este mensaje de ayuda (en inglés)
7070
--chapters CHAPTERS, --chapter CHAPTERS
7171
                       capítulos a descargar. Formato: primero..último o capítulos

manga.py

+21-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,30 @@
77
import signal
88
import argparse
99
import tempfile
10+
from urllib.parse import quote_plus
11+
from multiprocessing import freeze_support
12+
13+
def install_dependencies(dependencies_file):
14+
# Check dependencies
15+
import subprocess
16+
import sys
17+
from pathlib import Path
18+
import pkg_resources
19+
dependencies_path = Path(__file__).with_name(dependencies_file)
20+
dependencies = pkg_resources.parse_requirements(dependencies_path.open())
21+
try:
22+
for dependency in dependencies:
23+
dependency = str(dependency)
24+
pkg_resources.require(dependency)
25+
except pkg_resources.DistributionNotFound as e:
26+
print("Some dependencies are missing, installing...")
27+
# Install missing dependencies
28+
subprocess.check_call([sys.executable, "-m", "pip", "install", "-r", dependencies_file])
29+
30+
install_dependencies("dependencies.txt")
1031
from requests import get, post
1132
from bs4 import BeautifulSoup
12-
from urllib.parse import quote_plus
1333
from colorama import Fore, Style, init as init_console_colors
14-
from multiprocessing import freeze_support
1534

1635
WEBSITE = "https://inmanga.com"
1736
IMAGE_WEBSITE = f"{WEBSITE}/page/getPageImage/?identification="

0 commit comments

Comments
 (0)