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

KeyError: b'HEAD' #6873

Closed
4 tasks done
adam-grant-hendry opened this issue Oct 23, 2022 · 25 comments
Closed
4 tasks done

KeyError: b'HEAD' #6873

adam-grant-hendry opened this issue Oct 23, 2022 · 25 comments
Labels
kind/bug Something isn't working as expected status/triage This issue needs to be triaged

Comments

@adam-grant-hendry
Copy link

  • Poetry version: 1.2.2
  • Python version: 3.8.10
  • OS version and name: Windows 10, 21H2
pyproject.toml
[tool.poetry]
name = "qtpygraph"
version = "0.2.0"
description = "A pythonic interface to the Qt Graphics View Framework using qtpy"
authors = ["Hendry, Adam <adam.grant.hendry@gmail.com>"]
license = "Apache-2.0"
readme = "README.md"
repository = "https://github.com/adam-grant-hendry/qtpygraph"
classifiers = [
    "License :: OSI Approved :: Apache Software License",
    "Operating System :: Microsoft :: Windows :: Windows 10",
    "Operating System :: MacOS :: MacOS X",
    "Operating System :: POSIX :: Linux",
    "Programming Language :: Python :: 3",
    "Programming Language :: Python :: 3.8",
    "Programming Language :: Python :: 3.9",
    "Programming Language :: Python :: 3.10"
]
packages = [
    {include = "docs"},
    {include = "qtpygraph"},
    {include = "tests"},
    {include = "stubs"}
]

[tool.poetry.dependencies]
add-trailing-comma = ">=2.2.3"
appdirs = ">=1.4.4"
bandit = { extras = ["toml"], version = ">=1.7.4" }
beautifulsoup4 = ">=4.11.1"
black = ">=22.3.0"
blackdoc = ">=0.3.4"
blacken-docs = ">=1.12.1"
check-jsonschema = ">=0.14.3"
codecov = ">=2.1.12"
codespell = ">=2.1.0"
commitizen = { git = "https://github.com/adam-grant-hendry/commitizen.git", branch = "feat/unicode" }
coverage = { extras = ["toml"], version = ">=6.4" }
doc8 = ">=0.11.2"
docformatter = ">=1.4"
flake8 = ">=4.0.1"
flake8-bugbear = ">=22.9.11"
flake8-quotes = ">=3.3.1"
glfw = ">=2.5.3"
graphviz = ">=0.20"
h5py = ">=3.6.0"
html5lib = ">=1.1"
hypothesis = ">=6.46.2"
instaviz = ">=0.6.0"
ipdb = ">=0.13.9"
ipython = ">=8.3.0"
isort = ">=5.10.1"
lxml = ">=4.8.0"
matplotlib = ">=3.5.2"
memory-profiler = ">=0.60.0"
merry = ">=0.3.0"
mypy = ">=0.961"
mypy-extensions = ">=0.4.3"
myst-parser = ">=0.17.2"
ninja = ">=1.10.2"
numpy = ">=1.22.3"
numpydoc = ">=1.4.0"
objgraph = ">=3.5.0"
opencv-python = ">=4.5.5.64"
pep8-naming = ">=0.12.1"
pre-commit = ">=2.18.1"
pycln = ">=1.3.5"
pydantic = ">=1.9.1"
pydocstringformatter = ">=0.7.0"
pydocstyle = { extras = ["toml"], version = ">=6.1.1" }
pyinstaller = ">=5.1"
pylint = ">=2.13.8"
pyright = ">=1.1.253"
pytest = ">=7.1.2"
pytest-cov = ">=3.0.0"
pytest-doctestplus = ">=0.12.0"
pytest-env = ">=0.6.2"
pytest-memprof = ">=0.2.0"
pytest-mock = ">=3.7.0"
pytest-qt = ">=4.0.2"
pytest-randomly = ">=3.11.0"
pytest-xdist = ">=2.5.0"
python = ">=3.8,<3.11"
pyupgrade = ">=2.34.0"
PyYAML = ">=6.0"
QtPy = ">=2.1.0"
requests = ">=2.27.1"
rstcheck = { extras = ["toml", "sphinx" ], version = ">=5.0.0" }
seedir = ">=0.3.0"
setuptools = "^65.3.0"
setuptools-scm = "^7.0.5"
Sphinx = ">=4.5.0"
sphinx-book-theme = "^0.3.3"
sphinxcontrib-email = ">=0.3.5"
sphinxcontrib-mermaid = "^0.7.1"
sphinxcontrib-napoleon = ">=0.7"
toml = ">=0.10.2"
tomli = ">=2.0.1"
tox = ">=3.25.0"
tqdm = ">=4.64.0"
tqdm-stubs = ">=0.2.0"
types-beautifulsoup4 = ">=4.11.1"
types-setuptools = ">=57.4.17"
types-toml = ">=0.10.7"
typing-extensions = ">=4.2.0"
vulture = ">=2.3"
wheel = ">=0.37.1"
sphinx-rtd-theme = "^1.0.0"

