Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions jupyter_releaser/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,11 @@ def test_check_python_resource_path(monkeypatch, py_package, runner, build_mock,
path = bar_dir / "baz.txt"
path.write_text("hello", encoding="utf-8")

pyproject = Path(util.CHECKOUT_NAME / util.PYPROJECT)
pyproject_text = pyproject.read_text('utf-8')
pyproject_text = pyproject_text.replace("foo.py", "foo/__init__.py")
pyproject.write_text(pyproject_text, "utf-8")

runner(["build-python"])
runner(["check-python"])

Expand Down
47 changes: 14 additions & 33 deletions jupyter_releaser/tests/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,7 @@ def test_get_repo(git_repo, mocker):
assert util.get_repo() == repo


def test_get_version_pyproject_static(py_package):
assert util.get_version() == "0.0.1"
util.bump_version("0.0.2a0")
assert util.get_version() == "0.0.2a0"


def test_get_version_pyproject_dynamic(py_package):
py_project = py_package / "pyproject.toml"
text = py_project.read_text(encoding="utf-8")
text = text.replace("""[project]\nversion = "0.0.1\"""", "")
py_project.write_text(text, encoding="utf-8")
assert util.get_version() == "0.0.1"


def test_get_version_hatchling(py_package):
py_project = py_package / "pyproject.toml"
with open(py_project) as fid:
data = toml.load(fid)
del data["project"]["version"]
data["build-system"] = {"requires": ["hatchling>=1.0"], "build-backend": "hatchling.build"}
with open(py_project, "w") as fid:
fid.write(str(py_project))


def test_get_version_setuppy(py_package):
def test_get_version_pyproject_hatch(py_package):
assert util.get_version() == "0.0.1"
util.bump_version("0.0.2a0")
assert util.get_version() == "0.0.2a0"
Expand Down Expand Up @@ -252,8 +228,7 @@ def test_create_release_commit_hybrid(py_package, build_mock):
data["version"] = version
pkg_json.write_text(json.dumps(data, indent=4), encoding="utf-8")
util.run("pre-commit run --all-files", check=False)
txt = (py_package / "tbump.toml").read_text(encoding="utf-8")
txt += testutil.TBUMP_NPM_TEMPLATE
txt = testutil.TBUMP_NPM_TEMPLATE
(py_package / "tbump.toml").write_text(txt, encoding="utf-8")

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


def test_bump_version_dev(py_package):
util.bump_version("dev")
util.bump_version("dev", changelog_path="CHANGELOG.md")
assert util.get_version() == "0.1.0.dev0"
util.bump_version("dev")
util.bump_version("dev", changelog_path="CHANGELOG.md")
assert util.get_version() == "0.1.0.dev1"
util.bump_version("next")
util.bump_version("patch")
util.bump_version("minor")
assert util.get_version() == "0.2.0"
util.bump_version("next", changelog_path="CHANGELOG.md")
assert util.get_version() == "0.0.3"
util.bump_version("dev", changelog_path="CHANGELOG.md")
assert util.get_version() == "0.1.0.dev0"
util.bump_version("patch", changelog_path="CHANGELOG.md")
assert util.get_version() == "0.0.3"
util.bump_version("dev", changelog_path="CHANGELOG.md")
assert util.get_version() == "0.1.0.dev0"
util.bump_version("minor", changelog_path="CHANGELOG.md")
assert util.get_version() == "0.1.0"


def test_get_config_python(py_package):
Expand Down
51 changes: 10 additions & 41 deletions jupyter_releaser/tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,16 @@ def setup_cfg_template(package_name="foo", module_name=None):
README_TEMPLATE = "A fake readme\n"


def pyproject_template(project_name="foo", sub_packages=None):
def pyproject_template(project_name="foo", module_name="foo", sub_packages=None):
sub_packages = sub_packages or []
res = f"""
[build-system]
requires = ["hatchling>=1.5.0"]
requires = ["hatchling>=1.11"]
build-backend = "hatchling.build"

[project]
name = "{project_name}"
version = "0.0.1"
dynamic = ["version"]
description = "My package description"
readme = "README.md"
license = {{file = "LICENSE"}}
Expand All @@ -105,6 +105,10 @@ def pyproject_template(project_name="foo", sub_packages=None):
{{name = "foo"}}
]

[tool.hatch.version]
path = "{module_name}.py"
validate-bump = false

[project.urls]
homepage = "https://foo.com"
"""
Expand All @@ -118,31 +122,6 @@ def pyproject_template(project_name="foo", sub_packages=None):

PY_MODULE_TEMPLATE = '__version__ = "0.0.1"\n'


TBUMP_BASE_TEMPLATE = r"""
[version]
current = "0.0.1"
regex = '''
(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)
((?P<channel>a|b|rc|.dev)(?P<release>\d+))?
'''

[git]
message_template = "Bump to {new_version}"
tag_template = "v{new_version}"
"""


def tbump_py_template(package_name="foo"):
return f"""
[[file]]
src = "{package_name}.py"

[[file]]
src = "pyproject.toml"
"""


TBUMP_NPM_TEMPLATE = """
[[file]]
src = "package.json"
Expand Down Expand Up @@ -209,20 +188,10 @@ def write_files(git_repo, sub_packages=None, package_name="foo", module_name=Non

module_name = module_name or package_name

setuppy = git_repo / "setup.py"
setuppy.write_text(SETUP_PY_TEMPLATE, encoding="utf-8")

setuppy = git_repo / "setup.cfg"
setuppy.write_text(setup_cfg_template(package_name, module_name), encoding="utf-8")

tbump = git_repo / "tbump.toml"
tbump.write_text(
TBUMP_BASE_TEMPLATE + tbump_py_template(package_name),
encoding="utf-8",
)

pyproject = git_repo / "pyproject.toml"
pyproject.write_text(pyproject_template(package_name, sub_packages), encoding="utf-8")
pyproject.write_text(
pyproject_template(package_name, module_name, sub_packages), encoding="utf-8"
)

foopy = git_repo / f"{module_name}.py"
foopy.write_text(PY_MODULE_TEMPLATE, encoding="utf-8")
Expand Down
5 changes: 3 additions & 2 deletions jupyter_releaser/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ def bump_version(version_spec, *, changelog_path="", version_cmd=""):

# Add some convenience options on top of "tbump" and "hatch"
if "tbump" in version_cmd or "hatch" in version_cmd:

v = parse_version(get_version())
log(f"Current version was: {v}")
assert isinstance(v, Version)
Expand All @@ -300,7 +301,7 @@ def bump_version(version_spec, *, changelog_path="", version_cmd=""):
if vc.is_devrelease:
# Bump to the next dev release.
assert vc.dev is not None
version_spec = f"{vc.major}.{vc.minor}.{vc.micro}{vc.dev}{vc.dev + 1}"
version_spec = f"{vc.major}.{vc.minor}.{vc.micro}.dev{vc.dev + 1}"
else:
assert vc.pre is not None
# Bump to the next prerelease.
Expand All @@ -312,7 +313,7 @@ def bump_version(version_spec, *, changelog_path="", version_cmd=""):

# Move to the minor release
elif version_spec == "minor":
version_spec = f"{vc.major}.{v.minor+1}.0"
version_spec = f"{vc.major}.{vc.minor+1}.0"

# Bump to the next dev version.
elif version_spec == "dev":
Expand Down