Skip to content

Commit

Permalink
use custmized version (#1818)
Browse files Browse the repository at this point in the history
Signed-off-by: yangxuan <[email protected]>
  • Loading branch information
XuanYang-cn authored Dec 18, 2023
1 parent 8e4ad43 commit 0349a00
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check_milvus_proto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.11]
python-version: [3.8, 3.11]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/code_checker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.11]
python-version: [3.8, 3.11]
steps:
- name: Checkout code
uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.11]
python-version: [3.8, 3.11]

steps:
- name: Checkout code
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ The following collection shows Milvus versions and recommended PyMilvus versions
| 2.0.\* | 2.0.2 |
| 2.1.\* | 2.1.3 |
| 2.2.\* | 2.2.15 |
| 2.3.\* | 2.3.0 |
| 2.3.\* | 2.3.4 |


## Installation

You can install PyMilvus via `pip` or `pip3` for Python 3.7+:
You can install PyMilvus via `pip` or `pip3` for Python 3.8+:

```shell
$ pip3 install pymilvus
Expand All @@ -40,7 +40,7 @@ $ pip3 install pymilvus
You can install a specific version of PyMilvus by:

```shell
$ pip3 install pymilvus==2.3.0
$ pip3 install pymilvus==2.3.4
```

You can upgrade PyMilvus to the latest version by:
Expand Down Expand Up @@ -97,13 +97,13 @@ Documentation is available online: https://milvus.io/api-reference/pymilvus/v2.3

The commits on the development branch of each version will be packaged and uploaded to [Test PyPI](https://test.pypi.org/).

The package name generated by the development branch is x.y.z.dev<dist>, where <dist> is the number of commits that differ from the most recent release.
The package name generated by the development branch is x.y.z.rc<dist>, where <dist> is the number of commits that differ from the most recent release.

- For example, after the release of 2.0.1, two commits were submitted on the 2.0 branch.
The version number of the latest commit of 2.0 branch is **2.0.2.dev2**.
- For example, after the release of **2.3.4**, two commits were submitted on the 2.3 branch.
The version number of the latest commit of 2.3 branch is **2.3.5.rc2**.

- For example, after the release of 2.0.1, 10 commits were submitted on the master branch.
The version number of the latest commit of master branch is **2.1.0.dev10**.
- For example, after the release of **2.3.4**, 10 commits were submitted on the master branch.
The version number of the latest commit of master branch is **2.4.0.rc10**.


To install the package on Test PyPi, you need to append `--extra-index-url` after pip, for example:
Expand Down
95 changes: 95 additions & 0 deletions _version_helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
"""
this module is a hack only in place to allow for setuptools
to use the attribute for the versions
it works only if the backend-path of the build-system section
from pyproject.toml is respected
"""
from __future__ import annotations

import logging
from typing import Callable

from setuptools import build_meta as build_meta # noqa

from setuptools_scm import _types as _t
from setuptools_scm import Configuration
from setuptools_scm import get_version
from setuptools_scm import git
from setuptools_scm import hg
from setuptools_scm.fallbacks import parse_pkginfo
from setuptools_scm.version import (
get_no_local_node,
_parse_version_tag,
guess_next_simple_semver,
SEMVER_MINOR,
guess_next_version,
ScmVersion,
)

log = logging.getLogger("setuptools_scm")
# todo: take fake entrypoints from pyproject.toml
try_parse: list[Callable[[_t.PathT, Configuration], ScmVersion | None]] = [
parse_pkginfo,
git.parse,
hg.parse,
git.parse_archival,
hg.parse_archival,
]


def parse(root: str, config: Configuration) -> ScmVersion | None:
for maybe_parse in try_parse:
try:
parsed = maybe_parse(root, config)
except OSError as e:
log.warning("parse with %s failed with: %s", maybe_parse, e)
else:
if parsed is not None:
return parsed

fmt = "{guessed}.rc{distance}"

def custom_version(version: ScmVersion) -> str:
if version.exact:
return version.format_with("{tag}")
if version.branch is not None:
# Does the branch name (stripped of namespace) parse as a version?
branch_ver_data = _parse_version_tag(
version.branch.split("/")[-1], version.config
)
if branch_ver_data is not None:
branch_ver = branch_ver_data["version"]
if branch_ver[0] == "v":
# Allow branches that start with 'v', similar to Version.
branch_ver = branch_ver[1:]
# Does the branch version up to the minor part match the tag? If not it
# might be like, an issue number or something and not a version number, so
# we only want to use it if it matches.
tag_ver_up_to_minor = str(version.tag).split(".")[:SEMVER_MINOR]
branch_ver_up_to_minor = branch_ver.split(".")[:SEMVER_MINOR]
if branch_ver_up_to_minor == tag_ver_up_to_minor:
# We're in a release/maintenance branch, next is a patch/rc/beta bump:
return version.format_next_version(guess_next_version, fmt=fmt)
# We're in a development branch, next is a minor bump:
return version.format_next_version(guess_next_simple_semver, retain=SEMVER_MINOR, fmt=fmt)


def scm_version() -> str:
return get_version(
relative_to=__file__,
parse=parse,
version_scheme=custom_version,
local_scheme=get_no_local_node,
)


version: str


def __getattr__(name: str) -> str:
if name == "version":
global version
version = scm_version()
return version
raise AttributeError(name)
10 changes: 6 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ requires = [
]
build-backend = "setuptools.build_meta"


[project]
name="pymilvus"
authors = [
{name='Milvus Team', email="[email protected]"},
]
requires-python = '>=3.7'

requires-python = '>=3.8'
description = "Python Sdk for Milvus"
readme = "README.md"
dependencies=[
Expand All @@ -38,9 +38,10 @@ dynamic = ["version"]
[project.urls]
"repository" = 'https://github.com/milvus-io/pymilvus'

[tool.setuptools.dynamic]
version = { attr = "_version_helper.version"}

[tool.setuptools_scm]
'local_scheme'= 'no-local-version'
'version_scheme'= 'no-guess-dev'

[tool.black]
line-length = 100
Expand Down Expand Up @@ -166,3 +167,4 @@ builtins-ignorelist = [
"dict", # TODO
"filter",
]

0 comments on commit 0349a00

Please sign in to comment.