Skip to content

Commit fdd0712

Browse files
authored
Fix handling of dev mode (#473)
Fixes #472
1 parent ceb424c commit fdd0712

File tree

4 files changed

+32
-76
lines changed

4 files changed

+32
-76
lines changed

jupyter_releaser/tests/test_cli.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,11 @@ def test_check_python_resource_path(monkeypatch, py_package, runner, build_mock,
389389
path = bar_dir / "baz.txt"
390390
path.write_text("hello", encoding="utf-8")
391391

392+
pyproject = Path(util.CHECKOUT_NAME / util.PYPROJECT)
393+
pyproject_text = pyproject.read_text('utf-8')
394+
pyproject_text = pyproject_text.replace("foo.py", "foo/__init__.py")
395+
pyproject.write_text(pyproject_text, "utf-8")
396+
392397
runner(["build-python"])
393398
runner(["check-python"])
394399

jupyter_releaser/tests/test_functions.py

Lines changed: 14 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -25,31 +25,7 @@ def test_get_repo(git_repo, mocker):
2525
assert util.get_repo() == repo
2626

2727

28-
def test_get_version_pyproject_static(py_package):
29-
assert util.get_version() == "0.0.1"
30-
util.bump_version("0.0.2a0")
31-
assert util.get_version() == "0.0.2a0"
32-
33-
34-
def test_get_version_pyproject_dynamic(py_package):
35-
py_project = py_package / "pyproject.toml"
36-
text = py_project.read_text(encoding="utf-8")
37-
text = text.replace("""[project]\nversion = "0.0.1\"""", "")
38-
py_project.write_text(text, encoding="utf-8")
39-
assert util.get_version() == "0.0.1"
40-
41-
42-
def test_get_version_hatchling(py_package):
43-
py_project = py_package / "pyproject.toml"
44-
with open(py_project) as fid:
45-
data = toml.load(fid)
46-
del data["project"]["version"]
47-
data["build-system"] = {"requires": ["hatchling>=1.0"], "build-backend": "hatchling.build"}
48-
with open(py_project, "w") as fid:
49-
fid.write(str(py_project))
50-
51-
52-
def test_get_version_setuppy(py_package):
28+
def test_get_version_pyproject_hatch(py_package):
5329
assert util.get_version() == "0.0.1"
5430
util.bump_version("0.0.2a0")
5531
assert util.get_version() == "0.0.2a0"
@@ -252,8 +228,7 @@ def test_create_release_commit_hybrid(py_package, build_mock):
252228
data["version"] = version
253229
pkg_json.write_text(json.dumps(data, indent=4), encoding="utf-8")
254230
util.run("pre-commit run --all-files", check=False)
255-
txt = (py_package / "tbump.toml").read_text(encoding="utf-8")
256-
txt += testutil.TBUMP_NPM_TEMPLATE
231+
txt = testutil.TBUMP_NPM_TEMPLATE
257232
(py_package / "tbump.toml").write_text(txt, encoding="utf-8")
258233

259234
util.run("pipx run build .")
@@ -293,14 +268,20 @@ def test_bump_version_reg(py_package):
293268

294269

295270
def test_bump_version_dev(py_package):
296-
util.bump_version("dev")
271+
util.bump_version("dev", changelog_path="CHANGELOG.md")
297272
assert util.get_version() == "0.1.0.dev0"
298-
util.bump_version("dev")
273+
util.bump_version("dev", changelog_path="CHANGELOG.md")
299274
assert util.get_version() == "0.1.0.dev1"
300-
util.bump_version("next")
301-
util.bump_version("patch")
302-
util.bump_version("minor")
303-
assert util.get_version() == "0.2.0"
275+
util.bump_version("next", changelog_path="CHANGELOG.md")
276+
assert util.get_version() == "0.0.3"
277+
util.bump_version("dev", changelog_path="CHANGELOG.md")
278+
assert util.get_version() == "0.1.0.dev0"
279+
util.bump_version("patch", changelog_path="CHANGELOG.md")
280+
assert util.get_version() == "0.0.3"
281+
util.bump_version("dev", changelog_path="CHANGELOG.md")
282+
assert util.get_version() == "0.1.0.dev0"
283+
util.bump_version("minor", changelog_path="CHANGELOG.md")
284+
assert util.get_version() == "0.1.0"
304285

305286

306287
def test_get_config_python(py_package):

jupyter_releaser/tests/util.py

Lines changed: 10 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,16 @@ def setup_cfg_template(package_name="foo", module_name=None):
8787
README_TEMPLATE = "A fake readme\n"
8888

8989

90-
def pyproject_template(project_name="foo", sub_packages=None):
90+
def pyproject_template(project_name="foo", module_name="foo", sub_packages=None):
9191
sub_packages = sub_packages or []
9292
res = f"""
9393
[build-system]
94-
requires = ["hatchling>=1.5.0"]
94+
requires = ["hatchling>=1.11"]
9595
build-backend = "hatchling.build"
9696
9797
[project]
9898
name = "{project_name}"
99-
version = "0.0.1"
99+
dynamic = ["version"]
100100
description = "My package description"
101101
readme = "README.md"
102102
license = {{file = "LICENSE"}}
@@ -105,6 +105,10 @@ def pyproject_template(project_name="foo", sub_packages=None):
105105
{{name = "foo"}}
106106
]
107107
108+
[tool.hatch.version]
109+
path = "{module_name}.py"
110+
validate-bump = false
111+
108112
[project.urls]
109113
homepage = "https://foo.com"
110114
"""
@@ -118,31 +122,6 @@ def pyproject_template(project_name="foo", sub_packages=None):
118122

119123
PY_MODULE_TEMPLATE = '__version__ = "0.0.1"\n'
120124

121-
122-
TBUMP_BASE_TEMPLATE = r"""
123-
[version]
124-
current = "0.0.1"
125-
regex = '''
126-
(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)
127-
((?P<channel>a|b|rc|.dev)(?P<release>\d+))?
128-
'''
129-
130-
[git]
131-
message_template = "Bump to {new_version}"
132-
tag_template = "v{new_version}"
133-
"""
134-
135-
136-
def tbump_py_template(package_name="foo"):
137-
return f"""
138-
[[file]]
139-
src = "{package_name}.py"
140-
141-
[[file]]
142-
src = "pyproject.toml"
143-
"""
144-
145-
146125
TBUMP_NPM_TEMPLATE = """
147126
[[file]]
148127
src = "package.json"
@@ -209,20 +188,10 @@ def write_files(git_repo, sub_packages=None, package_name="foo", module_name=Non
209188

210189
module_name = module_name or package_name
211190

212-
setuppy = git_repo / "setup.py"
213-
setuppy.write_text(SETUP_PY_TEMPLATE, encoding="utf-8")
214-
215-
setuppy = git_repo / "setup.cfg"
216-
setuppy.write_text(setup_cfg_template(package_name, module_name), encoding="utf-8")
217-
218-
tbump = git_repo / "tbump.toml"
219-
tbump.write_text(
220-
TBUMP_BASE_TEMPLATE + tbump_py_template(package_name),
221-
encoding="utf-8",
222-
)
223-
224191
pyproject = git_repo / "pyproject.toml"
225-
pyproject.write_text(pyproject_template(package_name, sub_packages), encoding="utf-8")
192+
pyproject.write_text(
193+
pyproject_template(package_name, module_name, sub_packages), encoding="utf-8"
194+
)
226195

227196
foopy = git_repo / f"{module_name}.py"
228197
foopy.write_text(PY_MODULE_TEMPLATE, encoding="utf-8")

jupyter_releaser/util.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ def bump_version(version_spec, *, changelog_path="", version_cmd=""):
279279

280280
# Add some convenience options on top of "tbump" and "hatch"
281281
if "tbump" in version_cmd or "hatch" in version_cmd:
282+
282283
v = parse_version(get_version())
283284
log(f"Current version was: {v}")
284285
assert isinstance(v, Version)
@@ -300,7 +301,7 @@ def bump_version(version_spec, *, changelog_path="", version_cmd=""):
300301
if vc.is_devrelease:
301302
# Bump to the next dev release.
302303
assert vc.dev is not None
303-
version_spec = f"{vc.major}.{vc.minor}.{vc.micro}{vc.dev}{vc.dev + 1}"
304+
version_spec = f"{vc.major}.{vc.minor}.{vc.micro}.dev{vc.dev + 1}"
304305
else:
305306
assert vc.pre is not None
306307
# Bump to the next prerelease.
@@ -312,7 +313,7 @@ def bump_version(version_spec, *, changelog_path="", version_cmd=""):
312313

313314
# Move to the minor release
314315
elif version_spec == "minor":
315-
version_spec = f"{vc.major}.{v.minor+1}.0"
316+
version_spec = f"{vc.major}.{vc.minor+1}.0"
316317

317318
# Bump to the next dev version.
318319
elif version_spec == "dev":

0 commit comments

Comments
 (0)