-
Notifications
You must be signed in to change notification settings - Fork 44
Home
We highly recommend PyCharm for developing cameo.
Cameo code pretty much follows PEP8. Lines with > 72 character are ok though. It is safe to use PyCharm code reformatting feature for keeping things tidy and PEP8 conform. We also recommend enabling code reformatting in the commit menu (see screenshot below).
Cameo docstrings follow numpy's docstring convention because they're human readable (unlike ReStructuredText). Documentation generated with sphinx automatically generates ReStructuredText using the napoleon extension.
All files should declare utf-8 coding and include license information in the header. The following template should be used.
# -*- coding: utf-8 -*-
# Copyright 2014 Novo Nordisk Foundation Center for Biosustainability, DTU.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# 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
# limitations under the License.
Cameo uses mostly unittest.TestCase
to define test cases and nose as test runner. PyCharm makes developing unit tests very easy. For example, you can use the context menu to run individual tests. This behavior doesn't function though if a test is part of base class. In this case just temporarily put the test under the inheriting class and move it back to the base class when done.
This is the preferred way of logging in cameo:
import logging
logger = logging.getLogger(__name__)
logger.debug('Some debug information ...')
logger.info('Some useful information the user might want to see ...')
Access to all of cameo's logs inside a script or a Jupyter notebook can be enabled through
import logging
logger = logging.getLogger('cameo')
logger.setLevel(logging.INFO) # or logging.DEBUG, logging.ERROR, etc.
or
logger = logging.getLogger('cameo.strain_design.pathway_prediction')
if you want to restrict logging to a particular module.
Bottlenecks in code execution can be determined using IPython's prun
.
%prun -s cumtime function()
or
%%prun -s cumtime
function()
Cameo also provides a utility function for measuring the execution time of code blocks.
from cameo.util import Timer
with Timer('Some label ...'):
function_x()
function_y()
...