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

Is the value of the "platforms" field correctly checked and used ? #240

Open
2 tasks done
jypeter opened this issue Aug 1, 2024 · 8 comments
Open
2 tasks done

Is the value of the "platforms" field correctly checked and used ? #240

jypeter opened this issue Aug 1, 2024 · 8 comments
Labels
type::bug describes erroneous operation, use severity::* to classify the type

Comments

@jypeter
Copy link

jypeter commented Aug 1, 2024

Checklist

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

What happened?

I have kept on playing the the turtle minimal example and I'm not sure the platforms field is checked correctly

  • The documentation says that platforms is A dictionary with up to three keys. All of them are optional but you must at least define one. The presence of a key with a non-null value enables the shortcut for that platform. If you don’t include any, shortcuts
  • The schema says: Platform-specific options. Presence of a platform field enables menu items in that platform.

I'm using a Windows computer, and I would expect that something gets installed (on Windows) only if:

  • There is a win key
  • and The value associated to the win is non-null

What do you mean by non-null value anyway? Something that is True?
The turtle minimal example defines

      "platforms": {
        "linux": {},
        "osx": {},
        "win": {} }

In my opinion empty dictionaries test as False and should be considered as null values so the example is a bit odd

>>> bool(False)
False
>>> bool(None)
False
>>> bool({})
False
>>> bool({'desktop':False})
True

I have also experienced the following:

  1. If I install the Turtle example as-is, on my Windows machine, the shortcuts are installed, even in the value of the win key is (technically) False
  2. If I use an empty dictionary for platforms ( "platforms": {}), the shortcuts are still installed on my Windows computer (even if there is not even a win key!)
  3. If I only use a crappy name instead of the 3 names allowed, the shortcuts are still installed on my Windows computer
       "platforms": {
        "crappy": {}
      }
  1. If I don't define platform, the shortcuts are still installed on my Windows computer
  "menu_items": [
    {
      "name": "Launch Turtle",
      "command": ["python", "-m", "turtle"]
    }
  ]

It seems like shortcuts are always installed for Windows (regardless of how platforms is defined)

Conda Info

(base) PS C:\> conda info

     active environment : base
    active env location : C:\Utils\miniconda3_2024-03
            shell level : 3
       user config file : C:\Users\jypeter\.condarc
 populated config files : C:\Users\jypeter\.condarc
          conda version : 24.7.1
    conda-build version : not installed
         python version : 3.12.4.final.0
                 solver : libmamba (default)
       virtual packages : __archspec=1=icelake
                          __conda=24.7.1=0
                          __win=0=0
       base environment : C:\Utils\miniconda3_2024-03  (writable)
      conda av data dir : C:\Utils\miniconda3_2024-03\etc\conda
  conda av metadata url : None
           channel URLs : https://conda.anaconda.org/conda-forge/win-64
                          https://conda.anaconda.org/conda-forge/noarch
                          https://repo.anaconda.com/pkgs/main/win-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/r/win-64
                          https://repo.anaconda.com/pkgs/r/noarch
                          https://repo.anaconda.com/pkgs/msys2/win-64
                          https://repo.anaconda.com/pkgs/msys2/noarch
          package cache : C:\Utils\miniconda3_2024-03\pkgs
                          C:\Users\jypeter\.conda\pkgs
                          C:\Users\jypeter\AppData\Local\conda\conda\pkgs
       envs directories : C:\Utils\miniconda3_2024-03\envs
                          C:\Users\jypeter\.conda\envs
                          C:\Users\jypeter\AppData\Local\conda\conda\envs
               platform : win-64
             user-agent : conda/24.7.1 requests/2.32.3 CPython/3.12.4 Windows/10 Windows/10.0.19045 solver/libmamba conda-libmamba-solver/24.7.0 libmambapy/1.5.8 aau/0.4.4 c/. s/. e/.
          administrator : False
             netrc file : None
           offline mode : False

Conda Config

(base) PS C:\> conda config --show-sources
==> C:\Users\jypeter\.condarc <==
channel_priority: strict
channels:
  - conda-forge
  - defaults

Conda list

(base) PS C:\> conda list --show-channel-urls
# packages in environment at C:\Utils\miniconda3_2024-03:
#
# Name                    Version                   Build  Channel
anaconda-anon-usage       0.4.4           py312hfc23b7f_100    defaults
archspec                  0.2.3              pyhd8ed1ab_0    conda-forge
boltons                   24.0.0             pyhd8ed1ab_0    conda-forge
brotli-python             1.1.0           py312h53d5487_1    conda-forge
bzip2                     1.0.8                h2466b09_7    conda-forge
ca-certificates           2024.7.4             h56e8100_0    conda-forge
certifi                   2024.7.4           pyhd8ed1ab_0    conda-forge
cffi                      1.16.0          py312he70551f_0    conda-forge
charset-normalizer        3.3.2              pyhd8ed1ab_0    conda-forge
colorama                  0.4.6              pyhd8ed1ab_0    conda-forge
conda                     24.7.1          py312h2e8e312_0    conda-forge
conda-content-trust       0.2.0              pyhd8ed1ab_0    conda-forge
conda-libmamba-solver     24.7.0             pyhd8ed1ab_0    conda-forge
conda-package-handling    2.3.0              pyh7900ff3_0    conda-forge
conda-package-streaming   0.10.0             pyhd8ed1ab_0    conda-forge
console_shortcut_miniconda 0.1.1                haa95532_2    defaults
cryptography              43.0.0          py312h9500af3_0    conda-forge
distro                    1.9.0              pyhd8ed1ab_0    conda-forge
expat                     2.6.2                h63175ca_0    conda-forge
fmt                       10.2.1               h181d51b_0    conda-forge
frozendict                2.4.4           py312h4389bb4_0    conda-forge
h2                        4.1.0              pyhd8ed1ab_0    conda-forge
hpack                     4.0.0              pyh9f0ad1d_0    conda-forge
hyperframe                6.0.1              pyhd8ed1ab_0    conda-forge
idna                      3.7                pyhd8ed1ab_0    conda-forge
jsonpatch                 1.33               pyhd8ed1ab_0    conda-forge
jsonpointer               3.0.0           py312h2e8e312_0    conda-forge
krb5                      1.21.3               hdf4eb48_0    conda-forge
libarchive                3.7.4                haf234dc_0    conda-forge
libcurl                   8.9.1                h18fefc2_0    conda-forge
libexpat                  2.6.2                h63175ca_0    conda-forge
libffi                    3.4.4                hd77b12b_0    defaults
libiconv                  1.17                 hcfcfb64_2    conda-forge
libmamba                  1.5.8                h3f09ed1_0    conda-forge
libmambapy                1.5.8           py312h66cf91f_0    conda-forge
libsolv                   0.7.30               hbb528cf_0    conda-forge
libsqlite                 3.46.0               h2466b09_0    conda-forge
libssh2                   1.11.0               h7dfc565_0    conda-forge
libxml2                   2.12.7               h0f24e4e_4    conda-forge
libzlib                   1.3.1                h2466b09_1    conda-forge
lz4-c                     1.9.4                hcfcfb64_0    conda-forge
lzo                       2.10              hcfcfb64_1001    conda-forge
mamba                     1.5.8           py312h5494d5c_0    conda-forge
menuinst                  2.1.1           py312h275cf98_0    conda-forge
openssl                   3.3.1                h2466b09_2    conda-forge
packaging                 24.1               pyhd8ed1ab_0    conda-forge
pcre2                     10.44                h3d7b363_0    conda-forge
pip                       24.2               pyhd8ed1ab_0    conda-forge
platformdirs              4.2.2              pyhd8ed1ab_0    conda-forge
pluggy                    1.5.0              pyhd8ed1ab_0    conda-forge
powershell_shortcut_miniconda 0.0.1                haa95532_2    defaults
pybind11-abi              4                    hd8ed1ab_3    conda-forge
pycosat                   0.6.6           py312he70551f_0    conda-forge
pycparser                 2.22               pyhd8ed1ab_0    conda-forge
pysocks                   1.7.1              pyh0701188_6    conda-forge
python                    3.12.4          h889d299_0_cpython    conda-forge
python_abi                3.12                    4_cp312    conda-forge
reproc                    14.2.4.post0         hcfcfb64_1    conda-forge
reproc-cpp                14.2.4.post0         h63175ca_1    conda-forge
requests                  2.32.3             pyhd8ed1ab_0    conda-forge
ruamel.yaml               0.18.6          py312he70551f_0    conda-forge
ruamel.yaml.clib          0.2.8           py312he70551f_0    conda-forge
setuptools                71.0.4             pyhd8ed1ab_0    conda-forge
sqlite                    3.46.0               h2466b09_0    conda-forge
tk                        8.6.13               h5226925_1    conda-forge
tqdm                      4.66.4             pyhd8ed1ab_0    conda-forge
truststore                0.8.0              pyhd8ed1ab_0    conda-forge
tzdata                    2024a                h0c530f3_0    conda-forge
ucrt                      10.0.22621.0         h57928b3_0    conda-forge
urllib3                   2.2.2              pyhd8ed1ab_1    conda-forge
vc                        14.3                h8a93ad2_20    conda-forge
vc14_runtime              14.40.33810         ha82c5b3_20    conda-forge
vs2015_runtime            14.40.33810         h3bf8584_20    conda-forge
wheel                     0.43.0             pyhd8ed1ab_1    conda-forge
win_inet_pton             1.1.0              pyhd8ed1ab_6    conda-forge
xz                        5.4.6                h8cc25b3_0    defaults
yaml-cpp                  0.8.0                h63175ca_0    conda-forge
zlib                      1.3.1                h2466b09_1    conda-forge
zstandard                 0.23.0          py312h7606c53_0    conda-forge
zstd                      1.5.6                h0ea2cb4_0    conda-forge

Additional Context

This may be also related to #234

@jypeter jypeter added the type::bug describes erroneous operation, use severity::* to classify the type label Aug 1, 2024
@github-project-automation github-project-automation bot moved this to 🆕 New in 🧭 Planning Aug 1, 2024
@jaimergp
Copy link
Contributor

jaimergp commented Aug 1, 2024

The docs say non-null meaning any value that is not null or None. What you are thinking of is "falsey".

this_is_null: null,
this_is_null_too: None,
this_is_not_null: {}

@jaimergp
Copy link
Contributor

jaimergp commented Aug 1, 2024

It seems like shortcuts are always installed for Windows (regardless of how platforms is defined)

Can you show the paths of the shortcuts created, please? 🙏

@jypeter
Copy link
Author

jypeter commented Aug 1, 2024

OK about nullish vs falsey (though null is not Python)

@jypeter
Copy link
Author

jypeter commented Aug 1, 2024

If I use the following json file

{
  "$schema": "https://json-schema.org/draft-07/schema",
  "$id": "https://schemas.conda.io/menuinst-1.schema.json",
  "menu_name": "Python {{ DISTRIBUTION_NAME }} - {{ ENV_NAME }}",
  "menu_items": [
    {
      "name": "Launch Turtle",
      "command": ["python", "-m", "turtle"]
    }
  ]
}

I get these

>>> from menuinst.api import install
>>> installed_path = install('./turtle_v02.json')
>>> import pprint
>>> pprint.pprint(installed_path)
[WindowsPath('C:/Users/jypeter/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Python miniconda3_2024-03 - base'),
 WindowsPath('C:/Users/jypeter/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Python miniconda3_2024-03 - base/Launch Turtle.lnk'),
 WindowsPath('C:/Users/jypeter/Desktop/Launch Turtle.lnk'),
 WindowsPath('C:/Users/jypeter/AppData/Roaming/Microsoft/Internet Explorer/Quick Launch/Launch Turtle.lnk'),
 WindowsPath('C:/Utils/miniconda3_2024-03/Menu/Launch Turtle.bat')]

Is this what you need?

@jaimergp
Copy link
Contributor

jaimergp commented Aug 1, 2024

Yes, that confirms your report, thanks. I'm wondering at what point we accidentally changed the logic. Can you check if setting the platforms explicitly to null disables them?

@marcoesters
Copy link
Contributor

@jaimergp

I think this is the problem:

@staticmethod
def _initialize_on_defaults(data) -> Dict:
with open(data_path("menuinst.default.json")) as f:
defaults = json.load(f)["menu_items"][0]
return deep_update(defaults, data)

If there is no platforms key, the default will be used, which is all three platforms with a bunch of null values.

So, the documentation either needs to be changed or the requirement that there be a platforms must be enforced before loading the defaults.

@jypeter
Copy link
Author

jypeter commented Aug 1, 2024

@jaimergp I had forgotten that json files looked like a Python dictionaries, but were not. And that you have to use null instead of None

So, here is what I get with the following json file

{
  "$schema": "https://json-schema.org/draft-07/schema",
  "$id": "https://schemas.conda.io/menuinst-1.schema.json",
  "menu_name": "Python {{ PY_VER }}",
  "menu_items": [
    {
      "name": "Launch Turtle",
      "command": ["python", "-m", "turtle"],
      "platforms": {
        "linux": null,
        "osx": null,
        "win": {}
      }
    }
  ]
}
>>> installed_path = install('./turtle_v04.json')
>>> pprint.pprint(installed_path)
[WindowsPath('C:/Users/jypeter/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Python N.A'),
 WindowsPath('C:/Users/jypeter/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Python N.A/Launch Turtle.lnk'),
 WindowsPath('C:/Users/jypeter/Desktop/Launch Turtle.lnk'),
 WindowsPath('C:/Users/jypeter/AppData/Roaming/Microsoft/Internet Explorer/Quick Launch/Launch Turtle.lnk'),
 WindowsPath('C:/Utils/miniconda3_2024-03/Menu/Launch Turtle.bat')]

If I use instead

{
  "$schema": "https://json-schema.org/draft-07/schema",
  "$id": "https://schemas.conda.io/menuinst-1.schema.json",
  "menu_name": "Python {{ PY_VER }}",
  "menu_items": [
    {
      "name": "Launch Turtle",
      "command": ["python", "-m", "turtle"],
      "platforms": {
        "linux": null,
        "osx": null,
        "win": null
      }
    }
  ]
}

I get

>>> installed_path = install('./turtle_v04.json')
C:\Utils\miniconda3_2024-03\Lib\site-packages\menuinst\api.py:56: UserWarning: Metadata for Python {{ PY_VER }} is not enabled for win32
  warnings.warn(f"Metadata for {menu.name} is not enabled for {sys.platform}")

Same kind of message if I use ENV_NAME instead of PY_VER

>>> installed_path = install('./turtle_v04.json')
C:\Utils\miniconda3_2024-03\Lib\site-packages\menuinst\api.py:56: UserWarning: Metadata for Python {{ ENV_NAME }} is not enabled for win32
  warnings.warn(f"Metadata for {menu.name} is not enabled for {sys.platform}")

It seems I am triggering weird Placeholders related errors when I set win to null. So this is also kind of related to the Placeholders related issues I raised

@marcoesters
Copy link
Contributor

marcoesters commented Aug 1, 2024

That behavior here is expected (apart from the placeholders). In the first case, you have win as non-null, so it creates Windows shortcuts.

In the second example, you have all platforms set to null, so no shortcuts are created (or at least they shouldn't). Instead, they raise this warning, independent of placeholders: https://github.com/conda/menuinst/blob/main/menuinst/api.py#L55-L57

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type::bug describes erroneous operation, use severity::* to classify the type
Projects
Status: 🆕 New
Development

No branches or pull requests

3 participants