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
7 changed files
with
99 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
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,27 @@ | ||
from clikit.io import NullIO | ||
|
||
from poetry.masonry.builders import SdistBuilder | ||
from poetry.utils._compat import Path | ||
from poetry.utils.env import NullEnv | ||
from ..command import Command | ||
|
||
|
||
class SetupFileCommand(Command): | ||
""" | ||
Generate a setuptools compatible <comment>setup.py</comment> | ||
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 |
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,15 @@ | ||
from ..command import Command | ||
from poetry.console.commands.setuptools import SetupFileCommand | ||
|
||
|
||
class SetuptoolsCommand(Command): | ||
""" | ||
Manage setuptools assets for this project. | ||
setuptools | ||
""" | ||
|
||
commands = [SetupFileCommand()] | ||
|
||
def handle(self): # type: () -> int | ||
return self.call("help", self._config.name) |
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,37 @@ | ||
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"), str(project_dir)) | ||
yield Poetry.create(project_dir) | ||
shutil.rmtree(str(project_dir), ignore_errors=True) | ||
|
||
|
||
def test_setupfile(app): | ||
command = app.find("setuptools setupfile") | ||
setupfile = Path(app.poetry.file.parent, "setup.py") | ||
|
||
tester = CommandTester(command) | ||
tester.execute() | ||
|
||
assert setupfile.is_file() | ||
|
||
expected = "Writing to {}\n".format(setupfile) | ||
assert expected == tester.io.fetch_output() |