Repository: xonsh/xonsh
Pull request: try just using CaseSenssitiveDict from requests to see if it works
closes #5627 
replaces #5633 

option 1: just import `CaseInsensitiveDict` from `requests.strucures`
pros: 
 - not much typing
cons: 
 - replaces one dependency with another
 - requests is not typed natively so either has to be excluded from mypy, or also import `types-requests` as an additional dependency

Option 2: hard code `CaseInsensitiveDict` by overriding python native dict.  below is a possibility.
pros: behavior is then native in xonsh
cons: more code to maintain
```
class CaseInsensitiveDict(Dict[str, Any]):
    def __init__(self, *args, **kwargs):
        super().__init__()
        self._store = {}
        self.update(*args, **kwargs)

    def __setitem__(self, key, value):
        # Store the key in lowercase but preserve the original case for display
        self._store[key.lower()] = key
        super().__setitem__(key.lower(), value)

    def __getitem__(self, key):
        return super().__getitem__(key.lower())

    def __delitem__(self, key):
        del self._store[key.lower()]
        super().__delitem__(key.lower())

    def __contains__(self, key):
        return key.lower() in self._store

    def get(self, key, default=None):
        return super().get(key.lower(), default)

    def update(self, *args, **kwargs):
        for k, v in dict(*args, **kwargs).items():
            self[k] = v

    def keys(self):
        # Return the original keys with their original casing
        return (self._store[k] for k in self._store)

    def items(self):
        return ((self._store[k], self[k]) for k in self._store)

    def __repr__(self):
        return f"{self.__class__.__name__}({dict(self.items())})"

    def copy(self):
        return CaseInsensitiveDict(self.items())

```

## For community
⬇️  **Please click the 👍 reaction instead of leaving a `+1` or 👍  comment**


Problem statement:
problems importing case_insensitive_dict
## Current Behavior
<!---
The Regolith package imports Xonsh in its __init__ and when I rebuilt my env I go an import error:
-->

Traceback (if applicable):

<details>

```xsh
Traceback (most recent call last):
  File "C:\Users\simon\miniconda3\envs\r312\Scripts\regolith", line 2, in <module>
    from regolith.main import main
  File "C:\Users\simon\dev\regolith\src\regolith\__init__.py", line 6, in <module>
    XSH.load(execer=Execer())
  File "C:\Users\simon\miniconda3\envs\r312\Lib\site-packages\xonsh\built_ins.py", line 633, in load
    from xonsh.commands_cache import CommandsCache
  File "C:\Users\simon\miniconda3\envs\r312\Lib\site-packages\xonsh\commands_cache.py", line 27, in <module>
    from case_insensitive_dict import CaseInsensitiveDict as CacheDict
ModuleNotFoundError: No module named 'case_insensitive_dict'
```

