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

WIP: Set license and license-files key in project metadata to follow PEP639 #3699

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

weiji14
Copy link
Member

@weiji14 weiji14 commented Dec 19, 2024

Description of proposed changes

Specify exact variant of license using SPDX format (BSD-3-Clause) in the pyproject.toml file, remove license classifier.

References:

Fixes #

Preview:

Reminders

  • Run make format and make check to make sure the code follows the style guide.
  • Add tests for new features or tests that would have caught the bug that you're fixing.
  • Add new public functions/methods/classes to doc/api/index.rst.
  • Write detailed docstrings for all functions/methods.
  • If wrapping a new module, open a 'Wrap new GMT module' issue and submit reasonably-sized PRs.
  • If adding new functionality, add an example to docstrings or tutorials.
  • Use underscores (not hyphens) in names of Python files and directories.

Slash Commands

You can write slash commands (/command) in the first line of a comment to perform
specific operations. Supported slash command is:

  • /format: automatically format and lint the code

Adhere to https://peps.python.org/pep-0639 and specify exact variant of license used (BSD-3-Clause).
@weiji14 weiji14 added the documentation Improvements or additions to documentation label Dec 19, 2024
@weiji14 weiji14 added this to the 0.14.0 milestone Dec 19, 2024
@weiji14 weiji14 self-assigned this Dec 19, 2024
@weiji14 weiji14 marked this pull request as ready for review December 20, 2024 00:53
@seisman
Copy link
Member

seisman commented Dec 20, 2024

The changes look good to me, but I'm unsure if we need to wait for upstream changes in setuptools (e.g., pypa/setuptools#3596).

Also remove license-files, because it doesn't seem to be supported by setuptools yet.
@weiji14
Copy link
Member Author

weiji14 commented Dec 20, 2024

Hmm, you're right that license-key doesn't work. I ran make package on commit cddb3ee and got an error like this:

python -m build
* Creating isolated environment: venv+pip...
* Installing packages in isolated environment:
  - setuptools>=64
  - setuptools_scm[toml]>=6.2
* Getting build dependencies for sdist...
configuration error: `project.license` must be valid exactly by one definition (2 matches found):

    - keys:
        'file': {type: string}
      required: ['file']
    - keys:
        'text': {type: string}
      required: ['text']

DESCRIPTION:
    `Project license <https://peps.python.org/pep-0621/#license>`_.

GIVEN VALUE:
    "BSD-3-Clause"

OFFENDING RULE: 'oneOf'

DEFINITION:
    {
        "oneOf": [
            {
                "properties": {
                    "file": {
                        "type": "string",
                        "$$description": [
                            "Relative path to the file (UTF-8) which contains the license for the",
                            "project."
                        ]
                    }
                },
                "required": [
                    "file"
                ]
            },
            {
                "properties": {
                    "text": {
                        "type": "string",
                        "$$description": [
                            "The license of the project whose meaning is that of the",
                            "`License field from the core metadata",
                            "<https://packaging.python.org/specifications/core-metadata/#license>`_."
                        ]
                    }
                },
                "required": [
                    "text"
                ]
            }
        ]
    }
Traceback (most recent call last):
  File "/home/user/mambaforge/envs/pygmt/lib/python3.12/site-packages/pyproject_hooks/_in_process/_in_process.py", line 389, in <module>
    main()
  File "/home/user/mambaforge/envs/pygmt/lib/python3.12/site-packages/pyproject_hooks/_in_process/_in_process.py", line 373, in main
    json_out["return_val"] = hook(**hook_input["kwargs"])
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/mambaforge/envs/pygmt/lib/python3.12/site-packages/pyproject_hooks/_in_process/_in_process.py", line 317, in get_requires_for_build_sdist
    return hook(config_settings)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/build-env-97hptb3y/lib/python3.12/site-packages/setuptools/build_meta.py", line 337, in get_requires_for_build_sdist
    return self._get_build_requires(config_settings, requirements=[])
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/build-env-97hptb3y/lib/python3.12/site-packages/setuptools/build_meta.py", line 304, in _get_build_requires
    self.run_setup()
  File "/tmp/build-env-97hptb3y/lib/python3.12/site-packages/setuptools/build_meta.py", line 320, in run_setup
    exec(code, locals())
  File "<string>", line 1, in <module>
  File "/tmp/build-env-97hptb3y/lib/python3.12/site-packages/setuptools/__init__.py", line 117, in setup
    return distutils.core.setup(**attrs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/build-env-97hptb3y/lib/python3.12/site-packages/setuptools/_distutils/core.py", line 157, in setup
    dist.parse_config_files()
  File "/tmp/build-env-97hptb3y/lib/python3.12/site-packages/setuptools/dist.py", line 648, in parse_config_files
    pyprojecttoml.apply_configuration(self, filename, ignore_option_errors)
  File "/tmp/build-env-97hptb3y/lib/python3.12/site-packages/setuptools/config/pyprojecttoml.py", line 72, in apply_configuration
    config = read_configuration(filepath, True, ignore_option_errors, dist)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/build-env-97hptb3y/lib/python3.12/site-packages/setuptools/config/pyprojecttoml.py", line 140, in read_configuration
    validate(subset, filepath)
  File "/tmp/build-env-97hptb3y/lib/python3.12/site-packages/setuptools/config/pyprojecttoml.py", line 61, in validate
    raise ValueError(f"{error}\n{summary}") from None
ValueError: invalid pyproject.toml config: `project.license`.
configuration error: `project.license` must be valid exactly by one definition (2 matches found):

    - keys:
        'file': {type: string}
      required: ['file']
    - keys:
        'text': {type: string}
      required: ['text']


ERROR Backend subprocess exited when trying to invoke get_requires_for_build_sdist
make: *** [Makefile:29: package] Error 1

I changed it to just license = {text = "BSD-3-Clause"} following https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html#configuring-setuptools-using-pyproject-toml-files, and it seemed to work now, though unsure if this conforms to PEP639? We should monitor the Test PyPI build after merging this PR to see if it works on CI too.

@weiji14 weiji14 changed the title Set license and license-files key in project metadata to follow PEP639 Set license key in project metadata to follow PEP639 Dec 20, 2024
pyproject.toml Outdated
@@ -8,6 +8,7 @@ description = "A Python interface for the Generic Mapping Tools"
readme = "README.md"
requires-python = ">=3.11"
authors = [{name = "The PyGMT Developers", email = "[email protected]"}]
license = {text = "BSD-3-Clause"}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://peps.python.org/pep-0639/#deprecate-license-key-table-subkeys

If I understand it correctly, this syntax will be deprecated.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok, I'll revert the change then and mark this PR as draft until setuptools supports PEP639 properly.

@weiji14 weiji14 marked this pull request as draft December 20, 2024 03:22
@weiji14 weiji14 changed the title Set license key in project metadata to follow PEP639 WIP: Set license and license-files key in project metadata to follow PEP639 Dec 20, 2024
@seisman seisman removed this from the 0.14.0 milestone Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants