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

Pre-commit hook seems to not create the correct version #123

Open
WilliamJamieson opened this issue Aug 9, 2023 · 7 comments
Open

Pre-commit hook seems to not create the correct version #123

WilliamJamieson opened this issue Aug 9, 2023 · 7 comments

Comments

@WilliamJamieson
Copy link

When I add the following hook per the documentation:

  - repo: https://github.com/scientific-python/repo-review
    rev: "v0.9.2"
    hooks:
      - id: repo-review
        additional_dependencies: ["sp-repo-review==2023.08.03"]

I am getting the following error when pre-commit attempts to install the repo-review hook:

[INFO] Initializing environment for https://github.com/scientific-python/repo-review.
[INFO] Initializing environment for https://github.com/scientific-python/repo-review:sp-repo-review==2023.08.03.
[INFO] Installing environment for https://github.com/scientific-python/repo-review.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: CalledProcessError: command: ('/Users/wjamieson/.cache/pre-commit/repommi24uuq/py_env-python3.11/bin/python', '-mpip', 'install', '.', 'sp-repo-review==2023.08.03')
return code: 1
stdout:
    Processing /Users/wjamieson/.cache/pre-commit/repommi24uuq
      Installing build dependencies: started
      Installing build dependencies: finished with status 'done'
      Getting requirements to build wheel: started
      Getting requirements to build wheel: finished with status 'done'
      Preparing metadata (pyproject.toml): started
      Preparing metadata (pyproject.toml): finished with status 'done'
    Collecting sp-repo-review==2023.08.03
      Obtaining dependency information for sp-repo-review==2023.08.03 from https://files.pythonhosted.org/packages/88/fb/65ca8b7550de38f6cde1daa3cfe57160af3fc2f807d5993acb0a23ae968b/sp_repo_review-2023.8.3-py3-none-any.whl.metadata
      Using cached sp_repo_review-2023.8.3-py3-none-any.whl.metadata (10 kB)
    Collecting pyyaml (from sp-repo-review==2023.08.03)
      Obtaining dependency information for pyyaml from https://files.pythonhosted.org/packages/28/09/55f715ddbf95a054b764b547f617e22f1d5e45d83905660e9a088078fe67/PyYAML-6.0.1-cp311-cp311-macosx_11_0_arm64.whl.metadata
      Using cached PyYAML-6.0.1-cp311-cp311-macosx_11_0_arm64.whl.metadata (2.1 kB)
    INFO: pip is looking at multiple versions of sp-repo-review to determine which version is compatible with other requirements. This could take a while.
    
    The conflict is caused by:
        The user requested repo-review 0.1.dev1+gb62cba7 (from /Users/wjamieson/.cache/pre-commit/repommi24uuq)
        sp-repo-review 2023.8.3 depends on repo-review<0.10 and >=0.7
    
    To fix this you could try to:
    1. loosen the range of package versions you've specified
    2. remove package versions to allow pip attempt to solve the dependency conflict
stderr:
    ERROR: Cannot install repo-review 0.1.dev1+gb62cba7 (from /Users/wjamieson/.cache/pre-commit/repommi24uuq) and sp-repo-review==2023.8.3 because these package versions have conflicting dependencies.
    ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/topics/dependency-resolution/#dealing-with-dependency-conflicts
Check the log at /Users/wjamieson/.cache/pre-commit/pre-commit.log

When I examine the version of repo-review installed by pre-commit I find that its generated _version.py is:

# file generated by setuptools_scm
# don't change, don't track in version control
__version__ = version = '0.1.dev1+gb62cba7'
__version_tuple__ = version_tuple = (0, 1, 'dev1', 'gb62cba7')

which indicates to me that the dynamic versioning for repo-review is not correctly creating the version from the repo's tag.

Note that when I run sp-repo-review directly, I do get the right versions

❯ pipx run 'sp-repo-review[cli]' --version
sp-repo-review, version 0.9.2
@WilliamJamieson
Copy link
Author

The log file's contents:

version information

pre-commit version: 3.3.3
git --version: git version 2.39.2 (Apple Git-143)
sys.version:
    3.11.4 (main, Jul 25 2023, 17:36:13) [Clang 14.0.3 (clang-1403.0.22.14.1)]
