#12 Refactor/rewrite nodejs.prov
Closed by tomh. Opened by jstanek.
jstanek/nodejs-packaging refactor/nodejs.prov  into  master

Download 12.patch

I have attempted to re-write the nodejs.prov python script to more idiomatic Python and to be more easily modified for downstream purposes (i.e. adapted for software collection purposes).

Since I suspect that maintainers of NodeJS-related software might not also be Pythonistas, I will gladly explain anything confusing in the code (in other words, please help me add comments where necessary 😉).

Notable changes

  • The previous functions were replaced with more descriptive and separate ones. No global state is dependent upon (provides = set()).
  • More idiomatic Python. Ad-hoc directory traversal replaced with os.walk(), metadata processing is no longer in charge of opening the file, lazy generators utilized where possible.

I have run the provided tests on the new version, and no changes in the output were reported.

I have reviewed the Python and run a number of spot-tests on various Node package sources and it appears to work exactly as expected. I also agree that it's far more readable than the previous version, so I'm inclined to ack this.

I'd like for @tomh to have the final say, though.

One apparent change in behaviour is that IOError is now ignored when reading package.json when previously it would have terminated the script with an error?

Well, technically yes. However, the previous version went usually tried to prevent the IOError from being raised via various checks (os.path.isfile() and similar), while this version just tries to open the file and moves on if it fails for any reason (EAFP style).

In other words, as far as I am aware, the old version would ignore missing/unreadable package.json file before the exception can be raised, the current one ignores it because the exception is raised.

Pull-Request has been closed by tomh

Metadata