Skip to content

Cannot pass token #466

Open
Open

Description

@utdrmac

Which version of Python is the problem with?

3.14

What semver version are you using?

3.0.2

What OS are you using? (Add more in the Environment section)

No response

Situation

def bump_build(self, token: Optional[str] = "build") -> "Version":

How do I pass the option token parameter when calling on cli?

How to reproduce

See above

Expected behavior

I expect to be able to pass an optional token parameter to the various bump functions.

Environment

No response

Activity

  1. added a commit that references this issue on Dec 9, 2025
    b6ba2fc
  2. tomschr commented on Dec 9, 2025

    @tomschr
    Member

    Thank you @utdrmac! I've played around with this. It's not yet finished, tests and documentation are missing and I need to fix the CI issue. But it works for me.

    On a more basic level, I'm not sure about the name token. In #369 (comment), the comment said that "token" would be a misnomer and identifier could be another, better option. I haven't made up my mind yet. Any ideas about good naming is very appreciated.

    If you can try it out, let me know.

  3. added theissue type on Dec 9, 2025
  4. added
    BugError, flaw or fault to produce incorrect or unexpected results
    on Dec 9, 2025
  5. utdrmac commented on Dec 9, 2025

    @utdrmac
    Author

    Where exactly are you doing this? I'm using the CLI tool pysemver and there's no options for this, hence the FR/bug.

    $ pysemver bump build -h
    usage: semver bump build [-h] version
    
    positional arguments:
      version     Version to raise
    
    options:
      -h, --help  show this help message and exit
    
  6. tomschr commented on Dec 10, 2025

    @tomschr
    Member

    @utdrmac You are maybe in the wrong branch. I've opened PR#467 with branch 466-token.

    You can test it with the following steps (Linux & Mac):

    1. Clone this repo: git clone https://github.com/python-semver/python-semver.git && cd python-semver.
    2. Switch to the branch: git switch 466-token
    3. Download uv from https://github.com/astral-sh/uv and install it.
    4. Install a Python version, for example: uv python install 3.13
    5. Create a virtual environment (VENV): uv venv --python 3.13
    6. Activate the VENV: source .venv/bin/activate
    7. Install semver inside the VENV: uv pip install -e .
    8. Run the CLI tool uv run pysemver ...

    It should be similar for Windows, but I can't test it. If I execute all the steps from above, I get:

    $ uv run pysemver bump build -h
    usage: semver bump build [-h] [--token TOKEN] version
    
    positional arguments:
      version        Version to raise
    
    options:
      -h, --help     show this help message and exit
      --token TOKEN  The token to use for build
    
  7. utdrmac commented on Dec 10, 2025

    @utdrmac
    Author

    I'm not on any "branch". I simply executed pip install semver and this is what I got. Seems I need to wait until that feature/branch is merged to main.

    $ pip show semver
    Name: semver
    Version: 3.0.2
    Summary: Python helper for Semantic Versioning (https://semver.org)
    Home-page: https://github.com/python-semver/python-semver
    Author: Kostiantyn Rybnikov
    Author-email: k-bx@k-bx.com
    License: BSD
    Location: /usr/local/lib/python3.11/site-packages
    Requires:
    Required-by: circup
    
  8. tomschr commented on Dec 11, 2025

    @tomschr
    Member

    I'm not on any "branch".

    And that's the issue here. 😸 Currently, the change lives only inside the mentioned branch. It's not yet released to PyPI. As such, installing it with pip gives you only version 3.0.2.

    I simply executed pip install semver and this is what I got.

    That doesn't work to get the latest version. That's expected if you install it by pip and not from the branch.

    Seems I need to wait until that feature/branch is merged to main.

    You have two options:

    1. Test it with the above procedure and report back. It would help me to be sure everything works as expected.
    2. Wait until I find the time to complete the pull request.
  9. utdrmac commented on Dec 12, 2025

    @utdrmac
    Author

    Learned about this neato feature of pip:
    $ pip install git+https://github.com/python-semver/python-semver.git@466-token

    $ pysemver --version
    semver 3.0.4
    $ pysemver bump prerelease 1.1.0
    1.1.0-rc.1
    $ pysemver bump prerelease --token "ee" 1.1.0
    1.1.0-ee.1
    $ pysemver bump prerelease --token "eee" 1.1.0
    1.1.0-eee.1
    
    $ cat VERSION
    1.1.0-8
    $ pysemver bump prerelease $(cat VERSION)
    1.1.0-9  <-- expected default token "rc" to be added
    $ pysemver bump prerelease --token "foo" $(cat VERSION)
    1.1.0-9  <-- expected token "foo" to be added
    
  10. tomschr commented on Dec 12, 2025

    @tomschr
    Member

    Thank you Matthew! I forgot that pip allows installation via git+http. Good idea! 👍

    In regards to your interactive Python session, I think there is a misconception.

    The algorithm about incrementing prerelease has a very simple logic:

    1. Extract the prerelease part. In our case, it's 8.
    2. Look if there is a number at the end:
      • True? Yes, we have a number. Increment it => 8 + 1 = 9
      • False? Add .0 at the end.
    3. Return the new string. In our case it's 9

    There is no automatism that adds "rc" as a result. If there is already a string then it is used and incremented as shown (and the --token option is only used, if we don't have a prerelease).

    It's the exact same algorithm that is implemented in node's semver (JavaScript).

    Details for node's semver

    This is a short side track to JavaScript land and how they do it. Sometimes it helps how other languages implemented it.

    $ npm install semver
    $ node
    > const semver = require("semver");
    undefined
    > v = semver.parse("1.1.0-8");
    SemVer {
      options: {},
      loose: false,
      includePrerelease: false,
      raw: '1.1.0-8',
      major: 1,
      minor: 1,
      patch: 0,
      prerelease: [ 8 ],
      build: [],
      version: '1.1.0-8'
    }
    > semver.inc(sv1, 'prerelease')
    '1.1.0-9'
    

    If you had already a release candidate, then it would be possible:

    pysemver nextver 1.1.0-rc.8 prerelease
    1.1.0-rc.9
    

    But you can't create magically an "rc." if it wasn't there. I think the CLI tool (and semver) is working exactly as it should.

    If you really want that, you need to use the library:

    >>> import semver
    >>> v = semver.Version.parse("1.1.0-8")
    >>> str(v.replace(prerelease=f'rc.{int(v.prerelease) + 1}'))
    '1.1.0-rc.9'

    However, that works in this case if you kind of control or now the structure of your prerelease. It's not a general solution.

    If you really want a release candidate, my only recommendation is to create one right at the beginning as shown before. Then you won't have this problem.

  11. added
    Not SemverThis issue does not belong to semver or is an invalid issue
    and removed
    BugError, flaw or fault to produce incorrect or unexpected results
    on Dec 12, 2025
  12. added 2 commits that reference this issue on Jun 29, 2026
    1505c2d
    18149b4
  13. added a commit that references this issue on Oct 16, 2026
    d486f55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Not SemverThis issue does not belong to semver or is an invalid issue

Type

Fields

SIze

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions