Skip to content

Commit

Permalink
Add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
boehmseb committed Mar 18, 2024
1 parent 6a41774 commit 8b9f3e0
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions varats/varats/tools/driver_feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@


class Location:
"""A location in a source code file."""

LOCATION_FORMAT = re.compile(
r"(?P<file>[\w.]+)\s"
r"(?P<start_line>\d+):(?P<start_col>\d+)\s"
Expand All @@ -40,6 +42,7 @@ def parse_string(
s: str,
old_location: tp.Optional["Location"] = None
) -> tp.Optional["Location"]:
"""Create a location from a string."""
if old_location is not None and s.isnumeric():
new_line = int(s)
return Location(
Expand All @@ -61,6 +64,7 @@ def parse_string(
)

def to_xml(self) -> str:
"""Convert the location to SPLConqueror feature model format."""
xml = f"<path>{self.file}</path>\n"
xml += f"<start><line>{self.start_line}</line><column>{self.start_col}</column></start>\n"

Check failure on line 69 in varats/varats/tools/driver_feature.py

View workflow job for this annotation

GitHub Actions / pylint

[pylint] varats/varats/tools/driver_feature.py#L69 <301>

Line too long (98/80) (line-too-long)
Raw output
varats/varats/tools/driver_feature.py:69:0: C0301: Line too long (98/80) (line-too-long)
xml += f"<end><line>{self.end_line}</line><column>{self.end_col}</column></end>\n"

Check failure on line 70 in varats/varats/tools/driver_feature.py

View workflow job for this annotation

GitHub Actions / pylint

[pylint] varats/varats/tools/driver_feature.py#L70 <301>

Line too long (90/80) (line-too-long)
Raw output
varats/varats/tools/driver_feature.py:70:0: C0301: Line too long (90/80) (line-too-long)
Expand All @@ -71,6 +75,7 @@ def __str__(self) -> str:


class FeatureAnnotation:
"""A versioned feature source annotation."""

def __init__(
self,
Expand All @@ -85,6 +90,7 @@ def __init__(
self.removed = removed

def to_xml(self) -> str:
"""Convert the annotation to SPLConqueror feature model format."""
xml = "<sourceRange>\n"
xml += " <revisionRange>\n"
xml += f" <introduced>{self.introduced.hash}</introduced>\n"
Expand All @@ -97,7 +103,7 @@ def to_xml(self) -> str:
return xml


def prompt_location(
def __prompt_location(
feature_name: str,
commit_hash: FullCommitHash,
old_location: tp.Optional[Location] = None
Expand All @@ -116,8 +122,8 @@ def prompt_location(
)


def get_location_content(commit: Commit,
location: Location) -> tp.Optional[str]:
def __get_location_content(commit: Commit,
location: Location) -> tp.Optional[str]:
assert location.start_line == location.end_line, \
"Multiline locations are not supported yet."
lines = tp.cast(Blob, commit.tree[location.file]).data.splitlines()
Expand Down Expand Up @@ -177,11 +183,11 @@ def __annotate(
while click.confirm("Annotate another feature?"):
feature_name = click.prompt("Enter feature name to annotate", type=str)
commit_hash = FullCommitHash(str(first_commit.id))
location = prompt_location(feature_name, commit_hash)
location = __prompt_location(feature_name, commit_hash)
last_annotations[feature_name] = FeatureAnnotation(
feature_name, location, commit_hash

Check failure on line 188 in varats/varats/tools/driver_feature.py

View workflow job for this annotation

GitHub Actions / mypy

[mypy] varats/varats/tools/driver_feature.py#L188

error: Argument 2 to "FeatureAnnotation" has incompatible type "Optional[Location]"; expected "Location" [arg-type]
Raw output
varats/varats/tools/driver_feature.py:188:27: error: Argument 2 to "FeatureAnnotation" has incompatible type "Optional[Location]"; expected "Location"  [arg-type]
)
last_annotation_targets[feature_name] = get_location_content(
last_annotation_targets[feature_name] = __get_location_content(

Check failure on line 190 in varats/varats/tools/driver_feature.py

View workflow job for this annotation

GitHub Actions / mypy

[mypy] varats/varats/tools/driver_feature.py#L190

error: Incompatible types in assignment (expression has type "Optional[str]", target has type "str") [assignment]
Raw output
varats/varats/tools/driver_feature.py:190:49: error: Incompatible types in assignment (expression has type "Optional[str]", target has type "str")  [assignment]
first_commit, location

Check failure on line 191 in varats/varats/tools/driver_feature.py

View workflow job for this annotation

GitHub Actions / mypy

[mypy] varats/varats/tools/driver_feature.py#L191

error: Argument 2 to "__get_location_content" has incompatible type "Optional[Location]"; expected "Location" [arg-type]
Raw output
varats/varats/tools/driver_feature.py:191:27: error: Argument 2 to "__get_location_content" has incompatible type "Optional[Location]"; expected "Location"  [arg-type]
)
tracked_features[feature_name] = []
Expand All @@ -194,7 +200,7 @@ def __annotate(
click.echo(f"Current revision: {commit_hash.hash}")

for feature, annotation in last_annotations.items():
current_target = get_location_content(commit, annotation.location)
current_target = __get_location_content(commit, annotation.location)
if current_target != last_annotation_targets[feature]:
LOG.debug(
f"{feature}: {current_target} != {last_annotation_targets[feature]}"

Check failure on line 206 in varats/varats/tools/driver_feature.py

View workflow job for this annotation

GitHub Actions / pylint

[pylint] varats/varats/tools/driver_feature.py#L206 <301>

Line too long (88/80) (line-too-long)
Raw output
varats/varats/tools/driver_feature.py:206:0: C0301: Line too long (88/80) (line-too-long)
Expand All @@ -209,13 +215,13 @@ def __annotate(

# track new feature location
click.echo(f"Location of feature {feature} has changed.")
new_location = prompt_location(
new_location = __prompt_location(
feature, commit_hash, annotation.location
)
last_annotations[feature] = FeatureAnnotation(
feature, new_location, commit_hash

Check failure on line 222 in varats/varats/tools/driver_feature.py

View workflow job for this annotation

GitHub Actions / mypy

[mypy] varats/varats/tools/driver_feature.py#L222

error: Argument 2 to "FeatureAnnotation" has incompatible type "Optional[Location]"; expected "Location" [arg-type]
Raw output
varats/varats/tools/driver_feature.py:222:30: error: Argument 2 to "FeatureAnnotation" has incompatible type "Optional[Location]"; expected "Location"  [arg-type]
)
last_annotation_targets[feature] = get_location_content(
last_annotation_targets[feature] = __get_location_content(

Check failure on line 224 in varats/varats/tools/driver_feature.py

View workflow job for this annotation

GitHub Actions / mypy

[mypy] varats/varats/tools/driver_feature.py#L224

error: Incompatible types in assignment (expression has type "Optional[str]", target has type "str") [assignment]
Raw output
varats/varats/tools/driver_feature.py:224:52: error: Incompatible types in assignment (expression has type "Optional[str]", target has type "str")  [assignment]
commit, new_location

Check failure on line 225 in varats/varats/tools/driver_feature.py

View workflow job for this annotation

GitHub Actions / mypy

[mypy] varats/varats/tools/driver_feature.py#L225

error: Argument 2 to "__get_location_content" has incompatible type "Optional[Location]"; expected "Location" [arg-type]
Raw output
varats/varats/tools/driver_feature.py:225:29: error: Argument 2 to "__get_location_content" has incompatible type "Optional[Location]"; expected "Location"  [arg-type]
)
LOG.debug(
Expand Down

0 comments on commit 8b9f3e0

Please sign in to comment.