I was able to install `case_insensitive_dict` from pip (it wasn't found in conda-forge or conda defaults) but then I still got an import error:

```xsh
$ regolith --version
C:\Users\simon\dev\regolith\src\regolith\version.py:38: UserWarning: Package metadata not found.
  warn("Package metadata not found.")
Traceback (most recent call last):
  File "C:\Users\simon\miniconda3\envs\r312\Scripts\regolith", line 2, in <module>
    from regolith.main import main
  File "C:\Users\simon\dev\regolith\src\regolith\__init__.py", line 14, in <module>
    XSH.load(execer=Execer())
  File "C:\Users\simon\miniconda3\envs\r312\Lib\site-packages\xonsh\built_ins.py", line 633, in load
    from xonsh.commands_cache import CommandsCache
  File "C:\Users\simon\miniconda3\envs\r312\Lib\site-packages\xonsh\commands_cache.py", line 27, in <module>
    from case_insensitive_dict import CaseInsensitiveDict as CacheDict
ImportError: cannot import name 'CaseInsensitiveDict' from 'case_insensitive_dict' (C:\Users\simon\miniconda3\envs\r312\Lib\site-packages\case_insensitive_dict\__init__.py)
```
Any help with this would be appreciated.

</details>

## Expected Behavior
<!--- I would like regolith to run again without this importerror -->

## xonfig

<details>

```xsh
bash: xonfig: command not found
```

</details>

## For community
⬇️  **Please click the 👍 reaction instead of leaving a `+1` or 👍  comment**

Hints from issue discussion:
sorry, some stuff got cut off there in my back and forth.

I recently created a new conda env and got xonsh 0.18.2 py312h2e8e312_0 and got this error.  There was no such error in my previous env (which was also python 3.12 but built some time before)
Hey! I'm not the Windows user but I see there is `case_insensitive_dict` package in pypi. What if you install it? (https://pypi.org/project/case-insensitive-dictionary/)
Thanks @anki-code .  I tried that and then I got the import error (please see the second stack dump in the post for the full stack dump).
```
    from case_insensitive_dict import CaseInsensitiveDict as CacheDict
ImportError: cannot import name 'CaseInsensitiveDict' from 'case_insensitive_dict' (C:\Users\simon\miniconda3\envs\r312\Lib\site-packages\case_insensitive_dict\__init__.py)```
If you install xonsh 0.16.0 is it solves the issue?

```xsh
xpip install git+https://github.com/xonsh/xonsh@0.16.0
# restart xonsh
```

I just see no any installations of `case_insensitive_dict` in the xonsh code. Just [import](https://github.com/search?q=repo%3Axonsh%2Fxonsh%20case_insensitive_dict&type=code). It's interesting how it worked before...
@anki-code yes, I can confirm, going back to 0.16.0 cured the problem and allowed it to run.
It will be cool to catch the difference. PR with fix is welcome!
I will look into it.  All I know atm is that 0.16.0 it ran, and it gave the error in 0.17.0 and 0.18.0.  But I have a starting point for digging in to it.
We can remove this external dependency. 
Really, https://github.com/xonsh/xonsh/blob/31e7c4204ad41368aa0b47c18292f77c823c575b/xonsh/commands_cache.py#L26-L29

We can remove this completely and replace `CacheDict` to `dict` in the code.

@sbillinge if you can prepare the PR it will be cool.
> Really,
> 
> https://github.com/xonsh/xonsh/blob/31e7c4204ad41368aa0b47c18292f77c823c575b/xonsh/commands_cache.py#L26-L29
> 
> We can remove this completely and replace `CacheDict` to `dict` in the code.
> 
> @sbillinge if you can prepare the PR it will be cool.

Yes, I am happy to do that.  I can do it tonight or tomorrow. Meetings today...:(

Commit message: news

Patch to review:
diff --git a/news/remove-caseinsdict.rst b/news/remove-caseinsdict.rst
new file mode 100644
index 0000000000..8d1df06b0a
--- /dev/null
+++ b/news/remove-caseinsdict.rst
@@ -0,0 +1,23 @@
+**Added:**
+
+* <news item>
+
+**Changed:**
+
+* <news item>
+
+**Deprecated:**
+
+* <news item>
+
+**Removed:**
+
+* `case_insensitive_dictionary` dependency
+
+**Fixed:**
+
+* <news item>
+
+**Security:**
+
+* <news item>
diff --git a/pyproject.toml b/pyproject.toml
index fa6e2688be..0359f900ce 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -15,9 +15,7 @@ authors = [{ name = "Anthony Scopatz" }, { email = "scopatz@gmail.com" }]
 maintainers = [{ name = "Xonsh Community" }, { email = "xonsh@gil.forsyth.dev" }]
 license = { text = "BSD 2-Clause License" }
 requires-python = ">=3.9"
-dependencies = [
-    "case-insensitive-dictionary; platform_system=='Windows'",
-]
+dependencies = ["requests; platform_system=='Windows'",]
 
 [tool.setuptools.dynamic]
 version = {attr = "xonsh.__version__"}
diff --git a/xonsh/commands_cache.py b/xonsh/commands_cache.py
index 0e81915840..f3f2df94dd 100644
--- a/xonsh/commands_cache.py
+++ b/xonsh/commands_cache.py
@@ -24,7 +24,7 @@
 )
 
 if ON_WINDOWS:
-    from case_insensitive_dict import CaseInsensitiveDict as CacheDict
+    from requests.structures import CaseInsensitiveDict as CacheDict  # type: ignore
 else:
     CacheDict = dict
 


Code review comments:
diff_hunk: @@ -15,9 +15,7 @@ authors = [{ name = "Anthony Scopatz" }, { email = "scopatz@gmail.com" }]
 maintainers = [{ name = "Xonsh Community" }, { email = "xonsh@gil.forsyth.dev" }]
 license = { text = "BSD 2-Clause License" }
 requires-python = ">=3.9"
-dependencies = [
-    "case-insensitive-dictionary; platform_system=='Windows'",
-]
+dependencies = ["requests; platform_system=='Windows'",]
path: pyproject.toml
text: @user1:
Could you just use the code directly? It would be a single class and the implementation is simple

@author:
Yes, I like that better too.   Get rid of this dependency.....  I will do that and push.  I have to run for a plane.   I will try and push that at the airport.