Giter Club home page Giter Club logo

menuinst's Introduction

menuinst: cross platform menu item installation

This package provides cross platform menu item installation for conda packages.

If a conda package ships a menuinst JSON document under $PREFIX/Menu, conda will invoke menuinst to process the JSON file and install the menu items in your operating system. The menu items are removed when the package is uninstalled.

The following formats are supported:

  • Windows: .lnk files in the Start menu. Optionally, also in the Desktop and Quick Launch.
  • macOS: .app bundles in the Applications folder.
  • Linux: .desktop files as defined in the XDG standard.

Documentation

Documentation is available at https://conda.github.io/menuinst/.

History

This package was originally developed and maintained by Enthought under the name AppInst. The name appinst is a rename of what used to be called 'wininst'.

menuinst v1 was only supported on Windows. Legacy code existed in v1 for Linux and OS X - use at your own risk. It may mess up your menus.

menuinst v2 is a backwards-compatible rewrite to address cross-platform compatibility under a unified JSON schema, as discussed in CEP-11. The Windows bits of the v1 code are still available under the menuinst._legacy subpackage.

Build status

Build status Docs status codecov pre-commit.ci status Anaconda-Server Badge
conda install defaults::menuinst Anaconda-Server Badge
conda install conda-forge::menuinst Anaconda-Server Badge
conda install conda-canary/label/dev::menuinst Anaconda-Server Badge

menuinst's People

Contributors

aganders3 avatar asmeurer avatar chenghlee avatar cjmartian avatar conda-bot avatar dbast avatar dependabot[bot] avatar ericpre avatar ilanschnell avatar isuruf avatar jaimergp avatar jezdez avatar jtignor-raltron avatar kalefranz avatar katietz avatar kenodegard avatar lidavidm avatar marcoesters avatar mchilvers avatar mingwandroid avatar msarahan avatar mwiebe avatar nehaljwani avatar pankajp avatar prabhuramachandran avatar pre-commit-ci[bot] avatar scw avatar tpn avatar zklaus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

menuinst's Issues

MENU_ITEM_LOCATION is incorrect for all-user installation on macOS

Checklist

  • I added a descriptive title
  • I searched open reports and couldn't find a duplicate

What happened?

@jaimergp, when selecting "Install on a specific disk..." from a package installer created by constructor (to install for all users) on macOS, the environments are created in the correct place but the application bundle is created in ~/Applications instead of /Applications.

Conda Info

No response

Conda Config

No response

Conda list

No response

Additional Context

No response

passing arguments to pyscript windows

What is the correct way of passing arguments to a python script in menu.json?

I am trying to create a shortcut for a JupyterLab project that launch JupyterLab in a specific directory.

I tried this format which does not work

{
    "menu_name": "Anaconda3 (64-bit)",
    "menu_items":
        [
            {
                "pyscript": "${PYTHON_SCRIPTS}/jupyter-lab-script.py",
                "scriptarguments": ["path/to/directory"],
                "name": "Jupyter Lab",
                "desktop": true,
                "quicklaunch": true
            }
        ]
}

But this format works

{
    "menu_name": "Anaconda3 (64-bit)",
    "menu_items":
        [
            {
                "script": "${PREFIX}/python.exe",
                "scriptarguments":
                    [
                        "${PYTHON_SCRIPTS}/jupyter-lab-script.py",
                        "/path/to/directory"
                    ],
                "name": "Jupyter Lab",
                "desktop": true,
                "quicklaunch": true
            }
        ]
}

It taken me a while to figure this out. A more clearer documentation could have resolved this.

Latest release not 1.4.10

Was just noticing that 1.4.9 and 1.4.10 have been published, but 1.4.8 is still marked as the latest release. Are 1.4.9 and 1.4.10 official releases? Should 1.4.10 be marked as the latest release?

Windows: shortcut target is far too long

Consider the following situation:

  • Windows10 64bit
  • Miniconda3-Installation at C:\Program Files\Python\miniconda3
  • New Environment (e.g. py35) at default location: C:\Program Files\Python\miniconda3\envs\py35
  • Install some package that creates a shortcut (e.g. IPython)

The target-command for the IPython-shortcut is now (for my locale):

C:\Programme\Python\Miniconda3\envs\py35\python.exe
C:\Programme\Python\Miniconda3\cwp.py
C:\Programme\Python\Miniconda3\envs\py35
"C:/Programme/Python/Miniconda3/envs/py35/python.exe"
"C:/Programme/Python/Miniconda3/envs/py35/Scripts/ipython-script.py"

That is a total of 254 characters!!

If only one part of that path gets any longer, the command will be cut off at 260 characters (I have no idea why that is the maximum, but it is).

C:\Programme\Python\Miniconda3\envs\some_very_long_environment_name\python.exe
C:\Programme\Python\Miniconda3\cwp.py
C:\Programme\Python\Miniconda3\envs\some_very_long_environment_name
"C:/Programme/Python/Miniconda3/envs/some_very_long_environment_name/pytho

Installation as a user does not help either, as the base path is even longer:

C:\Users\USERNAME\AppData\Local\Miniconda3

I'm not sure what should be done here, but repeating the base path 5! times is definitely suboptimal.

New release 1.4.5 caused Anaconda shortcut not working.

After upgrade to menuinst 1.4.5, all shortcuts of anaconda(Anaconda Navigator, IPython,...etc) cannot work, I guess it caused by new win32.py but I cannot figure out which parts of it.

After downgrading it to 1.4.4, all shortcuts can work normally.

Below is my conda information.

Current conda install:

           platform : win-64
      conda version : 4.3.18
   conda is private : False
  conda-env version : 4.3.18