sys.executable: /Users/wjamieson/.local/pipx/venvs/pre-commit/bin/python
os.name: posix
sys.platform: darwin

error information

An unexpected error has occurred: CalledProcessError: command: ('/Users/wjamieson/.cache/pre-commit/repommi24uuq/py_env-python3.11/bin/python', '-mpip', 'install', '.', 'sp-repo-review==2023.08.03')
return code: 1
stdout:
    Processing /Users/wjamieson/.cache/pre-commit/repommi24uuq
      Installing build dependencies: started
      Installing build dependencies: finished with status 'done'
      Getting requirements to build wheel: started
      Getting requirements to build wheel: finished with status 'done'
      Preparing metadata (pyproject.toml): started
      Preparing metadata (pyproject.toml): finished with status 'done'
    Collecting sp-repo-review==2023.08.03
      Obtaining dependency information for sp-repo-review==2023.08.03 from https://files.pythonhosted.org/packages/88/fb/65ca8b7550de38f6cde1daa3cfe57160af3fc2f807d5993acb0a23ae968b/sp_repo_review-2023.8.3-py3-none-any.whl.metadata
      Using cached sp_repo_review-2023.8.3-py3-none-any.whl.metadata (10 kB)
    Collecting pyyaml (from sp-repo-review==2023.08.03)
      Obtaining dependency information for pyyaml from https://files.pythonhosted.org/packages/28/09/55f715ddbf95a054b764b547f617e22f1d5e45d83905660e9a088078fe67/PyYAML-6.0.1-cp311-cp311-macosx_11_0_arm64.whl.metadata
      Using cached PyYAML-6.0.1-cp311-cp311-macosx_11_0_arm64.whl.metadata (2.1 kB)
    INFO: pip is looking at multiple versions of sp-repo-review to determine which version is compatible with other requirements. This could take a while.
    
    The conflict is caused by:
        The user requested repo-review 0.1.dev1+gb62cba7 (from /Users/wjamieson/.cache/pre-commit/repommi24uuq)
        sp-repo-review 2023.8.3 depends on repo-review<0.10 and >=0.7
    
    To fix this you could try to:
    1. loosen the range of package versions you've specified
    2. remove package versions to allow pip attempt to solve the dependency conflict
stderr:
    ERROR: Cannot install repo-review 0.1.dev1+gb62cba7 (from /Users/wjamieson/.cache/pre-commit/repommi24uuq) and sp-repo-review==2023.8.3 because these package versions have conflicting dependencies.
    ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/topics/dependency-resolution/#dealing-with-dependency-conflicts
