renovatebot/pep440

Implement pep440 functions

rarkins opened this issue · 10 comments

We probably need the equivalent functions as in https://github.com/renovateapp/renovate/blob/master/lib/util/semver.js

Options:

  1. Machine translate an existing Python implementation of PEP440 and then add convenience wrappers
  2. Port existing Python implementation "line by line" into JS manually
  3. Write from scratch based on PEP440 specification

I think we want to avoid (3) due to the amount of work required.

wouldn't it be better to use the python code?
and use some kind of RPC to communicate with it?
possibly using https://www.npmjs.com/package/python-bridge

I think that would we’ll need to call these functions hundreds of times per run, I don’t think we want to spawn any interpreter.

We can spawn out for things like generating lock files because those are infrequent but to spawn for every “is less than” comparison would be too much (I assume).

Alternatively we might need to rewrite the entire “lookup dependency updates” function from js to python if that logic is not too much. Eg pass it the full list of deps via stdin and have it return via stdout

@rarkins for now I ported the code from https://github.com/pypa/packaging/blob/master/packaging/version.py as is, semver and pep440 have a lot of differences, and we need to sort them out, before deciding the common interface.

@kayoub5 is this list what you recommend for renovate <-> pep440, or simply a copy of what pep440 exposes in python?

module.exports = {
    // version
    valid,
    clean,
    explain,

    // operator
    lt,
    le,
    lte: le,
    eq,
    ne,
    neq: ne,
    ge,
    gte: ge,
    gt,
    compare,
    rcompare,
    
    // range
    satisfies,
};

For Renovate I like the idea of making the functions verbose in naming if they will be commonly used by potentially lots of of contributors in future.

@rarkins
This is part of what semver exposes, original python code uses classes.

OK. We probably don't want to mimic semver module directly but instead our lib/util/semver.js interface. Or at least we don't want want to implement anything not used by our wrapper.

So far I only implimented what renovate uses. For implimenting stuff specific to renovate that the semver module does not provide, I would need feedback.
What we have here should be enough for renovate to support upgrading all pip packages specifying a single dep version (with an operator)
for ranges the only support is the satisfies function but I don't think it's enough to support upgrading complex ranges out of the box
we could discuss the range support in a different thread

The code contains some handy regex, that could prove useful for version extraction