conda-build version : 2.1.13
     python version : 3.6.1.final.0
   requests version : 2.14.2
   root environment : D:\Apps\x64\Continuum\Miniconda3  (writable)
default environment : D:\Apps\x64\Continuum\Miniconda3
   envs directories : D:\Apps\x64\Continuum\Miniconda3\envs
                      C:\Users\jti\AppData\Local\conda\conda\envs
                      C:\Users\jti\.conda\envs
      package cache : D:\Apps\x64\Continuum\Miniconda3\pkgs
                      C:\Users\xxx\AppData\Local\conda\conda\pkgs
       channel URLs : https://conda.anaconda.org/anaconda-fusion/win-64
                      https://conda.anaconda.org/anaconda-fusion/noarch
                      https://repo.continuum.io/pkgs/free/win-64
                      https://repo.continuum.io/pkgs/free/noarch
                      https://repo.continuum.io/pkgs/r/win-64
                      https://repo.continuum.io/pkgs/r/noarch
                      https://repo.continuum.io/pkgs/pro/win-64
                      https://repo.continuum.io/pkgs/pro/noarch
                      https://repo.continuum.io/pkgs/msys2/win-64
                      https://repo.continuum.io/pkgs/msys2/noarch
                      https://conda.anaconda.org/intel/win-64
                      https://conda.anaconda.org/intel/noarch
        config file : C:\Users\xxx\.condarc
       offline mode : False
         user-agent : conda/4.3.18 requests/2.14.2 CPython/3.6.1 Windows/10 Windows/10.0.15063
      administrator : unknown

Linux shortcuts cannot be pinned to Dash

@jaimergp,
When creating an installer for Spyder with the latest napari/label/bundle_tools_2 for Linux, the resulting shortcut cannot be pinned to the Dash. By changing the shortcut file name from spyder_spyder.desktop to spyder.desktop, the shortcut can then be pinned to the Dash. I suspect that this issue may be related to a mismatch between the shortcut name and the script name. ๐Ÿคท๐Ÿผโ€โ™‚๏ธ

The name of the shortcut file is set here:

fn = menu.name_ + shortcut['id']

Is there a reason for using self.name_ + shortcut['id'] instead of self.name?

Error while installing jupyter notebook in anaconda

From @npatwa on October 12, 2016 14:10

An unexpected error has occurred, please consider sending the
following traceback to the conda GitHub issue tracker at:

https://github.com/conda/conda/issues

Include the output of the command 'conda info' in your report.

Traceback (most recent call last):
File "C:\Anaconda3\lib\site-packages\conda\cli\main.py", line 208, in args_func
File "C:\Anaconda3\lib\site-packages\conda\cli\common.py", line 612, in inner
File "C:\Anaconda3\lib\site-packages\conda\cli\main_install.py", line 46, in execute
File "C:\Anaconda3\lib\site-packages\conda\cli\install.py", line 413, in install
File "C:\Anaconda3\lib\site-packages\conda\plan.py", line 527, in execute_actions
File "C:\Anaconda3\lib\site-packages\conda\instructions.py", line 148, in execute_instructions
File "C:\Anaconda3\lib\site-packages\conda\instructions.py", line 95, in UNLINK_CMD
File "C:\Anaconda3\lib\site-packages\conda\install.py", line 674, in unlink
File "C:\Anaconda3\lib\site-packages\conda\install.py", line 311, in mk_menus
File "C:\Anaconda3\lib\site-packages\menuinst__init__.py", line 23, in
from .win32 import Menu, ShortCut, dirs
File "C:\Anaconda3\lib\site-packages\menuinst\win32.py", line 13, in
from .knownfolders import get_folder_path, FOLDERID
File "C:\Anaconda3\lib\site-packages\menuinst\knownfolders.py", line 152, in
SHGetKnownFolderPath = windll.shell32.SHGetKnownFolderPath # [5] [3]
File "C:\Anaconda3\lib\ctypes__init
_.py", line 364, in getattr
func = self.getitem(name)
File "C:\Anaconda3\lib\ctypes__init__.py", line 369, in getitem
func = self._FuncPtr((name_or_ordinal, self))
AttributeError: function 'SHGetKnownFolderPath' not found

Copied from original issue: conda/conda#3609

Incompatible cwp.py and menuinst package

Start menu shortcuts pull in multiple components to open a Python application, for example:

C:\path\to\venv\pythonw.exe \                # the Python executable from the VIRTUAL env
"C:\Program Files\Anaconda3\cwp.py" \        # the cwp script from the ROOT env
C:\path\to\venv \                            # the VIRTUAL env directory
"C:/path/to/venv/pythonw.exe" \              # the Python executable from the VIRTUAL env
"C:/path/to/venv/Scripts/spyder-script.py"   # the application script from the VIRTUAL env

As you can easily see, the call of the cwp.py script is done through the interpreter from the virtual environment. What happened on my computers is that the menuinst package (which currently has to be installed in the root env) was not compatible to the cwp.py script which made the whole shortcut fail silently.

Shouldn't the first part call the Python interpreter from the virtual root environment instead of the interpreter from the root virtual environment? Then, the menuinst package from the root environment would be used.

INFO messages are output even when Conda commands are run with `--json` or `--quiet`

Set up

  1. Install Conda package that includes menuinst menu shortcuts, e.g.:

    conda install '"microdrop-launcher"' -q --json -y
    

Expected behaviour

  • JSON output describing changes to Conda state (e.g., LINK, UNLINK, etc.)

Observed behaviour

JSON output is preceded by menuinst INFO log messages, like:

INFO menuinst_win32:__init__(182): Menu: name: 'MicroDrop', prefix: 'C:\Users\chris\Miniconda2\envs\dropbot.py', env_name: 'dropbot.py', mode: 'None', used_mode: 'user'

