Skip to content
Draft
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
15 changes: 10 additions & 5 deletions pretext/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,14 @@ def main(ctx: click.Context, targets: bool) -> None:
log.warning(
"Project's CLI version could not be detected from `requirements.txt`."
)
log.warning("Try `pretext update` to produce a compatible file.")
log.warning("Try `pretext update-project` to produce a compatible file.")
elif utils.requirements_version() != VERSION:
log.warning(f"Using CLI version {VERSION} but project's `requirements.txt`")
log.warning(
f"is configured to use {utils.requirements_version()}. Consider either installing"
)
log.warning(
f"CLI version {utils.requirements_version()} or running `pretext update`"
f"CLI version {utils.requirements_version()} or running `pretext update-update`"
)
log.warning(
f"to update `requirements.txt` and other managed files to match {VERSION}."
Expand Down Expand Up @@ -214,20 +214,25 @@ def upgrade() -> None:
pretext_cmd = "pretext"
subprocess.run([sys.executable, "-m", "pip", "install", "--upgrade", pretext_cmd])
log.info(
"Upgrade complete. Individual projects can be updated to align with the latest version of the CLI by running `pretext update` from their project folder."
"Upgrade complete. Individual projects can be updated to align with the latest version of the CLI by running `pretext update-project` from their project folder."
)


# pretext update
@click.command('update')
def old_update():
click.echo("This command is outdated. Use `pretext update-project` instead.")

# pretext update-project
@main.command(
'update-project',
short_help="Update the current project to match the installed version of PreTeXt. Note: to upgrade the installed version of pretext, use `pretext upgrade`.",
context_settings=CONTEXT_SETTINGS,
)
@click.option(
"-b", "--backup", is_flag=True, help="Backup project files before updating."
)
@click.option("-f", "--force", is_flag=True, help="Force update of project files.")
def update(backup: bool, force: bool) -> None:
def update_project(backup: bool, force: bool) -> None:
"""
Update the current project to match the installed version of PreTeXt.
"""
Expand Down
12 changes: 6 additions & 6 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,11 @@ def test_init_and_update(tmp_path: Path, script_runner: ScriptRunner) -> None:
assert not (tmp_path / constants.PROJECT_RESOURCES[resource]).exists()
else:
assert (tmp_path / constants.PROJECT_RESOURCES[resource]).exists()
assert script_runner.run([PTX_CMD, "-v", "debug", "update"], cwd=tmp_path).success
assert script_runner.run([PTX_CMD, "-v", "debug", "update-project"], cwd=tmp_path).success
for resource in ["requirements.txt", "codechat_config.yaml"]:
resource_path = tmp_path / constants.PROJECT_RESOURCES[resource]
resource_path.unlink(missing_ok=True)
assert script_runner.run([PTX_CMD, "-v", "debug", "update"], cwd=tmp_path).success
assert script_runner.run([PTX_CMD, "-v", "debug", "update-project"], cwd=tmp_path).success
for resource in constants.PROJECT_RESOURCES:
if resource in constants.GIT_RESOURCES:
assert not (tmp_path / constants.PROJECT_RESOURCES[resource]).exists()
Expand All @@ -217,18 +217,18 @@ def test_init_and_update_with_git(tmp_path: Path, script_runner: ScriptRunner) -
script_runner.run([PTX_CMD, "-v", "debug", "init"], cwd=tmp_path)
for resource in constants.PROJECT_RESOURCES:
assert (tmp_path / constants.PROJECT_RESOURCES[resource]).exists()
assert script_runner.run([PTX_CMD, "-v", "debug", "update"], cwd=tmp_path).success
assert script_runner.run([PTX_CMD, "-v", "debug", "update-project"], cwd=tmp_path).success
# Remove resources
for resource in ["requirements.txt", "codechat_config.yaml", ".gitignore"]:
resource_path = tmp_path / constants.PROJECT_RESOURCES[resource]
resource_path.unlink(missing_ok=True)
assert script_runner.run([PTX_CMD, "-v", "debug", "update"], cwd=tmp_path).success
assert script_runner.run([PTX_CMD, "-v", "debug", "update-project"], cwd=tmp_path).success
for resource in constants.PROJECT_RESOURCES:
assert (tmp_path / constants.PROJECT_RESOURCES[resource]).exists()
# Ensure modified files don't get updated.
with open(tmp_path / ".gitignore", "a") as f:
f.write("\n# Added by test\n")
assert script_runner.run([PTX_CMD, "-v", "debug", "update"], cwd=tmp_path).success
assert script_runner.run([PTX_CMD, "-v", "debug", "update-project"], cwd=tmp_path).success
assert "Added by test" in (tmp_path / ".gitignore").read_text()
# Ensure older version of requirements does get updated.
requirements_path = tmp_path / "requirements.txt"
Expand All @@ -240,7 +240,7 @@ def test_init_and_update_with_git(tmp_path: Path, script_runner: ScriptRunner) -
file.write("pretext == 1.0.0\n")
else:
file.write(line)
assert script_runner.run([PTX_CMD, "-v", "debug", "update"], cwd=tmp_path).success
assert script_runner.run([PTX_CMD, "-v", "debug", "update-project"], cwd=tmp_path).success
with open(requirements_path, "r") as file:
lines = file.readlines()
assert f"pretext == {pretext.VERSION}\n" in lines[1]
Expand Down
Loading