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

build command doesn't detect version from latest git tag from inside a sub-folder #2108

Closed
TommyDuc opened this issue Jul 16, 2023 · 4 comments
Labels
🐛 bug Something isn't working

Comments

@TommyDuc
Copy link

Steps to reproduce

In an empty directory:

git init
mkdir -p python/src
touch python/src/__init__.py
cd python
# copy pyproject.toml below
pdm lock
git add '*'
git commit -m "first commit"
git tag v1.0.0
pdm build -v
ls dist

Content of python/pyproject.toml:

[project]
name = "python-test-project"
dynamic = ["version"]
dependencies = []
requires-python = ">=3.8"

[tool.pdm]
version = { use_scm = true }

[build-system]
requires = ["pdm-pep517>=1.0"]
build-backend = "pdm.pep517.api"

Actual behavior

python_test_project-0.0.0-py3-none-any.whl python-test-project-0.0.0.tar.gz

Expected behavior

python_test_project-1.0.0-py3-none-any.whl python-test-project-1.0.0.tar.gz

# Paste the output of `pdm info && pdm info --env` below:

PDM version:
2.8.0a2
Python Interpreter:
/home/tommy/projects/misc/test/python/.venv/bin/python (3.11)
Project Root:
/home/tommy/projects/misc/test/python
Local Packages:

{
"implementation_name": "cpython",
"implementation_version": "3.11.1",
"os_name": "posix",
"platform_machine": "x86_64",
"platform_release": "5.15.0-76-generic",
"platform_system": "Linux",
"platform_version": "#83-Ubuntu SMP Thu Jun 15 19:16:32 UTC 2023",
"python_full_version": "3.11.1",
"platform_python_implementation": "CPython",
"python_version": "3.11",
"sys_platform": "linux"
}

@TommyDuc TommyDuc added the 🐛 bug Something isn't working label Jul 16, 2023
@frostming
Copy link
Collaborator

Can you change to pdm-backend?

https://pdm-backend.fming.dev/#quick-start

@quag-cactus
Copy link

Hello, @TommyDuc @frostming

I was also interested in this issue and tried changing the backend.

# build-system definition of pyproject.toml
[build-system]
requires = ["pdm-backend"]
build-backend = "pdm.backend"

However, an error occurred and the build failed.

Traceback (most recent call last):
  File "/home/ec2-user/.local/bin/pdm", line 8, in <module>
    sys.exit(main())
  File "/home/ec2-user/.local/share/pdm/venv/lib/python3.9/site-packages/pdm/core.py", line 289, in main
    return Core().main(args)
  File "/home/ec2-user/.local/share/pdm/venv/lib/python3.9/site-packages/pdm/core.py", line 207, in main
    raise cast(Exception, err).with_traceback(traceback) from None
  File "/home/ec2-user/.local/share/pdm/venv/lib/python3.9/site-packages/pdm/core.py", line 202, in main
    self.handle(project, options)
  File "/home/ec2-user/.local/share/pdm/venv/lib/python3.9/site-packages/pdm/core.py", line 157, in handle
    command.handle(project, options)
  File "/home/ec2-user/.local/share/pdm/venv/lib/python3.9/site-packages/pdm/cli/commands/build.py", line 110, in handle
    self.do_build(
  File "/home/ec2-user/.local/share/pdm/venv/lib/python3.9/site-packages/pdm/cli/commands/build.py", line 56, in do_build
    loc = SdistBuilder(project.root, project.environment).build(dest, config_settings)
  File "/home/ec2-user/.local/share/pdm/venv/lib/python3.9/site-packages/pdm/builders/sdist.py", line 21, in build
    filename = self._hook.build_sdist(out_dir, config_settings)
  File "/home/ec2-user/.local/share/pdm/venv/lib/python3.9/site-packages/pyproject_hooks/_impl.py", line 292, in build_sdist
    return self._call_hook('build_sdist', {
  File "/home/ec2-user/.local/share/pdm/venv/lib/python3.9/site-packages/pyproject_hooks/_impl.py", line 311, in _call_hook
    self._subprocess_runner(
  File "/home/ec2-user/.local/share/pdm/venv/lib/python3.9/site-packages/pdm/builders/base.py", line 260, in subprocess_runner
    return log_subprocessor(cmd, cwd, extra_environ=env)
  File "/home/ec2-user/.local/share/pdm/venv/lib/python3.9/site-packages/pdm/builders/base.py", line 107, in log_subprocessor
    raise build_error(e) from None
pdm.exceptions.BuildError: Build backend raised error: Showing the last 10 lines of the build output:
    return builder.build(sdist_directory).name
  File "/tmp/pdm-build-env-fwqm4hd8-shared/lib/python3.9/site-packages/pdm/backend/base.py", line 198, in build
    self.initialize(context)
  File "/tmp/pdm-build-env-fwqm4hd8-shared/lib/python3.9/site-packages/pdm/backend/base.py", line 165, in initialize
    self.call_hook("pdm_build_initialize", context)
  File "/tmp/pdm-build-env-fwqm4hd8-shared/lib/python3.9/site-packages/pdm/backend/base.py", line 138, in call_hook
    getattr(hook, hook_name)(context, *args, **kwargs)
  File "/tmp/pdm-build-env-fwqm4hd8-shared/lib/python3.9/site-packages/pdm/backend/hooks/version/__init__.py", line 60, in pdm_build_initialize
    raise ConfigError("tool.pdm.version.source is required")
pdm.backend.exceptions.ConfigError: tool.pdm.version.source is required

There seems to be a problem in pyproject.toml. The following changes made it work.

[tool.pdm]
#version = { use_scm = true }
version = { source = "scm"}

@frostming
Copy link
Collaborator

Nice, problem seems solved?

@TommyDuc
Copy link
Author

@quag-cactus @frostming Changing the build-system to pdm-backend and tool.pdm.source to {source = "scm"} solved my issue. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants