forked from python-poetry/poetry
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add setuptools command to generate setup.py
This change introduces `setuptools:setupfile` command that generates a `setup.py` file for the project. Resolves: python-poetry#761
- Loading branch information
Showing
5 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .setupfile import SetupFileCommand |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from poetry.console.commands.env_command import EnvCommand | ||
from poetry.io import NullIO | ||
from poetry.masonry.builders import SdistBuilder | ||
from poetry.utils._compat import Path | ||
from poetry.utils.env import NullEnv | ||
|
||
|
||
class SetupFileCommand(EnvCommand): | ||
""" | ||
Generate a setuptools compatible <comment>setup.py</comment> | ||
setuptools:setupfile | ||
""" | ||
|
||
def handle(self): | ||
try: | ||
setupfile = Path(self.poetry.file.parent, "setup.py") | ||
self.line("<info>Writing to <comment>{}</comment></info>".format(setupfile)) | ||
builder = SdistBuilder(self.poetry, NullEnv(), NullIO()) | ||
setupfile.write_bytes(builder.build_setup()) | ||
except Exception as e: | ||
self.line("<error>{}</error>".format(e)) | ||
self.line("<error>Failed to write <comment>setup.py</comment>.</error>") | ||
return 1 | ||
|
||
return 0 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import shutil | ||
import tempfile | ||
|
||
import pytest | ||
from cleo.testers import CommandTester | ||
|
||
from poetry.poetry import Poetry | ||
from poetry.utils._compat import Path | ||
from tests.test_poetry import fixtures_dir | ||
|
||
|
||
@pytest.fixture | ||
def tmp_dir(): | ||
dir_ = tempfile.mkdtemp(prefix="poetry_") | ||
yield dir_ | ||
shutil.rmtree(dir_) | ||
|
||
|
||
@pytest.fixture | ||
def poetry(repo, tmp_dir): | ||
project_dir = Path(tmp_dir, "sample_project") | ||
shutil.copytree(str(fixtures_dir / "simple_project"), project_dir) | ||
yield Poetry.create(project_dir) | ||
|
||
|
||
def test_setupfile(app): | ||
command = app.find("setuptools:setupfile") | ||
setupfile = Path(app.poetry.file.parent, "setup.py") | ||
|
||
tester = CommandTester(command) | ||
tester.execute([("command", command.get_name())]) | ||
|
||
assert setupfile.is_file() | ||
|
||
expected = "Writing to {}\n".format(setupfile) | ||
assert tester.get_display(True) == expected |