<commit_before># Copyright 2019 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the 'License');
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#            http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an 'AS IS' BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""
This is a utility module which defines and parses the command-line arguments
for the generate_custom_image.py script.
"""

import argparse
import json
import re

import constants


# Old style images: 1.2.3
# New style images: 1.2.3-deb8, 1.2.3-debian9, 1.2.3-RC10-debian9
_VERSION_REGEX = re.compile(r"^\d+\.\d+\.\d+(-RC\d+)?(-[a-z]+\d+)?$")
_FULL_IMAGE_URI = re.compile(r"^(https://www\.googleapis\.com/compute/([^/]+)/)?projects/([^/]+)/global/images/([^/]+)$")


def _version_regex_type(s):
  """Check if version string matches regex."""
  if not _VERSION_REGEX.match(s):
    raise argparse.ArgumentTypeError("Invalid version: {}.".format(s))
  return s

def _full_image_uri_regex_type(s):
  """Check if the partial image uri string matches regex."""
  if not _FULL_IMAGE_URI.match(s):
    raise argparse.ArgumentTypeError("Invalid image URI: {}.".format(s))
  return s

def parse_args(args):
  """Parses command-line arguments."""
  parser = argparse.ArgumentParser()
  required_args = parser.add_argument_group("required named arguments")
  required_args.add_argument(<commit_msg>Fix import of constants module (#38)<commit_after># Copyright 2019 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the 'License');
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#            http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an 'AS IS' BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""
This is a utility module which defines and parses the command-line arguments
for the generate_custom_image.py script.
"""

import argparse
import json
import re

from custom_image_utils import constants


# Old style images: 1.2.3
# New style images: 1.2.3-deb8, 1.2.3-debian9, 1.2.3-RC10-debian9
_VERSION_REGEX = re.compile(r"^\d+\.\d+\.\d+(-RC\d+)?(-[a-z]+\d+)?$")
_FULL_IMAGE_URI = re.compile(r"^(https://www\.googleapis\.com/compute/([^/]+)/)?projects/([^/]+)/global/images/([^/]+)$")


def _version_regex_type(s):
  """Check if version string matches regex."""
  if not _VERSION_REGEX.match(s):
    raise argparse.ArgumentTypeError("Invalid version: {}.".format(s))
  return s

def _full_image_uri_regex_type(s):
  """Check if the partial image uri string matches regex."""
  if not _FULL_IMAGE_URI.match(s):
    raise argparse.ArgumentTypeError("Invalid image URI: {}.".format(s))
  return s

def parse_args(args):
  """Parses command-line arguments."""
  parser = argparse.ArgumentParser()
  required_args = parser.add_argument_group("required named arguments")
  required_args.add_argument(
{'fraction_non_alphanumeric': 0.13015873015873017, 'fraction_numerical': 0.015007215007215007, 'mean_word_length': 4.432601880877743, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7568042', 'n_tokens_mistral': 1090, 'n_tokens_neox': 1041, 'n_words': 354}