-
Notifications
You must be signed in to change notification settings - Fork 168
chore: Bump version manually only in pyproject.toml #2514
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 18 commits
777495e
8485943
e213fcf
ed06050
a130984
50efe76
59ea2d2
4200ffc
49e1dc1
79d7a89
6636d60
8a79221
47192ae
798a6dd
71996c3
07f61c5
e29949b
205f38a
6fba9ba
2a77e7b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import typing as _t | ||
|
|
||
| from narwhals import dependencies | ||
| from narwhals import dtypes | ||
| from narwhals import exceptions | ||
|
|
@@ -81,7 +83,7 @@ | |
| from narwhals.utils import maybe_reset_index | ||
| from narwhals.utils import maybe_set_index | ||
|
|
||
| __version__ = "1.38.2" | ||
| __version__: str | ||
|
|
||
| __all__ = [ | ||
| "Array", | ||
|
|
@@ -165,3 +167,16 @@ | |
| "to_py_scalar", | ||
| "when", | ||
| ] | ||
|
|
||
|
|
||
| def __getattr__(name: _t.Literal["__version__"]) -> str: # type: ignore[misc] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be completely honest I'd rather just update in two places, I have no idea what this is doing Happy to take the installation update in the docs page though π There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to make sure I understand correctly - the concern with importing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i feel uneasy about the global - do you have a reference from another project that does this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking for A couple of projects I know that made it in the first few pages of the list are:
Edit: some other project do the analogous of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure, thanks still not sure we need it though - there's some other nice improvements in here though, happy to take those regarding perf, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some notes:
IMO, I don't think there's a use-case for checking @MarcoGorelli I understand your caution and ultimately will defer π to you, but I think this balances:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks - could you elaborate on the if we don't deem There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Sure @MarcoGorelli! I'm assuming you're referring to the projects in (#2514 (comment))?
I guess for some more info on
|
||
| if name == "__version__": | ||
| global __version__ # noqa: PLW0603 | ||
|
|
||
| from importlib import metadata | ||
|
|
||
| __version__ = metadata.version(__name__) | ||
| return __version__ | ||
| else: | ||
| msg = f"module {__name__!r} has no attribute {name!r}" | ||
| raise AttributeError(msg) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import re | ||
| from pathlib import Path | ||
|
|
||
| import narwhals as nw | ||
|
|
||
|
|
||
| def test_version_matches_pyproject() -> None: | ||
| with Path("pyproject.toml").open(encoding="utf-8") as file: | ||
| content = file.read() | ||
| pyproject_version = re.search(r'version = "(.*)"', content).group(1) # type: ignore[union-attr] | ||
|
|
||
| assert nw.__version__ == pyproject_version |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,80 +1,61 @@ | ||
| # mypy: ignore | ||
| # ruff: noqa | ||
| import re | ||
| import subprocess | ||
| from __future__ import annotations | ||
|
|
||
| import subprocess as sp | ||
| import sys | ||
|
|
||
| out = subprocess.run(["git", "fetch", "upstream", "--tags"]) | ||
| GIT = "git" | ||
| UV = "uv" | ||
| FETCH = "fetch" | ||
| PUSH = "push" | ||
| COMMIT = "commit" | ||
| UPSTREAM = "upstream" | ||
| TAGS = "--tags" | ||
| TAG = "tag" | ||
| VERSION = "version" | ||
|
|
||
| out = sp.run([GIT, FETCH, UPSTREAM, TAGS], check=False) | ||
| if out.returncode != 0: | ||
| print( | ||
| "Something went wrong with the release process, please check the Narwhals Wiki and try again." | ||
| "Something went wrong with the release process, please check the Narwhals Wiki for " | ||
| "at https://github.com/narwhals-dev/narwhals/wiki#release-process and try again." | ||
| ) | ||
| print(out) | ||
| sys.exit(1) | ||
| subprocess.run(["git", "reset", "--hard", "upstream/main"]) | ||
| sp.run([GIT, "reset", "--hard", "upstream/main"], check=False) | ||
|
|
||
| if ( | ||
| subprocess.run( | ||
| ["git", "branch", "--show-current"], text=True, capture_output=True | ||
| current_branch := sp.run( | ||
| [GIT, "branch", "--show-current"], text=True, capture_output=True, check=False | ||
| ).stdout.strip() | ||
| != "bump-version" | ||
| ): | ||
| msg = "`bump_version.py` should be run from `bump-version` branch" | ||
| ) != "bump-version": | ||
| msg = f"`bump_version.py` should be run from `bump-version` branch instead of `{current_branch}`" | ||
| raise RuntimeError(msg) | ||
|
|
||
| # Delete local tags, if present | ||
| try: | ||
| # Get the list of all tags | ||
| result = subprocess.run( | ||
| ["git", "tag", "-l"], capture_output=True, text=True, check=True | ||
| ) | ||
| result = sp.run([GIT, TAG, "-l"], capture_output=True, text=True, check=True) | ||
| tags = result.stdout.splitlines() # Split the tags into a list by lines | ||
|
|
||
| # Delete each tag using git tag -d | ||
| for tag in tags: | ||
| subprocess.run(["git", "tag", "-d", tag], check=True) | ||
| if tags: | ||
| # Delete each tag using git tag -d | ||
| sp.run([GIT, TAG, "-d", *tags], check=True) | ||
|
|
||
| print("All local tags have been deleted.") | ||
| except subprocess.CalledProcessError as e: | ||
| except sp.CalledProcessError as e: | ||
| print(f"An error occurred: {e}") | ||
|
|
||
| subprocess.run(["git", "fetch", "upstream", "--tags"]) | ||
| subprocess.run(["git", "fetch", "upstream", "--prune", "--tags"]) | ||
| sp.run([GIT, FETCH, UPSTREAM, TAGS], check=False) | ||
| sp.run([GIT, FETCH, UPSTREAM, "--prune", TAGS], check=False) | ||
|
|
||
| how = sys.argv[1] | ||
|
|
||
| with open("pyproject.toml", encoding="utf-8") as f: | ||
| content = f.read() | ||
| old_version = re.search(r'version = "(.*)"', content).group(1) # pyright: ignore[reportOptionalMemberAccess] | ||
| version = old_version.split(".") | ||
| if how == "patch": | ||
| version = ".".join(version[:-1] + [str(int(version[-1]) + 1)]) | ||
| elif how == "minor": | ||
| version = ".".join(version[:-2] + [str(int(version[-2]) + 1), "0"]) | ||
| elif how == "major": | ||
| version = ".".join([str(int(version[0]) + 1), "0", "0"]) | ||
| content = content.replace(f'version = "{old_version}"', f'version = "{version}"') | ||
| with open("pyproject.toml", "w", encoding="utf-8") as f: | ||
| f.write(content) | ||
|
|
||
| with open("narwhals/__init__.py", encoding="utf-8") as f: | ||
| content = f.read() | ||
| content = content.replace( | ||
| f'__version__ = "{old_version}"', | ||
| f'__version__ = "{version}"', | ||
| ) | ||
| with open("narwhals/__init__.py", "w", encoding="utf-8") as f: | ||
| f.write(content) | ||
|
|
||
| with open("docs/installation.md", encoding="utf-8") as f: | ||
| content = f.read() | ||
| content = content.replace( | ||
| f"'{old_version}'", | ||
| f"'{version}'", | ||
| ) | ||
| with open("docs/installation.md", "w", encoding="utf-8") as f: | ||
| f.write(content) | ||
| new_version = sp.run( | ||
| [UV, VERSION, "--bump", how, "--short"], capture_output=True, text=True, check=False | ||
| ).stdout | ||
|
|
||
| subprocess.run(["git", "commit", "-a", "-m", f"release: Bump version to {version}"]) | ||
| subprocess.run(["git", "tag", "-a", f"v{version}", "-m", f"v{version}"]) | ||
| subprocess.run(["git", "push", "upstream", "HEAD", "--follow-tags"]) | ||
| subprocess.run(["git", "push", "upstream", "HEAD:stable", "-f", "--follow-tags"]) | ||
| sp.run([GIT, COMMIT, "-a", "-m", f"release: Bump version to {new_version}"], check=False) | ||
| sp.run([GIT, TAG, "-a", f"v{new_version}", "-m", f"v{new_version}"], check=False) | ||
| sp.run([GIT, PUSH, UPSTREAM, "HEAD", "--follow-tags"], check=False) | ||
| sp.run([GIT, PUSH, UPSTREAM, "HEAD:stable", "-f", "--follow-tags"], check=False) |
Uh oh!
There was an error while loading. Please reload this page.