Skip to content

Commit

Permalink
feat: use sync instead of install by default (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidism authored Jul 19, 2022
1 parent 78ad225 commit 0f8e0ba
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
17 changes: 17 additions & 0 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,20 @@ def test_use_pdm_shell_scripts(tmpdir):
commands = lint-shell
""",
)


def test_pdm_install_not_sync(tmpdir):
execute_config(
tmpdir,
"""
[tox]
envlist = py3
passenv = LD_PRELOAD
isolated_build = True
[testenv]
groups = lint
pdm_sync = False
commands = flake8 --version
""",
)
6 changes: 5 additions & 1 deletion tox_pdm/plugin3.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ def tox_addoption(parser: config.Parser) -> Any:
parser.add_testenv_attribute(
"groups", "line-list", "Specify the dependency groups to install"
)
parser.add_testenv_attribute(
"pdm_sync", "bool", "Disable to use 'pdm install' instead of 'pdm sync'.", True
)
setup_env()
parser.add_argument("--pdm", default="pdm", help="The executable path of PDM")

Expand All @@ -40,9 +43,10 @@ def tox_configure(config: config.Config):
@hookimpl
def tox_testenv_install_deps(venv: VirtualEnv, action: action.Action) -> Any:
groups = venv.envconfig.groups or []
op = "sync" if venv.envconfig.pdm_sync else "install"
if not venv.envconfig.skip_install or groups:
action.setactivity("pdminstall", groups)
args = [venv.envconfig.config.option.pdm, "install"]
args = [venv.envconfig.config.option.pdm, op]
if "default" in groups:
groups.remove("default")
elif venv.envconfig.skip_install:
Expand Down
9 changes: 8 additions & 1 deletion tox_pdm/plugin4.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def _setup_env(self) -> None:
super()._setup_env()
groups = self.conf["groups"]
pdm = self.options.pdm
cmd = [pdm, "install", "--no-self"]
op = "sync" if self.conf["pdm_sync"] else "install"
cmd = [pdm, op, "--no-self"]
for group in groups:
cmd.extend(("--group", group))
if pdm not in self.conf["allowlist_externals"]:
Expand All @@ -58,6 +59,12 @@ def register_config(self) -> None:
default=[],
desc="Specify the dependency groups to install",
)
self.conf.add_config(
"pdm_sync",
of_type=bool,
default=True,
desc="Disable to use 'pdm install' instead of 'pdm sync'.",
)

@staticmethod
def id() -> str:
Expand Down

0 comments on commit 0f8e0ba

Please sign in to comment.