-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement init tasks #28
Conversation
Fixing flake8 errors now. |
@@ -11,7 +11,7 @@ | |||
# Unless required by applicable law or agreed to in writing, software | |||
# distributed under the License is distributed on an "AS IS" BASIS, | |||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
# See the License for the specific language governing permissions and | |||
# See the License for the specific dependency governing permissions and |
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.
Global replace error?
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.
Yes
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.
Fixed.
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.
I think most of this looks pretty good, but I think pulling the config generation out of init into its own thing should be fairly high priority, if I'm understanding that section correctly.
import os | ||
import logging | ||
from pkg_resources import resource_filename |
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.
Minor style notes: from
statements should go above import
statements, and pkg_resources
isn't part of the standard library, so it should be with jinja2
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.
Huh... did pkg_resources
become standard library in Python 3.x?
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.
I don't think it's standard in Python 3.x either, although I'm not entirely sure. It's part of setuptools
which just seems ubiquitous.
distutils
is part of the standard library, but setuptools
is a separate library.
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.
My docker experiments lead me to believe that pkg_resources
IS part of the standard library as of Python 2..12.
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.
Fixed.
'containenv.config.dockerfile_templates', | ||
self.from_image), 'r') as fh: | ||
self.dockerfile_template = fh.read() | ||
logger.warning('self.metasource: {}'.format(self.metasource)) |
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.
When formatting log messages you should use the old style syntax and pass your format parameters as args to the logger method.
logger.warning('self.metasource: %s', self.metasource)
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.
fixed.
|
||
def _check_project_existence(self): | ||
'''verify that self.proj_path is a valid project''' | ||
if not os.path.isdir(self.proj_path): |
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.
How can this ever be False? Something with metasource
? Why not just imply that it's cwd
the way git init
does?
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.
In case the User uses the tool improperly?
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.
I think I don't really understand why we're allowing the user to specify metasource
. Why not just always use the current directory?
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.
If the User passes in an invalid target (not a directory) I want to handle/report it ASAP. Is this OK? @dangle I think we need to discuss this a little more.
'argument it received was: {}\nwhich does not map to ' | ||
'a path to an existing directory.' | ||
''.format(self.metasource)) | ||
raise ProjectDirectoryDoesNotExist(error) |
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.
Since you're using a custom exception, I'd put most of this message in the exception class and only pass in self.metasource
.
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.
Ack.
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.
fixed.
|
||
def _make_task(self, method): | ||
'''create a run_tasks compliant task''' | ||
return (method.__doc__, method) |
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.
I think using method.__doc__
is a neat trick, but I'm not sure how i18n will work when doing that.
Is i18n even something we're concerned with?
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.
Yes.
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.
But not so concerned that I think we should block this PR on it. This is tracked in issue #29.
'''The argument does not _already_ possess a ".containenv".''' | ||
init_command = Init(testdirectory) | ||
init_command.make_path() | ||
assert init_command.check_initialization_state() is None |
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.
Add an assertion message, por favor.
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.
Ack.
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.
Fixed.
assert init_command.check_initialization_state() is None | ||
|
||
|
||
# tests post self.make_containenv_dir |
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.
Make this the docstring?
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.
Ack.
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.
Fixed.
def test__check_initialization_state_already_initialized(testdirskeleton): | ||
'''The argument _already_ (incorrectly) possesses a ".containenv".''' | ||
testdirectory, CONTAINENVPATH, SUBDIRPATH, init_command = testdirskeleton | ||
EXPECTED_ERROR = ('init can only be called once per project, but the {}\n' |
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.
Same as above. Test the value, not the message.
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.
Ack.
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.
OK, can we leave the fragiles in, and use best practice going forward.. (e.g. change to value checks WHEN the messages change?)
self._register_file(dirpath, fname, extension) | ||
for dirn in dirs: | ||
self._register_dirs(dirpath, dirn, dirs) | ||
if not self.registered_dependency_catalog: |
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.
Is this really an error? Can I run this on an empty directory?
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.
You shouldn't be running this on an empty directory. Should you?
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.
I've been thinking of this in terms of git init
and virtualenv .
.
git init
can happen at any time, and is often one of the first steps of the project (otherwise, I'm probably cloning).
virtualenv .
is pretty much the very first part of creating a new project. You create your virtualenv, activate it, then start working on your code from there. I was thinking containenv
would do the same thing. I'd create my project folder, run containenv init
in it, contain
to activate, then start working inside my container.
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.
I think containenv
has a contract with the User that says:
You give me a directory structure with source code, and meta-source code
I'll give you:
- an image config (including entrypoint and runner)
- an image
I'll run that image and give you:
- a contained environment for that source code you gave me.
If the User gives containenv
an empty directory containenv
breaks saying: You violated our contract. If the User gives containenv
a directory with 0 files that containenv
recognizes... containenv
breaks saying, you violated our contract.
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.
I added this blurb to the README.
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.
I think supporting empty directories is a pretty useful feature. If I want this for development, I want it for all of development, not just the end of it.
I'll log that that as a separate issue though.
{fnames[3], SUBDIRPATH, CONTAINENVPATH} | ||
|
||
|
||
BASH_GOT_GIT_MAKE_TMPL = 'FROM ubuntu:latest\n' +\ |
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.
Use r"""blah blah blah"""
for this so you don't have all the line wrapping and escaping.
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.
Ack.
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.
OK, can we fix this later... I'm reluctant to mess with it since it works, and flake8 doesn't complain at me.
I'll address these comments this afternoon. If it's OK with you @dangle, I'll probably make some of them (e.g. support other version control systems) into new issues, rather than block this PR. |
OK, As Far As I Can Tell, AFAICT, this is ready to merge. |
@dangle what do you think? |
Fixes #25
Check out this branch.
In an appropriate environment:
sudo pip install --upgrade containenv
cd SOMEPROJECT && containenv init
cd .containenv && bash runcontainenv.sh