fast-dev-cli 0.23.2__tar.gz → 0.24.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: fast-dev-cli
3
- Version: 0.23.2
3
+ Version: 0.24.1
4
4
  Summary: Python project development tool.
5
5
  Author-Email: Waket Zheng <waketzheng@gmail.com>>
6
6
  Classifier: Development Status :: 4 - Beta
@@ -0,0 +1 @@
1
+ __version__ = "0.24.1"
@@ -12,7 +12,7 @@ import subprocess # nosec:B404
12
12
  import sys
13
13
  from functools import cached_property
14
14
  from pathlib import Path
15
- from typing import TYPE_CHECKING, Any, Literal, cast, get_args, overload
15
+ from typing import TYPE_CHECKING, Annotated, Any, Literal, cast, get_args, overload
16
16
 
17
17
  import typer
18
18
  from typer import Exit, Option, echo, secho
@@ -316,11 +316,7 @@ def get_current_version(
316
316
  check_version: bool = False,
317
317
  ) -> str | tuple[bool, str]:
318
318
  if is_poetry is True or Project.manage_by_poetry():
319
- cmd = ["poetry", "version", "-s"]
320
- if verbose:
321
- echo(f"--> {' '.join(cmd)}")
322
- if out := capture_cmd_output(cmd, raises=True):
323
- out = out.splitlines()[-1].strip().split()[-1]
319
+ out = _get_poetry_project_version(verbose)
324
320
  if check_version:
325
321
  return True, out
326
322
  return out
@@ -354,6 +350,15 @@ def get_current_version(
354
350
  return current_version
355
351
 
356
352
 
353
+ def _get_poetry_project_version(verbose: bool) -> str:
354
+ cmd = ["poetry", "version", "-s"]
355
+ if verbose:
356
+ echo(f"--> {' '.join(cmd)}")
357
+ if out := capture_cmd_output(cmd, raises=True):
358
+ out = out.splitlines()[-1].strip().split()[-1]
359
+ return out
360
+
361
+
357
362
  def _ensure_bool(value: bool | OptionInfo) -> bool:
358
363
  if isinstance(value, bool):
359
364
  return value
@@ -442,7 +447,7 @@ class BumpUp(DryRun):
442
447
  or work_dir.joinpath(version_path).exists()
443
448
  ):
444
449
  return version_path
445
- # version = { source = "file", path = "fast_dev_cli/__init__.py" }
450
+ # e.g.: version = { source = "file", path = "fast_dev_cli/__init__.py" }
446
451
  v_key = "version = "
447
452
  p_key = 'path = "'
448
453
  if toml_text is None:
@@ -499,7 +504,6 @@ class BumpUp(DryRun):
499
504
  by_version_plugin = version_value in ("0", "0.0.0", "init")
500
505
  if by_version_plugin:
501
506
  return cls.parse_plugin_version(context, package_name)
502
-
503
507
  return TOML_FILE
504
508
 
505
509
  @staticmethod
@@ -1706,13 +1710,23 @@ class MakeDeps(DryRun):
1706
1710
  tool: str,
1707
1711
  prod: bool = False,
1708
1712
  dry: bool = False,
1709
- active: bool = True,
1710
- inexact: bool = True,
1713
+ active: bool = False,
1714
+ inexact: bool = False,
1715
+ no_dev: bool = False,
1716
+ verbose: bool = False,
1717
+ frozen: bool = False,
1718
+ no_extra: list[str] | None = None,
1719
+ no_group: list[str] | None = None,
1711
1720
  ) -> None:
1712
1721
  self._tool = tool
1713
1722
  self._prod = prod
1714
- self._active = active
1715
- self._inexact = inexact
1723
+ self._active = active or load_bool("FASTDEVCLI_DEPS_ACTIVE")
1724
+ self._inexact = inexact or load_bool("FASTDEVCLI_DEPS_INEXACT")
1725
+ self._verbose = verbose
1726
+ self._frozen = frozen
1727
+ self._no_dev = no_dev
1728
+ self._no_extra = no_extra
1729
+ self._no_group = no_group
1716
1730
  super().__init__(dry=dry)
1717
1731
 
1718
1732
  def should_ensure_pip(self) -> bool:
@@ -1727,13 +1741,55 @@ class MakeDeps(DryRun):
1727
1741
  return ["dev"]
1728
1742
 
1729
1743
  def gen(self) -> str:
