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

IndexError with my .gitignore file when trying to build a Python package #64

Closed
haimat opened this issue Nov 8, 2022 · 4 comments
Closed

Comments

@haimat
Copy link

haimat commented Nov 8, 2022

Problem description

I am trying to package my Python project/library. So first I created a pyproject.toml file, following the official Python docs, using hatchling - no fancy stuff here. Then, after upgrading to the latest build version, I ran this command from within the root folder of my project:

$ python -m build
* Creating venv isolated environment...
* Installing packages in isolated environment... (hatchling)
* Getting build dependencies for sdist...
* Building sdist...
Traceback (most recent call last):
  File "/home/mfb/.local/lib/python3.8/site-packages/pep517/in_process/_in_process.py", line 351, in <module>
    main()
  File "/home/mfb/.local/lib/python3.8/site-packages/pep517/in_process/_in_process.py", line 333, in main
    json_out['return_val'] = hook(**hook_input['kwargs'])
  File "/home/mfb/.local/lib/python3.8/site-packages/pep517/in_process/_in_process.py", line 302, in build_sdist
    return backend.build_sdist(sdist_directory, config_settings)
  File "/tmp/build-env-bgb1kk5q/lib/python3.8/site-packages/hatchling/build.py", line 21, in build_sdist
    return os.path.basename(next(builder.build(sdist_directory, ['standard'])))
  File "/tmp/build-env-bgb1kk5q/lib/python3.8/site-packages/hatchling/builders/plugin/interface.py", line 144, in build
    artifact = version_api[version](directory, **build_data)
  File "/tmp/build-env-bgb1kk5q/lib/python3.8/site-packages/hatchling/builders/sdist.py", line 156, in build_standard
    for included_file in self.recurse_included_files():
  File "/tmp/build-env-bgb1kk5q/lib/python3.8/site-packages/hatchling/builders/plugin/interface.py", line 168, in recurse_included_files
    yield from self.recurse_project_files()
  File "/tmp/build-env-bgb1kk5q/lib/python3.8/site-packages/hatchling/builders/plugin/interface.py", line 182, in recurse_project_files
    if self.config.include_path(relative_file_path, is_package=is_package):
  File "/tmp/build-env-bgb1kk5q/lib/python3.8/site-packages/hatchling/builders/config.py", line 82, in include_path
    and (explicit or self.path_is_included(relative_path))
  File "/tmp/build-env-bgb1kk5q/lib/python3.8/site-packages/hatchling/builders/config.py", line 90, in path_is_included
    return self.include_spec.match_file(relative_path)
  File "/tmp/build-env-bgb1kk5q/lib/python3.8/site-packages/pathspec/pathspec.py", line 176, in match_file
    return self._match_file(self.patterns, norm_file)
  File "/tmp/build-env-bgb1kk5q/lib/python3.8/site-packages/pathspec/gitignore.py", line 104, in _match_file
    dir_mark = match.match.group('ps_d')
IndexError: no such group

ERROR Backend subprocess exited when trying to invoke build_sdist

I do have a .gitignore file in my root folder, however, it includes only the default Python project template from Github.

Any ideas what is causing this error?

@cpburnz
Copy link
Owner

cpburnz commented Nov 10, 2022

@haimat Thanks for reporting this. I'm uncertain if this is a bug with pathspec or hatchling. I haven't been able to reproduce this using a simple project using hatchling (see example below).

What do you have in your pyproject.toml? In particular, what are your settings for hatchling and hatch? What's the folder structure of your project?


Example

Files:

  • .gitignore
  • pyproject.toml
  • issue_64/
    • __init__.py
    • issue_64.py

pyproject.toml contains:

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "issue_64"
version = "0.0.1"

.gitignore is from https://github.com/github/gitignore/blob/main/Python.gitignore.

issue_64/__init__.py is empty.

issue_64/issue_64.py is empty.

The output from python3.8 -m build is:

* Creating venv isolated environment...
* Installing packages in isolated environment... (hatchling)
* Getting build dependencies for sdist...
* Building sdist...
* Building wheel from sdist
* Creating venv isolated environment...
* Installing packages in isolated environment... (hatchling)
* Getting build dependencies for wheel...
* Building wheel...
Successfully built issue_64-0.0.1.tar.gz and issue_64-0.0.1-py2.py3-none-any.whl

@cpburnz
Copy link
Owner

cpburnz commented Nov 10, 2022

@haimat I have a way to debug this.

I created a new branch which will rethrow the error with some debugging information. Modify your pyproject.toml to include:

[build-system]
requires = [
	"hatchling",
	# Inject debug build of pathspec.
	"pathspec @ git+ssh://git@github.com/cpburnz/python-pathspec.git@detect-64",
]

A GitWildMatchPatternError error will be raised instead of the IndexError, and it will contain the info. When you get a chance, please try this and let me know what the resulting error is.

@haimat
Copy link
Author

haimat commented Nov 11, 2022

Ok I found the problem in my pyproject.toml file:

include = [
  "**"
]

As soon as I have removed this option, everything was fine again.

@cpburnz
Copy link
Owner

cpburnz commented Nov 13, 2022

@haimat Thanks, the ** pattern is now fixed in the new release v0.10.2.

@cpburnz cpburnz closed this as completed Nov 13, 2022
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