[tool.bandit]
skips = [
    "B101",
    "B301",
    "B403",
]

[tool.black]
line-length = 90
skip-string-normalization = true
target-version = ["py38"]
include = '.*\.pyi?$'
exclude = '\.eggs|\.git|\.mypy_cache|\.tox|\.venv|build|dist'

[tool.commitizen]
name = "cz_customize"
version = "0.2.0"
version_files = [
    "pyproject.toml:version",
]
update_changelog_on_bump = true
annotated_tag = true
tag_format = "$version"
style = [
    ["qmark", "fg:#ff9d00 bold"],
    ["question", "italic"],
    ["answer", "fg:#ff9d00 bold"],
    ["pointer", "fg:#ff9d00 bold"],
    ["highlighted", "fg:#ff9d00 bold"],
    ["selected", "fg:#cc5454"],
    ["separator", "fg:#cc5454"],
    ["instruction", ""],
    ["text", ""],
    ["disabled", "fg:#858585 italic"]
]

[tool.commitizen.customize]
message_template = "{{change_type}}({{scope}}){% if is_breaking_change == true %}!{% endif %}: {{subject}}{% if body %}\n\n{{body}}{% endif %}{% if footer %}\n\n{{footer}}{% endif %}"
schema_pattern = '(✨ feat|🐛 fix|♻️ refactor|📚 docs|🚀 release|🤖 ci|🧪 test|⬆️ perf|🗑️ deprecate|🧹 style|❓ other)(\(\S+\))?!?:(\s.*)'
bump_pattern = '^((?:✨ )feat|(?:🐛 )fix|(?:♻️ )refactor|(?:📚 )docs|(?:🚀 )release|(?:🤖 )ci|(?:🧪 )test|(?:⬆️ )perf|(?:🗑️ )deprecate|(?:🧹 )style|(?:❓ )other)(\(.+\))?(!)?'
bump_map = { ".*!" = "MAJOR", "✨ feat" = "MINOR", "🐛 fix" = "PATCH", "♻️ refactor" = "PATCH", "📚 docs" = "PATCH", "🚀 release" = "PATCH", "🤖 ci" = "PATCH", "🧪 test" = "PATCH", "⬆️ perf" = "PATCH", "🗑️ deprecate" = "PATCH", "🧹 style" = "PATCH", "❓ other" = "PATCH" }
change_type_order = ["!", "✨ feat", "🐛 fix", "♻️ refactor", "📚 docs", "🚀 release", "🤖 ci", "🧪 test", "⬆️ perf", "🗑️ deprecate", "🧹 style", "❓ other"]
commit_parser = '^(?P<change_type>(?:✨ )feat|🐛 fix|♻️ refactor|📚 docs|🚀 release|🤖 ci|🧪 test|⬆️ perf|🗑️ deprecate|🧹 style|❓ other)(?:\((?P<scope>[^()\r\n]*)\)|\()?(?P<breaking>!)?:\s(?P<message>.*)?'
changelog_pattern = '^(feat|🐛 fix|♻️ refactor|📚 docs|🚀 release|🤖 ci|🧪 test|⬆️ perf|🗑️ deprecate|🧹 style|❓ other)?(?:[)])(!)?'
change_type_map = { "✨ feat" = "Feat", "🐛 fix" = "Fix", "♻️ refactor" = "Refactor", "📚 docs" = "Docs", "🚀 release" = "Release", "🤖 ci" = "CI", "🧪 test" = "Test", "⬆️ perf" = "Performance", "🗑️ deprecate" = "Deprecate", "🧹 style" = "Style", "❓ other" = "Other"}

[[tool.commitizen.customize.questions]]
name = "change_type"
type = "list"
message = "Select the type of change you are committing"
choices = [
    { value = "✨ feat", name = "✨ feat: (Bumps MINOR) Add/remove an item/feature" },
    { value = "🐛 fix", name = "🐛 fix: (Bumps PATCH) Fix/modify an existing item/feature" },
    { value = "♻️ refactor", name = "♻️  refactor: (Bumps PATCH) Reorganizes item(s); not a 'feat' or 'fix'" },
    { value = "📚 docs", name = "📚 docs: (Bumps X) Does Y" },
    { value = "🚀 release", name = "🚀 release: (Bumps X) Does Y" },
    { value = "🤖 ci", name = "🤖 ci: (Bumps X) Does Y" },
    { value = "🧪 test", name = "🧪 test: (Bumps X) Does Y" },
    { value = "⬆️ perf", name = "⬆️  perf: (Bumps X) Does Y" },
    { value = "🗑️ deprecate", name = "🗑️  deprecate: (Bumps X) Does Y" },
    { value = "🧹 style", name = "🧹 style: (Bumps X) Does Y" },
    { value = "❓ other", name = "❓ other: (Bumps X) Does Y" },
]

[[tool.commitizen.customize.questions]]
name = "scope"
type = "input"
message = "Scope. Enter the scope of the change, category first (docs/test/ci/build/perf), followed by class or file name if applicable (comma-separated, no spaces):\n"

[[tool.commitizen.customize.questions]]
name = "subject"
type = "input"
message = "Subject. Enter the short summary of the change (imperative tone, lowercase, no period):\n"

[[tool.commitizen.customize.questions]]
name = "is_breaking_change"
type = "confirm"
message = "Is this a BREAKING CHANGE (backwards incompatible)? (Bumps MAJOR; default: N):\n"
default = false

[[tool.commitizen.customize.questions]]
name = "body"
type = "input"
message = "Body. Enter complete details about the change (use full sentences with proper grammar): (press [enter] to skip):\n"

[[tool.commitizen.customize.questions]]
name = "footer"
type = "input"
message = "Footer. Reference any Issues this change addresses. If a BREAKING CHANGE, enter details. (press [enter] to skip):\n"

[tool.coverage.run]
branch = true
# Append machine name, process id, and random number to data file name so coverage can be
# run in parallel environments, e.g. in tox.
parallel = true
# `shiboken6`, which creates the python bindings for `Qt` C++ source, imports from a
# `zip` file into the top-level directory at runtime. These files are deleted after
# running, but `coverage` attempts to look at their source after they're gone, causing
# warnings to appear. Namely, it looks for these modules/files:
#
#    project_dir/pysrcript
#    project_dir/shibokensupport
#    project_dir/signature_bootstrap.py
#
# To avoid this error, `source` is specified to the package subdirectory. However, this
# can also be avoided by explicitly omitting these folders in the `omit` section.
#
# See https://github.com/nedbat/coveragepy/issues/1392
source = [
    'qtpygraph/'
]
omit = [
    'qtpygraph/__main__.py',
    '.vscode/',
    '.venv/',
    'tests/',
    'stubs/'
]
disable_warnings = ['no-data-collected']

[tool.coverage.html]
directory = 'logs/coverage/html'

[tool.coverage.json]
output = 'logs/coverage/coverage.json'

[tool.coverage.xml]
output = 'logs/coverage/coverage.xml'

[tool.coverage.report]
exclude_lines = [
    'pragma: no cover',
    'def __repr__',
    'raise AssertionError',
    'raise NotImplementedError',
    'if __name__ == .__main__.:',
    '@(abc\.)?abstractmethod'
]

[tool.coverage.paths]
source = [
    "qtpygraph/",
    "*/site-packages"
]
others = [
    "qtpygraph/",
    "*/qtpygraph",
]

[tool.doc8]
ignore = [
    "D004"  # Ignore CRLF (Not working: see https://github.com/PyCQA/doc8/issues/78)
]
max-line-length = 90

[tool.isort]
profile = "black"
add_imports = [
    "from __future__ import annotations"  # Automatically add to module on save if not there
]
multi_line_output = 3
include_trailing_comma = true
force_grid_wrap = 0
use_parentheses = true
ensure_newline_before_comments = true
line_length = 90
skip_glob = [
    # Certain packages require a specific sort order
    # See: https://github.com/pyvista/pyvista/issues/3141
    ".venv/Lib/site-packages/*",
]

[tool.mypy]
python_executable = ".venv/Scripts/python.exe"
python_version = "3.8"
disallow_untyped_defs = true
warn_return_any = true
warn_unused_configs = true
# ``warn_unused_ignores`` seems to be giving several false positives.
# See:
#   - https://github.com/python/mypy/issues/4412
#   - https://github.com/python/mypy/issues/5940
#   - https://github.com/python/mypy/issues/8823
#   - https://github.com/python/mypy/issues/2960
warn_unused_ignores = false
warn_redundant_casts = true
show_error_codes = true
no_pretty = true
show_column_numbers = true
plugins = [
    "pydantic.mypy"
]
exclude = [
    'stubs/',
    '[.]venv/',
    'build/',
    'dist/',
    'ci/',
]
fast_module_lookup = true

[[tool.mypy.overrides]]
module = [
    "stubs.*",
]
ignore_errors = true
follow_imports = "skip"
follow_imports_for_stubs = false
ignore_missing_imports = true

[tool.pycln]
all = true
include = '.*\.pyi?$'

[tool.pydocstyle]
convention = "numpy"
ignore = [
    # Magic methods don't need docstrings
    "D105"
]

[tool.pylint.format]
# Ignore ``line-too-long`` errors for hyperlinks, which must remain on one line
ignore-long-lines = "https?://\\S+?$"

[tool.pylint.main]
# ``pylint`` cannot lint (perform static analysis on) C extension modules since it has
# no way to get an AST object out of the extension module. ``extension-pkg-allow-list``
# is a ``pylint`` mechanism through which you can tell ``pylint`` to import C extension
# modules and build an AST from that imported module. Be aware that using this flag
# means ``pylint`` loads extensions into the active Python interpreter and may run
# arbitrary code, which you may not want and is the reason why ``pylint`` disables it by
# default.
# See:
# - https://pylint.pycqa.org/en/latest/user_guide/messages/error/no-member.html?highlight=%22c%20extension%22#no-member-e1101
# - https://github.com/PyCQA/pylint/issues/1524#issuecomment-1214435049
extension-pkg-allow-list = [
    "PyQt5",
    "PyQt6",
    "PySide2",
    "PySide6",
]
fail-under = 10
ignore = [
    ".venv",
]
load-plugins = [
    "pylint.extensions.bad_builtin",
    "pylint.extensions.broad_try_clause",
    "pylint.extensions.check_elif",
    "pylint.extensions.consider_ternary_expression",
    "pylint.extensions.docparams",
    # I like lines between paragraphs
    # "pylint.extensions.empty_comment",
    "pylint.extensions.redefined_loop_name",
    # Untidy data structures require while
    # See: https://pylint.pycqa.org/en/latest/user_guide/messages/warning/while-used.html
    # See: https://stackoverflow.com/questions/920645/when-to-use-while-or-for-in-python
    # "pylint.extensions.while_used",
    "pylint.extensions.for_any_all",
    "pylint.extensions.no_self_use",
    "pylint.extensions.set_membership",
]

[tool.pylint."messages control"]
confidence = []
disable = [
    "too-few-public-methods",
    "too-many-arguments",
    "too-many-instance-attributes",
    "useless-import-alias",
    "fixme"  # TODO's can be useful
]

[tool.pylint.parameter_documentation]
default-docstring-type = "numpy"

[tool.pyright]
defineConstant = [
  { PYSIDE6 = true },
  { PYQT5 = false },
  { PYSIDE2 = false },
  { PYQT6 = false }
]

[tool.pytest.ini_options]
minversion = "7.0"
# We want different runs each time (don't use seed)
# --randomly-seed=1234
addopts = """\
--last-failed --last-failed-no-failures all \
-p no:faulthandler \
--import-mode=importlib \
--cov \
--cov-report term-missing \
--doctest-rst \
--doctest-modules"""
testpaths = [
    "tests",
]
doctest_plus = "enabled"
env = [
    # See https://github.com/pytest-dev/pytest-qt/issues/437
    # "D:PYTEST_QT_API=pyside6",  # pytest-qt
    # "D:QT_API=pyside6"  # qtpy
    # "D:QT_QPA_PLATFORM=offscreen"
    # "D:COVERAGE_DEBUG=trace",
    # "D:COVERAGE_DEBUG_FILE=debug_log.txt"
]
filterwarnings = [
    # Occurs when mocking QWidgets
    'ignore:pyside_type_init:RuntimeWarning'
]

[tool.rstcheck]
# `rstcheck` is known to be buggy on Windows
# See Issue #107: https://github.com/rstcheck/rstcheck/issues/107
ignore_messages = [
    "(Duplicate label .*, other instance in .*)"
]

[tool.tox]
legacy_tox_ini = """
[tox]
minversion = 3.25.0
envlist = py{38,39,310}-{pyqt5,pyside2,pyqt6,pyside6},coverage
isolated_build = true

[gh-actions]
python =
    3.8: py38-{pyqt5,pyside2,pyqt6,pyside6}
    3.9: py39-{pyqt5,pyside2,pyqt6,pyside6}
    3.10: py310-{pyqt5,pyside2,pyqt6,pyside6}

[testenv]
allowlist_externals =
    poetry
    pytest
setenv =
    # See: https://github.com/tox-dev/tox/issues/1550
    PYTHONIOENCODING=utf-8
    COVERAGE_FILE=tox-.coverage.{envname}
commands =
    poetry install --no-root --sync
    pyqt5: poetry run python -m pip install PyQt5 PyQt5-stubs
    pyside2: poetry run python -m pip install PySide2 PySide2-stubs
    pyqt6: poetry run python -m pip install PyQt6 IceSpringPySideStubs-PyQt6
    pyside6: poetry run python -m pip install PySide6 IceSpringPySideStubs-PySide6
    poetry run pytest

# Not run by default. To run, use `tox -e coverage`
[testenv:coverage]
depends = py{38,39,310}-{pyqt5,pyside2,pyqt6,pyside6}
allowlist_externals =
    sh
deps =
    coverage
    tox
basepython = python3.10
setenv =
    COVERAGE_FILE=tox-.coverage
    COVERAGE_DEBUG=trace
    COVERAGE_DEBUG_FILE=stdout
commands =
    coverage debug data
    coverage combine --debug=pathmap
    coverage report -m --skip-covered
    coverage html
    coverage json
    sh -c 'mv -f tox-.coverage .coverage'
    sh -c 'rm -f tox-.coverage'
parallel_show_output = true

# Not run by default. To run, use `tox -e docs`
[testenv:docs]
allowlist_externals =
    sphinx-build
commands =
    sphinx-build -W --keep-going -b docs docs/build
"""

# Currently, poetry only supports pure python builds. This (undocumented) feature
# tells poetry to build wheels for the Host OS
[tool.poetry.build]
generate-setup-file = false
script = 'build.py'

[build-system]
requires = [
    "setuptools>=45",
    "wheel",
    "toml",
]
build-backend = "setuptools.build_meta"
  • I am on the latest stable Poetry version, installed using a recommended method.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • I have consulted the FAQ and blog for any relevant entries or release notes.
  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option) and have included the output below.

Issue

Specifying a git branch as a dependency

# pyproject.toml

[tool.poetry.dependencies]
commitizen = { git = "https://github.com/adam-grant-hendry/commitizen.git", branch = "feat/unicode" }

results in a KeyError from dulwich:

KeyError

b'HEAD'

Steps to Reproduce