Traceback (most recent call last):
  File "/Users/wjamieson/.local/pipx/venvs/pre-commit/lib/python3.11/site-packages/pre_commit/error_handler.py", line 73, in error_handler
    yield
  File "/Users/wjamieson/.local/pipx/venvs/pre-commit/lib/python3.11/site-packages/pre_commit/main.py", line 414, in main
    return run(args.config, store, args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/wjamieson/.local/pipx/venvs/pre-commit/lib/python3.11/site-packages/pre_commit/commands/run.py", line 442, in run
    install_hook_envs(to_install, store)
  File "/Users/wjamieson/.local/pipx/venvs/pre-commit/lib/python3.11/site-packages/pre_commit/repository.py", line 248, in install_hook_envs
    _hook_install(hook)
  File "/Users/wjamieson/.local/pipx/venvs/pre-commit/lib/python3.11/site-packages/pre_commit/repository.py", line 95, in _hook_install
    lang.install_environment(
  File "/Users/wjamieson/.local/pipx/venvs/pre-commit/lib/python3.11/site-packages/pre_commit/languages/python.py", line 214, in install_environment
    lang_base.setup_cmd(prefix, install_cmd)
  File "/Users/wjamieson/.local/pipx/venvs/pre-commit/lib/python3.11/site-packages/pre_commit/lang_base.py", line 86, in setup_cmd
    cmd_output_b(*cmd, cwd=prefix.prefix_dir, **kwargs)
  File "/Users/wjamieson/.local/pipx/venvs/pre-commit/lib/python3.11/site-packages/pre_commit/util.py", line 110, in cmd_output_b
    raise CalledProcessError(returncode, cmd, stdout_b, stderr_b)
pre_commit.util.CalledProcessError: command: ('/Users/wjamieson/.cache/pre-commit/repommi24uuq/py_env-python3.11/bin/python', '-mpip', 'install', '.', 'sp-repo-review==2023.08.03')
return code: 1
stdout:
    Processing /Users/wjamieson/.cache/pre-commit/repommi24uuq
      Installing build dependencies: started
      Installing build dependencies: finished with status 'done'
      Getting requirements to build wheel: started
      Getting requirements to build wheel: finished with status 'done'
      Preparing metadata (pyproject.toml): started
      Preparing metadata (pyproject.toml): finished with status 'done'
    Collecting sp-repo-review==2023.08.03
      Obtaining dependency information for sp-repo-review==2023.08.03 from https://files.pythonhosted.org/packages/88/fb/65ca8b7550de38f6cde1daa3cfe57160af3fc2f807d5993acb0a23ae968b/sp_repo_review-2023.8.3-py3-none-any.whl.metadata
      Using cached sp_repo_review-2023.8.3-py3-none-any.whl.metadata (10 kB)
    Collecting pyyaml (from sp-repo-review==2023.08.03)
      Obtaining dependency information for pyyaml from https://files.pythonhosted.org/packages/28/09/55f715ddbf95a054b764b547f617e22f1d5e45d83905660e9a088078fe67/PyYAML-6.0.1-cp311-cp311-macosx_11_0_arm64.whl.metadata
      Using cached PyYAML-6.0.1-cp311-cp311-macosx_11_0_arm64.whl.metadata (2.1 kB)
    INFO: pip is looking at multiple versions of sp-repo-review to determine which version is compatible with other requirements. This could take a while.
    
    The conflict is caused by:
        The user requested repo-review 0.1.dev1+gb62cba7 (from /Users/wjamieson/.cache/pre-commit/repommi24uuq)
        sp-repo-review 2023.8.3 depends on repo-review<0.10 and >=0.7
    
    To fix this you could try to:
    1. loosen the range of package versions you've specified
    2. remove package versions to allow pip attempt to solve the dependency conflict
stderr:
    ERROR: Cannot install repo-review 0.1.dev1+gb62cba7 (from /Users/wjamieson/.cache/pre-commit/repommi24uuq) and sp-repo-review==2023.8.3 because these package versions have conflicting dependencies.
    ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/topics/dependency-resolution/#dealing-with-dependency-conflicts

@henryiii
Copy link
Collaborator

It isn't doing a full checkout. With the shallow checkout, it's not able to figure out its own version. If we have to give up svn versioning, we could do that, but work investigating a bit. It's right on a tag, so I'd have thought it would still be able to use that.

@henryiii
Copy link
Collaborator

Hmm, psf/black uses the same versioning method. Maybe it's not usually a problem because usually you don't check the version with a dependency?

@WilliamJamieson
Copy link
Author

I just tried removing the additional_dependencies after running pre-commit clean and then checking the _version.py in the new virtual environment it created for it; however, the generated file remains the same.

@henryiii
Copy link
Collaborator

henryiii commented Aug 10, 2023

Pre-commit recently changed its checkout method to make it faster, it could have broken this. It's also possible that it rarely matters, since normally you don't have pinning between the repo and the additional dependencies.

Two possible fixes (other than removing VCS versioning): you can use the cookie repo as a pre-commit (it's supported, see https://pypi.org/project/sp-repo-review/). Or we can remove the pinning in sp-repo-review on repo-review (PR above) - it's really not that important and sometimes causes issues. It's better to just fix quickly than try to guess breakages.

@WilliamJamieson
Copy link
Author

you can use the cookie repo as a pre-commit (it's supported, see pypi.org/project/sp-repo-review).

Found a few small issues with the sp-repo-review hook as well, see scientific-python/cookie#257 for a possible solution which seems to solve all the issues I was having.

@henryiii
Copy link
Collaborator

henryiii commented Aug 10, 2023

I think we need to make a mirror. I don't see a way to install [cli] here (additional_dependenices won't work, since users have to override it). There's also the same bug with passing files - I think I'll delete the current file and make a mirror.

Though extras aren't currently supported, made pre-commit/pre-commit-mirror-maker#185.

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

No branches or pull requests

2 participants