Skip to content
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

Merged
merged 37 commits into from
Jan 2, 2017
Merged

Implement init tasks #28

merged 37 commits into from
Jan 2, 2017

Conversation

zancas
Copy link
Collaborator

@zancas zancas commented Dec 30, 2016

Fixes #25

Check out this branch.

In an appropriate environment:

sudo pip install --upgrade containenv
cd SOMEPROJECT && containenv init
cd .containenv && bash runcontainenv.sh

@zancas
Copy link
Collaborator Author

zancas commented Dec 30, 2016

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Global replace error?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Copy link
Collaborator

@dangle dangle left a 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
Copy link
Collaborator

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

Copy link
Collaborator Author

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?

Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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))
Copy link
Collaborator

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)

Copy link
Collaborator Author

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):
Copy link
Collaborator

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?

Copy link
Collaborator Author

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?

Copy link
Collaborator

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?

Copy link
Collaborator Author

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)
Copy link
Collaborator

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack.

Copy link
Collaborator Author

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)
Copy link
Collaborator

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

Copy link
Collaborator Author

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
Copy link
Collaborator

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack.

Copy link
Collaborator Author

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this the docstring?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack.

Copy link
Collaborator Author

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'
Copy link
Collaborator

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack.

Copy link
Collaborator Author

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:
Copy link
Collaborator

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?

Copy link
Collaborator Author

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?

Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator

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' +\
Copy link
Collaborator

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack.

Copy link
Collaborator Author

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.

@zancas
Copy link
Collaborator Author

zancas commented Dec 30, 2016

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.

@zancas
Copy link
Collaborator Author

zancas commented Jan 2, 2017

OK, As Far As I Can Tell, AFAICT, this is ready to merge.

@zancas
Copy link
Collaborator Author

zancas commented Jan 2, 2017

@dangle what do you think?

@dangle dangle assigned zancas and unassigned dangle Jan 2, 2017
@dangle dangle merged commit 50ff009 into development Jan 2, 2017
@dangle dangle deleted the implement_init_tasks branch January 15, 2017 05:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants