Skip to content

Commit eafaaa3

Browse files
committed
add script to set version of all packages in IDOM
1 parent 878c2ea commit eafaaa3

File tree

11 files changed

+145
-60
lines changed

11 files changed

+145
-60
lines changed

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.32.0

noxfile.py

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from nox.sessions import Session
1111

1212

13-
HERE = Path(__file__).parent
13+
ROOT = Path(__file__).parent
1414
POSARGS_PATTERN = re.compile(r"^(\w+)\[(.+)\]$")
1515

1616

@@ -39,7 +39,7 @@ def example(session: Session) -> None:
3939
"""Run an example"""
4040
if not session.posargs:
4141
print("No example name given. Choose from:")
42-
for found_example_file in (HERE / "docs" / "source" / "examples").glob("*.py"):
42+
for found_example_file in (ROOT / "docs" / "source" / "examples").glob("*.py"):
4343
print("-", found_example_file.stem)
4444
return None
4545

@@ -175,6 +175,51 @@ def test_docs(session: Session) -> None:
175175
session.run("sphinx-build", "-b", "doctest", "docs/source", "docs/build")
176176

177177

178+
@nox.session
179+
def tag(session: Session):
180+
try:
181+
session.run(
182+
"git",
183+
"diff",
184+
"--cached",
185+
"--exit-code",
186+
silent=True,
187+
external=True,
188+
)
189+
except Exception:
190+
session.error("Cannot create a tag - tROOT are uncommited changes")
191+
192+
version = (ROOT / "VERSION").read_text().strip()
193+
install_requirements_file(session, "make-release")
194+
session.run("pysemver", "check", version)
195+
196+
changelog_file = ROOT / "docs" / "source" / "changelog.rst"
197+
for line in changelog_file.read_text().splitlines():
198+
if line == version:
199+
break
200+
else:
201+
session.error(f"No changelog entry for {version} in {changelog_file}")
202+
203+
session.run("git", "tag", version, external=True)
204+
205+
if "push" in session.posargs:
206+
session.run("git", "push", "--tags", external=True)
207+
208+
209+
@nox.session
210+
def update_version(session: Session) -> None:
211+
if len(session.posargs) > 1:
212+
session.error("To many arguments")
213+
214+
try:
215+
version = session.posargs[0]
216+
except IndexError:
217+
session.error("No version tag given")
218+
219+
install_requirements_file(session, "make-release")
220+
session.run("python", "scripts/update_versions.py", version)
221+
222+
178223
@nox.session(reuse_venv=True)
179224
def latest_pull_requests(session: Session) -> None:
180225
"""A basic script for outputing changelog info"""
@@ -190,7 +235,7 @@ def latest_closed_issues(session: Session) -> None:
190235

191236

192237
def install_requirements_file(session: Session, name: str) -> None:
193-
file_path = HERE / "requirements" / (name + ".txt")
238+
file_path = ROOT / "requirements" / (name + ".txt")
194239
assert file_path.exists(), f"requirements file {file_path} does not exist"
195240
session.install("-r", str(file_path))
196241

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
-r requirements/build-pkg.txt
33
-r requirements/check-style.txt
44
-r requirements/check-types.txt
5+
-r requirements/make-release.txt
56
-r requirements/pkg-deps.txt
67
-r requirements/pkg-extras.txt
78
-r requirements/test-env.txt

requirements/make-release.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
semver >=2, <3

scripts/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# Scripts
22

