From 750a99e044afdef489ba2f0f697443ab203752e5 Mon Sep 17 00:00:00 2001 From: Mahe Iram Khan Date: Tue, 19 Aug 2025 13:29:51 +0200 Subject: [PATCH 01/11] add test --- tests/conftest.py | 6 ++++++ tests/test_cli_reset.py | 15 +++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index c8dd9dc..2e9c46a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1 +1,7 @@ from conda.testing.fixtures import conda_cli # noqa + +pytest_plugins = ( + # Add testing fixtures and internal pytest plugins here + "conda.testing", + "conda.testing.fixtures", +) \ No newline at end of file diff --git a/tests/test_cli_reset.py b/tests/test_cli_reset.py index 57fa685..da5f290 100644 --- a/tests/test_cli_reset.py +++ b/tests/test_cli_reset.py @@ -1,6 +1,8 @@ import sys +import subprocess from conda.core.prefix_data import PrefixData +from conda.testing.fixtures import conda_cli, TmpEnvFixture def test_help(conda_cli): @@ -23,3 +25,16 @@ def test_reset(conda_cli, tmp_path): ) assert len(tuple(PrefixData(tmp_prefix).query("numpy"))) == 0 + + +def test_reset_conda_self_present(conda_cli, tmp_env: TmpEnvFixture): + with tmp_env("conda", "conda-self") as prefix: + # platform is "win32" even in win64 machines + if sys.platform=="win32": + python_bin = prefix / "python.exe" + else: + python_bin=prefix / "python" / "bin" + + result=subprocess.run([str(python_bin), "-m", "conda", "self"], capture_output=True) + print(result.stdout) + From 188e7b484c2948e1cf2368a87487ade7ec1ccc29 Mon Sep 17 00:00:00 2001 From: Mahe Iram Khan <65779580+ForgottenProgramme@users.noreply.github.com> Date: Tue, 19 Aug 2025 14:44:13 +0200 Subject: [PATCH 02/11] Update tests/test_cli_reset.py Co-authored-by: jaimergp --- tests/test_cli_reset.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_cli_reset.py b/tests/test_cli_reset.py index da5f290..5ec409a 100644 --- a/tests/test_cli_reset.py +++ b/tests/test_cli_reset.py @@ -2,7 +2,7 @@ import subprocess from conda.core.prefix_data import PrefixData -from conda.testing.fixtures import conda_cli, TmpEnvFixture +from conda.testing.fixtures import TmpEnvFixture def test_help(conda_cli): From 5811c813e7868788d05be113017fadb8b7494906 Mon Sep 17 00:00:00 2001 From: Mahe Iram Khan <65779580+ForgottenProgramme@users.noreply.github.com> Date: Tue, 19 Aug 2025 14:44:19 +0200 Subject: [PATCH 03/11] Update tests/test_cli_reset.py Co-authored-by: jaimergp --- tests/test_cli_reset.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/test_cli_reset.py b/tests/test_cli_reset.py index 5ec409a..4980f56 100644 --- a/tests/test_cli_reset.py +++ b/tests/test_cli_reset.py @@ -35,6 +35,8 @@ def test_reset_conda_self_present(conda_cli, tmp_env: TmpEnvFixture): else: python_bin=prefix / "python" / "bin" - result=subprocess.run([str(python_bin), "-m", "conda", "self"], capture_output=True) - print(result.stdout) + subprocess.run([str(python_bin), "-m", "conda", "self", "reset"], check=True) + result=subprocess.run([str(python_bin), "-m", "conda", "self", "--help"], check=True) + assert PrefixData(prefix).get("conda") # make sure conda-self didn't remove itself + assert PrefixData(prefix).get("conda-self") # make sure conda-self didn't remove itself From 0d2e3288c4ad979125bf92d6e38a71187c326fd1 Mon Sep 17 00:00:00 2001 From: Mahe Iram Khan Date: Tue, 19 Aug 2025 14:49:32 +0200 Subject: [PATCH 04/11] fix indentation error --- tests/test_cli_reset.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/test_cli_reset.py b/tests/test_cli_reset.py index 4980f56..a9c0caa 100644 --- a/tests/test_cli_reset.py +++ b/tests/test_cli_reset.py @@ -34,9 +34,9 @@ def test_reset_conda_self_present(conda_cli, tmp_env: TmpEnvFixture): python_bin = prefix / "python.exe" else: python_bin=prefix / "python" / "bin" - - subprocess.run([str(python_bin), "-m", "conda", "self", "reset"], check=True) - result=subprocess.run([str(python_bin), "-m", "conda", "self", "--help"], check=True) - assert PrefixData(prefix).get("conda") # make sure conda-self didn't remove itself - assert PrefixData(prefix).get("conda-self") # make sure conda-self didn't remove itself + + result=subprocess.run([str(python_bin), "-m", "conda", "self", "reset"], check=True) + + assert PrefixData(prefix).get("conda") # make sure conda-self didn't remove itself + assert PrefixData(prefix).get("conda-self") # make sure conda-self didn't remove itself From 4188da4d53837c9c3082e098c60313306b623662 Mon Sep 17 00:00:00 2001 From: Mahe Iram Khan Date: Tue, 19 Aug 2025 14:50:22 +0200 Subject: [PATCH 05/11] fix comment --- tests/test_cli_reset.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_cli_reset.py b/tests/test_cli_reset.py index a9c0caa..66fa68b 100644 --- a/tests/test_cli_reset.py +++ b/tests/test_cli_reset.py @@ -36,7 +36,7 @@ def test_reset_conda_self_present(conda_cli, tmp_env: TmpEnvFixture): python_bin=prefix / "python" / "bin" result=subprocess.run([str(python_bin), "-m", "conda", "self", "reset"], check=True) - - assert PrefixData(prefix).get("conda") # make sure conda-self didn't remove itself + + assert PrefixData(prefix).get("conda") # make sure conda-self didn't remove conda assert PrefixData(prefix).get("conda-self") # make sure conda-self didn't remove itself From d1984e33e41fe5c4f633967d63b8693c49a5eb36 Mon Sep 17 00:00:00 2001 From: Mahe Iram Khan Date: Tue, 19 Aug 2025 14:54:09 +0200 Subject: [PATCH 06/11] correct the bin/python path --- tests/test_cli_reset.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_cli_reset.py b/tests/test_cli_reset.py index 66fa68b..e4d8964 100644 --- a/tests/test_cli_reset.py +++ b/tests/test_cli_reset.py @@ -33,7 +33,7 @@ def test_reset_conda_self_present(conda_cli, tmp_env: TmpEnvFixture): if sys.platform=="win32": python_bin = prefix / "python.exe" else: - python_bin=prefix / "python" / "bin" + python_bin=prefix / "bin"/"python" result=subprocess.run([str(python_bin), "-m", "conda", "self", "reset"], check=True) From 8426b414a96999bf7c207c195d9ccaea3c0e4587 Mon Sep 17 00:00:00 2001 From: Mahe Iram Khan <65779580+ForgottenProgramme@users.noreply.github.com> Date: Tue, 19 Aug 2025 18:02:19 +0200 Subject: [PATCH 07/11] Update tests/test_cli_reset.py Co-authored-by: jaimergp --- tests/test_cli_reset.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_cli_reset.py b/tests/test_cli_reset.py index e4d8964..ae1d5cb 100644 --- a/tests/test_cli_reset.py +++ b/tests/test_cli_reset.py @@ -37,6 +37,7 @@ def test_reset_conda_self_present(conda_cli, tmp_env: TmpEnvFixture): result=subprocess.run([str(python_bin), "-m", "conda", "self", "reset"], check=True) + PrefixData._cache_.clear() assert PrefixData(prefix).get("conda") # make sure conda-self didn't remove conda assert PrefixData(prefix).get("conda-self") # make sure conda-self didn't remove itself From d2d2df39d5ddc4f3637d079d84ab45ddb1e33856 Mon Sep 17 00:00:00 2001 From: Mahe Iram Khan Date: Wed, 20 Aug 2025 11:21:52 +0200 Subject: [PATCH 08/11] debugging failing test --- conda_self/query.py | 2 ++ conda_self/reset.py | 1 + tests/test_cli_reset.py | 5 +++++ 3 files changed, 8 insertions(+) diff --git a/conda_self/query.py b/conda_self/query.py index 0247820..d71a12c 100644 --- a/conda_self/query.py +++ b/conda_self/query.py @@ -69,8 +69,10 @@ def permanent_dependencies() -> set[str]: prefix_graph = PrefixGraph(installed.iter_records()) packages = [] + print(PERMANENT_PACKAGES) for pkg in PERMANENT_PACKAGES: node = next((rec for rec in prefix_graph.records if rec.name == pkg), None) if node: packages.extend([record.name for record in prefix_graph.all_ancestors(node)]) + print(packages) return set(packages) diff --git a/conda_self/reset.py b/conda_self/reset.py index f6a1716..19cc8e3 100644 --- a/conda_self/reset.py +++ b/conda_self/reset.py @@ -10,6 +10,7 @@ def reset(prefix: str = sys.prefix, uninstallable_packages: set[str] = set()): packages_to_remove = [ pkg for pkg in installed if pkg.name not in uninstallable_packages ] + print("remove", packages_to_remove) stp = PrefixSetup( target_prefix=prefix, diff --git a/tests/test_cli_reset.py b/tests/test_cli_reset.py index e4d8964..33fdbde 100644 --- a/tests/test_cli_reset.py +++ b/tests/test_cli_reset.py @@ -34,9 +34,14 @@ def test_reset_conda_self_present(conda_cli, tmp_env: TmpEnvFixture): python_bin = prefix / "python.exe" else: python_bin=prefix / "bin"/"python" + + print("before",sorted(list((prefix/"conda-meta").glob("*.json")))) result=subprocess.run([str(python_bin), "-m", "conda", "self", "reset"], check=True) + print("after", sorted(list((prefix/"conda-meta").glob("*.json")))) + + assert PrefixData(prefix).get("conda") # make sure conda-self didn't remove conda assert PrefixData(prefix).get("conda-self") # make sure conda-self didn't remove itself From 5b18c163d1189415cc3b7fa5d76254e5437cfb1a Mon Sep 17 00:00:00 2001 From: jaimergp Date: Wed, 20 Aug 2025 11:50:43 +0200 Subject: [PATCH 09/11] fix tests, pre-commit Co-authored-by: Mahe Iram Khan <65779580+ForgottenProgramme@users.noreply.github.com> --- CONTRIBUTING.md | 16 ++++++++-------- conda_self/query.py | 7 ++++--- conda_self/reset.py | 1 - tests/conftest.py | 2 +- tests/test_cli_reset.py | 31 ++++++++++++++++--------------- 5 files changed, 29 insertions(+), 28 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index efcf35a..7796aab 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -3,15 +3,15 @@ ## With `pixi` 1. Make sure `pixi` and `git` are installed. [Instructions for `pixi`](https://pixi.sh/latest/installation/). -2. Clone this repository. +2. Clone this repository. ``` git clone https://github.com/conda-incubator/conda-self ``` -3. Change to that directory. +3. Change to that directory. ``` cd conda-self ``` -4. Run the help message. +4. Run the help message. ``` pixi run conda self --help ``` @@ -25,19 +25,19 @@ pixi run conda create -p .pixi/envs/demo conda pip 2. `conda-spawn` is included in the pixi configuration, which you can use to pseudo-activate the environment: ``` pixi run conda spawn ./.pixi/envs/demo -``` +``` If not, simply activate the environment. ``` conda activate .pixi/envs/demo ``` -3. Install `conda-self` in it. +3. Install `conda-self` in it. ``` pip install -e . ``` 4. Play with `python -m conda self`. 1. `python -m conda self update` 2. `python -m conda self install numpy` - 3. `python -m conda self install conda-rich` + 3. `python -m conda self install conda-rich` 4. `python -m conda self remove conda-rich` ### Included Tasks @@ -52,7 +52,7 @@ pip install -e . ``` git clone https://github.com/conda-incubator/conda-self ``` -2. Change to that directory. +2. Change to that directory. ``` cd conda-self ``` @@ -74,4 +74,4 @@ python -m pip install -e . --no-deps 1. `python -m conda self install numpy` 2. `python -m conda self install conda-rich` 3. `python -m conda self update` - 4. `python -m conda self remove conda-rich` \ No newline at end of file + 4. `python -m conda self remove conda-rich` diff --git a/conda_self/query.py b/conda_self/query.py index d71a12c..9dad7b3 100644 --- a/conda_self/query.py +++ b/conda_self/query.py @@ -69,10 +69,11 @@ def permanent_dependencies() -> set[str]: prefix_graph = PrefixGraph(installed.iter_records()) packages = [] - print(PERMANENT_PACKAGES) for pkg in PERMANENT_PACKAGES: node = next((rec for rec in prefix_graph.records if rec.name == pkg), None) if node: - packages.extend([record.name for record in prefix_graph.all_ancestors(node)]) - print(packages) + packages.append(node.name) + packages.extend( + [record.name for record in prefix_graph.all_ancestors(node)] + ) return set(packages) diff --git a/conda_self/reset.py b/conda_self/reset.py index 19cc8e3..f6a1716 100644 --- a/conda_self/reset.py +++ b/conda_self/reset.py @@ -10,7 +10,6 @@ def reset(prefix: str = sys.prefix, uninstallable_packages: set[str] = set()): packages_to_remove = [ pkg for pkg in installed if pkg.name not in uninstallable_packages ] - print("remove", packages_to_remove) stp = PrefixSetup( target_prefix=prefix, diff --git a/tests/conftest.py b/tests/conftest.py index 2e9c46a..4d69e8f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -4,4 +4,4 @@ # Add testing fixtures and internal pytest plugins here "conda.testing", "conda.testing.fixtures", -) \ No newline at end of file +) diff --git a/tests/test_cli_reset.py b/tests/test_cli_reset.py index 33fdbde..fb0f869 100644 --- a/tests/test_cli_reset.py +++ b/tests/test_cli_reset.py @@ -1,5 +1,5 @@ -import sys import subprocess +import sys from conda.core.prefix_data import PrefixData from conda.testing.fixtures import TmpEnvFixture @@ -27,21 +27,22 @@ def test_reset(conda_cli, tmp_path): assert len(tuple(PrefixData(tmp_prefix).query("numpy"))) == 0 -def test_reset_conda_self_present(conda_cli, tmp_env: TmpEnvFixture): +def test_reset_conda_self_present(tmp_env: TmpEnvFixture): with tmp_env("conda", "conda-self") as prefix: # platform is "win32" even in win64 machines - if sys.platform=="win32": + if sys.platform == "win32": python_bin = prefix / "python.exe" else: - python_bin=prefix / "bin"/"python" - - print("before",sorted(list((prefix/"conda-meta").glob("*.json")))) - - result=subprocess.run([str(python_bin), "-m", "conda", "self", "reset"], check=True) - - print("after", sorted(list((prefix/"conda-meta").glob("*.json")))) - - - assert PrefixData(prefix).get("conda") # make sure conda-self didn't remove conda - assert PrefixData(prefix).get("conda-self") # make sure conda-self didn't remove itself - + python_bin = prefix / "bin" / "python" + + PrefixData._cache_.clear() + # Note: Running python -m conda self incidentally loads 'conda_self' from + # the repo because the working directory happens to contain it. We should + # actually 'pip install .' the repo but in this case we are lucky and don't + # need to. + subprocess.run([str(python_bin), "-m", "conda", "self", "reset"], check=True) + + # make sure conda-self didn't remove conda + assert PrefixData(prefix).get("conda") + # make sure conda-self didn't remove itself + assert PrefixData(prefix).get("conda-self") From d9563c0d6415a39714cbe510e7b792b9758d1210 Mon Sep 17 00:00:00 2001 From: jaimergp Date: Wed, 20 Aug 2025 11:52:08 +0200 Subject: [PATCH 10/11] satisfy linter --- .github/PULL_REQUEST_TEMPLATE/4_pr.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/PULL_REQUEST_TEMPLATE/4_pr.yaml b/.github/PULL_REQUEST_TEMPLATE/4_pr.yaml index efc7bd3..496b8ce 100644 --- a/.github/PULL_REQUEST_TEMPLATE/4_pr.yaml +++ b/.github/PULL_REQUEST_TEMPLATE/4_pr.yaml @@ -5,7 +5,7 @@ through the checklist. --> - [ ] Add a file to the `news` directory ([using the template]([[ repo.html_url ]]/blob/main/news/TEMPLATE)) for the next release's release notes? -