[neon-notifications] Changes in repo-metadata
Neon CI
noreply at kde.org
Mon Jun 17 19:46:48 BST 2024
commit c7a9cca38d719a39778b85ed625128d7bff727f0
Author: Andrew Shark <ashark at linuxcomp.ru>
Date: Mon Jun 17 19:00:03 2024 +0300
Reformat verify script to pep 8
Also, fix some typos and remove dependency on regex (use re).
diff --git a/requirements.txt b/requirements.txt
index d7b66b1c..c8c677fe 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,3 +1,2 @@
pydantic
pyyaml
-regex
diff --git a/verify-repo-metadata.py b/verify-repo-metadata.py
index 3b8159ac..9bbc6e7a 100755
--- a/verify-repo-metadata.py
+++ b/verify-repo-metadata.py
@@ -1,77 +1,78 @@
#!/usr/bin/env python3
+
+import argparse
import os
+import re
import sys
-import argparse
-import regex
+
import yaml
# Gather the command line arguments we need
-parser = argparse.ArgumentParser(description='Verifies the metadata files')
-parser.add_argument('--metadata-path', help='Path to the metadata to check', required=True)
+parser = argparse.ArgumentParser(description="Verifies the metadata files")
+parser.add_argument("--metadata-path", help="Path to the metadata to check", required=True)
args = parser.parse_args()
# Make sure our configuration file exists
-if not os.path.exists( args.metadata_path ):
+if not os.path.exists(args.metadata_path):
print(f"Unable to locate specified metadata location: {args.metadata_path}")
sys.exit(1)
-# Regular expression used to validate project names
-# Taken from Gitlab itself (with slight adaptation to be Python compatible)
-projectRegex = regex.compile(r'^[\p{Alnum}\u00A9-\u1f9ff_][\p{Alnum}\p{Pd}\u00A9-\u1f9ff_\. ]*$', flags=regex.V1)
+# Regular expression used to validate project names that are valid for Gitlab itself
+gitlab_project_name_regex = re.compile(r"^[\w\u00A9-\u1f9ff_][\w\-\u00A9-\u1f9ff_. ]*$", flags=re.UNICODE)
# Start a list of used project identifiers and names
-projectIdentifiersInUse = []
-projectNamesInUse = []
+project_identifiers_in_use = []
+project_names_in_use = []
# Start going over the location in question...
-for currentPath, subdirectories, filesInFolder in os.walk( args.metadata_path, topdown=False, followlinks=False ):
+for current_path, subdirectories, files_in_folder in os.walk(args.metadata_path, topdown=False, followlinks=False):
# Do we have a metadata.yaml file?
- if 'metadata.yaml' not in filesInFolder:
+ if "metadata.yaml" not in files_in_folder:
# We're not interested then....
continue
# Now that we know we have something to work with....
- # Lets load the current metadata up
- metadataPath = os.path.join( currentPath, 'metadata.yaml' )
- with open( metadataPath, 'r', encoding="utf-8" ) as metadataFile:
- metadata = yaml.safe_load( metadataFile )
+ # Let's load the current metadata up
+ metadata_path = os.path.join(current_path, "metadata.yaml")
+ with open(metadata_path, "r", encoding="utf-8") as metadataFile:
+ metadata = yaml.safe_load(metadataFile)
# Trim the base path to the metadata off to make it a bit nicer to read
- currentLocation = currentPath[len(args.metadata_path):]
+ current_location = current_path[len(args.metadata_path):]
- # check sanity of the description and make sure that it is less then 250
+ # check sanity of the description and make sure that it is less than 250
# (part of gitlab restriction)
- if metadata['description'] is not None and len(metadata['description']) > 250:
- print(currentLocation + ": Project description is longer than 250 characters")
+ if metadata["description"] is not None and len(metadata["description"]) > 250:
+ print(current_location + ": Project description is longer than 250 characters")
# check the description and ensure that it is not empty
# currently warning, but still best to list it out
- if metadata['description'] is not None and len(metadata['description']) == 0:
- print(currentLocation + ": Project description is empty")
+ if metadata["description"] is not None and len(metadata["description"]) == 0:
+ print(current_location + ": Project description is empty")
# Check if name have supported characters only
- if projectRegex.match(metadata['name']) is None:
- print(currentLocation + ": Project name contains characters not allowed by Gitlab - " + metadata['name'])
+ if gitlab_project_name_regex.match(metadata["name"]) is None:
+ print(current_location + ": Project name contains characters not allowed by Gitlab - " + metadata["name"])
# Make sure the name is not already in use
- if metadata['name'] in projectNamesInUse:
- print(currentLocation + ": Project name is already in use - " + metadata['name'])
+ if metadata["name"] in project_names_in_use:
+ print(current_location + ": Project name is already in use - " + metadata["name"])
# Make sure that identifier is not empty
- identifier = metadata.get('identifier')
+ identifier = metadata.get("identifier")
if identifier is None:
- print(currentLocation + ": CRITICAL ERROR - Project identifier is not set")
+ print(current_location + ": CRITICAL ERROR - Project identifier is not set")
sys.exit(1)
# Make sure the identifier is not in use already
- if identifier in projectIdentifiersInUse:
- print(currentLocation + ": CRITICAL ERROR - Project identifier is already in use - " + metadata['identifier'])
+ if identifier in project_identifiers_in_use:
+ print(current_location + ": CRITICAL ERROR - Project identifier is already in use - " + metadata["identifier"])
sys.exit(1)
# All checks done for this project
# Add it to the list of identifiers and names in use
- projectNamesInUse.append( metadata['name'] )
- projectIdentifiersInUse.append( identifier )
+ project_names_in_use.append(metadata["name"])
+ project_identifiers_in_use.append(identifier)
# All done!
sys.exit(0)
More information about the neon-notifications
mailing list