Commit 10e471a0 by finswimmer Committed by Sébastien Eustace

create PEP508 compliant dependency string for directory and file dependencies (#1796)

* fix (directory_dependency, file_dependency): create PEP508 compliant dependency string for directory and file dependencies

* fix (directory_dependency, file_dependency): making isort and black happy
parent cbb1c181
......@@ -74,6 +74,17 @@ class DirectoryDependency(Dependency):
def develop(self):
return self._develop
@property
def base_pep_508_name(self): # type: () -> str
requirement = self.pretty_name
if self.extras:
requirement += "[{}]".format(",".join(self.extras))
requirement += " @ {}".format(self._path)
return requirement
def supports_poetry(self):
return self._supports_poetry
......
......@@ -49,6 +49,17 @@ class FileDependency(Dependency):
def full_path(self):
return self._full_path.resolve()
@property
def base_pep_508_name(self): # type: () -> str
requirement = self.pretty_name
if self.extras:
requirement += "[{}]".format(",".join(self.extras))
requirement += " @ {}".format(self._path)
return requirement
def is_file(self):
return True
......
......@@ -8,12 +8,24 @@ from poetry.utils.env import EnvCommandError
from poetry.utils.env import MockEnv as BaseMockEnv
fixtures_dir = Path(__file__).parent.parent / "fixtures"
DIST_PATH = Path(__file__).parent.parent / "fixtures" / "git" / "github.com" / "demo"
class MockEnv(BaseMockEnv):
def run(self, bin, *args):
raise EnvCommandError(CalledProcessError(1, "python", output=""))
DIST_PATH = Path(__file__).parent.parent / "fixtures" / "git" / "github.com" / "demo"
def test_directory_dependency():
dependency = DirectoryDependency("simple_project", fixtures_dir / "simple_project")
assert dependency.pretty_name == "simple_project"
assert dependency.develop
assert dependency.path == fixtures_dir / "simple_project"
assert dependency.base_pep_508_name == "simple_project @ {}".format(
fixtures_dir / "simple_project"
)
def test_directory_dependency_must_exist():
......
......@@ -7,6 +7,16 @@ from poetry.utils._compat import Path
DIST_PATH = Path(__file__).parent.parent / "fixtures" / "distributions"
def test_file_dependency():
dependency = FileDependency("demo", DIST_PATH / "demo-0.1.0.tar.gz")
assert dependency.pretty_name == "demo"
assert dependency.path == DIST_PATH / "demo-0.1.0.tar.gz"
assert dependency.base_pep_508_name == "demo @ {}".format(
DIST_PATH / "demo-0.1.0.tar.gz"
)
def test_file_dependency_wrong_path():
with pytest.raises(ValueError):
FileDependency("demo", DIST_PATH / "demo-0.2.0.tar.gz")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment