Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ repos:
- id: check-api-reference
name: check-api-reference
pass_filenames: false
entry: python -m utils.check_api_reference
entry: python utils/check_api_reference.py
language: python
additional_dependencies: [polars]
additional_dependencies: [narwhals, polars]
- id: imports-are-banned
name: import are banned (use `get_pandas` instead of `import pandas`)
entry: python utils/import_check.py
Expand Down
8 changes: 4 additions & 4 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@

To verify the installation, start the Python REPL and execute:

```python
>>> import narwhals
>>> narwhals.__version__
'1.38.1'
```python exec="1" source="above" session="quickstart" result="python"
import narwhals

print(narwhals.__version__)
```

If you see the version number, then the installation was successful!
Expand Down
4 changes: 3 additions & 1 deletion narwhals/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

from importlib import metadata

from narwhals import dependencies
from narwhals import dtypes
from narwhals import exceptions
Expand Down Expand Up @@ -81,7 +83,7 @@
from narwhals.utils import maybe_reset_index
from narwhals.utils import maybe_set_index

__version__ = "1.38.1"
__version__ = metadata.version(__name__)

__all__ = [
"Array",
Expand Down
14 changes: 14 additions & 0 deletions tests/version_test.py
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
36 changes: 4 additions & 32 deletions utils/bump_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
out = subprocess.run(["git", "fetch", "upstream", "--tags"])
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)
Expand Down Expand Up @@ -42,37 +43,8 @@

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)
subprocess.run(["uv", "version", "--bump", how])
version = subprocess.run(["uv", "version", "--short"], capture_output=True).stdout.decode("utf-8")

subprocess.run(["git", "commit", "-a", "-m", f"release: Bump version to {version}"])
subprocess.run(["git", "tag", "-a", f"v{version}", "-m", f"v{version}"])
Expand Down
4 changes: 3 additions & 1 deletion utils/check_api_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ def iter_api_reference_names(tp: type[Any]) -> Iterator[str]:

# Top level functions
top_level_functions = [
i for i in dir(nw) if not i[0].isupper() and i[0] != "_" and i not in files
i
for i in dir(nw)
if not i[0].isupper() and i[0] != "_" and i not in files and i != "metadata"
]
with open("docs/api-reference/narwhals.md") as fd:
content = fd.read()
Expand Down
Loading