Skip to content

Tidy: Check Cargo.lock for packages with same version and different sources - #14715

Merged
bors-servo merged 2 commits into
servo:masterfrom
UK992:tidy-check-lock
Dec 26, 2016
Merged

bors-servo merged 2 commits into
servo:masterfrom
UK992:tidy-check-lock

Conversation

@UK992

@UK992 UK992 commented Dec 24, 2016 •

Copy link
Copy Markdown
Contributor

r? @Wafflespeanut

cc @SimonSapin


  • There are tests for these changes

This change is Reviewable

@highfive highfive assigned ghost Dec 24, 2016
@highfive

Copy link
Copy Markdown

Heads up! This PR modifies the following files:

  • @wafflespeanut: python/requirements.txt, python/tidy/servo_tidy_tests/test_tidy.py, python/tidy/servo_tidy_tests/duplicated_package.lock, python/tidy/servo_tidy/tidy.py

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Dec 24, 2016
Comment thread python/tidy/servo_tidy/tidy.py Outdated
norm_paths = []
for path in paths:
norm_paths += [os.path.join(*path.split('/'))]
return norm_paths

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could just be

return [os.path.join(*path.split('/')) for path in paths]

Comment thread python/tidy/servo_tidy/tidy.py Outdated

highest = max(versions)
for version in versions:
highest = max(data["version"])

@ghost ghost Dec 25, 2016 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also add a similar comment here? That, it's for Packages with same names but different versions?

Comment thread python/tidy/servo_tidy/tidy.py Outdated
yield (1, message)

# Packages with same version from different sources
if (len(set(data["version"])) < len(data["version"])

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should have names for version and source, so that we don't have to address them as data["version"] and data["source"] everywhere.

Comment thread python/tidy/servo_tidy/tidy.py Outdated
# Set recommended source
if r"registry+https://github.com/rust-lang/crates.io-index" in data["source"]:
req_source = r"registry+https://github.com/rust-lang/crates.io-index"
elif "github.com/servo/" in data["source"]:

@ghost ghost Dec 25, 2016 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enlighten me. Do we have such a case in that list? This looks for an exact match of "github.com/servo/servo in the data["source"] list, no? Don't you think this should be something like,

elif any('github.com/servo/' in source for source in data["source"]):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, we probably need a test for this case.

@ghost

ghost commented Dec 25, 2016

Copy link
Copy Markdown

Just a few comments. Overall, the PR looks good. Thanks for doing this :)

@ghost ghost added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. and removed S-awaiting-review There is new code that needs to be reviewed. labels Dec 25, 2016
@SimonSapin

Copy link
Copy Markdown
Member

I’m sorry, the way I filed the issue was misleading. It should have been:

Check that Cargo.lock doesn’t contain duplicate crates (with the same name)

… because the algorithm should be no more complicated than this. Then, the issue could have said:

(By the way, the current algorithm almost works but only misses the case where duplicate packages have the same version number. This can happen for example when one is from crates.io while the other is from a git repository.)

I think the code should not care about what the version numbers or source are, except to include them in the error message.

In other words, I think the check_lock function after content = toml.loads(contents) should be something along the lines of: (code completely untested)

    packages_by_name = {}
    for package in content.get("package", []):
        source = package.get("source", "")
        if source == "registry+https://github.com/rust-lang/crates.io-index":
            source = "crates.io"
        packages_by_name.setdefault(package["name"], []).append((package["version"], source))

    for (name, packages) in packages_by_name.iteritems():
        if name in exceptions or len(packages) <= 1:
            continue

        message = "duplicate versions for package " + name
        packages.sort()
        for version, source in packages:
            message += "\n\tThe following packages depend on version {} from {}:" \
                       .format(version, source)
            for name in find_reverse_dependencies(name, version, content):
                message += "\n\t\t" + name
        yield (1, message)

@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels Dec 26, 2016
@SimonSapin

Copy link
Copy Markdown
Member

Looks good to me! r=me with the fixup commits squashed

@ghost ghost added S-needs-squash Some (or all) of the commits in the PR should be combined. and removed S-awaiting-review There is new code that needs to be reviewed. labels Dec 26, 2016
@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Dec 26, 2016
@UK992

UK992 commented Dec 26, 2016

Copy link
Copy Markdown
Contributor Author

done!

@SimonSapin

Copy link
Copy Markdown
Member

@bors-servo r+

@bors-servo

Copy link
Copy Markdown
Contributor

📌 Commit b760578 has been approved by SimonSapin

@highfive highfive assigned SimonSapin and unassigned ghost Dec 26, 2016
@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-awaiting-review There is new code that needs to be reviewed. S-needs-squash Some (or all) of the commits in the PR should be combined. labels Dec 26, 2016
@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Testing commit b760578 with merge 37a5e29...

bors-servo pushed a commit that referenced this pull request Dec 26, 2016
Tidy: Check Cargo.lock for packages with same version and different sources

<!-- Please describe your changes on the following line: -->
r? @Wafflespeanut

cc @SimonSapin

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #14695

<!-- Either: -->
- [X] There are tests for these changes
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/14715)
<!-- Reviewable:end -->
@bors-servo

Copy link
Copy Markdown
Contributor

@bors-servo
bors-servo merged commit b760578 into servo:master Dec 26, 2016
@highfive highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Dec 26, 2016
@UK992
UK992 deleted the tidy-check-lock branch January 26, 2017 23:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make tidy reject duplicate crates with same version number & different source

4 participants