mirror of
https://github.com/f-droid/fdroidserver.git
synced 2025-11-11 17:50:29 +03:00
Merge branch 'yamllint' into 'master'
yamllint See merge request fdroid/fdroidserver!721
This commit is contained in:
commit
410901d3bd
7 changed files with 150 additions and 18 deletions
|
|
@ -63,7 +63,7 @@ import fdroidserver.metadata
|
|||
import fdroidserver.lint
|
||||
from fdroidserver import _
|
||||
from fdroidserver.exception import FDroidException, VCSException, NoSubmodulesException,\
|
||||
BuildException, VerificationException
|
||||
BuildException, VerificationException, MetaDataException
|
||||
from .asynchronousfilereader import AsynchronousFileReader
|
||||
|
||||
# The path to this fdroidserver distribution
|
||||
|
|
@ -1809,6 +1809,36 @@ def get_app_from_url(url):
|
|||
return app
|
||||
|
||||
|
||||
def parse_srclib_spec(spec):
|
||||
|
||||
if type(spec) != str:
|
||||
raise MetaDataException(_("can not parse scrlib spec "
|
||||
"(not a string): '{}'")
|
||||
.format(spec))
|
||||
|
||||
tokens = spec.split('@')
|
||||
if len(tokens) > 2:
|
||||
raise MetaDataException(_("could not parse srclib spec "
|
||||
"(too many '@' signs): '{}'")
|
||||
.format(spec))
|
||||
elif len(tokens) < 2:
|
||||
raise MetaDataException(_("could not parse srclib spec "
|
||||
"(no ref specified): '{}'")
|
||||
.format(spec))
|
||||
|
||||
name = tokens[0]
|
||||
ref = tokens[1]
|
||||
number = None
|
||||
subdir = None
|
||||
|
||||
if ':' in name:
|
||||
number, name = name.split(':', 1)
|
||||
if '/' in name:
|
||||
name, subdir = name.split('/', 1)
|
||||
|
||||
return (name, ref, number, subdir)
|
||||
|
||||
|
||||
def getsrclib(spec, srclib_dir, subdir=None, basepath=False,
|
||||
raw=False, prepare=True, preponly=False, refresh=True,
|
||||
build=None):
|
||||
|
|
@ -3735,3 +3765,25 @@ def force_exit(exitvalue=0):
|
|||
sys.stdout.flush()
|
||||
sys.stderr.flush()
|
||||
os._exit(exitvalue)
|
||||
|
||||
|
||||
YAML_LINT_CONFIG = {'extends': 'default',
|
||||
'rules': {'document-start': 'disable',
|
||||
'line-length': 'disable',
|
||||
'truthy': 'disable'}}
|
||||
|
||||
|
||||
def run_yamllint(path, indent=0):
|
||||
|
||||
try:
|
||||
import yamllint.config
|
||||
import yamllint.linter
|
||||
except ImportError:
|
||||
return ''
|
||||
|
||||
result = []
|
||||
with open(path, 'r', encoding='utf-8') as f:
|
||||
problems = yamllint.linter.run(f, yamllint.config.YamlLintConfig(json.dumps(YAML_LINT_CONFIG)))
|
||||
for problem in problems:
|
||||
result.append(' ' * indent + path + ':' + str(problem.line) + ': ' + problem.message)
|
||||
return '\n'.join(result)
|
||||
|
|
|
|||
|
|
@ -574,6 +574,9 @@ def main():
|
|||
common.setup_global_opts(parser)
|
||||
parser.add_argument("-f", "--format", action="store_true", default=False,
|
||||
help=_("Also warn about formatting issues, like rewritemeta -l"))
|
||||
parser.add_argument('--force-yamllint', action="store_true", default=False,
|
||||
help=_("When linting the entire repository yamllint is disabled by default. "
|
||||
"This option forces yamllint regardless."))
|
||||
parser.add_argument("appid", nargs='*', help=_("applicationId in the form APPID"))
|
||||
metadata.add_metadata_arguments(parser)
|
||||
options = parser.parse_args()
|
||||
|
|
@ -600,6 +603,29 @@ def main():
|
|||
if app.Disabled:
|
||||
continue
|
||||
|
||||
# only run yamllint when linting individual apps.
|
||||
if len(options.appid) > 0 or options.force_yamllint:
|
||||
|
||||
# run yamllint on app metadata
|
||||
ymlpath = os.path.join('metadata', appid + '.yml')
|
||||
if os.path.isfile(ymlpath):
|
||||
yamllintresult = common.run_yamllint(ymlpath)
|
||||
if yamllintresult != '':
|
||||
print(yamllintresult)
|
||||
|
||||
# run yamllint on srclib metadata
|
||||
srclibs = set()
|
||||
for build in app.builds:
|
||||
for srclib in build.srclibs:
|
||||
srclibs.add(srclib)
|
||||
for srclib in srclibs:
|
||||
name, ref, number, subdir = common.parse_srclib_spec(srclib)
|
||||
srclibpath = os.path.join('srclibs', name + '.yml')
|
||||
if os.path.isfile(srclibpath):
|
||||
yamllintresult = common.run_yamllint(srclibpath)
|
||||
if yamllintresult != '':
|
||||
print(yamllintresult)
|
||||
|
||||
app_check_funcs = [
|
||||
check_app_field_types,
|
||||
check_regexes,
|
||||
|
|
|
|||
|
|
@ -747,7 +747,7 @@ def parse_txt_srclib(metadatapath):
|
|||
return thisinfo
|
||||
|
||||
|
||||
def parse_yml_srclib(metadatapath):
|
||||
def parse_yaml_srclib(metadatapath):
|
||||
|
||||
thisinfo = {'RepoType': '',
|
||||
'Repo': '',
|
||||
|
|
@ -765,9 +765,11 @@ def parse_yml_srclib(metadatapath):
|
|||
data = yaml.load(f, Loader=SafeLoader)
|
||||
except yaml.error.YAMLError as e:
|
||||
warn_or_exception(_("Invalid srclib metadata: could not "
|
||||
"parse '{file}'"
|
||||
.format(file=metadatapath)),
|
||||
e)
|
||||
"parse '{file}'")
|
||||
.format(file=metadatapath) + '\n'
|
||||
+ fdroidserver.common.run_yamllint(metadatapath,
|
||||
indent=4),
|
||||
cause=e)
|
||||
return thisinfo
|
||||
|
||||
for key in data.keys():
|
||||
|
|
@ -820,7 +822,7 @@ def read_srclibs():
|
|||
|
||||
for metadatapath in sorted(glob.glob(os.path.join(srcdir, '*.yml'))):
|
||||
srclibname = os.path.basename(metadatapath[:-4])
|
||||
srclibs[srclibname] = parse_yml_srclib(metadatapath)
|
||||
srclibs[srclibname] = parse_yaml_srclib(metadatapath)
|
||||
|
||||
|
||||
def read_metadata(xref=True, check_vcs=[], refresh=True, sort_by_time=False):
|
||||
|
|
@ -1102,7 +1104,14 @@ def parse_json_metadata(mf, app):
|
|||
|
||||
|
||||
def parse_yaml_metadata(mf, app):
|
||||
yamldata = yaml.load(mf, Loader=SafeLoader)
|
||||
try:
|
||||
yamldata = yaml.load(mf, Loader=SafeLoader)
|
||||
except yaml.YAMLError as e:
|
||||
warn_or_exception(_("could not parse '{path}'")
|
||||
.format(path=mf.name) + '\n'
|
||||
+ fdroidserver.common.run_yamllint(mf.name,
|
||||
indent=4),
|
||||
cause=e)
|
||||
|
||||
deprecated_in_yaml = ['Provides']
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue