pypa / packaging-problems

An issue tracker for the problems in packaging
151 stars 35 forks source link

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

Closed haimat closed 2 years ago

haimat commented 2 years ago

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?

ofek commented 2 years ago

Please open an issue: https://github.com/cpburnz/python-pathspec

For now you can: https://hatch.pypa.io/latest/config/build/#vcs

haimat commented 2 years ago

@ofek Done. As reference: https://github.com/cpburnz/python-pathspec/issues/64

haimat commented 2 years ago

@ofek I have followed your advice and tried it with the following option in my pyproject.toml file:

[tool.hatch.build]
ignore-vcs = true

Unfortunately that does not change anything, I get the same error as before.

ofek commented 2 years ago

show pyproject.toml

haimat commented 2 years ago

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

include = [
  "**"
]

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