fast-dev-cli 0.23.2__tar.gz → 0.24.0__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.0
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.0"
@@ -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,21 @@ 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
+ no_extra: list[str] | None = None,
1718
+ no_group: list[str] | None = None,
1711
1719
  ) -> None:
1712
1720
  self._tool = tool
1713
1721
  self._prod = prod
1714
- self._active = active
1715
- self._inexact = inexact
1722
+ self._active = active or load_bool("FASTDEVCLI_DEPS_ACTIVE")
1723
+ self._inexact = inexact or load_bool("FASTDEVCLI_DEPS_INEXACT")
1724
+ self._verbose = verbose
1725
+ self._no_dev = no_dev
1726
+ self._no_extra = no_extra
1727
+ self._no_group = no_group
1716
1728
  super().__init__(dry=dry)
1717
1729
 
1718
1730
  def should_ensure_pip(self) -> bool:
@@ -1727,13 +1739,53 @@ class MakeDeps(DryRun):
1727
1739
  return ["dev"]
1728
1740
 
1729
1741
  def gen(self) -> str:
1742
+ cmd = self._gen()
1743
+ if self._verbose:
1744
+ cmd += " --verbose"
1745
+ if self._no_dev:
1746
+ opt = " --no-dev"
1747
+ if opt not in cmd:
1748
+ cmd += opt
1749
+ if self._no_extra:
1750
+ cmd += " " + " ".join(f"--no-extra {i}" for i in self._no_extra)
1751
+ if self._no_group:
1752
+ cmd += " " + " ".join(f"--no-group {i}" for i in self._no_group)
1753
+ if opts := os.getenv("FASTDEVCLI_DEPS_OPTS"):
1754
+ cmd += " " + opts.strip()
1755
+ return cmd
1756
+
1757
+ def get_package_name(self) -> str:
1758
+ with contextlib.suppress(FileNotFoundError, KeyError):
1759
+ try:
1760
+ toml_text = Project.load_toml_text()
1761
+ except EnvError:
1762
+ return ""
1763
+ doc = tomllib.loads(toml_text)
1764
+ tool_section = doc["tool"]
1765
+ uv_package = tool_section.get("uv", {}).get("package")
1766
+ if uv_package is not None:
1767
+ return doc["project"]["name"] if uv_package else ""
1768
+ match doc["build-system"]["build-backend"]:
1769
+ case "pdm.backend":
1770
+ if not tool_section.get("pdm", {}).get("distribution", True):
1771
+ return ""
1772
+ case x if x.startswith("poetry"):
1773
+ if not tool_section.get("poetry", {}).get("package-mode", True):
1774
+ return ""
1775
+ return doc["project"]["name"]
1776
+ return ""
1777
+
1778
+ def _gen(self) -> str:
1730
1779
  if self._tool == "pdm":
1731
1780
  return "pdm install --frozen " + ("--prod" if self._prod else "-G :all")
1732
1781
  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")
1782
+ uv_sync = "uv sync"
1783
+ if project := self.get_package_name():
1784
+ uv_sync += f" --reinstall-package={project}"
1785
+ uv_sync += " --inexact" * self._inexact + " --active" * self._active
1786
+ return uv_sync + (
1787
+ " --no-dev" if self._prod else " --all-extras --all-groups"
1788
+ )
1737
1789
  elif self._tool == "poetry":
1738
1790
  return "poetry install " + (
1739
1791
  "--only=main" if self._prod else "--all-extras --all-groups"
@@ -1763,11 +1815,15 @@ def make_deps(
1763
1815
  use_pip: bool = Option(False, "--pip", help="Use `pip` to install deps"),
1764
1816
  use_poetry: bool = Option(False, "--poetry", help="Use `poetry` to install deps"),
1765
1817
  active: bool = Option(
1766
- True, help="Add `--active` to uv sync command(Only work for uv project)"
1818
+ False, help="Add `--active` to uv sync command(Only work for uv project)"
1767
1819
  ),
1768
1820
  inexact: bool = Option(
1769
- True, help="Add `--inexact` to uv sync command(Only work for uv project)"
1821
+ False, help="Add `--inexact` to uv sync command(Only work for uv project)"
1770
1822
  ),
1823
+ no_dev: bool = Option(False, "--no-dev"),
1824
+ no_extra: Annotated[list[str] | None, Option()] = None,
1825
+ no_group: Annotated[list[str] | None, Option()] = None,
1826
+ verbose: bool = Option(False, "--verbose"),
1771
1827
  dry: bool = DryOption,
1772
1828
  ) -> None:
1773
1829
  """Run: ruff check/format to reformat code and then mypy to check"""
@@ -1786,7 +1842,14 @@ def make_deps(
1786
1842
  tool = "poetry"
1787
1843
  elif tool == ToolOption.default:
1788
1844
  tool = Project.get_manage_tool(cache=True) or "pip"
1789
- MakeDeps(tool, prod, active=active, inexact=inexact, dry=dry).run()
1845
+ bool_opts = {
1846
+ "active": active,
1847
+ "inexact": inexact,
1848
+ "no_dev": no_dev,
1849
+ "verbose": verbose,
1850
+ "dry": dry,
1851
+ }
1852
+ MakeDeps(tool, prod, no_extra=no_extra, no_group=no_group, **bool_opts).run()
1790
1853
 
1791
1854
 
1792
1855
  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.0"
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