duckinator / bork

A Python build and release management tool.
https://bork.readthedocs.io
MIT License
12 stars 2 forks source link

Doesn't actually make a build environment #347

Closed AstraLuma closed 8 months ago

AstraLuma commented 9 months ago
astraluma@nandi ~/code/unholy trunk @ bork build
Traceback (most recent call last):
  File "/home/astraluma/.local/bin/bork", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/astraluma/src/bork/bork/cli.py", line 227, in main
    args.func(args)
  File "/home/astraluma/src/bork/bork/cli.py", line 52, in build
    api.build()
  File "/home/astraluma/src/bork/bork/api.py", line 32, in build
    builder.dist()
  File "/home/astraluma/src/bork/bork/builder.py", line 23, in dist
    builder.build('sdist', './dist/')
  File "/home/astraluma/.local/pipx/venvs/bork/lib64/python3.12/site-packages/build/__init__.py", line 298, in build
    return self._call_backend(f'build_{distribution}', output_directory, config_settings, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/astraluma/.local/pipx/venvs/bork/lib64/python3.12/site-packages/build/__init__.py", line 344, in _call_backend
    with self._handle_backend(hook_name):
  File "/usr/lib64/python3.12/contextlib.py", line 155, in __exit__
    self.gen.throw(value)
  File "/home/astraluma/.local/pipx/venvs/bork/lib64/python3.12/site-packages/build/__init__.py", line 354, in _handle_backend
    raise BuildBackendException(
build._exceptions.BuildBackendException: Backend 'poetry.core.masonry.api' is not available.

I think you don't make a build environment with build-system.requires installed.

duckinator commented 9 months ago

You know, this actually explains quite a lot, in retrospect.

I think basically, in https://github.com/duckinator/bork/blob/main/bork/builder.py, we need to change:

    builder = build.ProjectBuilder('.')
    builder.build('sdist', './dist/')
    builder.build('wheel', './dist/')

to something like this (untested, based off parts of https://github.com/pypa/build/blob/main/src/build/__main__.py):

srcdir = "."
outdir = "./dist"
backend_settings = None # TODO

with build.DefaultIsolatedEnv() as env:
    builder = ProjectBuilder.from_isolated_env(env, srcdir)
    # Install deps from `project.build_system_requires`
    env.install(builder.build_system_requires)
    # Install deps that are required to build the distribution.
    env.install(builder.get_requires_for_build(distribution, backend_config_settings or {}))
    # TODO: builder.build() returns the location of the build dist. Maybe store/use it?
    for distribution in ['sdist', wheel']:
        builder.build(distribution, outdir, backend_config_settings or {})
AstraLuma commented 9 months ago

I should see if I have some code that'll help over in GoBuild.it