This repository has been archived by the owner on Jan 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #203 from conda/requirements-spec
Requirements spec
- Loading branch information
Showing
6 changed files
with
80 additions
and
1 deletion.
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,44 @@ | ||
import os | ||
|
||
from .. import env | ||
|
||
|
||
class RequirementsSpec(object): | ||
''' | ||
Reads depedencies from a requirements.txt file | ||
and returns an Environment object from it. | ||
''' | ||
msg = None | ||
|
||
def __init__(self, filename=None, name=None, **kwargs): | ||
self.filename = filename | ||
self.name = name | ||
self.msg = None | ||
|
||
def _valid_file(self): | ||
if os.path.exists(self.filename): | ||
return True | ||
else: | ||
self.msg = "There is no requirements.txt" | ||
return False | ||
|
||
def _valid_name(self): | ||
if self.name is None: | ||
self.msg = "Environment with requierements.txt file needs a name" | ||
return False | ||
else: | ||
return True | ||
|
||
def can_handle(self): | ||
return self._valid_file() and self._valid_name() | ||
|
||
@property | ||
def environment(self): | ||
dependencies = [] | ||
with open(self.filename) as reqfile: | ||
for line in reqfile: | ||
dependencies.append(line) | ||
return env.Environment( | ||
name=self.name, | ||
dependencies=dependencies | ||
) |
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,28 @@ | ||
import unittest | ||
|
||
from .. import utils | ||
|
||
from conda_env import env | ||
from conda_env.specs.requirements import RequirementsSpec | ||
|
||
|
||
class TestRequiremets(unittest.TestCase): | ||
def test_no_environment_file(self): | ||
spec = RequirementsSpec(name=None, filename='not-a-file') | ||
self.assertEqual(spec.can_handle(), False) | ||
|
||
def test_no_name(self): | ||
spec = RequirementsSpec(filename=utils.support_file('requirements.txt')) | ||
self.assertEqual(spec.can_handle(), False) | ||
|
||
def test_req_file_and_name(self): | ||
spec = RequirementsSpec(filename=utils.support_file('requirements.txt'), name='env') | ||
self.assertTrue(spec.can_handle()) | ||
|
||
def test_environment(self): | ||
spec = RequirementsSpec(filename=utils.support_file('requirements.txt'), name='env') | ||
self.assertIsInstance(spec.environment, env.Environment) | ||
self.assertEqual( | ||
spec.environment.dependencies['conda'][0], | ||
'flask ==0.10.1' | ||
) |
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 @@ | ||
flask==0.10.1 |