See also

See this forum discussion also discussing this issue.

Anaconda won't instal notebook app form Launcher in XP

From @kturkalj on August 18, 2016 6:21

Anaconda3-2.2.0-Windows-x86.exe won't install notebook app on Windows XP from Launcher:
Traceback (most recent call last):
File "C:\Anaconda3\lib\site-packages\conda\cli\main.py", line 207, in args_func
File "C:\Anaconda3\lib\site-packages\conda\cli\main_install.py", line 46, in execute
File "C:\Anaconda3\lib\site-packages\conda\cli\install.py", line 420, in install
File "C:\Anaconda3\lib\site-packages\conda\plan.py", line 502, in execute_actions
File "C:\Anaconda3\lib\site-packages\conda\instructions.py", line 140, in execute_instructions
File "C:\Anaconda3\lib\site-packages\conda\instructions.py", line 88, in UNLINK_CMD
File "C:\Anaconda3\lib\site-packages\conda\install.py", line 601, in unlink
File "C:\Anaconda3\lib\site-packages\conda\install.py", line 304, in mk_menus
File "C:\Anaconda3\lib\site-packages\menuinst__init__.py", line 23, in
from .win32 import Menu, ShortCut, dirs
File "C:\Anaconda3\lib\site-packages\menuinst\win32.py", line 13, in
from .knownfolders import get_folder_path, FOLDERID
File "C:\Anaconda3\lib\site-packages\menuinst\knownfolders.py", line 152, in
SHGetKnownFolderPath = windll.shell32.SHGetKnownFolderPath # [5] [3]
File "C:\Anaconda3\lib\ctypes__init
_.py", line 364, in getattr
func = self.getitem(name)
File "C:\Anaconda3\lib\ctypes__init__.py", line 369, in getitem
func = self._FuncPtr((name_or_ordinal, self))
AttributeError: function 'SHGetKnownFolderPath' not found

How can it be done form cmd prompt?
Thnx

Copied from original issue: conda/conda#3313

Allow suppressing cmd.exe windows on launching applications

Checklist

  • I added a descriptive title
  • I searched open requests and couldn't find a duplicate

What is the idea?

When launching applications from shortcuts created by menuinst on Windows, a cmd.exe window opens. A key should be provided in the menu.json file to specify whether the shortcut should suppress this behavior and menuinst should take the necessary steps to enforce this when creating the shortcut.

Why is this needed?

Unwanted cmd.exe windows are not suppressed.

What should happen?

cmd.exe windows should be suppressed or not according to specification in the menu.json file.

Additional Context

No response

When I create a virtual environment in Conda, why does it not create corresponding shortcuts for Conda, Jupyter, Spyder, etc?

Previously when I installed Anaconda, when I created a virtual environment, corresponding shortcuts for Conda, Jupyter, and Spyder were automatically created for the new virtual environment.

Now, after installing the latest version of Anaconda on a new machine, it does not automatically create shortcuts for the new virtual environment. How do I get Conda to automatically do this?

API/CLI discussion

I had this in the CEP proposal but I removed it for simplicity since it doesn't really matter for the JSON metadata. It can be added in a separate one (e.g. for the plugin hook request). Note some of the details below are no longer current, but I am copying it here verbatim.


Python API

Current state

menuinst 1.x provides a Python API comprised of a single function menuinst.install(...) with the following signature:

def install(path, remove=False, prefix=sys.prefix, recursing=False, root_prefix=sys.prefix):
  ...

Note that calling menuinst.install for platforms other than Windows currently fails due to the extra root_prefix argument added for conda-standalone compatibility.

Other projects provide a layer on top of menuinst.install:

  • constructor/nsis/_nsis.py introduces mk_menus and rm_menus, which iterate PREFIX/Menu looking for suitable JSON files. These functions only exist to offer support for constructor's menu_packages option. Adding a --shortcuts-only filter CLI flag to conda would make this unnecessary.
def mk_menus(remove=False, prefix=None, pkg_names=None, root_prefix=None):
    ...

def rm_menus(prefix=None, root_prefix=None):
    ...
  • conda provides make_menu, which actively excludes Linux / MacOS.
def make_menu(prefix, file_path, remove=False):
    ...

Motivation

The official API is confusing (install can also remove) and leaves opportunity for downstream to create their own logic for basic functionality. menuinst should be the sole provider here.

Suggested actions

menuinst needs to provide two functions: install and remove.

def install(metadata: [str, dict], target_prefix: str = sys.prefix, root_prefix: str = sys.prefix) -> List[str]:
  ...

def remove(metadata: [str, dict], target_prefix: str = sys.prefix, root_prefix: str = sys.prefix) -> List[str]:
  ...

metadata can be either a path to a JSON file, a file handler or an already parsed object. Regardless the source, the resulting metadata object needs to satisfy the metadata schema. Both functions return a list of strings that point to the path of the menu items created or removed.

Additionally, an utility function for prefixes could provide:

def install_all(prefix: str, root_prefix: str = sys.prefix, filter: callable = None) -> List[List[str]]:
  ...

def remove_all(prefix: str, root_prefix: str = sys.prefix, filter: callable = None) -> List[List[str]]:
  ...

It should be discussed whether:

  • root_prefix is only used internally by conda-standalone / constructor and hence should be made a private name _root_prefix.
  • recursing is needed on Windows or not.
  • A list (of lists) of strings is the best way to return the created shortcuts. Some platforms create a directory with shortcuts (Windows), some create several directories (MacOS), some create a list of files in a given location (Linux).

Backwards compatibility

New conda releases will pin accordingly. Releasing this API would entail a new major version, which should be enough to prevent breakages. Current version 4.12 is pinning menuinst as >=1.4.11,<2.

CLI API

Current state

menuinst 1.x does provide a CLI through menuinst.main:

$> menuinst [--remove] [--prefix=sys.prefix] [json_file json_file ...]

However, constructor needs a way to call it from conda-standalone, which prompted this project to provide a custom entry point that mimics a conda sub-command:

$> conda-standalone constructor [--prefix] [--make-menus|--rm-menus] ...

This is needed because, even with menuinst own CLI, conda-standalone is a pyinstaller-frozen executable which cannot call arbitrary entry points in the bundle.

Motivation

A standard menuinst CLI (standalone or through conda) is needed and must not be provided as part of the conda-standalone project only. It is a surprising behaviour that needs to be replicated by other implementations and, as such, should be part of the main codebase.

constructor allows a different standalone conda executable to be bundled through the --conda-exe option, which opens the possibility of using micromamba as the bundled conda. The constructor sub-command is expected though, so micromamba needs to provide it as well.

Suggested actions

Provide a conda constructor subcommand, officially part of the conda core. It should implement the same CLI as currently found in the constructor entry point, delegating the menu creation and removal to the menuinst public API. This CLI should be standardized so other projects can implement it if needed.

menuinst itself does not need to provide a CLI, but if it does, it should be as similar as possible to the constructor counterparts.

Alternatively, add support in conda-standalone for conda run, so one can call arbitrary code within the frozen binary. This would allow us to place scripts and executables inside conda-standalone without having to patch the entry point:

$> conda-standalone run python -m menuinst ...
$> conda-standalone run python -m constructor_helper ...

Unfortunately, this is difficult to replicate in non-Python implementations.

Handle URL protocols

Checklist

  • I added a descriptive title
  • I searched open requests and couldn't find a duplicate

What is the idea?

Associate a given URL/URI protocol with an application via its shortcut. This is different in each platform:

  • Linux supports it as part of the .desktop metadata. The URL is passed via argv.
    • Tests needed: #119
  • Windows requires registry keys. The URL is passed via argv.
  • macOS requires:
    • some keys in the .app .plist file
    • an event listener in the program being launched.

Notes for macOS

The URL is not passed via argv. Instead an event is emitted, containing the URL. In macOS, we have a C launcher because macOS expects a single identifiable binary inside the .app directory. This cannot be a shell script, because those are executed with a shell outside the app. The C launcher forks and spawns the command (whose main executable should be symlinked inside the app too). This way, macOS ties everything nicely, including the event loop, plus keyboard shortcut menus and more. Without it, the app does launch but it's not as well integrated in the system. Check this thread for more info.

We would need to teach the C launcher to listen to those events, but the Apple APIs are mostly available in Swift and Objective C, so we need to create something. After some research we have found some resources:

@aganders3 has been experimenting with other setups too so we might need change how all this works. More info in #117.

Why is this needed?

Applications often need to be associated with file types and URL protocols to handle special links being clicked on a website (e.g. app store stuff, authentication workflows...).

What should happen?

The associated app should launch with the URL being passed through standard means.

Additional Context

Note, this only covers launching an app with a given URL. If you want an open app to recognize URLs or files being passed, you might need a running service that dispatches to a listener or something, and this is not in the scope of menuinst. We might probably create a general solution for that though? Or maybe something exists.

ImportError: No module named 'menuinst.winshortcut'

Similar as Issue #16.

I was trying to conda install a module that only has py36 support so conda had to also downgrade Python from 3.7 to 3.6 in the same batch.

Upon attempting I got the exact same error as described by #16.

It was on a clean Miniconda3-latest-Windows-x86_64 install on Windows 10.

I solved it by downgrading conda install conda python=3.6 first then continuing to install stuff.

conda uncontrollably spawning python processes when creating/removing envs

From @cwreid18 on March 2, 2017 16:48

On Windows 7, with Anaconda installed for all users in C:\Anaconda3. No problem creating and removing envs with admin rights. However, when running as user without admin rights, I get the following problem when creating environments: packages are downloaded ok, but then it hangs (usually at the linking or unlinking packages step) and I can see pythonw.exe processes being launched in task manager at a rate of several per second. Only way to stop this is to shut down the machine. The problem is intermittent and seems to occur more frequently when creating envs with all the anaconda packages (e.g. conda create -n test anaconda=4.1.1) rather than environments that only contain a few packages. Happens occasionally when trying to remove envs. I have tried reinstalling with multiple versions of anaconda (inc. the latest, 4.3.0) but the problem keeps occurring.

Copied from original issue: conda/conda#4782

PermissionsError when accessing some directories with os module

This issue was fixed already, but I am adding a reference here for provenance and better tracking in the future.
See napari/packaging#38 (comment) for full discussion and resolution


๐Ÿ› Bug

A PermissionError is raised when using os.scandir with the conda-based application bundle.
I've noticed the same issue with Spyder as well with conda-based application bundle.

This issue only manifests with the three user directories ~/Desktop, ~/Documents, and ~/Downloads (and anything therein). No other directories on the system produce the error.

Interestingly, this issue does not manifest when launching the application executable directly.

$ ~/Applications/napari\ \(0.4.16rc7\).app/Contents/MacOS/napari_\(0.4.16rc7\)

I've observed identical behavior on two separate machines:

  • iMac with arm64 running 12.5.1
  • Macbook Pro with x86_64 running 12.5.1

To Reproduce

Steps to reproduce the behavior:

  1. Launch condo-based napari application bundle napari (0.4.16rc7).app from Finder
  2. View the iPython console
  3. Attempt os.scandir for any of the three user directories ~/Desktop, ~/Documents, or ~/Downloads
  4. Observe the error
In [1]: import os

In [2]: os.scandir('/Users/ryan/')
Out[2]: <posix.ScandirIterator at 0x179e18960>

In [3]: os.scandir('/Users/ryan/Documents/')
---------------------------------------------------------------------------
PermissionError                           Traceback (most recent call last)
Input In [3], in <cell line: 1>()
----> 1 os.scandir('/Users/ryan/Documents/')

PermissionError: [Errno 1] Operation not permitted: '/Users/ryan/Documents/'
/Users/ryan/Library/napari-0.4.16rc7/envs/napari-0.4.16rc7/lib/python3.9/site-packages/ipykernel/kernelbase.py:751: RuntimeWarning: coroutine 'InProcessKernel._abort_queues' was never awaited!

Environment

napari: 0.4.16rc7
Platform: macOS-12.5.1-x86_64-i386-64bit
System: MacOS 12.5.1
Python: 3.9.13 | packaged by conda-forge | (main, May 27 2022, 17:00:52) [Clang 13.0.1 ]
Qt: 5.15.3
PySide2: 5.15.4
NumPy: 1.22.4
SciPy: 1.8.1
Dask: 2022.05.2
VisPy: 0.9.6

OpenGL:

  • GL version: 2.1 Metal - 76.3
  • MAX_TEXTURE_SIZE: 16384

Screens:

  • screen 1: resolution 2240x1260, scale 2.0

Plugins:

  • console: 0.0.4
  • napari-svg: 0.1.6
  • scikit-image: 0.4.16rc7

windows.knownfolders.get_path uses incorrect locale handling

At knownfolders.py#L213 we see this code:

    # convert to unicode
    codec = sys.getdefaultencoding()
    if not codec:
        codec="utf-8"
    if hasattr(path, "decode"):
        path = path.decode(codec)

This entire block is incorrect and unnecessary, and actually broken on Python 2:

  • sys.getdefaultencoding() is for transparently converting between str and unicode (ascii on Python 2!) - you actually want sys.getfilesystemencoding()
  • the ctypes code above uses wchar_t, so path is already str on Python 3.x and unicode on Python 2.x
  • on Python 3.x this is a no-op (hasattr(str(), "decode") is always False)
  • on Python 2.x this throws if path has "invalid" characters, but by definition it cannot have invalid characters because it has come from the OS. Without changing the codec, "invalid" means "non-ASCII", which is very restrictive

The end result is that if you invoke this code path - for example, by installing Anaconda2 with non-ASCII characters in your username - you will get a UnicodeEncodeError while doing an unnecessary decode.

Removing the entire quoted block above is the simplest and most correct fix.

Set app ID on Windows

Checklist

  • I added a descriptive title
  • I searched open requests and couldn't find a duplicate

What is the idea?

Comes from spyder-ide/spyder#20791 (comment)


Set some sort of application ID on Windows shortcuts so icons are properly grouped when needed.

Why is this needed?

No response

What should happen?

We need to add:

  • A new field on the schema, with validation according to this info
  • Some code on the C extension for windows shortcuts. Essentially, fetch the property store for the shortcut and set the adequate key-value pair. (see Resources below)

Additional Context

Useful resources:

Provide "force" or "replace" functionality

Checklist

  • I added a descriptive title
  • I searched open requests and couldn't find a duplicate

What is the idea?

The current API will raise an exception if a shortcut with the same name/location is already in place. It would be nice to have some sort of "force" functionality so that the command does not fail, and overwrites the found menu item with the new one.

Why is this needed?

In the context of updates of application packages, the package containing the menu might be the same for different versions, so having the ability to replace an existing menu with a new version without having to first delete the all one "manually" via the API would be benefitial.

What should happen?

Add a parameter to the create remove API could be an option.

Additional Context

No response

how to add menuinst support for MacOs and Linux?

Checklist

  • I added a descriptive title
  • I searched open reports and couldn't find a duplicate

What happened?

How can we install menuinst on linux?

I see only windows support
https://github.com/conda-forge/menuinst-feedstock

image

Conda Info

active environment : None
       user config file : /home/jmatres/.condarc
 populated config files : /home/jmatres/mambaforge/.condarc
                          /home/jmatres/.condarc
          conda version : 4.14.0
    conda-build version : not installed
         python version : 3.10.6.final.0
       virtual packages : __linux=5.18.16=0
                          __glibc=2.35=0
                          __unix=0=0
                          __archspec=1=x86_64
       base environment : /home/jmatres/mambaforge  (writable)
      conda av data dir : /home/jmatres/mambaforge/etc/conda
  conda av metadata url : None
           channel URLs : https://conda.anaconda.org/conda-forge/linux-64
                          https://conda.anaconda.org/conda-forge/noarch
                          https://conda.anaconda.org/simpetus/linux-64
                          https://conda.anaconda.org/simpetus/noarch
                          https://repo.anaconda.com/pkgs/main/linux-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/r/linux-64
                          https://repo.anaconda.com/pkgs/r/noarch
          package cache : /home/jmatres/mambaforge/pkgs
                          /home/jmatres/.conda/pkgs
       envs directories : /home/jmatres/mambaforge/envs
                          /home/jmatres/.conda/envs
               platform : linux-64
             user-agent : conda/4.14.0 requests/2.28.1 CPython/3.10.6 Linux/5.18.16-1rodete4-amd64 debian/rodete glibc/2.35
                UID:GID : 768879:89939
             netrc file : /home/jmatres/.netrc
           offline mode : False

Conda Config

==> /home/jmatres/mambaforge/.condarc <==
channels:
  - conda-forge

==> /home/jmatres/.condarc <==
channels:
  - conda-forge
  - simpetus
  - defaults
anaconda_upload: False

Conda list

No response

Additional Context

No response

Various failures on linux + python3

In linux.py:

  • the utils and freedesktop imports should be relative (from .utils import ...)
  • there is no get_executable defined anywhere so the import fails.
  • tree.write (line 88) tries to write bytes to a unicode-opened file.
  • the 3rd argument to ShortCut.__init__ should be target_prefix, not prefix (also line 203).
    Even after fixing all this, running menuinst.install wiped out my KDE menu instead of installing a proper menu entry :-(

An unexpected error has occurred while execute "conda upgrade --all -v"

From @nanhu on January 21, 2018 2:34

Menu: name: 'Anaconda${PY_VER} ${PLATFORM}', prefix: 'D:\ProgramData\Anaconda3',
env_name: 'None', mode: 'None', used_mode: 'system'

Shortcut cmd is D:\ProgramData\Anaconda3\pythonw.exe, args are ['D:\ProgramData
\Anaconda3\cwp.py', 'D:\ProgramData\Anaconda3', 'D:\ProgramData\Anaconda3
\pythonw.exe', 'D:\ProgramData\Anaconda3\Scripts\anaconda-navigator-script.p
y']

===> REVERSING PACKAGE UNLINK: defaults::anaconda-client-1.6.5-py36hd36550c_0 <=

prefix=D:\ProgramData\Anaconda3

===> REVERSING PACKAGE UNLINK: defaults::anaconda-5.0.1-py36h8316230_2 <===
prefix=D:\ProgramData\Anaconda3

An unexpected error has occurred.
Please consider posting the following information to the
conda GitHub issue tracker at:

https://github.com/conda/conda/issues

Current conda install:

           platform : win-64
      conda version : 4.3.30
   conda is private : False
  conda-env version : 4.3.30
conda-build version : 3.0.27
     python version : 3.6.3.final.0
   requests version : 2.18.4
   root environment : D:\ProgramData\Anaconda3  (writable)
default environment : D:\ProgramData\Anaconda3
   envs directories : D:\ProgramData\Anaconda3\envs
                      C:\Users\Administrator\AppData\Local\conda\conda\envs
                      C:\Users\Administrator\.conda\envs
      package cache : D:\ProgramData\Anaconda3\pkgs
                      C:\Users\Administrator\AppData\Local\conda\conda\pkgs
       channel URLs : https://repo.continuum.io/pkgs/main/win-64
                      https://repo.continuum.io/pkgs/main/noarch
                      https://repo.continuum.io/pkgs/free/win-64
                      https://repo.continuum.io/pkgs/free/noarch
                      https://repo.continuum.io/pkgs/r/win-64
                      https://repo.continuum.io/pkgs/r/noarch
                      https://repo.continuum.io/pkgs/pro/win-64
                      https://repo.continuum.io/pkgs/pro/noarch
                      https://repo.continuum.io/pkgs/msys2/win-64
                      https://repo.continuum.io/pkgs/msys2/noarch
        config file : None
         netrc file : None
       offline mode : False
         user-agent : conda/4.3.30 requests/2.18.4 CPython/3.6.3 Windows/7 W

indows/6.1.7601
administrator : True

Copied from original issue: conda/conda#6761

import menuinst fails during conda install

I'm on Windows 7 64-bit and was trying to update my anaconda root environment from python 3.4 to 3.5.

When I ran conda install anaconda python=3.5 in an Administrator cmd prompt, after all the downloads, and after extracting, I got the following Traceback:

Traceback (most recent call last):
  File "C:\Anaconda3\lib\site-packages\conda\install.py", line 326, in mk_menus
    import menuinst
  File "C:\Anaconda3\lib\site-packages\menuinst\__init__.py", line 19, in <modul
    from .win32 import Menu, ShortCut
  File "C:\Anaconda3\lib\site-packages\menuinst\win32.py", line 13, in <module>
    from .winshortcut import create_shortcut
ImportError: No module named 'menuinst.winshortcut'

I see that winshortcut is a *.cpp file which is different from the other submodules of menuist, so I figure that might be an issue?

This is crashing the install, so any help is appreciated.

pywin32 dependency / size of menuinst in Miniconda etc.

Since #27 win_elevate.py is included, which is great since it resolved interactive elevation. This added pywin32 as a dependency though.
Since pywin32 is a rather "heavy" package, now menuinst (with its dependency) will account for a considerable size of minimal installers like Miniconda.
Sadly, I do not know of an alternative to pywin32 which provides similar functionality for Windows' interactive UAC.

CEP-11 & release v2 roadmap

Keyboard shortcuts and function key assignment (for touchbars) established in macOS preferences are not respected

This issue was fixed already, but I am pasting the report here for provenance and better tracking in the future.


@jaimergp, I have discovered another issue with respect to macOS integration. Keyboard shortcuts and function key assignment (for touchbars) established in macOS preferences are not respected. This is resolved by creating a symbolic link Contents/MacOS/python that points to $PREFIX/bin/python, and using this python to start the application.

For example:

/Users/rclary/Applications/Spyder.app
โ””โ”€โ”€ Contents
    โ”œโ”€โ”€ Info.plist
    โ”œโ”€โ”€ MacOS
    โ”‚ย ย  โ”œโ”€โ”€ Spyder
    โ”‚ย ย  โ””โ”€โ”€ python -> /Users/rclary/Library/spyder-5.4.0.dev0/envs/spyder-5.4.0.dev0/bin/python
    โ”œโ”€โ”€ PkgInfo
    โ””โ”€โ”€ Resources
        โ””โ”€โ”€ spyder.icns

Where the application executable, Spyder, is:

#!/bin/bash
eval "$("/Users/rclary/Library/spyder-5.4.0.dev0/_conda.exe" shell.bash activate "/Users/rclary/Library/spyder-5.4.0.dev0/envs/spyder-5.4.0.dev0")"
$(dirname $BASH_SOURCE)/python /Users/rclary/Library/spyder-5.4.0.dev0/envs/spyder-5.4.0.dev0/bin/spyder "$@"

It seems to me that this symbolic link should be created by menuinst as standard behavior (or at least an option). This is how python.app (via pythonw) works. Can this be included in your merge requests to menuinst?

Originally posted by @mrclary in spyder-ide/spyder#18870 (comment)


The issue does show up in napari. One could use pythonw (which just links to python.app/Contents/MacOS/python, which just links to /bin/python), but then python.app gets integrated to the macOS, not the user application. Application shortcuts in macOS preferences would have to use python.app rather than the user's application and "python" will show up in the menubar instead of the user's app name.

The reason is that the final application bundle executable is inside python.app. This is fine for most commandline python applications because you want "python" to integrate to macOS. For the user's application, we just need to apply the same technique, i.e. have python executable "appear" to originate from inside the user's application bundle.

The two screencasts illustrate.

Unadulterated napari does not integrate shortcuts in macOS preferences...
integration

Modified napari has improved integration with macOS...
integration-2

Originally posted by @mrclary in spyder-ide/spyder#18870 (comment)

Rework linux/osx support plus new simplified format?

@kalefranz, @msarahan, @mingwandroid

I have been wanting to update the linux/osx support for some time, but it might also be a good opportunity to reevaluate the current format. Since conda uses jinja2, yaml and selectors, it would be pretty natural to do the same for menuinst (lets say version 2.0):

Based on https://github.com/ContinuumIO/menuinst/wiki/Menu-Shortcut-Config-Structure

Could we turn the format into yaml, and use jinja2 and selectors, and make it more uniform among all OSs? We could still use separate files for separate OSs, but we could just have one file that knows what to do everywhere

This would create subfolders for environments and no subfolder for the root (hopefully). Overriding the creation for other envs, should probably be handed by the CLI when called, instead of including the info inside this file

../conda.recipe/
   menu.yaml
   icons/
      someicon.ico
      someicon.icns
{% set BASE_DIR = 'Anaconda'PY_VER PLATFORM %}
{% set ICO_EXT = 'ico' if WIN or LINUX else 'icns' %}

version: 2.0
menu:
  - path: {% if ROOT_PREFIX != ENV_PREFIX %}{{ BASE_DIR }}/{{ ENVNAME }}{% else %}{{ BASE_DIR }}{{% endif %}
    shortcuts:
      - name: 'SomeApp'
        version: 1.8.9
        cmd:    #  Or we can split cmd, and args...
          - '{{ PYTHONW }}'
          - '{{ PYTHON_SCRIPTS }}/someapp'
        comment: 'Some description of someapp'
        icon: '{{ MENU_DIR }}/someicon.{{ ICO_EXT }}'
        icon_path: 'icons/someicon.{{ ICO_EXT }}'
        desktop: True                         # [win]
        quicklaunch: True                     # [linux and win]
# Check the need of keys
terminal
id

# "new" env variables
FILEBROWSER
WEBBROWSER
CMD/BASH ?

# deprecate keys
icns 
pywscript
pyscript
script
scriptarguments
system
webbrowser

Plus adding a programmatic api menuinst.api

from menuninst.api import Menu, Shortcut

menu = Menu('My awesome thing/submenu/')
shortcut = Shortcut('App', ['command'], desktop=True, icon=None)
shortcut.icon = '{{ MENU_DIR }}/icon.ico'
shortcut.icon_path = 'icons/icon.ico'
menu.add(shortcut)
menu.install(context={...})
menu.uninstall(...)
yaml_data = menu.to_yaml()
json_data = menu.to_json()

Thoughts?

Canonical location in `PREFIX` for menu item artifacts

The CEP preview of menuinst creates shortcuts for Linux, macOS and Windows in three default locations:

  • Linux: ~/.local/share/applications
  • macOS: ~/Applications
  • Windows: whatever the default locations for Start Menu, Quick Launch and Desktop are.

For this we create full files with computable paths, so we can re-obtain these paths at uninstall time if needed. The problem is that these files might not be there by the time we want to uninstall them (Windows users might rename or move the shortcuts, and they'd still work; macOS users might put the .app directory somewhere else; I am not expecting Linux users to mess with their .desktop files but you never know).

Instead of doing this, @goanpeca and I were talking about creating the actual menu files in PREFIX itself (under var/menuinst or similar), and the symlink to this canonical location from the system parts. This needs to be tested (specially on Windows, with different letter units?), but it should work. It would also have the benefit of having an easy-to-find location for the generated shortcuts without having to re-run menuinst to find out.

Provide "dry-run" functionality

Checklist

  • I added a descriptive title
  • I searched open requests and couldn't find a duplicate

What is the idea?

The current (and in development?) API supports the ability to create and remove shortcuts by pointing to a path or providing a dictionary of metadata.

Why is this needed?

In some cases it is nice to know what will happen without actually running the creation or removal process.

What should happen?

Provide a parameter or flag so that the result of create/remove is the same, but without actually executing the process of creation or removal in a similar vein to the "--dry-run" functionality of condaProvide a parameter or flag so that the result of create/remove is the same, but without actually executing the process of creation or removal in a similar vein to the "--dry-run" functionality of conda

Additional Context

No response

Error handling for permissions failures

Presently, if menuinst fails for any reason during conda install, it kills the whole conda install. Part of that needs fixing in conda install, but menuinst also needs saner fallbacks: if we don't have admin rights, or if permissions fail for any reason, try to install as user (to the AppData\Roaming\Microsoft\Start Menu folder - or however we get a shortcut to that).

Failing all permissions attempts, we should still raise an error, and Conda needs to be more intelligent about not falling over if/when that error comes.

Change the API to menuinst.install(path_or_dict)

All's in the title: allowing passing a dict (basically, the contents of the json file) to menuinst.install would simplify programmatic use of menuinst. Alternatively, another function (install_from_dict) would be fine too.

cwp.py overrides working directory

Using cwp.py under windows to start an application overrides the working directory set in the shortcut properties (the "start in" option).

Would it be possible to either remove that override (to the Documents folder) or to add an option to skip the override if needed.

Update on PyPI required

When trying to > pip install menuinst in a Python 3.6, I get this response:

pip install menuinst
Collecting menuinst
  Could not find a version that satisfies the requirement menuinst (from versions: )
No matching distribution found for menuinst
You are using pip version 9.0.1, however version 9.0.3 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

Running > pip show menuinst shows the latest release is 1.0.0:

pip search menuinst
menuinst (1.0.0)  - cross platform install of menu items
  INSTALLED: 1.4.7
  LATEST:    1.0.0
You are using pip version 9.0.1, however version 9.0.3 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

This is verified when searching menuinst at PyPI.

At the moment, this hinders installing menuinst via pip. Can the latest releases be published to PyPI?

Multiple start menu folders

See ContinuumIO/anaconda-issues#1087

I installed anaconda by following these steps on Windows 10:

Install Anaconda 4.1.1 (Python 2.7 64 bit) using the installer from the website
conda update conda
conda update anaconda
After step 1 a folder appears in my start menu called "Anaconda2 (64-bit)". After completing step 3, another folder shows up called "Anaconda (64-bit)"

They seem to contain (slightly) different things:

Anaconda (64-bit):

Ipython notebook, QTconsole
Spyder
Launcher
Anaconda2 (64-bit):

Anaconda navigator (doesnt start, see #1086)
Ipython
Jupyter notebook, QTConsole
Spyder
None of the links in the Anaconda2 folder seem to work when you click them

Are both of these folders meant to exist or can I safely delete one of them? What is the purpose of multiple folders?

Anaconda Prompt broken

from conda/conda#6704 (comment)


The Anaconda Prompt shortcut uses

%windir%\System32\cmd.exe "/K" "C:\ProgramData\Anaconda 3\Scripts\activate.bat" "C:\ProgramData\Anaconda 3"

for which the last parameter is passed on to activate.bat as "C:\ProgramData\Anaconda 3 (note the missing end quote).
If I change the target to

%windir%\System32\cmd.exe /K ""C:\ProgramData\Anaconda 3\Scripts\activate.bat" "C:\ProgramData\Anaconda 3""

, everything works fine and activate.bat/conda.bat get "C:\ProgramData\Anaconda 3".
Conclusion: For the Anaconda Prompt this is a menuinst (+console_shortcut) issue quoting in menuinst is broken...


What we'd actually need, is that in console_shortcut

"scriptarguments": ["/K", "${ROOT_PREFIX}\\Scripts\\activate.bat", "${PREFIX}"],

should be changed to

"scriptarguments": ["/K", "\"${ROOT_PREFIX}\\Scripts\\activate.bat\" \"${PREFIX}\""],

and in menuinst.win32 not add quotes around /K via menuinst.win32.quoted in https://github.com/ContinuumIO/menuinst/blob/1.4.10/menuinst/win32.py#L292 and not let menuinst.win32.quoted unconditionally remove quotes at the beginning and end of the arguments in https://github.com/ContinuumIO/menuinst/blob/1.4.10/menuinst/win32.py#L292-L293, cc @mingwandroid. As previously discussed, it would be wise to add a bunch of test cases to menuinst to get all those subtleties right; breaking changes might likely have to be postponed for a menuinst 2.x, I think.

PythonW.exe not found during installation of "spyder" and other GUI items with conda

I have Win7-X86 and latest Anaconda3-X86, menuinst version 14.x.
During installation of "spyder" and other GUI items I got message box "Windows can not find pythonw" along with suspicious log from "menuinst".
I use Windows command line: "py -m conda install spyder". My own py.bat uses proper full path to python.exe followed by the above arguments from command line (Windows cmd.exe prompt).
I did review sources in "Anaconda\Lib\site-packages\menuinst" and I found suspicious place in:

    Anaconda\Lib\site-packages\menuinst\ __init__.py, function install().

Original fragment presented below:

        runAsAdmin(['pythonw', '-c',
                    "import menuinst; menuinst.install(%r, %r, %r)" % (
                        path, bool(remove), prefix)])

Problem is that somebody is using full path everywhere in the generated menu item, while "pythonw" itself is caled without any path. I did modify call to "runAsAdmin" as below. I did change only the first item in [] argument from 'pythonw' to full path to pythonw (path is available in prefix variable):

  runAsAdmin(["%s\\pythonw.exe" % (prefix),
           '-c',
           "import menuinst; menuinst.install(%r, %r, %r)" % (
              path, bool(remove), prefix)])

After this modification I can see that pythonw.exe is started and request administrative elevation, as it supposed to be (maybe). It looks like that somebody have to fix something.

means to disable menu generation for a given instalaltion of conda

Since menuinst is now a mandatory package when installing conda (at least on windows https://github.com/conda/conda/blob/master/setup.py#L40) once can no longer simply remove menuinst from allowed package as directed here (https://docs.conda.io/projects/conda-build/en/latest/resources/add-win-start-menu-items.html) or by excluding it in the .condarc. doing so will fail any updates attempted on conda itself (from condarc) or fail installation of conda outright (if done from constructor).
Is there a way one could configure to disable completely start menu creation for a specific conda installation ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.