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

Schema validation for hatch fails with [tool.hatch.env] #31

Open
kratsg opened this issue Apr 20, 2024 · 9 comments
Open

Schema validation for hatch fails with [tool.hatch.env] #31

kratsg opened this issue Apr 20, 2024 · 9 comments

Comments

@kratsg
Copy link

kratsg commented Apr 20, 2024

In the hatch documentation, if one wants to use a different environment type, then you need to specify, for instance with juftin/hatch-pip-compile

[tool.hatch.env]
requires = [
    "hatch-pip-compile"
]

However, the current schema definition seems to fail with

Invalid file: pyproject.toml
[ERROR] `tool.hatch` must not contain {'env'} properties

I'm not sure if this is expected, as I'm having a hard time reading the associated PEPs to understand (and digging into the code to understand what is expected).

@henryiii
Copy link
Owner

@henryiii
Copy link
Owner

@flying-sheep, was this hand written or generated somehow?

@kratsg
Copy link
Author

kratsg commented Apr 20, 2024

The part that's a bit confusing is one can see the definitions in the schema: https://github.com/SchemaStore/schemastore/blob/7a7f32e81810a8909773810564fe52b43f31bcd4/src/schemas/json/hatch.json#L376-L413 with requires right there, but it seems to be that the .env portion of the definition is at the CollectorEnv level: https://github.com/SchemaStore/schemastore/blob/7a7f32e81810a8909773810564fe52b43f31bcd4/src/schemas/json/hatch.json#L890-L892.

My pre-commit is:

  - repo: https://github.com/abravalheri/validate-pyproject
    rev: "v0.16"
    hooks:
      - id: validate-pyproject
        additional_dependencies: ["validate-pyproject-schema-store[all]"]
        stages: [manual] # temporarily disable

Am I just maybe somehow pinned to an older version of the schema store?

@henryiii
Copy link
Owner

henryiii commented Apr 20, 2024

Ahh, I think this might not be updating. It should have changed in SchemaStore/schemastore@c20b9a0 but don't see anything in our last release. Oh, maybe it was the previous release, it does seem to be there.

Ahh, let's just add your snippet as a test.

@henryiii
Copy link
Owner

Ahh, you are not pinning on us, so it's using an old cached version. Pre-commit globally caches. If you put >=2024.04.20 or probably 2024.04.08 is fine, it should work.

You can instead put this repo as your pre-commit hook, then it pins on this instead of validate-pyproject.

@kratsg
Copy link
Author

kratsg commented Apr 20, 2024

Ahh, you are not pinning on us, so it's using an old cached version. Pre-commit globally caches. If you put >=2024.04.20 or probably 2024.04.08 is fine, it should work.

I did follow the README instructions you have in this project

```yaml
repos:
- repo: https://github.com/abravalheri/validate-pyproject
rev: <insert here>
hooks:
- id: validate-pyproject
additional_dependencies: [validate-pyproject[all], validate-pyproject-schema-store]
```
so it's not clear to me what I messed up initially. I can re-clear and update pre-commit, but I can also add a >= in additional dependencies.

@henryiii
Copy link
Owner

I'd add >= whenever you start using a new hatch feature that was added at some point, such as >=2024.04.08 for .env.

The other way to do it would be to use

repos:
  - repo: https://github.com/henryiii/validate-pyproject-schema-store
    rev: <insert here>
    hooks:
      - id: validate-pyproject

Which is an alternative suggested in the README.

@kratsg
Copy link
Author

kratsg commented Apr 24, 2024

So the former suggestion you mentioned doesn't work for me using

  - repo: https://github.com/abravalheri/validate-pyproject
    rev: "v0.16"
    hooks:
      - id: validate-pyproject
        additional_dependencies: ["validate-pyproject-schema-store[all]>=2024.04.08"]

which gives

$ pre-commit run --all-files
[INFO] Initializing environment for https://github.com/abravalheri/validate-pyproject:validate-pyproject-schema-store[all]>=2024.04.08.
[INFO] Installing environment for https://github.com/abravalheri/validate-pyproject.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: CalledProcessError: command: ('/Users/kratsg/.cache/pre-commit/repo7mvk_xvx/py_env-python3.8/bin/python', '-mpip', 'install', '.', 'validate-pyproject-schema-store[all]>=2024.04.08')
return code: 1
stdout:
    Processing /Users/kratsg/.cache/pre-commit/repo7mvk_xvx
      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'
      Installing backend dependencies: started
      Installing backend dependencies: finished with status 'done'
      Preparing metadata (pyproject.toml): started
      Preparing metadata (pyproject.toml): finished with status 'done'
    Collecting validate-pyproject-schema-store>=2024.04.08 (from validate-pyproject-schema-store[all]>=2024.04.08)
      Downloading validate_pyproject_schema_store-2024.4.20-py3-none-any.whl.metadata (4.1 kB)
    Collecting fastjsonschema<=3,>=2.16.2 (from validate-pyproject==0.0.post1.dev1+g34b52d9)
      Using cached fastjsonschema-2.19.1-py3-none-any.whl.metadata (2.1 kB)
    Collecting importlib-resources (from validate-pyproject-schema-store>=2024.04.08->validate-pyproject-schema-store[all]>=2024.04.08)
      Using cached importlib_resources-6.4.0-py3-none-any.whl.metadata (3.9 kB)
    INFO: pip is looking at multiple versions of validate-pyproject-schema-store[all] to determine which version is compatible with other requirements. This could take a while.
    Collecting validate-pyproject-schema-store[all]>=2024.04.08
      Downloading validate_pyproject_schema_store-2024.4.8-py3-none-any.whl.metadata (4.1 kB)

    The conflict is caused by:
        The user requested validate-pyproject 0.0.post1.dev1+g34b52d9 (from /Users/kratsg/.cache/pre-commit/repo7mvk_xvx)
        validate-pyproject-schema-store[all] 2024.4.20 depends on validate-pyproject>=0.16; extra == "all"
        The user requested validate-pyproject 0.0.post1.dev1+g34b52d9 (from /Users/kratsg/.cache/pre-commit/repo7mvk_xvx)
        validate-pyproject-schema-store[all] 2024.4.8 depends on validate-pyproject>=0.16; extra == "all"

    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 validate-pyproject 0.0.post1.dev1+g34b52d9 (from /Users/kratsg/.cache/pre-commit/repo7mvk_xvx), validate-pyproject-schema-store[all]==2024.4.20 and validate-pyproject-schema-store[all]==2024.4.8 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/kratsg/.cache/pre-commit/pre-commit.log

so I'll switch to using this repo as the source for the pre-commit hook.

@henryiii
Copy link
Owner

Ahh, yes, that’s a pre-commit quirk, svn versioning no longer works for the main repo being checked out. Maybe we should drop the min version requirement.

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