hatch icon indicating copy to clipboard operation
hatch copied to clipboard

[`1.16.0`] `hatch version` fails with "No module named hatchling"

Open dhirschfeld opened this issue 1 month ago • 9 comments

CI broke yesterday with the above error when running hatch version.

Pinning hatch<1.16 fixed the problem for us.

dhirschfeld avatar Nov 27 '25 21:11 dhirschfeld

Please provide more information about where this is being run, what OS? What Python version? How hatch is being installed in your CI?

cjames23 avatar Nov 27 '25 23:11 cjames23

Linux container in CI Python version 3.10. Hatch is being installed from PyPI using pixi.

Image

The output from CI is:

++ hatch version
Creating environment: hatch-build
Checking dependencies
Syncing dependencies
Inspecting build dependencies
/home/runner/.local/share/hatch/env/virtual/mypkg/dkW19B8f/hatch-build/bin/python: No module named hatchling
+ version=
Error: Process completed with exit code 1.

dhirschfeld avatar Nov 27 '25 23:11 dhirschfeld

Just tested with 1.16.1:

Image

Same error unfortunately.

Edit: hatchling is actually installed.

dhirschfeld avatar Nov 28 '25 00:11 dhirschfeld

I can't repro locally unfortunately

❯ hatch --version
Hatch, version 1.16.1

❯ hatch version
0.47.2.post.dev001+dirty

So, it's something specific to the CI, even though I'm installing the same environment locally as in CI :/

dhirschfeld avatar Nov 28 '25 00:11 dhirschfeld

Are you putting the output of version into GITHUB_OUTPUT? Wondering if it is the same issue as https://github.com/pypa/hatch/issues/2107#event-21232683998 Which there has been a fix that has been merged, expecting to release next week for this.

cjames23 avatar Nov 28 '25 00:11 cjames23

~~Nope - literally just running version=$(hatch version)~~

Actually it's running:

version=$(hatch version)
echo "path=${BUCKET}/${repo#*/}/${folder}/${version}" >> "$GITHUB_OUTPUT"

So yeah - it looks like it's putting the output into GITHUB_OUTPUT (though it doesn't seem to ever get to that line)

Edit: Also, I'm not setting HATCH_VERBOSE

dhirschfeld avatar Nov 28 '25 01:11 dhirschfeld

I mapped my local checkout into a container, installed the env and hatch version works there.

It's just in my CI container where it fails... which is very odd, and very hard to debug :pensive:

dhirschfeld avatar Nov 28 '25 01:11 dhirschfeld

Can you share what your CI setup looks like for steps that install hatch before calling hatch version? I think I have an idea what is causing this but I need to try to reproduce this in a local container.

cjames23 avatar Nov 30 '25 04:11 cjames23

The GitHub Actions code is:

      - id: install_deps
        name: Install doc dependencies
        shell: bash --noprofile --norc -euxo pipefail {0}
        run: python -m pip install -v --no-compile --prefer-binary .[docs] fsspec s3fs

<snip>
# ... docs build correctly here ... #
</snip>

      - id: publish_dir
        name: Determine publish directory
        shell: bash --noprofile --norc -euxo pipefail {0}
        env:
          BUCKET: "<BUCKET>/docs"
        run: |
          # determine the folder to publish to based on the event type
          repo="${{ github.repository }}"
          if [[ ${{ github.event_name }} == "pull_request" ]]; then
            folder="pr/${{ github.event.number }}"
          elif [[ ${{ github.event_name }} == "push" ]]; then
            folder="dev"
          elif [[ ${{ github.event_name }} == "release" ]]; then
            folder="stable"
          else
            echo "Unknown event ${{ github.event_name }}!"
            exit 1
          fi
          version=$(hatch version)  # <--- BOOM!!!
          echo "path=${BUCKET}/${repo#*/}/${folder}/${version}" >> "$GITHUB_OUTPUT"

The docs deps are:

docs = [
  "black>=25.1.0",  # for formatting signatures
  "hatch>=1.14.0",  # for determining the version
  "hatch-vcs>=0.4.0",
  "hatchling>=1.27.0",
  "hippogriffe>=0.2.0",
  "ipykernel>=6.29.5,<7",
  "mkdocs>=1.6.1",
  "mkdocs-autorefs>=1.4.1",
  "mkdocs-gen-files>=0.5.0",
  "mkdocs-jupyter>=0.25.1",
  "mkdocs-literate-nav>=0.6.2",
  "mkdocs-material>=9.6.10",
  "mkdocs-material-extensions>=1.3.1",
  "mkdocs-section-index>=0.3.9",
  "mkdocstrings>=0.29.1",
  "mkdocstrings-python>=1.16.8",
  "nbconvert>=7.16.5",  # https://github.com/jupyter/nbconvert/releases/tag/v7.16.5
  "numpydoc>=1.8.0",
]

dhirschfeld avatar Dec 01 '25 11:12 dhirschfeld