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

Change the primary name of the console script to setuptools-pyproject-migration #127

Merged
merged 5 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,18 @@ After that, in any directory that has a `setup.py` and/or `setup.cfg` file, you
can run

```console
setup-to-pyproject
setuptools-pyproject-migration
```

and it will print out the content of `pyproject.toml` as computed from your
`setup.py` and/or `setup.cfg`. Running `setup-to-pyproject -h` will print
a brief usage summary.
`setup.py` and/or `setup.cfg`. Running `setuptools-pyproject-migration -h` will
print a brief usage summary.

You can also install and run the application in one go as follows:

```console
pipx run setuptools-pyproject-migration
```

### Virtual environment

Expand Down
1 change: 1 addition & 0 deletions changelog.d/107.removal.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Deprecate setup-to-pyproject console script in favor of setuptools-pyproject-migration to support ``pipx run``
11 changes: 9 additions & 2 deletions docs/usage-cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,18 @@ you can run

.. code-block::

$ setup-to-pyproject
$ setuptools-pyproject-migration

and it will print out the content of ``pyproject.toml`` as computed from your
``setup.py`` and/or ``setup.cfg``.

Running ``setup-to-pyproject --help`` will print a brief usage summary.
Running ``setuptools-pyproject-migration --help`` will print a brief usage
summary.

You can also install and run the application in one go as follows:

```console
pipx run setuptools-pyproject-migration
```

.. _pipx: https://pypa.github.io/pipx/
3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ docs =

[options.entry_points]
console_scripts =
setup-to-pyproject = setuptools_pyproject_migration.cli:main
setup-to-pyproject = setuptools_pyproject_migration.cli:old_main
setuptools-pyproject-migration = setuptools_pyproject_migration.cli:main
distutils.commands =
pyproject = setuptools_pyproject_migration:WritePyproject
9 changes: 9 additions & 0 deletions src/setuptools_pyproject_migration/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import argparse
import os.path
import sys
import warnings


def _parse_args() -> argparse.Namespace:
Expand Down Expand Up @@ -66,6 +67,14 @@ def main() -> None:
exec(setup_bytecode)


def old_main() -> None:
"""
Print a deprecation warning and then call :py:func:`main()`.
"""
warnings.warn(f"{sys.argv[0]} is deprecated; run setuptools-pyproject-migration instead", category=FutureWarning)
main()


# Allow running as `python -m setuptools_pyproject_migration.cli`
if __name__ == "__main__": # pragma: no cover
main()
8 changes: 4 additions & 4 deletions test_support/test_support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ def run(self, runner: ProjectRunner) -> ProjectRunResult:

def run_cli(self, runner: ProjectRunner) -> ProjectRunResult:
"""
Run the console script ``setup-to-pyproject`` on the created project and
return the output.
Run the console script ``setuptools-pyproject-migration`` on the created
project and return the output.

In contrast to :py:meth:`run()`, if ``setup.py`` doesn't exist, it will
not be created, because the script is supposed to work without it. If
Expand All @@ -173,8 +173,8 @@ def run_cli(self, runner: ProjectRunner) -> ProjectRunResult:

:param runner: The callable to use to run the script
"""
_logger.debug("Running setup-to-pyproject in %s", self.root)
return runner(["setup-to-pyproject"], cwd=self.root)
_logger.debug("Running setuptools-pyproject-migration in %s", self.root)
return runner(["setuptools-pyproject-migration"], cwd=self.root)

def generate(self) -> Pyproject:
"""
Expand Down
50 changes: 50 additions & 0 deletions tests/test_deprecated_console_script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import pytest
import tomlkit

from test_support import ProjectRunner


def test_future_warning(project, console_script_project_runner: ProjectRunner) -> None:
"""
Test that a ``FutureWarning`` is issued when calling the old script name.
"""
setup_cfg = """\
[metadata]
name = test-project
version = 0.0.1
"""
project.setup_cfg(setup_cfg)
with pytest.warns(FutureWarning):
console_script_project_runner(["setup-to-pyproject"], cwd=project.root)


def test_name_and_version(project, console_script_project_runner: ProjectRunner) -> None:
"""
Test we can generate a basic project skeleton.
"""
setup_cfg = """\
[metadata]
name = test-project
version = 0.0.1
"""
expected = tomlkit.parse(
"""\
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[project]
name = "test-project"
version = "0.0.1"
"""
)
project.setup_cfg(setup_cfg)

result = console_script_project_runner(["setup-to-pyproject"], cwd=project.root)

assert result.returncode == 0

prefix = "running pyproject\n"
assert result.stdout.startswith(prefix)
actual = tomlkit.parse(result.stdout[len(prefix) :])
assert expected == actual
Loading