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

build: main() not required any more #635

Closed

Conversation

DimitriPapadopoulos
Copy link
Contributor

@DimitriPapadopoulos DimitriPapadopoulos commented Jan 8, 2024

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

Copy link
Owner

@adrienverge adrienverge left a comment

Choose a reason for hiding this comment

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

With the removal of __main__.py, is it still possible to run python -m yamllint?

@DimitriPapadopoulos
Copy link
Contributor Author

DimitriPapadopoulos commented Jan 9, 2024

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.

Since adding "yamllint.cli:run", we don't need a main() function.
@DimitriPapadopoulos
Copy link
Contributor Author

DimitriPapadopoulos commented Jan 11, 2024

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
Copy link
Owner

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
Copy link
Contributor Author

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
Copy link
Contributor Author

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
Copy link
Contributor Author

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
$ 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants