pythonpython-3.xlinuxdebiantoml

how to prepare hatch and toml source to provide python3.11 with set up data?


hatch build pyproject.toml
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /home/gort/Saber/lib/python3.11/site-packages/hatch/cli/__init__.py:221 in main                  │
│                                                                                                  │
│   218                                                                                            │
│   219 def main():  # no cov                                                                      │
│   220 │   try:                                                                                   │
│ ❱ 221 │   │   hatch(prog_name='hatch', windows_expand_args=False)                                │
│   222 │   except Exception:  # noqa: BLE001                                                      │
│   223 │   │   import sys                                                                         │
│   224                                                                                            │
│                                                                                                  │
│ /home/gort/Saber/lib/python3.11/site-packages/click/core.py:1157 in __call__                     │
│                                                                                                  │
│ /home/gort/Saber/lib/python3.11/site-packages/click/core.py:1078 in main                         │
│                                                                                                  │
│ /home/gort/Saber/lib/python3.11/site-packages/click/core.py:1688 in invoke                       │
│                                                                                                  │
│ /home/gort/Saber/lib/python3.11/site-packages/click/core.py:1434 in invoke                       │
│                                                                                                  │
│ /home/gort/Saber/lib/python3.11/site-packages/click/core.py:783 in invoke                        │
│                                                                                                  │
│ /home/gort/Saber/lib/python3.11/site-packages/click/decorators.py:45 in new_func                 │
│                                                                                                  │
│ /home/gort/Saber/lib/python3.11/site-packages/hatch/cli/build/__init__.py:55 in build            │
│                                                                                                  │
│    52 @click.pass_obj                                                                            │
│    53 def build(app: Application, location, targets, hooks_only, no_hooks, ext, clean, clean_h   │
│    54 │   """Build a project."""                                                                 │
│ ❱  55 │   app.ensure_environment_plugin_dependencies()                                           │
│    56 │                                                                                          │
│    57 │   from hatch.config.constants import AppEnvVars                                          │
│    58 │   from hatch.utils.fs import Path                                                        │
│                                                                                                  │
│ /home/gort/Saber/lib/python3.11/site-packages/hatch/cli/application.py:239 in                    │
│ ensure_environment_plugin_dependencies                                                           │
│                                                                                                  │
│   236 │                                                                                          │
│   237 │   def ensure_environment_plugin_dependencies(self) -> None:                              │
│   238 │   │   self.ensure_plugin_dependencies(                                                   │
│ ❱ 239 │   │   │   self.project.config.env_requires_complex, wait_message='Syncing environment    │
│   240 │   │   )                                                                                  │
│   241 │                                                                                          │
│   242 │   def ensure_plugin_dependencies(self, dependencies: list[Requirement], *, wait_messag   │
│                                                                                                  │
│ /home/gort/Saber/lib/python3.11/site-packages/hatch/project/core.py:46 in config                 │
│                                                                                                  │
│    43 │   │   if self._config is None:                                                           │
│    44 │   │   │   from hatch.project.config import ProjectConfig                                 │
│    45 │   │   │                                                                                  │
│ ❱  46 │   │   │   self._config = ProjectConfig(self.location, self.metadata.hatch.config, self   │
│    47 │   │                                                                                      │
│    48 │   │   return self._config                                                                │
│    49                                                                                            │
│                                                                                                  │
│ /home/gort/Saber/lib/python3.11/site-packages/hatch/project/core.py:127 in metadata              │
│                                                                                                  │
│   124 │   │   if self._metadata is None:                                                         │
│   125 │   │   │   from hatchling.metadata.core import ProjectMetadata                            │
│   126 │   │   │                                                                                  │
│ ❱ 127 │   │   │   self._metadata = ProjectMetadata(self.location, self.plugin_manager, self.ra   │
│   128 │   │                                                                                      │
│   129 │   │   return self._metadata                                                              │
│   130                                                                                            │
│                                                                                                  │
│ /home/gort/Saber/lib/python3.11/site-packages/hatch/project/core.py:140 in raw_config            │
│                                                                                                  │
│   137 │   │   │   else:                                                                          │
│   138 │   │   │   │   from hatch.utils.toml import load_toml_file                                │
│   139 │   │   │   │                                                                              │
│ ❱ 140 │   │   │   │   raw_config = load_toml_file(str(self._project_file_path))                  │
│   141 │   │   │   │   # Assume environment management only                                       │
│   142 │   │   │   │   if 'project' not in raw_config:                                            │
│   143 │   │   │   │   │   raw_config['project'] = {'name': self.location.name}                   │
│                                                                                                  │
│ /home/gort/Saber/lib/python3.11/site-packages/hatch/utils/toml.py:18 in load_toml_file           │
│                                                                                                  │
│   15                                                                                             │
│   16 def load_toml_file(path: str) -> dict[str, Any]:                                            │
│   17 │   with open(path, encoding='utf-8') as f:                                                 │
│ ❱ 18 │   │   return tomllib.loads(f.read())                                                      │
│   19                                                                                             │
│                                                                                                  │
│ /usr/lib/python3.11/tomllib/_parser.py:102 in loads                                              │
│                                                                                                  │
│    99 │   │   │   pos += 1                                                                       │
│   100 │   │   │   continue                                                                       │
│   101 │   │   if char in KEY_INITIAL_CHARS:                                                      │
│ ❱ 102 │   │   │   pos = key_value_rule(src, pos, out, header, parse_float)                       │
│   103 │   │   │   pos = skip_chars(src, pos, TOML_WS)                                            │
│   104 │   │   elif char == "[":                                                                  │
│   105 │   │   │   try:                                                                           │
│                                                                                                  │
│ /usr/lib/python3.11/tomllib/_parser.py:326 in key_value_rule                                     │
│                                                                                                  │
│   323 def key_value_rule(                                                                        │
│   324 │   src: str, pos: Pos, out: Output, header: Key, parse_float: ParseFloat                  │
│   325 ) -> Pos:                                                                                  │
│ ❱ 326 │   pos, key, value = parse_key_value_pair(src, pos, parse_float)                          │
│   327 │   key_parent, key_stem = key[:-1], key[-1]                                               │
│   328 │   abs_key_parent = header + key_parent                                                   │
│   329                                                                                            │
│                                                                                                  │
│ /usr/lib/python3.11/tomllib/_parser.py:369 in parse_key_value_pair                               │
│                                                                                                  │
│   366 │   │   raise suffixed_err(src, pos, "Expected '=' after a key in a key/value pair")       │
│   367 │   pos += 1                                                                               │
│   368 │   pos = skip_chars(src, pos, TOML_WS)                                                    │
│ ❱ 369 │   pos, value = parse_value(src, pos, parse_float)                                        │
│   370 │   return pos, key, value                                                                 │
│   371                                                                                            │
│   372                                                                                            │
│                                                                                                  │
│ /usr/lib/python3.11/tomllib/_parser.py:616 in parse_value                                        │
│                                                                                                  │
│   613 │                                                                                          │
│   614 │   # Arrays                                                                               │
│   615 │   if char == "[":                                                                        │
│ ❱ 616 │   │   return parse_array(src, pos, parse_float)                                          │
│   617 │                                                                                          │
│   618 │   # Inline tables                                                                        │
│   619 │   if char == "{":                                                                        │
│                                                                                                  │
│ /usr/lib/python3.11/tomllib/_parser.py:428 in parse_array                                        │
│                                                                                                  │
│   425 │   │   if c == "]":                                                                       │
│   426 │   │   │   return pos + 1, array                                                          │
│   427 │   │   if c != ",":                                                                       │
│ ❱ 428 │   │   │   raise suffixed_err(src, pos, "Unclosed array")                                 │
│   429 │   │   pos += 1                                                                           │
│   430 │   │                                                                                      │
│   431 │   │   pos = skip_comments_and_array_ws(src, pos)                                         │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
TOMLDecodeError: Unclosed array (at line 25, column 31)

I am currently using a Debian Distro based SBC for communication and library building via hatch/hatchling and .toml files.

In setup.py days before the deprecation, I was able to provide a go-to method each time to set up a python3 library. Although I was not able to alter it midstream once compiled, I like this method. Moving on...

How can I use tomli to decode/encode decisions when it fails at it? I know there is a workaround because pep517 is still around due to used source within that specific file. pep660 cannot really be installed without setuptools-pep660 via pip.

Anyway, on my SBC using Debian with python3.11, I have used a venv as an environment.

This way, I can use pip3 or python3 -m pip willingly to get packages and remove them.

Here is my pyproject.toml file:

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

[project]
name = "Saber"
version = "0.5.0"
dependencies = [
  "*pyserial",
#  "gidgethub[httpx]>4.0.0",
#  "django>2.1; os_name != 'nt'",
#  "django>2.0; os_name == 'nt'",
]
requires-python = ">=3.11"
authors = [
  {name = "User_One", email = "<User_One@example.com>"},
  {name = "User_Two", email = "<User_Two@example.com>"},
]
maintainers = [
  {name = "Seth", email = "seth@example.com"},
]
description = "Making UARTs work on new 64-bit Machines with Dimension Engineering!"
readme = "readme.rst"
license = {file = "MIT"}
keywords = ["beagleboard.org" "BeagleY-AI" "UART" "Dimension Engineering"]
classifiers = [
  "Development Status :: 4 - Beta",
  "Programming Language :: Python",
]

[project.optional-dependencies]
#gui = ["PyQt5"]
cli = [
  "tomli",
  "pep517",
  "setuptools-pep660",
]

So, the first blotch of source is the error output on the SBC when attempting to run:

  1. hatch build pyproject.toml and/or...
  2. python3 -m build pyproject.toml

If you have any ideas on the errors and workaround, please be my guest and send guidance.

Seth

P.S. Even deprecated setup.py and setuptools is not done in 3.11. I was able to use it with success. I am currently trying to move on and get with the current system of Python3.11.

This is similar but outdated (I think): How to load toml file in python

I tried to type the command hatch build pyproject.toml.

I expected the .toml file to build a library from one file.

I was greeted with many tomli imported files of error as output.


Solution

  • This is a workaround and a retraction of sorts.

    So, I have built the lib. now with:
    python3 -m pip install My_Lib.py
    

    But, I stopped using hatch as the backend and started to use poetry.

    Anyway, hatch was giving me way too many things to look into during my build efforts. So, I switched and now everything builds...

    [tool.poetry]
    license == "MIT"
    name == 'Saber'
    version == '0.0.1'
    
    [tool.poetry.dependencies]
    dependencies == [
                    "requirements.txt = *",
                    python == '3.11.2',
                    "gar.py",
                   ]
    
    [build-system]
    requires = ['poetry-core ^1.0']
    build-backend == 'poetry.core.masonry.api'
    

    That is my new pyproject.toml file and it builds but with error still:

    1. The error is due to dependencies and sudo.
    2. python3 -m pip install My_Lib.py works but errors out at permissions...
    3. sudo python3 -m pip install My_Lib.py works but gives the use a virtual environment instead and still builds...

    Building libraries is a difficult task to a newcomer like myself.

    I am not using the .py file infrastructure to build and call the .toml file any longer because of mass errors. I am using just the .toml file to call the build of this library.

    Seth

    P.S. If you see where I may be making errors or know of how to build python3 libs, please be my guest and give some type of updates or good resources.