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 can now check for version conflicts... #7438

Merged
merged 1 commit into from Sep 1, 2015
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Tidy could now check for version conflicts!

  • Loading branch information
wafflespeanut committed Sep 1, 2015
commit da1c8581d9d0fd133063ea5e39ce06d8abcc9218

Some generated files are not rendered by default. Learn more.

@@ -16,7 +16,7 @@
import sys
from licenseck import licenses

filetypes_to_check = [".rs", ".rc", ".cpp", ".c", ".h", ".py", ".toml", ".webidl"]
filetypes_to_check = [".rs", ".rc", ".cpp", ".c", ".h", ".lock", ".py", ".toml", ".webidl"]
reftest_dir = "./tests/ref"
reftest_filetype = ".list"
python_dependencies = [
@@ -70,7 +70,7 @@ def should_check_reftest(file_name):


def check_license(file_name, contents):
if file_name.endswith(".toml"):
if file_name.endswith(".toml") or file_name.endswith(".lock"):
raise StopIteration
while contents.startswith(EMACS_HEADER) or contents.startswith(VIM_HEADER):
_, _, contents = contents.partition("\n")
@@ -148,6 +148,46 @@ def stdout_redirect(where):
yield line_num, message.strip()


def check_lock(file_name, contents):
if not file_name.endswith(".lock"):
raise StopIteration
contents = contents.splitlines(True)
idx = 1
packages = {}
exceptions = ["glutin", "wayland-kbd"] # package names to be neglected (as named by cargo)

while idx < len(contents):
content = contents[idx].strip()
if 'name' in content:
base_name = content.split('"')[1]
# we need the base package because some other package might demand a new version in the following lines
packages[base_name] = contents[idx + 1].split('"')[1], idx + 2, base_name
if 'dependencies' in content:
idx += 1
while contents[idx].strip() != ']':
package = contents[idx].strip().strip('",').split()
name, version = package[0], package[1]
if name not in packages: # store the line number & base package name for future comparison
packages[name] = (version, idx + 1, base_name)
elif all([packages[name][0] != version, name not in exceptions, base_name not in exceptions]):
line = idx + 1
version_1 = tuple(map(int, packages[name][0].split('.')))
version_2 = tuple(map(int, version.split('.')))
if version_1 < version_2: # get the line & base package containing the older version
packages[name], (version, line, base_name) = (version, line, base_name), packages[name]

message = 'conflicting versions for package "%s"' % name
error = '\n\t\033[93mexpected maximum version "{}"\033[0m'.format(packages[name][0]) + \
'\n\t\033[91mbut, "{}" demands "{}"\033[0m' \
.format(base_name, version)
suggest = "\n\t\033[93mtry upgrading with\033[0m " + \
"\033[96m./mach cargo-update -p {}:{}\033[0m" \
.format(name, version)
yield (line, message + error + suggest)
idx += 1
idx += 1


def check_toml(file_name, contents):
if not file_name.endswith(".toml"):
raise StopIteration
@@ -390,7 +430,7 @@ def scan():
files_to_check = filter(should_check, all_files)

checking_functions = [check_license, check_by_line, check_flake8, check_toml,
check_rust, check_webidl_spec, check_spec]
check_lock, check_rust, check_webidl_spec, check_spec]
errors = collect_errors_for_files(files_to_check, checking_functions)

reftest_files = (os.path.join(r, f) for r, _, files in os.walk(reftest_dir) for f in files)
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.