1744
+ cmd = self._gen()
1745
+ if self._verbose:
1746
+ cmd += " --verbose"
1747
+ if self._no_dev:
1748
+ opt = " --no-dev"
1749
+ if opt not in cmd:
1750
+ cmd += opt
1751
+ if self._no_extra:
1752
+ cmd += " " + " ".join(f"--no-extra {i}" for i in self._no_extra)
1753
+ if self._no_group:
1754
+ cmd += " " + " ".join(f"--no-group {i}" for i in self._no_group)
1755
+ if self._frozen:
1756
+ cmd += " --frozen"
1757
+ if opts := os.getenv("FASTDEVCLI_DEPS_OPTS"):
1758
+ cmd += " " + opts.strip()
1759
+ return cmd
1760
+
1761
+ def get_package_name(self) -> str:
1762
+ with contextlib.suppress(FileNotFoundError, KeyError):
1763
+ try:
1764
+ toml_text = Project.load_toml_text()
1765
+ except EnvError:
1766
+ return ""
1767
+ doc = tomllib.loads(toml_text)
1768
+ tool_section = doc["tool"]
1769
+ uv_package = tool_section.get("uv", {}).get("package")
1770
+ if uv_package is not None:
1771
+ return doc["project"]["name"] if uv_package else ""
1772
+ match doc["build-system"]["build-backend"]:
1773
+ case "pdm.backend":
1774
+ if not tool_section.get("pdm", {}).get("distribution", True):
1775
+ return ""
1776
+ case x if x.startswith("poetry"):
1777
+ if not tool_section.get("poetry", {}).get("package-mode", True):
1778
+ return ""
1779
+ return doc["project"]["name"]
1780
+ return ""
1781
+
1782
+ def _gen(self) -> str:
1730
1783
  if self._tool == "pdm":
1731
1784
  return "pdm install --frozen " + ("--prod" if self._prod else "-G :all")
1732
1785
  elif self._tool == "uv":
1733
- uv_sync = "uv sync" + " --inexact" * self._inexact
1734
- if self._active:
1735
- uv_sync += " --active"
1736
- return uv_sync + ("" if self._prod else " --all-extras --all-groups")
1786
+ uv_sync = "uv sync"
1787
+ if project := self.get_package_name():
1788
+ uv_sync += f" --reinstall-package={project}"
1789
+ uv_sync += " --inexact" * self._inexact + " --active" * self._active
1790
+ return uv_sync + (
1791
+ " --no-dev" if self._prod else " --all-extras --all-groups"
1792
+ )
1737
1793
  elif self._tool == "poetry":
1738
1794
  return "poetry install " + (
1739
1795
  "--only=main" if self._prod else "--all-extras --all-groups"
@@ -1763,11 +1819,16 @@ def make_deps(
1763
1819
  use_pip: bool = Option(False, "--pip", help="Use `pip` to install deps"),
1764
1820
  use_poetry: bool = Option(False, "--poetry", help="Use `poetry` to install deps"),
1765
1821
  active: bool = Option(
1766
- True, help="Add `--active` to uv sync command(Only work for uv project)"
1822
+ False, help="Add `--active` to uv sync command(Only work for uv project)"
1767
1823
  ),
1768
1824
  inexact: bool = Option(
1769
- True, help="Add `--inexact` to uv sync command(Only work for uv project)"
1825
+ False, help="Add `--inexact` to uv sync command(Only work for uv project)"
1770
1826
  ),
1827
+ no_dev: bool = Option(False, "--no-dev"),
1828
+ no_extra: Annotated[list[str] | None, Option()] = None,
1829
+ no_group: Annotated[list[str] | None, Option()] = None,
1830
+ frozen: bool = Option(False, "--frozen", "--frozen-lockfile", "--no-lock"),
1831
+ verbose: bool = Option(False, "--verbose"),
1771
1832
  dry: bool = DryOption,
1772
1833
  ) -> None:
1773
1834
  """Run: ruff check/format to reformat code and then mypy to check"""
@@ -1786,7 +1847,15 @@ def make_deps(
1786
1847
  tool = "poetry"
1787
1848
  elif tool == ToolOption.default:
1788
1849
  tool = Project.get_manage_tool(cache=True) or "pip"
1789
- MakeDeps(tool, prod, active=active, inexact=inexact, dry=dry).run()
1850
+ bool_opts = {
1851
+ "active": active,
1852
+ "inexact": inexact,
1853
+ "no_dev": no_dev,
1854
+ "verbose": verbose,
1855
+ "frozen": frozen,
1856
+ "dry": dry,
1857
+ }
1858
+ MakeDeps(tool, prod, no_extra=no_extra, no_group=no_group, **bool_opts).run()
1790
1859
 
1791
1860
 
1792
1861
  class UvPypi(DryRun):
@@ -29,7 +29,7 @@ dependencies = [
29
29
  "typer>=0.24.0,<1",
30
30
  "tomli >=2.0.1,<3; python_version < '3.11'",
31
31
  ]
32
- version = "0.23.2"
32
+ version = "0.24.1"
33
33
 
34
34
  [project.urls]
35
35
  Homepage = "https://github.com/waketzheng/fast-dev-cli"
@@ -54,6 +54,7 @@ fast = "fast_dev_cli.cli:main"
54
54
  dev = [
55
55
  "asynctor>=0.13.0",
56
56
  "httpx2>=2.5.0",
57
+ "tomli-w>=1.2.0",
57
58
  ]
58
59
 
59
60
  [build-system]
@@ -1 +0,0 @@
1
- __version__ = "0.23.2"
File without changes
File without changes