[setup] drop deprecated `distutils` usage
Author: XuehaiPan
Pull request: yes

# What does this PR do?

<!--
Congratulations! You've made it this far! You're not quite done yet though.

Once merged, your PR is going to appear in the release notes with the title you set, so make sure it's a great title that fully reflects the extent of your awesome contribution.

Then, please replace this with a description of the change and which issue is fixed (if applicable). Please also include relevant motivation and context. List any dependencies (if any) that are required for this change.

Once you're done, someone will review your PR shortly (see the section "Who can review?" below to tag some potential reviewers). They may suggest changes to make the code even better. If no one reviewed your PR after a week has passed, don't hesitate to post a new comment @-mentioning the same persons---sometimes notifications get lost.
-->

<!-- Remove if not applicable -->

Migrate setup script to `pyproject.toml` ([PEP 517 – A build-system independent format for source trees](https://peps.python.org/pep-0517)).

Changes:

- drop deprecated `distutils` usage
- ~~migrate setup script to `pyproject.toml`~~
- ~~migrate `isort` and `pytest` configs to `pyproject.toml`~~
- ~~migrate `flake8` configs to `.flake8` and remove `setup.cfg` file~~

## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [X] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests),
      Pull Request section?
- [ ] Was this discussed/approved via a Github issue or the [forum](https://discuss.huggingface.co/)? Please add a link
      to it if that's the case.
- [ ] Did you make sure to update the documentation with your changes? Here are the
      [documentation guidelines](https://github.com/huggingface/transformers/tree/main/docs), and
      [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [ ] Did you write any new necessary tests?


## Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

<!-- Your PR will be replied to more quickly if you can figure out the right person to tag with @

 If you know how to use git blame, that is the easiest way, otherwise, here is a rough guide of **who to tag**.
 Please tag fewer than 3 people.

Models:

- text models: @ArthurZucker and @younesbelkada
- vision models: @amyeroberts
- speech models: @sanchit-gandhi
- graph models: @clefourrier

Library:

- flax: @sanchit-gandhi
- generate: @gante
- pipelines: @Narsil
- tensorflow: @gante and @Rocketknight1
- tokenizers: @ArthurZucker
- trainer: @sgugger

Integrations:

- deepspeed: HF Trainer: @stas00, Accelerate: @pacman100
- ray/raytune: @richardliaw, @amogkam

Documentation: @sgugger, @stevhliu and @MKhalusova

HF projects:

- accelerate: [different repo](https://github.com/huggingface/accelerate)
- datasets: [different repo](https://github.com/huggingface/datasets)
- diffusers: [different repo](https://github.com/huggingface/diffusers)
- rust tokenizers: [different repo](https://github.com/huggingface/tokenizers)

Maintained examples (not research project or legacy):

- Flax: @sanchit-gandhi
- PyTorch: @sgugger
- TensorFlow: @Rocketknight1

 -->


Comments:
_The documentation is not available anymore as the PR was closed or merged._

> but we are very happy with the setup as it is.

Thanks for the clarification. The `pyprojct.toml` format is the recommended packaging method in [PEP 517 – A build-system independent format for source trees](https://peps.python.org/pep-0517). I have reverted some of the commits but kept the first one. The `distutils` module is deprecated and will be removed in Python 3.12 (See also [PEP 632 – Deprecate distutils module](https://peps.python.org/pep-0632)). In this PR, I changed `distutils.core.Command` to `setuptools.Command`.

I think you can suggest the changes thate removed the setup.cfg in a separate PR, it's a good cleanup (but not relevant to this PR anymore)

For migrating the setup.py to the pyproject, let's see with @LysandreJik what he thinks. My first reaction is to keep what's been working for us all these years ;-)

Thanks for the clarification. Since we have already dropped Python 3.6 support, `setuptools` works very well with `pyproject.toml` based project. We can move the static parts in `setup.py` to `pyproject.toml`. Note that the optional dependencies are too dynamic, so we still need a `setup.py` file.

Most Python utilities support `pyproject.toml` configuration (`black`, `isort`, `ruff`, `pytest`, ...). And some do not even support other config files like `setup.cfg` (e.g., `black`). I think maintaining configurations in a single file is a good practice. If you decide to migrate to `pyproject.toml`, pin me if I can help.

Yes, moving all configurations to the pyproject.toml is something we would like to clean up. If you want to contribute it, please open a PR :-) Note that we kept the isort and flake8 configurations for a bit after our migration to ruff, but they can now be completely removed, so it would just be pytest if I'm not mistaken.