Repository: cogent3/cogent3 (language: python)

Issue:
DEV: minor edits before bug-fix release



Discussion / hints:

Fix patch:
diff --git a/changelog.md b/changelog.md
index 88f27977d..c2ce06ece 100755
--- a/changelog.md
+++ b/changelog.md
@@ -1,4 +1,17 @@
 
+<a id='changelog-2024.7.19a4'></a>
+# Changes in release "2024.7.19a4"
+
+This is a minor bug fix release.
+
+## Contributors
+
+- Contribution from @rmcar17 on fixing an encoding error when loading small newick trees.
+
+## BUG
+
+- Fixed an issue with `load_tree` incorrectly detecting the encoding of very small newick files.
+
 <a id='changelog-2024.7.19a3'></a>
 # Changes in release "2024.7.19a3"
 
diff --git a/pyproject.toml b/pyproject.toml
index 0b7281c12..d9899f0ef 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -13,7 +13,7 @@ authors = [
 keywords = ["biology", "genomics", "statistics", "phylogeny", "evolution", "bioinformatics"]
 readme = "README.md"
 license = { file = "LICENSE" }
-dependencies = ["charset-normalizer",
+dependencies = ["chardet",
         "numpy",
         "numba>0.53; python_version>='3.9' and python_version <'3.12'",
         "numba>0.54; python_version>='3.10' and python_version <'3.12'",
@@ -47,7 +47,7 @@ Changelog = "https://github.com/cogent3/cogent3/blob/develop/changelog.md"
 
 [project.optional-dependencies]
 test = [
-    "ruff==0.5.5",
+    "ruff==0.5.7",
     "kaleido",
     "pandas",
     "plotly",
@@ -57,7 +57,7 @@ test = [
     "pytest-xdist",
     "tinydb",
     "nox"]
-doc  = ["click==8.1.7",
+doc  = ["click",
         "ipykernel",
         "ipython",
         "ipywidgets",
@@ -81,7 +81,7 @@ doc  = ["click==8.1.7",
         "sphinxcontrib-bibtex",
         "sphinxcontrib-video"]
 extra = ["pandas", "plotly", "psutil", "kaleido"]
-dev = ["ruff==0.5.5",
+dev = ["ruff==0.5.7",
        "flit",
        "ipykernel",
        "ipython",
diff --git a/src/cogent3/_version.py b/src/cogent3/_version.py
index dda4d6761..82ce2fc46 100644
--- a/src/cogent3/_version.py
+++ b/src/cogent3/_version.py
@@ -1,2 +1,1 @@
-# remember to update version in pyproject.toml too!
-__version__ = "2024.7.19a3"
+__version__ = "2024.7.19a4"
diff --git a/src/cogent3/util/io.py b/src/cogent3/util/io.py
index 6f34a1afb..1c9891a6a 100644
--- a/src/cogent3/util/io.py
+++ b/src/cogent3/util/io.py
@@ -13,7 +13,7 @@
 from urllib.request import urlopen
 from zipfile import ZipFile
 
-from charset_normalizer import detect
+from chardet import detect
 
 from cogent3.util.misc import _wout_period
 


Test patch:
diff --git a/tests/test_core/test_tree.py b/tests/test_core/test_tree.py
index 2c5019703..8e4f3c25b 100644
--- a/tests/test_core/test_tree.py
+++ b/tests/test_core/test_tree.py
@@ -2316,3 +2316,18 @@ def test_parser():
     tidied = tree.get_newick(with_distances=1)
     assert tidied == nice
     assert tree.get_node_matching_name("pair").params["other"] == ["com\nment"]
+
+
+def test_load_tree_bad_encoding():
+    """
+    charset_normalizer rather than chardet as a dependency
+    incorrectly detected the encoding of a file as UTF-16LE.
+    """
+    newick = "(a,b);"
+
+    with TemporaryDirectory(dir=".") as dirname:
+        tree_path = os.path.join(dirname, "tree.tree")
+        with open(tree_path, "wb") as f:
+            f.write(newick.encode("ascii"))
+
+        assert load_tree(tree_path).get_newick() == newick