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

move build configuration from setup.cfg to pyproject.toml #38

Merged
merged 4 commits into from
Jun 22, 2023

Conversation

zacharyburnett
Copy link
Contributor

@zacharyburnett zacharyburnett commented Apr 25, 2023

setuptools now supports the [project] table for project metadata, defined by PEP621.

Additionally, setuptools now supports its own entry in pyproject.toml called [tool.setuptools] (pypa/setuptools#1688, https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html#setuptools-specific-configuration); however, it comes with the following disclaimer:

Support for declaring configurations not standardized by PEP 621 (i.e. the [tool.setuptools] table), is still in beta stage and might change in future releases.

Reading toml is supported natively in Python 3.11 with tomllib. Given this, we can consolidate the build configuration into a single pyproject.toml file that can possibly be read by other build systems in the future.

@zacharyburnett zacharyburnett marked this pull request as ready for review April 25, 2023 13:35
@zacharyburnett
Copy link
Contributor Author

zacharyburnett commented Apr 26, 2023

docs for this PR are hosted at https://oa-packaging-guide-preview--38.org.readthedocs.build/en/38/:

image

@zacharyburnett zacharyburnett force-pushed the pep621 branch 6 times, most recently from 3a500aa to ac48dbe Compare April 26, 2023 13:28
@pllim
Copy link

pllim commented Apr 28, 2023

@WilliamJamieson already did this transition for several Astropy related projects, so maybe he can help review if he is willing? 🙏

@Cadair Cadair requested review from Cadair and astrofrog June 22, 2023 09:41
Copy link
Member

@Cadair Cadair left a comment

Choose a reason for hiding this comment

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

Looks good to me. Going to let @astrofrog have a look as well.

docs/minimal.rst Outdated Show resolved Hide resolved
Copy link
Contributor

@astrofrog astrofrog left a comment

Choose a reason for hiding this comment

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

Thank you for your work on this! This seems like a good idea and the changes look good to me though I did not try out the template.

@Cadair
Copy link
Member

Cadair commented Jun 22, 2023

I am going to merge this as-is and then tidy up any loose ends after

@Cadair Cadair merged commit 0c01dbd into OpenAstronomy:main Jun 22, 2023
@zacharyburnett zacharyburnett deleted the pep621 branch June 22, 2023 12:58
@matteobachetti
Copy link

matteobachetti commented Jun 27, 2023

Hi, I was trying out the new package template. To make the installation work, I had to put a bunch of double quotes around the name and description of the project, and my name and email. Also, I had to comment out the include_package_date line in the [tool.setuptools] section, and make sure there was the schema in each url ("https://" or whatever)

@Cadair
Copy link
Member

Cadair commented Jun 27, 2023

Thanks for the report, I am planning on getting back to this tomorrow and finishing up the cleanup in #27

Why did you have to remove include_package_date? I haven't even heard of that config before.

@matteobachetti
Copy link

@Cadair I attach the exact report for this error:

Obtaining file:///Users/meo/devel/heasarc_retrieve_pipeline
  Installing build dependencies ... done
  Checking if build backend supports build_editable ... done
  Getting requirements to build editable ... error
  error: subprocess-exited-with-error
  
  × Getting requirements to build editable did not run successfully.
  │ exit code: 1
  ╰─> [707 lines of output]
      /private/var/folders/xy/8sw1hd2d6zlgjgfb8h8zw2r00000gq/T/pip-build-env-4__h464n/overlay/lib/python3.10/site-packages/setuptools/config/pyprojecttoml.py:66: _BetaConfiguration: Support for `[tool.setuptools]` in `pyproject.toml` is still *beta*.
        config = read_configuration(filepath, True, ignore_option_errors, dist)
      configuration error: `tool.setuptools` must not contain {'include-package-date'} properties
      DESCRIPTION:
          Please notice for the time being the ``setuptools`` project does not specify
          a way of configuring builds via ``pyproject.toml``. Therefore this schema
          should be taken just as a *"thought experiment"* on how this *might be
          done*, by following the principles established in `ini2toml
          <https://ini2toml.readthedocs.io/en/latest/setuptools_pep621.html>`_. It
          considers only ``setuptools`` `parameters
          <https://setuptools.pypa.io/en/latest/userguide/declarative_config.html>`_
          that can currently be configured via ``setup.cfg`` and are not covered by
          :pep:`621` but intentionally excludes ``dependency_links`` and
          ``setup_requires``. NOTE: ``scripts`` was renamed to ``script-files`` to
          avoid confusion with entry-point based scripts (defined in :pep:`621`).
      
      GIVEN VALUE:
(...)
      Traceback (most recent call last):
        File "/Users/meo/opt/anaconda3/envs/py310/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
          main()
        File "/Users/meo/opt/anaconda3/envs/py310/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
        File "/Users/meo/opt/anaconda3/envs/py310/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 132, in get_requires_for_build_editable
          return hook(config_settings)
        File "/private/var/folders/xy/8sw1hd2d6zlgjgfb8h8zw2r00000gq/T/pip-build-env-4__h464n/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 450, in get_requires_for_build_editable
          return self.get_requires_for_build_wheel(config_settings)
        File "/private/var/folders/xy/8sw1hd2d6zlgjgfb8h8zw2r00000gq/T/pip-build-env-4__h464n/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 341, in get_requires_for_build_wheel
          return self._get_build_requires(config_settings, requirements=['wheel'])
        File "/private/var/folders/xy/8sw1hd2d6zlgjgfb8h8zw2r00000gq/T/pip-build-env-4__h464n/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 323, in _get_build_requires
          self.run_setup()
        File "/private/var/folders/xy/8sw1hd2d6zlgjgfb8h8zw2r00000gq/T/pip-build-env-4__h464n/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 338, in run_setup
          exec(code, locals())
        File "<string>", line 6, in <module>
        File "/private/var/folders/xy/8sw1hd2d6zlgjgfb8h8zw2r00000gq/T/pip-build-env-4__h464n/overlay/lib/python3.10/site-packages/setuptools/__init__.py", line 107, in setup
          return distutils.core.setup(**attrs)
        File "/private/var/folders/xy/8sw1hd2d6zlgjgfb8h8zw2r00000gq/T/pip-build-env-4__h464n/overlay/lib/python3.10/site-packages/setuptools/_distutils/core.py", line 159, in setup
          dist.parse_config_files()
        File "/private/var/folders/xy/8sw1hd2d6zlgjgfb8h8zw2r00000gq/T/pip-build-env-4__h464n/overlay/lib/python3.10/site-packages/setuptools/dist.py", line 898, in parse_config_files
          pyprojecttoml.apply_configuration(self, filename, ignore_option_errors)
        File "/private/var/folders/xy/8sw1hd2d6zlgjgfb8h8zw2r00000gq/T/pip-build-env-4__h464n/overlay/lib/python3.10/site-packages/setuptools/config/pyprojecttoml.py", line 66, in apply_configuration
          config = read_configuration(filepath, True, ignore_option_errors, dist)
        File "/private/var/folders/xy/8sw1hd2d6zlgjgfb8h8zw2r00000gq/T/pip-build-env-4__h464n/overlay/lib/python3.10/site-packages/setuptools/config/pyprojecttoml.py", line 128, in read_configuration
          validate(subset, filepath)
        File "/private/var/folders/xy/8sw1hd2d6zlgjgfb8h8zw2r00000gq/T/pip-build-env-4__h464n/overlay/lib/python3.10/site-packages/setuptools/config/pyprojecttoml.py", line 55, in validate
          raise ValueError(f"{error}\n{summary}") from None
      ValueError: invalid pyproject.toml config: `tool.setuptools`.
      configuration error: `tool.setuptools` must not contain {'include-package-date'} properties
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× Getting requirements to build editable did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

@Cadair
Copy link
Member

Cadair commented Jun 27, 2023

haha ok! 😆

@matteobachetti
Copy link

The thing about the thought experiment is hilarious indeed :D

@saimn
Copy link

saimn commented Jun 27, 2023

Should be include-package-data.

@matteobachetti
Copy link

Should be include-package-data.

Yep, it works!

docs = [
"sphinx",
"sphinx-automodapi",
"tomli; python_version <\"3.11\"",
Copy link
Member

Choose a reason for hiding this comment

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

@zacharyburnett Sorry to necrobump this, but why do we need this one for the docs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no worries! If a package ever wants to read metadata from pyproject.toml (for instance to set author and version for Sphinx), it needs a TOML reader; before Python 3.11, an external package tomli provided that, but the reading functionality was folded into the builtins in 3.11 with tomllib. Thus, if you add this to conf.py:
https://github.com/spacetelescope/jwst/blob/970bac9ac635aed35c7c1934761d42cd5934d981/docs/conf.py#L20-L23

if sys.version_info < (3, 11):
     import tomli as tomllib
else:
     import tomllib

then you can read the metadata regardless of which package is installed:
https://github.com/spacetelescope/jwst/blob/970bac9ac635aed35c7c1934761d42cd5934d981/docs/conf.py#L71-L72

with open(Path(__file__).parent.parent / "pyproject.toml", "rb") as metadata_file:
   metadata = tomllib.load(metadata_file)['project']

Now that I think of it, I imagine that this can be done simpler with a __future__ import.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the info. I think because we don't do that in this guide I will probably drop it for now 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sounds good, sorry to include extra stuff!

Copy link
Member

Choose a reason for hiding this comment

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

No worries!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants