adrienverge / yamllint

A linter for YAML files.
GNU General Public License v3.0
2.79k stars 265 forks source link

build: main() not required any more #635

Closed DimitriPapadopoulos closed 6 months ago

DimitriPapadopoulos commented 6 months ago

Since adding "yamllint.cli:run", we don't need a main() function.

DimitriPapadopoulos commented 6 months ago

I think it should work, "yamllint.cli:run" both generates a console script and defines the module entry point:

>>> import importlib.metadata as metadata
>>> 
>>> metadata.entry_points(name='yamllint')
[EntryPoint(name='yamllint', value='yamllint.cli:run', group='console_scripts')]
>>> 

Needs more work though, to get coverage tests to work.

DimitriPapadopoulos commented 6 months ago

Actually python -m yamllint never works, with this change or without. It is a non-issue.

$ pip install yamllint
Defaulting to user installation because normal site-packages is not writeable
Collecting yamllint
  Using cached yamllint-1.33.0-py3-none-any.whl.metadata (4.2 kB)
Requirement already satisfied: pathspec>=0.5.3 in /usr/lib/python3/dist-packages (from yamllint) (0.9.0)
Requirement already satisfied: pyyaml in ./.local/lib/python3.11/site-packages (from yamllint) (6.0.1)
Using cached yamllint-1.33.0-py3-none-any.whl (65 kB)
Installing collected packages: yamllint
Successfully installed yamllint-1.33.0
$ 
$ yamllint --version
yamllint 1.33.0
$ 
$ python -m yamllint --version
/usr/bin/python: No module named yamllint
$ 
adrienverge commented 6 months ago

On my system, python -m yamllint does work if __main__.py is present, and doesn't if this file is missing. (I just rechecked the exact commands from your snippet.)

The documentation seems to agree with that:

__main__.py will be executed when the package itself is invoked directly from the command line using the -m flag. For example:

$ python -m bandclass

Can you double-check?

DimitriPapadopoulos commented 6 months ago

I am installing yamllint from PyPI:

$ 
$ pip install yamllint --user --verbose
Using pip 22.0.2 from /usr/lib/python3/dist-packages/pip (python 3.11)
Collecting yamllint
  Downloading yamllint-1.33.0-py3-none-any.whl (65 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 65.4/65.4 KB 2.0 MB/s eta 0:00:00
Requirement already satisfied: pyyaml in /usr/lib/python3/dist-packages (from yamllint) (5.4.1)
Requirement already satisfied: pathspec>=0.5.3 in /usr/lib/python3/dist-packages (from yamllint) (0.9.0)
Installing collected packages: yamllint
  changing mode of /home/username/.local/bin/yamllint to 775
Successfully installed yamllint-1.33.0
$ 
$ yamllint --version
yamllint 1.33.0
$ 
$ python -m yamllint --version
/usr/bin/python: No module named yamllint
$ 

Have I done something wrong?

DimitriPapadopoulos commented 6 months ago

Something is wrong after all:

$ which python
/usr/bin/python
$ 
$ ls -l /usr/bin/python
lrwxrwxrwx 1 root root 7 Oct 11  2021 /usr/bin/python -> python3
$ 
$ ls -l /usr/bin/python3
lrwxrwxrwx 1 root root 10 Aug 18  2022 /usr/bin/python3 -> python3.10
$ 
$ python --version
Python 3.10.12
$ 
$ which pip
/home/username/.local/bin/pip
$ 
$ /home/username/.local/bin/pip --version
pip 22.0.2 from /usr/lib/python3/dist-packages/pip (python 3.11)
$ 

This version of pip had been installed for a different version of Python than the default version 3.10 available on Ubuntu 22.04:

$ ls -ld /home/username/.local/lib/python3.10/site-packages/yaml*
ls: cannot access '/home/username/.local/lib/python3.10/site-packages/yaml*': No such file or directory
$ 
$ ls -ld /home/username/.local/lib/python3.11/site-packages/yaml*
drwxrwxr-x 5 username username 4096 Jan 12 08:41 /home/username/.local/lib/python3.11/site-packages/yamllint
drwxrwxr-x 2 username username 4096 Jan 12 08:41 /home/username/.local/lib/python3.11/site-packages/yamllint-1.33.0.dist-info
$ 

Let me retry after cleaning up.

DimitriPapadopoulos commented 6 months ago

It works now:

$ pip --version
pip 22.0.2 from /usr/lib/python3/dist-packages/pip (python 3.10)
$ 
$ pip install yamllint --user
Collecting yamllint
  Using cached yamllint-1.33.0-py3-none-any.whl (65 kB)
Requirement already satisfied: pathspec>=0.5.3 in /usr/lib/python3/dist-packages (from yamllint) (0.9.0)
Requirement already satisfied: pyyaml in /usr/lib/python3/dist-packages (from yamllint) (5.4.1)
Installing collected packages: yamllint
Successfully installed yamllint-1.33.0
$ 
$ python -m yamllint --version
yamllint 1.33.0
$