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: | diff --git a/menuinst/_legacy/cwp.py b/menuinst/_legacy/cwp.py index c2d0a643..df8086b3 100644 --- a/menuinst/_legacy/cwp.py +++ b/menuinst/_legacy/cwp.py @@ -7,41 +7,48 @@ import sys from os.path import join, pathsep -from menuinst._legacy.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)) +# this must be an absolute import since the cwp.py script is copied to $PREFIX +from menuinst.knownfolders import FOLDERID, get_folder_path + + +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() 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__': 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 + +* diff --git a/tests/test_backwards_compatibility.py b/tests/test_backwards_compatibility.py index 20bb4d77..c18938c1 100644 --- a/tests/test_backwards_compatibility.py +++ b/tests/test_backwards_compatibility.py @@ -5,8 +5,13 @@ @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.""" + 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 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