Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from Dec 26, 2016

Conversation

@UK992
Copy link
Contributor

UK992 commented Dec 24, 2016

r? @wafflespeanut

cc @SimonSapin


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #14695
  • There are tests for these changes

This change is Reviewable

@highfive
Copy link

highfive commented Dec 24, 2016

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
norm_paths = []
for path in paths:
norm_paths += [os.path.join(*path.split('/'))]
return norm_paths

This comment has been minimized.

Copy link
@wafflespeanut

wafflespeanut Dec 25, 2016

Member

This could just be

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

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

This comment has been minimized.

Copy link
@wafflespeanut

wafflespeanut Dec 25, 2016

Member

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

@@ -360,6 +351,43 @@ def find_reverse_dependencies(dependency, version, content):
""".format(**substitutions).strip()
yield (1, message)

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

This comment has been minimized.

Copy link
@wafflespeanut

wafflespeanut Dec 25, 2016

Member

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.

# 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"]:

This comment has been minimized.

Copy link
@wafflespeanut

wafflespeanut Dec 25, 2016

Member

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"]):

This comment has been minimized.

Copy link
@wafflespeanut

wafflespeanut Dec 25, 2016

Member

Also, we probably need a test for this case.

@wafflespeanut
Copy link
Member

wafflespeanut commented Dec 25, 2016

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

@SimonSapin
Copy link
Member

SimonSapin commented Dec 25, 2016

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)
@SimonSapin
Copy link
Member

SimonSapin commented Dec 26, 2016

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

@UK992 UK992 force-pushed the UK992:tidy-check-lock branch from 675ca70 to b760578 Dec 26, 2016
@UK992
Copy link
Contributor Author

UK992 commented Dec 26, 2016

done!

@SimonSapin
Copy link
Member

SimonSapin commented Dec 26, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Dec 26, 2016

📌 Commit b760578 has been approved by SimonSapin

@bors-servo
Copy link
Contributor

bors-servo commented Dec 26, 2016

Testing commit b760578 with merge 37a5e29...

bors-servo added 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 bors-servo merged commit b760578 into servo:master Dec 26, 2016
3 checks passed
3 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
@UK992 UK992 deleted the UK992:tidy-check-lock branch Jan 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

5 participants
You can’t perform that action at this time.