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
Requirements spec #203
Merged
Merged
Requirements spec #203
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,43 @@ | ||
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 can_handle(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be nice to have normal methods after private ones... so def __init__ ...
def _valid_file ...
def _valid_name ....
def can_handle ... |
||
return self._valid_file() and self._valid_name() | ||
|
||
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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a typo here: |
||
return False | ||
else: | ||
return True | ||
|
||
@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,26 @@ | ||
import unittest | ||
from conda_env import env | ||
from conda_env.specs.requirements import RequirementsSpec | ||
from .. import utils | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as comment from before :-) |
||
|
||
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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is nice to have imports separated by the origin like...