PS> poetry install -vvv
stdout/stderr
Loading configuration file C:\Users\hendra11\AppData\Roaming\pypoetry\config.toml
Loading configuration file C:\Users\hendra11\AppData\Roaming\pypoetry\auth.toml
Using virtualenv: C:\Users\hendra11\Code\external\qtpygraph\.venv

  Stack trace:

  19  ~\.poetry\venv\lib\site-packages\cleo\application.py:329 in run
       327│ 
       328│             try:
     → 329│                 exit_code = self._run(io)
       330│             except Exception as e:
       331│                 if not self._catch_exceptions:

  18  ~\.poetry\venv\lib\site-packages\poetry\console\application.py:185 in _run
       183│         self._load_plugins(io)
       184│
     → 185│         exit_code: int = super()._run(io)
       186│         return exit_code
       187│

  17  ~\.poetry\venv\lib\site-packages\cleo\application.py:423 in _run
       421│             io.input.set_stream(stream)
       422│ 
     → 423│         exit_code = self._run_command(command, io)
       424│         self._running_command = None
       425│

  16  ~\.poetry\venv\lib\site-packages\cleo\application.py:465 in _run_command
       463│ 
       464│         if error is not None:
     → 465│             raise error
       466│
       467│         return event.exit_code

  15  ~\.poetry\venv\lib\site-packages\cleo\application.py:446 in _run_command
       444│ 
       445│         try:
     → 446│             self._event_dispatcher.dispatch(event, COMMAND)
       447│
       448│             if event.command_should_run():

  14  ~\.poetry\venv\lib\site-packages\cleo\events\event_dispatcher.py:23 in dispatch
        21│
        22│         if listeners:
     →  23│             self._do_dispatch(listeners, event_name, event)
        24│
        25│         return event

  13  ~\.poetry\venv\lib\site-packages\cleo\events\event_dispatcher.py:84 in _do_dispatch
        82│                 break
        83│
     →  84│             listener(event, event_name, self)
        85│
        86│     def _sort_listeners(self, event_name: str) -> None:

  12  ~\.poetry\venv\lib\site-packages\poetry\console\application.py:316 in configure_installer_for_event
       314│             return
       315│
     → 316│         cls.configure_installer_for_command(command, event.io)
       317│
       318│     @staticmethod

  11  ~\.poetry\venv\lib\site-packages\poetry\console\application.py:323 in configure_installer_for_command
       321│ 
       322│         poetry = command.poetry
     → 323│         installer = Installer(
       324│             io,
       325│             command.env,

  10  ~\.poetry\venv\lib\site-packages\poetry\installation\installer.py:79 in __init__
        77│         self._installer = self._get_installer()
        78│         if installed is None:
     →  79│             installed = self._get_installed()
        80│
        81│         self._installed_repository = installed

   9  ~\.poetry\venv\lib\site-packages\poetry\installation\installer.py:573 in _get_installed
       571│ 
       572│     def _get_installed(self) -> InstalledRepository:
     → 573│         return InstalledRepository.load(self._env)
       574│

   8  ~\.poetry\venv\lib\site-packages\poetry\repositories\installed_repository.py:291 in load
       289│                     continue
       290│
     → 291│                 package = cls.create_package_from_distribution(distribution, env)
       292│
       293│                 if with_dependencies:

   7  ~\.poetry\venv\lib\site-packages\poetry\repositories\installed_repository.py:141 in create_package_from_distribution
       139│                                 source_url,
       140│                                 source_reference,
     → 141│                             ) = cls.get_package_vcs_properties_from_path(src)
       142│                             break
       143│

   6  ~\.poetry\venv\lib\site-packages\poetry\repositories\installed_repository.py:89 in get_package_vcs_properties_from_path
        87│         from poetry.vcs.git import Git
        88│
     →  89│         info = Git.info(repo=src)
        90│         return "git", info.origin, info.revision
        91│

   5  ~\.poetry\venv\lib\site-packages\poetry\vcs\git\backend.py:174 in info
       172│     @classmethod
       173│     def info(cls, repo: Repo | Path | str) -> GitRepoLocalInfo:
     → 174│         return GitRepoLocalInfo(repo=repo)
       175│
       176│     @staticmethod

   4  <string>:3 in __init__
         1│

   3  ~\.poetry\venv\lib\site-packages\poetry\vcs\git\backend.py:146 in __post_init__
       144│         repo = Git.as_repo(repo=repo) if not isinstance(repo, Repo) else repo
       145│         self.origin = Git.get_remote_url(repo=repo, remote="origin")
     → 146│         self.revision = Git.get_revision(repo=repo)
       147│
       148│

   2  ~\.poetry\venv\lib\site-packages\poetry\vcs\git\backend.py:170 in get_revision
       168│     def get_revision(repo: Repo) -> str:
       169│         with repo:
     → 170│             return repo.head().decode("utf-8")
       171│
       172│     @classmethod

   1  ~\.poetry\venv\lib\site-packages\dulwich\repo.py:599 in head
        597│     def head(self) -> bytes:
        598│         """Return the SHA1 pointed at by HEAD."""
     →  599│         return self.refs[b"HEAD"]
        600│
        601│     def _get_object(self, sha, cls):

  KeyError

  b'HEAD'

  at ~\.poetry\venv\lib\site-packages\dulwich\refs.py:320 in __getitem__
       316│         This method follows all symbolic references.
       317│         """
       318│         _, sha = self.follow(name)
       319│         if sha is None:
    →  320│             raise KeyError(name)
       321│         return sha
       322│
       323│     def set_if_equals(
       324│         self,

stack_trace.txt

@dimbleby
Copy link
Contributor

works fine here

@dimbleby
Copy link
Contributor

dimbleby commented Oct 23, 2022

stack trace looks as though it is reading the installed repositories - which would be consistent with my computer and your computer giving different answers.

Have you somehow gotten the git checkout in your virtual environment in some funny state? If you use a fresh virtual environment, does this work?

If yes, you are by far the best placed person in the world to figure out the state of your environment, good luck...

@adam-grant-hendry
Copy link
Author

adam-grant-hendry commented Oct 23, 2022

@dimbleby Thank you for your reply. A couple notes:

works fine here

Can you please elaborate?

  • Are you a poetry developer?
  • What OS are you on? What version of poetry?
  • What exactly did you try?

stack trace looks as though it is reading the installed repositories - which would be consistent with my computer and your computer giving different answers.

Do you mean from my project virtual environment?:

PS> poetry config --list
...
virtualenvs.create = false
virtualenvs.in-project = true
...

Do you use different settings in your setup?

Have you somehow gotten the git checkout in your virtual environment in some funny state?

No, it's on a clean branch. Except for the change from

# pyproject.toml
[tool.poetry.dependencies]
commitizen = ">=2.27.0"

to

[tool.poetry.dependencies]
commitizen = { git = "https://github.com/adam-grant-hendry/commitizen.git", branch = "feat/unicode" }

nothing else is staged. It's not in the middle of anything like a cherry pick, rebase, merge conflict, etc. Perfectly clean.

If you use a fresh virtual environment, does this work?

Yes, but why? I never experienced this error in poetry <1.2 before it switched to dulwich...? The error is specifically coming from dulwich.

If yes, you are by far the best placed person in the world to figure out the state of your environment, good luck...

I never experienced this error in poetry <1.2 before it switched to dulwich...? The error is specifically coming from dulwich, so that's not a fair assessment.

I believe this warrants some investigation on poetry's side since it chose to switch to dulwich and the KeyError: b'HEAD' has been reported as an issue on dulwich in the past:

@adam-grant-hendry
Copy link
Author

@dimbleby Are you able to reproduce the error if you first create a venv and poetry install the pyproject.toml with

# pyproject.toml
[tool.poetry.dependencies]
commitizen = ">=2.27.0"

and then change it to

[tool.poetry.dependencies]
commitizen = { git = "https://github.com/adam-grant-hendry/commitizen.git", branch = "feat/unicode" }

and run poetry update?

@dimbleby
Copy link
Contributor

dimbleby commented Oct 23, 2022

By "works fine here" I mean that where I am, this works fine.

Your second proposed repro also works fine for me.

If you believe you have a repro, perhaps you could put it into a docker container so that anyone can execute it. If nothing else, trying to do this will likely help you to narrow down the things that aren't the problem.

Yes, but why?

presumably because something in your virtual environment is in an unusual state. Most likely the git checkout in ~/.virtualenvs/foo/src/commitizen, or whatever the equivalent directory is for you.

@jelmer
Copy link
Contributor

jelmer commented Oct 23, 2022

.

I believe this warrants some investigation on poetry's side since it chose to switch to dulwich and the KeyError: b'HEAD' has been reported as an issue on dulwich in the past:

That's not really a good signal; this error is super generic, and the equivalent of git telling you the current branch is broken.

A missing HEAD can happen for a wide variety of reasons, only some caused by bugs, and most of them completely unrelated to each other.

Jelmer

@neersighted
Copy link
Member

@jelmer can you PTAL at #6874 and tell us if that's a correct/sane usage?

@adam-grant-hendry
Copy link
Author

By "works fine here" I mean that where I am, this works fine.

That doesn't give me any basis for comparison for narrowing down the problem because I don't know what your setup is. Please, in the future, add a little more information because then I/we could narrow down whether "works fine here" means on Windows, in a version of poetry, in a version of python, or something else entirely.

That's not really a good signal; this error is super generic, and the equivalent of git telling you the current branch is broken. A missing HEAD can happen for a wide variety of reasons, only some caused by bugs, and most of them completely unrelated to each other.

Agreed. To be clear, I'm not arguing that my setup is without fault, i.e. this:

presumably because something in your virtual environment is in an unusual state.

I'm in agreement with, for sure. I'd just like to debug a little to figure out where this is happening and why...?

@adam-grant-hendry
Copy link
Author

@dimbleby To @jelmer 's point, if we can figure out what's happening and perhaps add a useful error message, that would be ideal. I can get by now with a new virtual environment (i.e. Docker/etc. not necessary), which is great for me because it means this is less urgent, but it would be good to debug for the next user if/when this happens again.

@dimbleby
Copy link
Contributor

You yourself now have both a working and a non-working case to compare, it's obviously much more sensible to do that than to try and involve my environment.

Again, the thing whose state you should check is very likely to be the git checkout containing commitizen in the broken virtual environment. Presumably there's something about it that dulwich is unhappy with, only you can tell us how you got into that state.

@adam-grant-hendry
Copy link
Author

Closing issue as getting no where.

@jelmer
Copy link
Contributor

jelmer commented Oct 24, 2022

@jelmer can you PTAL at #6874 and tell us if that's a correct/sane usage?

I'm not sure that I understand that code well enough to comment, but will try to spend a bit more time on it this evening.

IIRC it is possible for remote repositories to not have a HEAD, in which case you'd have to explicitly specify a branch to check out. That doesn't appear to be the case here though.

As a first step towards debugging this, I would look at the contents of .git/HEAD and all the files under .git/refs and .git/packed-refs in the local repository

@neersighted
Copy link
Member

Re-opening as it would be nice to at least merge a PR and be more confident we're defending against this. A zip of the repository in question to introspect would be wonderful if at all possible.

@neersighted neersighted reopened this Oct 24, 2022
@adam-grant-hendry
Copy link
Author

Re-opening

@neersighted That's fine, but I won't help if contributors won't help me back in return. Development is a two-way street: I took the time out of my busy schedule to write a decent issue report and would expect reciprocation if I need more information to debug. That's the respectful and decent thing to do.

@neersighted
Copy link
Member

I think things are getting unnecessarily heated here -- David (and I, as well) cannot reproduce using the pyproject fragments locally (I tried on my system with a pyenv-managed Python as well as in a python:3.10 container). Nonetheless, we have a sophisticated contributor available as the reporter, so it seems like there might be some point in trying to reproduce this.

I think the key thing to keep in mind is that it's much easier to bring a repro to others, than to have them try to meet you. What I mean is, I can't reproduce this on an arbitrary Linux box (and neither can someone else) -- so ideally you can reproduce it in a way that is portable, either as a set of steps in a container image with a well-known tag or a SHA, or as a zip of the environment that is giving you trouble (as well as specifics of the system that created that environment) so that others can try to create as similar an environment as possible, and compare the differences.

Even if you don't have time to create an isolated/minimal reproduction for the issue you are hitting, I do want to see if @dimbleby's speculative PR works for you -- would you mind installing Poetry from the PR (we have instructions here: https://python-poetry.org/docs/contributing#multiple-versions) and seeing if you can reproduce on your system?

@neersighted
Copy link
Member

(also, the 'container as a minimal' repro is a very good solution as it typically also means you are reproducing commands verbatim -- describing steps in prose is not the same thing as writing down precisely what code/commands were run, and can often be revealing when stuff like this is consistently reproduced for one person, but not for another)

@dimbleby
Copy link
Contributor

(that MR is completely unrelated to this, it's pure coincidence that they happen to look superficially similar)

@adam-grant-hendry
Copy link
Author

Even if you don't have time to create an isolated/minimal reproduction for the issue you are hitting, I do want to see if @dimbleby's speculative PR works for you -- would you mind installing Poetry from the PR (we have instructions here: https://python-poetry.org/docs/contributing#multiple-versions) and seeing if you can reproduce on your system?

No, I don't have time.

@neersighted
Copy link
Member

Sorry to hear that -- unfortunately, when you have something that is not trivial to reproduce, throwing things over the wall tends not to work very well.

@adam-grant-hendry
Copy link
Author

throwing things over the wall

That was not was I was doing. Please don't be rude to me.

@neersighted
Copy link
Member

If there is not enough detail to reproduce (we don't know what hidden variable in your environment is causing this; certainly, I cannot get it to happen for the life of me on Linux or Windows) the equivalent of a NullPointerException with no useful stacktrace, I am not sure what to tell you.

You have been very pleasant to work with in the past, I hope you return to the project in the future and make more contributions.

@matburnham
Copy link

matburnham commented Jan 15, 2023

Hmmm. I've had a similar error message shortly after getting started with Poetry. Just tried to do this:

$ poetry add git+ssh://git@github.com/matburnham/django-oscar.git#fix-dependencies

b'HEAD'

and now it's proper stuck:

$ poetry show

b'HEAD'

It would be nice if I had a clue where the b'HEAD' response is coming from as I've nothing to go on.

I've fixed it by removing the cached virtualenv and poetry install once I'd edited pyroject.toml to include

django-oscar = { git = "https://github.com/matburnham/django-oscar.git", branch = "fix-dependencies" }

@gnowland
Copy link

gnowland commented Jun 2, 2023

I've fixed it by removing the cached virtualenv and poetry install once I'd edited pyroject.toml to include

How did you remove the cached virtualenv? I can't find it... poetry env list returns empty

EDIT: nevermind, I ran poetry env info, rm -rf'd the directory listed under "Path:", then re-installed the python version I'd just deleted. that fixed it.

@matburnham
Copy link

Just hit this again. For my own sanity see #8384 (comment) for where the problem is. Fix by removing the empty directory in src/[library]

Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/bug Something isn't working as expected status/triage This issue needs to be triaged
Projects
None yet
Development

No branches or pull requests

6 participants