3-
All scripts should be run from the repository root.
3+
All scripts should be run from the repository root
4+
(typically using [`nox`](https://nox.thea.codes/en/stable/)).

scripts/update_versions.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import json
2+
import sys
3+
from pathlib import Path
4+
from typing import List
5+
6+
import semver
7+
8+
9+
ROOT = Path("__file__").parent.parent
10+
VERSION_FILE = ROOT / Path("VERSION")
11+
PY_PKG_INIT_FILE = ROOT / "src" / "idom" / "__init__.py"
12+
JS_ROOT_DIR = ROOT / "src" / "client"
13+
JS_PACKAGE_JSON_FILES = [
14+
pkg_dir / "package.json" for pkg_dir in (JS_ROOT_DIR / "packages").iterdir()
15+
] + [JS_ROOT_DIR / "package.json"]
16+
17+
VERSION_INFO = semver.VersionInfo.parse(VERSION_FILE.read_text().strip())
18+
19+
20+
def main(args: List[str]) -> None:
21+
version_str = str(VERSION_INFO)
22+
update_py_version(version_str)
23+
update_js_versions(version_str)
24+
25+
26+
def update_py_version(new_version: str) -> None:
27+
new_lines = PY_PKG_INIT_FILE.read_text().splitlines()
28+
for index, line in enumerate(new_lines):
29+
if line.startswith('__version__ = "') and line.endswith('" # DO NOT MODIFY'):
30+
line = f'__version__ = "{new_version}" # DO NOT MODIFY'
31+
new_lines[index] = line
32+
break
33+
else:
34+
raise RuntimeError(f"No __version__ assignment found in {PY_PKG_INIT_FILE}")
35+
PY_PKG_INIT_FILE.write_text("\n".join(new_lines) + "\n")
36+
37+
38+
def update_js_versions(new_version: str) -> None:
39+
for pkg_json_file in JS_PACKAGE_JSON_FILES:
40+
pkg_json = json.loads(pkg_json_file.read_text())
41+
pkg_json["version"] = new_version
42+
pkg_json_file.write_text(json.dumps(pkg_json, indent=2, sort_keys=True) + "\n")
43+
44+
45+
if __name__ == "__main__":
46+
main(sys.argv)

setup.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ def list2cmdline(cmd_list):
5050
"keywords": ["interactive", "widgets", "DOM", "React"],
5151
"include_package_data": True,
5252
"zip_safe": False,
53-
"setup_requires": ["setuptools_scm"],
54-
"use_scm_version": True,
5553
"classifiers": [
5654
"Environment :: Web Environment",
5755
"Framework :: AsyncIO",

src/client/package.json

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
{
2-
"workspaces": [
3-
"./packages/*"
4-
],
2+
"dependencies": {
3+
"idom-client-react": "file:packages/idom-client-react"
4+
},
5+
"devDependencies": {
6+
"prettier": "^2.2.1",
7+
"snowpack": "^3.5.2"
8+
},
59
"license": "MIT",
610
"repository": {
711
"type": "git",
@@ -12,11 +16,8 @@
1216
"format": "npm --workspaces run format",
1317
"test": "npm --workspaces test"
1418
},
15-
"devDependencies": {
16-
"prettier": "^2.2.1",
17-
"snowpack": "^3.5.2"
18-
},
19-
"dependencies": {
20-
"idom-client-react": "file:packages/idom-client-react"
21-
}
19+
"version": "0.32.0",
20+
"workspaces": [
21+
"./packages/*"
22+
]
2223
}
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
{
2-
"name": "idom-app-react",
3-
"description": "A client application for IDOM implemented in React",
4-
"version": "0.1.0",
52
"author": "Ryan Morshead",
3+
"dependencies": {
4+
"idom-client-react": "file:packages/idom-client-react",
5+
"react": "^16.13.1",
6+
"react-dom": "^16.13.1"
7+
},
8+
"description": "A client application for IDOM implemented in React",
9+
"devDependencies": {
10+
"prettier": "^2.2.1"
11+
},
612
"license": "MIT",
713
"main": "src/index.js",
14+
"name": "idom-app-react",
815
"repository": {
916
"type": "git",
1017
"url": "https://github.com/idom-team/idom"
@@ -13,12 +20,5 @@
1320
"format": "prettier --write ./src",
1421
"test": "echo 'no tests'"
1522
},
16-
"devDependencies": {
17-
"prettier": "^2.2.1"
18-
},
19-
"dependencies": {
20-
"idom-client-react": "file:packages/idom-client-react",
21-
"react": "^16.13.1",
22-
"react-dom": "^16.13.1"
23-
}
23+
"version": "0.32.0"
2424
}
Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
{
2-
"name": "idom-client-react",
3-
"description": "A client for IDOM implemented in React",
4-
"version": "0.10.0",
52
"author": "Ryan Morshead",
6-
"license": "MIT",
7-
"type": "module",
8-
"repository": {
9-
"type": "git",
10-
"url": "https://github.com/idom-team/idom"
11-
},
12-
"main": "src/index.js",
13-
"files": [
14-
"src/**/*.js"
15-
],
16-
"scripts": {
17-
"format": "prettier --write ./src",
18-
"test": "uvu tests"
3+
"dependencies": {
4+
"fast-json-patch": "^3.0.0-1",
5+
"htm": "^3.0.3"
196
},
7+
"description": "A client for IDOM implemented in React",
208
"devDependencies": {
219
"jsdom": "16.3.0",
2210
"prettier": "^2.2.1",
2311
"uvu": "^0.5.1"
2412
},
25-
"dependencies": {
26-
"fast-json-patch": "^3.0.0-1",
27-
"htm": "^3.0.3"
28-
},
13+
"files": [
14+
"src/**/*.js"
15+
],
16+
"license": "MIT",
17+
"main": "src/index.js",
18+
"name": "idom-client-react",
2919
"peerDependencies": {
3020
"react": ">=16",
3121
"react-dom": ">=16"
32-
}
22+
},
23+
"repository": {
24+
"type": "git",
25+
"url": "https://github.com/idom-team/idom"
26+
},
27+
"scripts": {
28+
"format": "prettier --write ./src",
29+
"test": "uvu tests"
30+
},
31+
"type": "module",
32+
"version": "0.32.0"
3333
}

src/idom/__init__.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
from pkg_resources import DistributionNotFound as _DistributionNotFound
2-
from pkg_resources import get_distribution as _get_distribution
3-
4-
5-
try:
6-
__version__: str = _get_distribution(__name__).version
7-
except _DistributionNotFound: # pragma: no cover
8-
# package is not installed
9-
__version__ = "0.0.0"
10-
11-
__author__ = "idom-team"
12-
131
from . import config, html, log, web
142
from .core import hooks
153
from .core.component import Component, component
@@ -21,6 +9,9 @@
219
from .widgets import hotswap, multiview
2210

2311

12+
__author__ = "idom-team"
13+
__version__ = "0.32.0" # DO NOT MODIFY
14+
2415
__all__ = [
2516
"component",
2617
"Component",

0 commit comments

Comments
 (0)