warpnet / salt-lint

A command-line utility that checks for best practices in SaltStack.
https://salt-lint.readthedocs.io/en/latest/
MIT License
152 stars 39 forks source link

Cannot install salt-lint because salt-lint requires salt-lint to be able to import __init__.py #308

Closed clickthisnick closed 8 months ago

clickthisnick commented 1 year ago

Describe the bug

[2023-04-25T13:38:28.676Z] An unexpected error has occurred: CalledProcessError: command: ('/bin/bash', '/home/myuser/.cache/pre-commit/repokh6trj85/py_env-python3.11/bin/python', '-mpip', 'install', '.')
[2023-04-25T13:38:28.676Z] return code: 1
[2023-04-25T13:38:28.676Z] stdout:
[2023-04-25T13:38:28.676Z]     Processing /home/myuser/.cache/pre-commit/repokh6trj85
[2023-04-25T13:38:28.676Z]       Preparing metadata (setup.py): started
[2023-04-25T13:38:28.676Z]       Preparing metadata (setup.py): finished with status 'error'
[2023-04-25T13:38:28.676Z] stderr:
[2023-04-25T13:38:28.676Z]       error: subprocess-exited-with-error
[2023-04-25T13:38:28.676Z]       
[2023-04-25T13:38:28.676Z]       × python setup.py egg_info did not run successfully.
[2023-04-25T13:38:28.676Z]       │ exit code: 1
[2023-04-25T13:38:28.676Z]       ╰─> [6 lines of output]
[2023-04-25T13:38:28.676Z]           Traceback (most recent call last):
[2023-04-25T13:38:28.676Z]             File "<string>", line 2, in <module>
[2023-04-25T13:38:28.676Z]             File "<pip-setuptools-caller>", line 34, in <module>
[2023-04-25T13:38:28.676Z]             File "/home/myuser/.cache/pre-commit/repokh6trj85/setup.py", line 25, in <module>
[2023-04-25T13:38:28.676Z]               from saltlint import (__author__, __license__,
[2023-04-25T13:38:28.676Z]           ModuleNotFoundError: No module named 'saltlint'
[2023-04-25T13:38:28.676Z]           [end of output]
[2023-04-25T13:38:28.676Z]       
[2023-04-25T13:38:28.676Z]       note: This error originates from a subprocess, and is likely not a problem with pip.
[2023-04-25T13:38:28.676Z]     error: metadata-generation-failed
[2023-04-25T13:38:28.676Z]     
[2023-04-25T13:38:28.676Z]     × Encountered error while generating package metadata.
[2023-04-25T13:38:28.676Z]     ╰─> See above for output.
[2023-04-25T13:38:28.677Z]     
[2023-04-25T13:38:28.677Z]     note: This is an issue with the package mentioned above, not pip.
[2023-04-25T13:38:28.677Z]     hint: See above for details.
[2023-04-25T13:38:28.677Z] Check the log at /home/myuser/.cache/pre-commit/pre-commit.log

To Reproduce I don't have a great reproduction tutorial but its somewhat described in https://stackoverflow.com/a/2058872

  1. Use python3.11 and install pre-commit in a venv
  2. pre-commit will create its own venv that fallsback to a sys python
  3. Use pre-commit or use a subprocess.Popen to install salt-lint via the setup.py but don't have the cwd set the root of salt-lint repo
  4. pip will not be able to install salt-lint because it's looking for the relative path to salt-lint to import the versioning information

Expected behavior I should be able to install salt-lint without needing any relative directory or path to be accessible

Desktop (please complete the following information):

Additional context

If you'd like me to take a stab at it, I believe if we require python3.8 (remember python3.7 is deprecated https://endoflife.date/python)

Then we can do the following code in the cli.py which is the reason the versioning appears to be in init.py and not just hardcoded in setup.py

$ python3.11
Type "help", "copyright", "credits" or "license" for more information.
>>> from importlib.metadata import version  
>>> version("salt-lint")
'0.9.2'