henryiii / validate-pyproject-schema-store

Weekly mirror of SchemaStore for validate-pyproject
Apache License 2.0
1 stars 0 forks source link

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

Open kratsg opened 2 months ago

kratsg commented 2 months ago

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 commented 2 months ago

https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/hatch.json probably needs to be fixed, then.

henryiii commented 2 months ago

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

kratsg commented 2 months ago

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 commented 2 months ago

Ahh, I think this might not be updating. It should have changed in https://github.com/SchemaStore/schemastore/commit/c20b9a01ec850d7bf19559bd7e20d565b74f3832 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 commented 2 months ago

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 commented 2 months ago

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 https://github.com/henryiii/validate-pyproject-schema-store/blob/353a7a8a74a6c3aa552c21e8017b9e5629a7981e/README.md?plain=1#L25-L32 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 commented 2 months ago

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 commented 2 months ago

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 commented 2 months ago

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.