Skip to content

Conversation

@wking
Copy link
Contributor

@wking wking commented May 14, 2014

I'm pushing this as a heads-up that I'm churning this section of code
(let me know if someone else is working here, and I'll wait until
they're done). Don't merge it yet ;).

While reviewing #213 I noticed a wildcard import (from … import *),
and thought I'd take a moment to clean it up. However, my first pass
at that (through chemkin.py) turned up a number of large, complicated
functions that could use some refactoring. This series is my attempt
to polish up the Python in chemkin without breaking any of the logic
that I don't particularly understand ;). I'll push periodically so
Travis can see if I broke anything, while I try to split this logic
into easily-digestible bites.

wking added 2 commits May 14, 2014 16:31
…space

From PEP 8 [1]:

  Wildcard imports (from <module> import *) should be avoided, as they
  make it unclear which names are present in the namespace, confusing
  both readers and many automated tools. There is one defensible use
  case for a wildcard import, which is to republish an internal
  interface as part of a public API (for example, overwriting a pure
  Python implementation of an interface with the definitions from an
  optional accelerator module and exactly which definitions will be
  overwritten isn't known in advance).

I use a leading underscore in the name to avoid conflicts with local
'kinetics' variables, and because the imported module is a private
member of chemkin.  We don't want folks using:

  from rmgpy.chemkin import kinetics

[1]: http://legacy.python.org/dev/peps/pep-0008/#imports
Split it into _readKineticsReaction (for the first line) and
_readKineticsLine (for subsequent lines).  This makes reading
readKineticsEntry easier by limiting the scope of local variables and
allowing you to focus on the higher-level logic without line-level
distraction.

I left as many lines unchanged as possible, excepting some reworking
to handle state during the _readKineticsLine loop.  Instead of
maintaining a handful of per-model variables and using 'None' to
detect which have been set, I've used a single 'kinetics' dict and use
key presence to detect which have been set.  The allows subsequent
lines to clobber kinetics entries from previous lines (e.g. shifting
'arrhenius high' to 'arrhenius low') without having to pass around a
bunch of None variables.
@rwest rwest closed this in 2e16170 Jun 19, 2014
@wking
Copy link
Contributor Author

wking commented Jun 19, 2014

On Thu, Jun 19, 2014 at 10:10:58AM -0700, Richard West wrote:

Closed #215 via 2e16170.

Thanks for fixing my bugs :p.

@rwest
Copy link
Member

rwest commented Jun 19, 2014

Hard to blame you for a few bugs: coverage reports that our unit tests check a whopping 3% of that code! :)

Name                                   Stmts   Miss Branch BrMiss  Cover   Missing
----------------------------------------------------------------------------------
rmgpy.chemkin                            980    936    484    483     3%   69, 79-156, 167-456, 466-615, 626-646, 652-665, 672-687, 695-846, 858-900, 914-972, 982-1130, 1138-1148, 1160-1202, 1213-1277, 1285-1321, 1338-1488, 1498-1514, 1524-1527, 1535-1538, 1545-1556, 1578-1601, 1620-1666, 1674-1705

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.

2 participants