Skip to content

Commit

Permalink
feat: support poetry-dynamic-versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
waketzheng committed Oct 29, 2024
1 parent fdf2ca7 commit 30c8bc4
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ jobs:
python -m pip install --upgrade pip pdm poetry
poetry config virtualenvs.create false
poetry self add poetry-version-plugin
poetry self add poetry-dynamic-versioning
git config --global user.email "waketzheng@gmail.com"
git config --global user.name "Waket Zheng"
- name: Install uv
uses: astral-sh/setup-uv@v3
- name: Install requirements/Check code style and Type Hint
run: make check
- name: Test with pytest
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Support uv
- Fix `get_current_version` error
- Auto use pdm/uv to export for sync command
- Support poetry-dynamic-versioning

## 0.10

Expand Down
13 changes: 7 additions & 6 deletions fast_dev_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def parse_filename() -> str:
version_value = context["tool"]["poetry"]["version"]
except KeyError:
return TOML_FILE
if version_value == "0":
if version_value in ("0", "0.0.0"):
try:
package_item = context["tool"]["poetry"]["packages"]
except KeyError:
Expand Down Expand Up @@ -741,21 +741,22 @@ def gen(self) -> str:
raise EnvError("There project is not managed by uv/pdm/poetry!")
return f"python -m pip install -r {self.filename}"
prefix = "" if is_venv() else f"{tool} run "
ensurepip = ""
ensurepip = " {1}python -m ensurepip && {1}python -m pip install -U pip &&"
match tool:
case "uv":
export_cmd = "uv export --no-hashes --all-extras --frozen"
if not check_call(prefix + "python -m pip --version"):
ensurepip = (
" {1}python -m ensurepip && {1}python -m pip install -U pip &&"
)
if check_call(prefix + "python -m pip --version"):
ensurepip = ""
case "poetry" | "pdm":
export_cmd = f"{tool} export --without-hashes --with=dev"
if tool == "poetry":
ensurepip = ""
if not UpgradeDependencies.should_with_dev():
export_cmd = export_cmd.replace(" --with=dev", "")
if extras and isinstance(extras, str | list):
export_cmd += f" --{extras=}".replace("'", '"')
elif check_call(prefix + "python -m pip --version"):
ensurepip = ""
install_cmd = "{2} -o {0} &&%s {1}python -m pip install -r {0}" % ensurepip
if should_remove and not save:
install_cmd += " && rm -f {0}"
Expand Down
28 changes: 26 additions & 2 deletions tests/test_poetry_version_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,21 @@
[tool.poetry-version-plugin]
source = "init"
"""
CONF_2 = """
[tool.poetry-dynamic-versioning]
enable = true
"""


@contextmanager
def _prepare_package(
package_path: Path, define_include=False
package_path: Path, define_include=False, mark="0"
) -> Generator[Path, None, None]:
toml_file = package_path / TOML_FILE
package_name = package_path.name.replace(" ", "_")
init_file = package_path / package_name / "__init__.py"
a, b = 'version = "0.1.0"', 'version = "0"'
a, b = 'version = "0.1.0"', f'version = "{mark}"'
if define_include:
b += '\npackages = [{include = "%s"}]' % package_name
with chdir(package_path.parent):
Expand Down Expand Up @@ -62,9 +67,28 @@ def test_version_plugin(tmp_path: Path) -> None:
BumpUp(part="patch", commit=False, dry=True).gen()


def test_version_plugin_2(tmp_path: Path) -> None:
with _prepare_package(tmp_path / "helloworld", mark="0.0.0") as init_file:
command = _build_bump_cmd(init_file)
assert BumpUp(part="patch", commit=False, dry=True).gen() == command
run_and_echo("poetry run fast bump patch")
assert init_file.read_text() == '__version__ = "0.0.2"\n'
init_file.unlink()
with pytest.raises(ParseError, match=r"Version file not found!.*"):
BumpUp(part="patch", commit=False, dry=True).gen()


def test_version_plugin_include_defined(tmp_path: Path) -> None:
with _prepare_package(tmp_path / "hello world", True) as init_file:
command = _build_bump_cmd(init_file)
assert BumpUp(part="patch", commit=False, dry=True).gen() == command
run_and_echo("poetry run fast bump patch")
assert init_file.read_text() == '__version__ = "0.0.2"\n'


def test_version_plugin_include_defined_2(tmp_path: Path) -> None:
with _prepare_package(tmp_path / "hello world", True, mark="0.0.0") as init_file:
command = _build_bump_cmd(init_file)
assert BumpUp(part="patch", commit=False, dry=True).gen() == command
run_and_echo("poetry run fast bump patch")
assert init_file.read_text() == '__version__ = "0.0.2"\n'

0 comments on commit 30c8bc4

Please sign in to comment.