Skip to content
Merged
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
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ reportUnknownLambdaType = false
reportUnknownMemberType = false
reportUnknownParameterType = false
reportUnknownVariableType = false
reportUnnecessaryComparison = false
reportUnnecessaryIsInstance = false
reportUnusedCallResult = false
reportUnusedParameter = false
Expand Down
10 changes: 2 additions & 8 deletions src/usethis/_core/readme.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,16 @@ def add_readme() -> None:
except PyprojectTOMLError:
project_description = None

if project_name is not None and project_description is not None:
if project_description is not None:
content = f"""\
# {project_name}

{project_description}
"""
elif project_name is not None:
else:
content = f"""\
# {project_name}
"""
elif project_description is not None:
content = f"""\
{project_description}
"""
else:
content = ""

tick_print("Writing 'README.md'.")
(usethis_config.cpd() / "README.md").write_text(content, encoding="utf-8")
Expand Down
100 changes: 47 additions & 53 deletions src/usethis/_integrations/ci/bitbucket/pipeweld.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,15 @@ def get_pipeweld_object(
elif isinstance(item, schema.ParallelItem):
parallel_steps: set[str] = set()

if item.parallel is not None:
if isinstance(item.parallel.root, schema.ParallelSteps):
step_items = item.parallel.root.root
elif isinstance(item.parallel.root, schema.ParallelExpanded):
step_items = item.parallel.root.steps.root
else:
assert_never(item.parallel.root)
if isinstance(item.parallel.root, schema.ParallelSteps):
step_items = item.parallel.root.root
elif isinstance(item.parallel.root, schema.ParallelExpanded):
step_items = item.parallel.root.steps.root
else:
assert_never(item.parallel.root)

for step_item in step_items:
parallel_steps.add(get_pipeweld_step(step_item.step))
for step_item in step_items:
parallel_steps.add(get_pipeweld_step(step_item.step))

return usethis._pipeweld.containers.Parallel(frozenset(parallel_steps))
elif isinstance(item, schema.StageItem):
Expand Down Expand Up @@ -245,28 +244,27 @@ def _extract_step_from_parallel_item(
items: list[schema.StepItem | schema.ParallelItem | schema.StageItem],
idx: int,
) -> schema.Step | None:
if item.parallel is not None:
if isinstance(item.parallel.root, schema.ParallelSteps):
step_items = item.parallel.root.root
elif isinstance(item.parallel.root, schema.ParallelExpanded):
step_items = item.parallel.root.steps.root
else:
assert_never(item.parallel.root)

for step_idx, step_item in enumerate(step_items):
if get_pipeweld_step(step_item.step) == step_name:
# Found it - remove from the parallel block
extracted_step = step_item.step
step_items.pop(step_idx)

# If only one step remains in the parallel, convert to a simple step
if len(step_items) == 1:
items[idx] = step_items[0]
elif len(step_items) == 0:
# No steps left, remove the parallel item
items.pop(idx)

return extracted_step
if isinstance(item.parallel.root, schema.ParallelSteps):
step_items = item.parallel.root.root
elif isinstance(item.parallel.root, schema.ParallelExpanded):
step_items = item.parallel.root.steps.root
else:
assert_never(item.parallel.root)

for step_idx, step_item in enumerate(step_items):
if get_pipeweld_step(step_item.step) == step_name:
# Found it - remove from the parallel block
extracted_step = step_item.step
step_items.pop(step_idx)

# If only one step remains in the parallel, convert to a simple step
if len(step_items) == 1:
items[idx] = step_items[0]
elif len(step_items) == 0:
# No steps left, remove the parallel item
items.pop(idx)

return extracted_step
return None


Expand Down Expand Up @@ -296,17 +294,14 @@ def _insert_parallel_step(
)
items[idx] = parallel_item
elif isinstance(item, schema.ParallelItem):
if item.parallel is not None:
if isinstance(item.parallel.root, schema.ParallelSteps):
# Add to the existing list of parallel steps
item.parallel.root.root.append(schema.StepItem(step=step_to_insert))
elif isinstance(item.parallel.root, schema.ParallelExpanded):
# Add to the expanded parallel steps
item.parallel.root.steps.root.append(
schema.StepItem(step=step_to_insert)
)
else:
assert_never(item.parallel.root)
if isinstance(item.parallel.root, schema.ParallelSteps):
# Add to the existing list of parallel steps
item.parallel.root.root.append(schema.StepItem(step=step_to_insert))
elif isinstance(item.parallel.root, schema.ParallelExpanded):
# Add to the expanded parallel steps
item.parallel.root.steps.root.append(schema.StepItem(step=step_to_insert))
else:
assert_never(item.parallel.root)
elif isinstance(item, schema.StageItem):
# StageItems are trickier since they aren't supported in ParallelSteps. But we
# never need to add them in practice anyway. The only reason this is really here
Expand All @@ -324,17 +319,16 @@ def _is_insertion_necessary(
if isinstance(item, schema.StepItem):
return get_pipeweld_step(item.step) == instruction.after
elif isinstance(item, schema.ParallelItem):
if item.parallel is not None:
if isinstance(item.parallel.root, schema.ParallelSteps):
step_items = item.parallel.root.root
elif isinstance(item.parallel.root, schema.ParallelExpanded):
step_items = item.parallel.root.steps.root
else:
assert_never(item.parallel.root)

for step_item in step_items:
if get_pipeweld_step(step_item.step) == instruction.after:
return True
if isinstance(item.parallel.root, schema.ParallelSteps):
step_items = item.parallel.root.root
elif isinstance(item.parallel.root, schema.ParallelExpanded):
step_items = item.parallel.root.steps.root
else:
assert_never(item.parallel.root)

for step_item in step_items:
if get_pipeweld_step(step_item.step) == instruction.after:
return True
return False
elif isinstance(item, schema.StageItem):
step1s = item.stage.steps.copy()
Expand Down
8 changes: 2 additions & 6 deletions src/usethis/_integrations/ci/bitbucket/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,14 +495,10 @@ def get_steps_in_pipeline_item(
else:
assert_never(_p)

steps = [
step_item.step for step_item in step_items if step_item.step is not None
]
steps = [step_item.step for step_item in step_items]
return steps
elif isinstance(item, schema.StageItem):
return [
step1tostep(step1) for step1 in item.stage.steps if step1.step is not None
]
return [step1tostep(step1) for step1 in item.stage.steps]
else:
assert_never(item)

Expand Down
Loading