tox-dev/pyproject-fmt

`pyproject-fmt` misplaces `[[project.authors]]` causing the build to fail

Saransh-cpp opened this issue · 4 comments

Formatting the following file with pyproject-fmt causes the build to fail, and I am guessing the root cause is the misplaced [[project.authors]] section.

This can be fixed manually by the users, but it definitely is a bug.

Original file

(https://github.com/scikit-hep/vector/blob/cac88a2e0f1c4bf7bceaafbea6e234b3147e3ca3/pyproject.toml)
Installs the package correctly -

[build-system]
requires = [
    "hatchling",
    "hatch-vcs",
]
build-backend = "hatchling.build"

[project]
name = "vector"
description = "Vector classes and utilities"
readme = { file = "README.md", content-type = "text/markdown" }
maintainers = [ {name = "The Scikit-HEP admins", email = "scikit-hep-admins@googlegroups.com"} ]
license = "BSD-3-Clause"
requires-python = ">=3.6"
keywords = [
    "vector",
]
classifiers = [
    "Development Status :: 5 - Production/Stable",
    "Intended Audience :: Developers",
    "Intended Audience :: Science/Research",
    "License :: OSI Approved :: BSD License",
    "Operating System :: OS Independent",
    "Programming Language :: Python",
    "Programming Language :: Python :: 3",
    "Programming Language :: Python :: 3 :: Only",
    "Programming Language :: Python :: 3.6",
    "Programming Language :: Python :: 3.7",
    "Programming Language :: Python :: 3.8",
    "Programming Language :: Python :: 3.9",
    "Programming Language :: Python :: 3.10",
    "Topic :: Scientific/Engineering",
    "Topic :: Scientific/Engineering :: Information Analysis",
    "Topic :: Scientific/Engineering :: Mathematics",
    "Topic :: Scientific/Engineering :: Physics",
    "Typing :: Typed",
]
dependencies = [
    "importlib-metadata>=0.22;python_version<\"3.8\"",
    "numpy>=1.13.3",
    "packaging>=19.0",
    "typing-extensions;python_version<\"3.8\"",
]
dynamic = [
    "version",
]

[[project.authors]]
name = "Jim Pivarski, Henry Schreiner, Eduardo Rodrigues"
email = "eduardo.rodrigues@cern.ch"

[project.optional-dependencies]
awkward = [
    "awkward>=1.2.0",
]
dev = [
    "awkward>=1.2.0",
    "numba>=0.50; python_version>=\"3.6\"",
    "pytest-cov>=3.0.0",
    "pytest>=6",
    "xdoctest>=1.0.0",
]
docs = [
    "awkward",
    "ipykernel",
    "myst-parser>0.13",
    "nbsphinx",
    "sphinx-math-dollar",
    "Sphinx>=4.0",
    "sphinx_book_theme>=0.0.42",
    "sphinx_copybutton",
]
test = [
    "pytest-cov>=3.0.0",
    "pytest>=6",
    "xdoctest>=1.0.0",
]
test-extras = [
    "spark-parser",
    "uncompyle6",
]

[project.entry-points.numba_extensions]
init = "vector:register_numba"

[project.urls]
"Bug Tracker" = "https://github.com/scikit-hep/vector/issues"
Changelog = "https://vector.readthedocs.io/en/latest/changelog.html"
Discussions = "https://github.com/scikit-hep/vector/discussions"
Documentation = "https://vector.readthedocs.io/"
Homepage = "https://github.com/scikit-hep/vector"

[tool.hatch]
version.source = "vcs"
build.hooks.vcs.version-file = "src/vector/version.py"

[tool.pytest.ini_options]
minversion = "6.0"
xfail_strict = true
addopts = [
    "-ra",
    "--strict-markers",
    "--strict-config",
]
testpaths = [
    "tests",
]
markers = [
    "slow",
    "numba",
    "awkward",
    "dis",
]
log_cli_level = "DEBUG"
filterwarnings = [
    "error",
    "ignore::DeprecationWarning",
    "ignore::UserWarning",
]

[tool.isort]
profile = "black"

[tool.mypy]
files = [
    "src/vector",
]
python_version = "3.8"
strict = true
warn_return_any = false
show_error_codes = true
warn_unreachable = true
enable_error_code = [
    "ignore-without-code",
    "truthy-bool",
    "redundant-expr",
]

[[tool.mypy.overrides]]
module = "vector._compute.*.*"
disallow_untyped_defs = false
disallow_untyped_calls = false

[[tool.mypy.overrides]]
module = [
    "numba.*",
    "awkward.*",
]
ignore_missing_imports = true

[tool.check-manifest]
ignore = [
    ".*",
    "environment.yml",
    "src/vector/version.py",
    "docs/**",
    "noxfile.py",
]

Formatted file

Does not build -

[build-system]
build-backend = "hatchling.build"
requires = [
  "hatch-vcs",
  "hatchling",
]

[project]
name = "vector"
description = "Vector classes and utilities"
readme = { file = "README.md", content-type = "text/markdown" }
keywords = [
  "vector",
]
license = "BSD-3-Clause"
maintainers = [ {name = "The Scikit-HEP admins", email = "scikit-hep-admins@googlegroups.com"} ]
[[project.authors]]
name = "Jim Pivarski, Henry Schreiner, Eduardo Rodrigues"
email = "eduardo.rodrigues@cern.ch"

requires-python = ">=3.6"
dependencies = [
  'importlib-metadata>=0.22; python_version < "3.8"',
  "numpy>=1.13.3",
  "packaging>=19",
  'typing-extensions; python_version < "3.8"',
]
dynamic = [
  "version",
]
classifiers = [
    "Development Status :: 5 - Production/Stable",
    "Intended Audience :: Developers",
    "Intended Audience :: Science/Research",
    "License :: OSI Approved :: BSD License",
    "Operating System :: OS Independent",
    "Programming Language :: Python",
    "Programming Language :: Python :: 3",
    "Programming Language :: Python :: 3 :: Only",
    "Programming Language :: Python :: 3.6",
    "Programming Language :: Python :: 3.7",
    "Programming Language :: Python :: 3.8",
    "Programming Language :: Python :: 3.9",
    "Programming Language :: Python :: 3.10",
    "Topic :: Scientific/Engineering",
    "Topic :: Scientific/Engineering :: Information Analysis",
    "Topic :: Scientific/Engineering :: Mathematics",
    "Topic :: Scientific/Engineering :: Physics",
    "Typing :: Typed",
]
[project.optional-dependencies]
awkward = [
  "awkward>=1.2",
]
dev = [
  "awkward>=1.2",
  'numba>=0.50; python_version >= "3.6"',
  "pytest>=6",
  "pytest-cov>=3",
  "xdoctest>=1",
]
docs = [
  "awkward",
  "ipykernel",
  "myst-parser>0.13",
  "nbsphinx",
  "Sphinx>=4",
  "sphinx-math-dollar",
  "sphinx_book_theme>=0.0.42",
  "sphinx_copybutton",
]
test = [
  "pytest>=6",
  "pytest-cov>=3",
  "xdoctest>=1",
]
test-extras = [
  "spark-parser",
  "uncompyle6",
]

[project.urls]
"Bug Tracker" = "https://github.com/scikit-hep/vector/issues"
Changelog = "https://vector.readthedocs.io/en/latest/changelog.html"
Discussions = "https://github.com/scikit-hep/vector/discussions"
Documentation = "https://vector.readthedocs.io/"
Homepage = "https://github.com/scikit-hep/vector"

[project.entry-points.numba_extensions]
init = "vector:register_numba"



[tool.hatch]
version.source = "vcs"
build.hooks.vcs.version-file = "src/vector/version.py"

[tool.pytest.ini_options]
minversion = "6.0"
xfail_strict = true
addopts = [
    "-ra",
    "--strict-markers",
    "--strict-config",
]
testpaths = [
    "tests",
]
markers = [
    "slow",
    "numba",
    "awkward",
    "dis",
]
log_cli_level = "DEBUG"
filterwarnings = [
    "error",
    "ignore::DeprecationWarning",
    "ignore::UserWarning",
]

[tool.isort]
profile = "black"

[tool.mypy]
files = [
    "src/vector",
]
python_version = "3.8"
strict = true
warn_return_any = false
show_error_codes = true
warn_unreachable = true
enable_error_code = [
    "ignore-without-code",
    "truthy-bool",
    "redundant-expr",
]

[[tool.mypy.overrides]]
module = "vector._compute.*.*"
disallow_untyped_defs = false
disallow_untyped_calls = false

[[tool.mypy.overrides]]
module = [
    "numba.*",
    "awkward.*",
]
ignore_missing_imports = true

pyproject-fmt output

pyproject-fmt............................................................Failed
- hook id: pyproject-fmt
- exit code: 1
- files were modified by this hook

--- pyproject.toml

+++ pyproject.toml

@@ -1,19 +1,32 @@

 [build-system]
+build-backend = "hatchling.build"
 requires = [
-    "hatchling",
-    "hatch-vcs",
+  "hatch-vcs",
+  "hatchling",
 ]
-build-backend = "hatchling.build"

 [project]
 name = "vector"
 description = "Vector classes and utilities"
 readme = { file = "README.md", content-type = "text/markdown" }
+keywords = [
+  "vector",
+]
+license = "BSD-3-Clause"
 maintainers = [ {name = "The Scikit-HEP admins", email = "scikit-hep-admins@googlegroups.com"} ]
-license = "BSD-3-Clause"
+[[project.authors]]
+name = "Jim Pivarski, Henry Schreiner, Eduardo Rodrigues"
+email = "eduardo.rodrigues@cern.ch"
+
 requires-python = ">=3.6"
-keywords = [
-    "vector",
+dependencies = [
+  'importlib-metadata>=0.22; python_version < "3.8"',
+  "numpy>=1.13.3",
+  "packaging>=19",
+  'typing-extensions; python_version < "3.8"',
+]
+dynamic = [
+  "version",
 ]
 classifiers = [
     "Development Status :: 5 - Production/Stable",
@@ -35,53 +48,36 @@

     "Topic :: Scientific/Engineering :: Physics",
     "Typing :: Typed",
 ]
-dependencies = [
-    "importlib-metadata>=0.22;python_version<\"3.8\"",
-    "numpy>=1.13.3",
-    "packaging>=19.0",
-    "typing-extensions;python_version<\"3.8\"",
-]
-dynamic = [
-    "version",
-]
-
-[[project.authors]]
-name = "Jim Pivarski, Henry Schreiner, Eduardo Rodrigues"
-email = "eduardo.rodrigues@cern.ch"
-
 [project.optional-dependencies]
 awkward = [
-    "awkward>=1.2.0",
+  "awkward>=1.2",
 ]
 dev = [
-    "awkward>=1.2.0",
-    "numba>=0.50; python_version>=\"3.6\"",
-    "pytest-cov>=3.0.0",
-    "pytest>=6",
-    "xdoctest>=1.0.0",
+  "awkward>=1.2",
+  'numba>=0.50; python_version >= "3.6"',
+  "pytest>=6",
+  "pytest-cov>=3",
+  "xdoctest>=1",
 ]
 docs = [
-    "awkward",
-    "ipykernel",
-    "myst-parser>0.13",
-    "nbsphinx",
-    "sphinx-math-dollar",
-    "Sphinx>=4.0",
-    "sphinx_book_theme>=0.0.42",
-    "sphinx_copybutton",
+  "awkward",
+  "ipykernel",
+  "myst-parser>0.13",
+  "nbsphinx",
+  "Sphinx>=4",
+  "sphinx-math-dollar",
+  "sphinx_book_theme>=0.0.42",
+  "sphinx_copybutton",
 ]
 test = [
-    "pytest-cov>=3.0.0",
-    "pytest>=6",
-    "xdoctest>=1.0.0",
+  "pytest>=6",
+  "pytest-cov>=3",
+  "xdoctest>=1",
 ]
 test-extras = [
-    "spark-parser",
-    "uncompyle6",
+  "spark-parser",
+  "uncompyle6",
 ]
-
-[project.entry-points.numba_extensions]
-init = "vector:register_numba"

 [project.urls]
 "Bug Tracker" = "https://github.com/scikit-hep/vector/issues"
@@ -89,6 +85,11 @@

 Discussions = "https://github.com/scikit-hep/vector/discussions"
 Documentation = "https://vector.readthedocs.io/"
 Homepage = "https://github.com/scikit-hep/vector"
+
+[project.entry-points.numba_extensions]
+init = "vector:register_numba"
+
+

 [tool.hatch]
 version.source = "vcs"

pip error

Processing d:\opensource\hep\vector
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... error
  error: subprocess-exited-with-error

  × Preparing metadata (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [27 lines of output]
      Traceback (most recent call last):
        File "C:\Users\Saransh\Saransh_softwares\Python_3.9\lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py", line 156, in prepare_metadata_for_build_wheel
          hook = backend.prepare_metadata_for_build_wheel
      AttributeError: module 'hatchling.build' has no attribute 'prepare_metadata_for_build_wheel'
     
      During handling of the above exception, another exception occurred:
     
      Traceback (most recent call last):
        File "C:\Users\Saransh\Saransh_softwares\Python_3.9\lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py", line 363, in <module>
          main()
        File "C:\Users\Saransh\Saransh_softwares\Python_3.9\lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py", line 345, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
        File "C:\Users\Saransh\Saransh_softwares\Python_3.9\lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py", line 160, in prepare_metadata_for_build_wheel
          whl_basename = backend.build_wheel(metadata_directory, config_settings)
        File "C:\Users\Saransh\AppData\Local\Temp\pip-build-env-rkvsxn2i\overlay\Lib\site-packages\hatchling\build.py", line 41, in build_wheel
          return os.path.basename(next(builder.build(wheel_directory, ['standard'])))
        File "C:\Users\Saransh\AppData\Local\Temp\pip-build-env-rkvsxn2i\overlay\Lib\site-packages\hatchling\builders\plugin\interface.py", line 80, in build
          self.metadata.validate_fields()
        File "C:\Users\Saransh\AppData\Local\Temp\pip-build-env-rkvsxn2i\overlay\Lib\site-packages\hatchling\metadata\core.py", line 168, in validate_fields          _ = self.version
        File "C:\Users\Saransh\AppData\Local\Temp\pip-build-env-rkvsxn2i\overlay\Lib\site-packages\hatchling\metadata\core.py", line 55, in version
          self._set_version()
        File "C:\Users\Saransh\AppData\Local\Temp\pip-build-env-rkvsxn2i\overlay\Lib\site-packages\hatchling\metadata\core.py", line 148, in _set_version   
          version = core_metadata.version
        File "C:\Users\Saransh\AppData\Local\Temp\pip-build-env-rkvsxn2i\overlay\Lib\site-packages\hatchling\metadata\core.py", line 330, in version        
          raise ValueError(
      ValueError: Field `project.version` can only be resolved dynamically if `version` is in field `project.dynamic`
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

Pull request fixing this is definitely welcome! 😎

Will try to open a PR this weekend!

Yeah, also have seen this for license files being not captured The Way It Expects.

It seems like an invariant of this tool should be that before and after should always be parsed to exactly the same effective data. Old json.dumps(sort_keys=True) isn't quite enough, due to custom ordering of arrays.

Irrespective of how that worked, perhaps a --safe flag would work (or perhaps default into such a check, and expose --unsafe).

Please check with https://github.com/tox-dev/pyproject-fmt/releases/tag/2.0.0 and report if still a problem.