Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix menuinst._legacy.cwp #168

Merged
merged 7 commits into from
Dec 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
83 changes: 45 additions & 38 deletions menuinst/_legacy/cwp.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,48 @@
import sys
from os.path import join, pathsep

from menuinst._legacy.knownfolders import FOLDERID, get_folder_path
Copy link
Contributor

@jaimergp jaimergp Dec 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the record, this was the bad import.


# 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))
jaimergp marked this conversation as resolved.
Show resolved Hide resolved


if __name__ == "__main__":
main()
7 changes: 3 additions & 4 deletions menuinst/_legacy/main.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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__':
Expand Down
19 changes: 19 additions & 0 deletions news/168-fix-legacy-cwp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### Enhancements

* <news item>

### Bug fixes

* Fix invalid import in `menuinst v1`'s legacy `cwp.py`. (#168)

### Deprecations

* <news item>

### Docs

* <news item>

### Other

* <news item>
15 changes: 10 additions & 5 deletions tests/test_backwards_compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading