From 45de1ae50e0dce96e95606bb4d0f8de3d6ced847 Mon Sep 17 00:00:00 2001 From: Alexander Bonkowski <57258530+ab5424@users.noreply.github.com> Date: Thu, 2 May 2024 14:36:03 +0200 Subject: [PATCH] Make BeautifulSoup optional (#3774) Signed-off-by: Alexander Bonkowski <57258530+ab5424@users.noreply.github.com> --- dev_scripts/update_pt_data.py | 8 +++++++- pymatgen/io/vasp/help.py | 8 +++++++- requirements-optional.txt | 1 + requirements.txt | 1 - 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/dev_scripts/update_pt_data.py b/dev_scripts/update_pt_data.py index 8799adef19b..58bdc301f99 100644 --- a/dev_scripts/update_pt_data.py +++ b/dev_scripts/update_pt_data.py @@ -11,12 +11,17 @@ from itertools import product import requests -from bs4 import BeautifulSoup +from monty.dev import requires from monty.serialization import dumpfn, loadfn from ruamel import yaml from pymatgen.core import Element, get_el_sp +try: + from bs4 import BeautifulSoup +except ImportError: + BeautifulSoup = None + ptable_yaml_path = "periodic_table.yaml" @@ -231,6 +236,7 @@ def gen_iupac_ordering(): periodic_table[el]["IUPAC ordering"] = iupac_ordering_dict[get_el_sp(el)] +@requires(BeautifulSoup, "BeautifulSoup must be installed to use this method.") def add_electron_affinities(): """Update the periodic table data file with electron affinities.""" diff --git a/pymatgen/io/vasp/help.py b/pymatgen/io/vasp/help.py index f057cb09b81..92c54913caf 100644 --- a/pymatgen/io/vasp/help.py +++ b/pymatgen/io/vasp/help.py @@ -5,12 +5,18 @@ import re import requests -from bs4 import BeautifulSoup +from monty.dev import requires + +try: + from bs4 import BeautifulSoup +except ImportError: + BeautifulSoup = None class VaspDoc: """A VASP documentation helper.""" + @requires(BeautifulSoup, "BeautifulSoup must be installed to fetch from the VASP wiki.") def __init__(self) -> None: """Init for VaspDoc.""" self.url_template = "http://www.vasp.at/wiki/index.php/%s" diff --git a/requirements-optional.txt b/requirements-optional.txt index b5a29956285..2c5019a6523 100644 --- a/requirements-optional.txt +++ b/requirements-optional.txt @@ -1,4 +1,5 @@ ase>=3.22.1 +beautifulsoup4==4.12.2 BoltzTraP2>=22.3.2 chemview>=0.6 f90nml>=1.4.3 diff --git a/requirements.txt b/requirements.txt index 2794ea355e0..384479945c4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,7 +11,6 @@ spglib==2.1.0 pandas==2.1.1 networkx==3.1 plotly==5.17.0 -beautifulsoup4==4.12.2 uncertainties==3.1.7 Cython==3.0.2 pybtex==0.24.0