From fdb62d9542e1ed4bdd115494133b7e3da7964cf4 Mon Sep 17 00:00:00 2001 From: Ken Odegard Date: Fri, 8 Dec 2023 17:20:19 -0600 Subject: [PATCH 1/7] More tests --- tests/test_backwards_compatibility.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/tests/test_backwards_compatibility.py b/tests/test_backwards_compatibility.py index 20bb4d77..1c126a3f 100644 --- a/tests/test_backwards_compatibility.py +++ b/tests/test_backwards_compatibility.py @@ -5,8 +5,16 @@ @pytest.mark.skipif(os.name != "nt", reason="Windows only") def test_import_paths(): - "These import paths are/were used by conda <=23.7.2. Ensure they still work." - from menuinst import install # noqa - from menuinst.knownfolders import FOLDERID, get_folder_path # noqa - from menuinst.win32 import dirs_src # noqa - from menuinst.winshortcut import create_shortcut # noqa + """Imports used by conda <=23.7.2. Ensure they still work.""" + # ensure apipkg generated submodules work + from menuinst import install # noqa: F401 + from menuinst.knownfolders import FOLDERID, get_folder_path # noqa: F401 + from menuinst.win32 import dirs_src # noqa: F401 + from menuinst.winshortcut import create_shortcut # noqa: F401 + from menuinst.win_elevate import runAsAdmin, isUserAdmin # noqa: F401 + + # ensure legacy submodules work + import menuinst._legacy.cwd # noqa: F401 + import menuinst._legacy.main # noqa: F401 + import menuinst._legacy.utils # noqa: F401 + import menuinst._legacy.win32 # noqa: F401 From c5188ad7f947cf13444fad06bce3d0a49d772212 Mon Sep 17 00:00:00 2001 From: Ken Odegard Date: Fri, 8 Dec 2023 17:25:17 -0600 Subject: [PATCH 2/7] Remove conda#11882 patch --- .github/workflows/tests.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 922de82a..144917c6 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -59,11 +59,6 @@ jobs: --file tests/requirements.txt \ python=${{ matrix.python-version }} - - name: Patch conda with PR#11882 (TEMPORARY) - shell: bash -el {0} - run: | - pip install -U --no-deps https://github.com/conda/conda/archive/cep-menuinst.tar.gz - - shell: bash -el {0} name: Conda info run: | From 417b1d40f6ea692699b58a92bc72b26938b570ae Mon Sep 17 00:00:00 2001 From: Ken Odegard Date: Fri, 8 Dec 2023 17:26:14 -0600 Subject: [PATCH 3/7] Update test_backwards_compatibility.py --- tests/test_backwards_compatibility.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/tests/test_backwards_compatibility.py b/tests/test_backwards_compatibility.py index 1c126a3f..ada0cb8a 100644 --- a/tests/test_backwards_compatibility.py +++ b/tests/test_backwards_compatibility.py @@ -6,15 +6,12 @@ @pytest.mark.skipif(os.name != "nt", reason="Windows only") def test_import_paths(): """Imports used by conda <=23.7.2. Ensure they still work.""" - # ensure apipkg generated submodules work - from menuinst import install # noqa: F401 - from menuinst.knownfolders import FOLDERID, get_folder_path # noqa: F401 - from menuinst.win32 import dirs_src # noqa: F401 - from menuinst.winshortcut import create_shortcut # noqa: F401 - from menuinst.win_elevate import runAsAdmin, isUserAdmin # noqa: F401 - - # ensure legacy submodules work import menuinst._legacy.cwd # noqa: F401 import menuinst._legacy.main # noqa: F401 import menuinst._legacy.utils # noqa: F401 import menuinst._legacy.win32 # noqa: F401 + from menuinst import install # noqa: F401 + from menuinst.knownfolders import FOLDERID, get_folder_path # noqa: F401 + from menuinst.win32 import dirs_src # noqa: F401 + from menuinst.win_elevate import isUserAdmin, runAsAdmin # noqa: F401 + from menuinst.winshortcut import create_shortcut # noqa: F401 From 34edd8bf9dd6f444970b83984ffa54d5d26be546 Mon Sep 17 00:00:00 2001 From: Ken Odegard Date: Fri, 8 Dec 2023 17:32:48 -0600 Subject: [PATCH 4/7] cwd -> cwp --- tests/test_backwards_compatibility.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_backwards_compatibility.py b/tests/test_backwards_compatibility.py index ada0cb8a..c18938c1 100644 --- a/tests/test_backwards_compatibility.py +++ b/tests/test_backwards_compatibility.py @@ -6,7 +6,7 @@ @pytest.mark.skipif(os.name != "nt", reason="Windows only") def test_import_paths(): """Imports used by conda <=23.7.2. Ensure they still work.""" - import menuinst._legacy.cwd # noqa: F401 + import menuinst._legacy.cwp # noqa: F401 import menuinst._legacy.main # noqa: F401 import menuinst._legacy.utils # noqa: F401 import menuinst._legacy.win32 # noqa: F401 From 95bd9d2a34f396b44bae4d0c7fd2fd9bc529ec01 Mon Sep 17 00:00:00 2001 From: Ken Odegard Date: Fri, 8 Dec 2023 17:48:06 -0600 Subject: [PATCH 5/7] Fix imports --- menuinst/_legacy/cwp.py | 3 ++- menuinst/_legacy/main.py | 7 +++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/menuinst/_legacy/cwp.py b/menuinst/_legacy/cwp.py index c2d0a643..00f3a91a 100644 --- a/menuinst/_legacy/cwp.py +++ b/menuinst/_legacy/cwp.py @@ -7,7 +7,8 @@ import sys from os.path import join, pathsep -from menuinst._legacy.knownfolders import FOLDERID, get_folder_path +# this must be an absolute import since the cwp.py script is copied to $PREFIX +from menuinst.knownfolders import FOLDERID, get_folder_path # call as: python cwp.py [--no-console] PREFIX ARGs... parser = argparse.ArgumentParser() diff --git a/menuinst/_legacy/main.py b/menuinst/_legacy/main.py index 78e8f38e..6c62f2aa 100644 --- a/menuinst/_legacy/main.py +++ b/menuinst/_legacy/main.py @@ -1,8 +1,7 @@ import sys from os.path import join -import menuinst._legacy as menuinst - +from .. import __version__, install from ..utils import DEFAULT_PREFIX @@ -20,11 +19,11 @@ def main(): opts, args = p.parse_args() if opts.version: - sys.stdout.write("menuinst: %s\n" % menuinst.__version__) + sys.stdout.write("menuinst: %s\n" % __version__) return for arg in args: - menuinst.install(join(opts.prefix, arg), opts.remove, opts.prefix) + install(join(opts.prefix, arg), opts.remove, opts.prefix) if __name__ == '__main__': From 1ee31935f2e4bf83f6654572ba947626d8ba67f6 Mon Sep 17 00:00:00 2001 From: Ken Odegard Date: Fri, 8 Dec 2023 17:56:37 -0600 Subject: [PATCH 6/7] Update cwp.py --- menuinst/_legacy/cwp.py | 78 ++++++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 36 deletions(-) diff --git a/menuinst/_legacy/cwp.py b/menuinst/_legacy/cwp.py index 00f3a91a..df8086b3 100644 --- a/menuinst/_legacy/cwp.py +++ b/menuinst/_legacy/cwp.py @@ -10,39 +10,45 @@ # this must be an absolute import since the cwp.py script is copied to $PREFIX from menuinst.knownfolders import FOLDERID, get_folder_path -# call as: python cwp.py [--no-console] PREFIX ARGs... -parser = argparse.ArgumentParser() -parser.add_argument( - "--no-console", action="store_true", help="Create subprocess with CREATE_NO_WINDOW flag." -) -parser.add_argument("prefix", help="Prefix to be 'activated' before calling `args`.") -parser.add_argument("args", nargs="*", help="Command (and arguments) to be executed.") -parsed_args = parser.parse_args() - -no_console = parsed_args.no_console -prefix = parsed_args.prefix -args = parsed_args.args - -new_paths = pathsep.join( - [ - prefix, - join(prefix, "Library", "mingw-w64", "bin"), - join(prefix, "Library", "usr", "bin"), - join(prefix, "Library", "bin"), - join(prefix, "Scripts"), - ] -) -env = os.environ.copy() -env["PATH"] = new_paths + pathsep + env["PATH"] -env["CONDA_PREFIX"] = prefix - -documents_folder, exception = get_folder_path(FOLDERID.Documents) -if exception: - documents_folder, exception = get_folder_path(FOLDERID.PublicDocuments) -if not exception: - os.chdir(documents_folder) - -creationflags = {} -if no_console: - creationflags["creationflags"] = getattr(subprocess, "CREATE_NO_WINDOW", 0x08000000) -sys.exit(subprocess.call(args, env=env, **creationflags)) + +def main(): + # call as: python cwp.py [--no-console] PREFIX ARGs... + parser = argparse.ArgumentParser() + parser.add_argument( + "--no-console", action="store_true", help="Create subprocess with CREATE_NO_WINDOW flag." + ) + parser.add_argument("prefix", help="Prefix to be 'activated' before calling `args`.") + parser.add_argument("args", nargs="*", help="Command (and arguments) to be executed.") + parsed_args = parser.parse_args() + + no_console = parsed_args.no_console + prefix = parsed_args.prefix + args = parsed_args.args + + new_paths = pathsep.join( + [ + prefix, + join(prefix, "Library", "mingw-w64", "bin"), + join(prefix, "Library", "usr", "bin"), + join(prefix, "Library", "bin"), + join(prefix, "Scripts"), + ] + ) + env = os.environ.copy() + env["PATH"] = new_paths + pathsep + env["PATH"] + env["CONDA_PREFIX"] = prefix + + documents_folder, exception = get_folder_path(FOLDERID.Documents) + if exception: + documents_folder, exception = get_folder_path(FOLDERID.PublicDocuments) + if not exception: + os.chdir(documents_folder) + + creationflags = {} + if no_console: + creationflags["creationflags"] = getattr(subprocess, "CREATE_NO_WINDOW", 0x08000000) + sys.exit(subprocess.call(args, env=env, **creationflags)) + + +if __name__ == "__main__": + main() From 878d5af8070189c721e11c778691c3126b1978a8 Mon Sep 17 00:00:00 2001 From: Ken Odegard Date: Fri, 8 Dec 2023 18:06:27 -0600 Subject: [PATCH 7/7] Create 168-fix-legacy-cwp --- news/168-fix-legacy-cwp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 news/168-fix-legacy-cwp diff --git a/news/168-fix-legacy-cwp b/news/168-fix-legacy-cwp new file mode 100644 index 00000000..32972ddb --- /dev/null +++ b/news/168-fix-legacy-cwp @@ -0,0 +1,19 @@ +### Enhancements + +* + +### Bug fixes + +* Fix invalid import in `menuinst v1`'s legacy `cwp.py`. (#168) + +### Deprecations + +* + +### Docs + +* + +### Other + +*