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

PDM Fails to Parse license-expression #1131

Closed
1 task done
adam-grant-hendry opened this issue Jun 12, 2022 · 1 comment · Fixed by #1133
Closed
1 task done

PDM Fails to Parse license-expression #1131

adam-grant-hendry opened this issue Jun 12, 2022 · 1 comment · Fixed by #1133
Labels
🐛 bug Something isn't working

Comments

@adam-grant-hendry
Copy link

adam-grant-hendry commented Jun 12, 2022

  • I have searched the issue tracker and believe that this is not a duplicate.

Steps to reproduce

  1. Import from poetry project
pdm import -f poetry -- pyproject.toml
  1. Run pdm install

Actual behavior

pdm fails with:

[AttributeError]: 'dict' object has no attribute split

error_log.txt

Note:

I have manually edited all outputs in this issue with Windows environment variable equivalents:

%USERPROFILE% = C:\Users\username
%LOCALAPPDATA% = C:\Users\username\AppData\Local
%APPDATA% = C:\Users\username\AppData\Roaming

Expected behavior

pdm is able to parse "Apache-2.0" as an SPDX license name per PEP 639

Environment Information

PDM version:        1.15.2
Python Interpreter: %USERPROFILE%\Code\myproj\.venv\Scripts\python.exe (3.8)
Project Root:       %USERPROFILE%/Code/myproj
Project Packages:   None
{
  "implementation_name": "cpython",
  "implementation_version": "3.8.10",
  "os_name": "nt",
  "platform_machine": "AMD64",
  "platform_release": "10",
  "platform_system": "Windows",
  "platform_version": "10.0.19042",
  "python_full_version": "3.8.10",
  "platform_python_implementation": "CPython",
  "python_version": "3.8",
  "sys_platform": "win32"
}

Additional Information

  1. Virtual environments are used (pdm config python.use_env True)
  2. Build system is setuptools:
[tool.pdm.build]
generate-setup-file = false
script = "build.py"

[build-system]
requires = [
    "setuptools>=45",
    "wheel"
]
build-backend = "setuptools.build_meta"
  1. pdm was installed using the PowerShell command listed on the homepage:
(Invoke-WebRequest -Uri https://raw.githubusercontent.com/pdm-project/pdm/main/install-pdm.py -UseBasicParsing).Content | python -

pdm config

Home configuration (%USERPROFILE%\.pdm\config.toml):
  build_isolation = True
  cache_dir = %LOCALAPPDATA%\pdm\pdm\Cache  
  check_update = True
  global_project.fallback = False
  global_project.path = %USERPROFILE%/.pdm/global-project
  global_project.user_site = False
  install.cache = True
  install.cache_method = symlink
  install.parallel = True
  project_max_depth = 5
  pypi.json_api = False
  pypi.url = https://pypi.org/simple
  pypi.verify_ssl = True
  python.use_pyenv = True
  python.use_venv = True
  strategy.resolve_max_rounds = 10000
  strategy.save = minimum
  strategy.update = reuse

Project configuration (%USERPROFILE%\Code\myproj\.pdm.toml):

Update

This was fixed by recognizing that the table must become [tool.pdm], rather than [tool.pdm.build] that pdm auto-generated (adopted from [tool.poetry.build]) and properly specifying "script" as "build":

[tool.pdm]
includes = [
    "docs",
    "myproj",
    "logs",
    "resources",
    "tests"
]
generate-setup-file = false
build = "build.py"

However, pdm fails to build because it does not find build.py module in my top-level directory:

Directory Structure

./
├─.codespellrc
├─.flake8
├─.gitignore
├─.pre-commit-config.yaml
├─build.py
├─CHANGELOG.md
├─CODE_OF_CONDUCT.md
├─CONTRIBUTING.md
├─myproj/
│ ├─main.py
│ ├─py.typed
│ ├─__init__.py
│ └─__version__.py
├─LICENSE
├─pdm.lock
├─pyproject.toml
└─README.md

build.py

"""Setup script for building wheel."""
from pathlib import Path
from typing import Any, Dict

import toml
from setuptools import find_packages

project_metadata = toml.load('pyproject.toml')['project']
short_description = (  # pylint: disable=invalid-name
    'My project.'
)
long_description = Path('README.md').read_text(encoding='utf-8')

kwargs = {
    'name': project_metadata['name'],
    'version': project_metadata['version'],
    'license': project_metadata['license-expression'],
    'author': project_metadata['authors'],
    'python_requires': project_metadata['requires-python'],
    'zip_safe': False,
    'packages': find_packages(),
    'description': short_description,
    'long_description': long_description,
    'long_description_content_type': 'text/markdown',
}


def build(setup_kwargs: Dict[str, Any]) -> None:
    """Force pdm to build with these kwargs."""
    setup_kwargs.update(**kwargs)

Error Log

build_error_log.txt

If instead I use is-purelib

[tool.pdm]
# build = "build.py"
is-purelib = false

pdm will install my editable project. Running pdm build still gives the error that it cannot find build:

ModuleNotFoundError: No module named 'build'

and even if I try pdm build --no-isolation, I get the error:

configuration error: `project` must not contain {'license-expression'} properties

pdm_build_error_log.txt
pdm_build_no_isolation_error_log.txt

The error with --no-isolation specified persists even when 'license' is manually updated in build.py:

kwargs = {
    ...
    'license': 'Apache-2.0',
    ...
}

because the information is pulled from the pyproject.toml where license-expression is specified.

@adam-grant-hendry adam-grant-hendry added the 🐛 bug Something isn't working label Jun 12, 2022
@adam-grant-hendry
Copy link
Author

The above is fixed by changing the build system to pdm-pep517 and adding toml to requires since I use it

[build-system]
requires = [
    "pdm-pep517>=0.12.0",
    "toml>=0.10.2",
]
build-backend = "pdm.pep517.api"

and specifying the license to project as follows:

[project]
license = { text = "Apache-2.0" }

If you want to keep this PR open to debug and identify areas where pdm import could be improved or adding disclaimers about using other build systems, feel free. Otherwise, you may close this Issue.

Aside:

I use venv and was trying to use setuptools for now to slowly adopt PDM. I'm also waiting to see how the Python community responds to using PEP 517 over time.

Bottom line, I would still use this over poetry as it is faster, gives me far less dependency grief, and doesn't automatically upper-bound my constraints.

Would definitely like to see how flit build backend works with this in the future.

Thanks for the great package!

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

Successfully merging a pull request may close this issue.

1 participant