#1 Use raw strings for all regexes.
Merged 10 months ago by eclipseo. Opened 10 months ago by qulogic.
GoSIG/ qulogic/go2rpm raw-re  into  master

file modified
+38 -19

@@ -52,42 +52,41 @@ 

      # lowercase and end with '/'

      goname = goipath.lower() + '/'

      # remove eventual protocol prefix

-     goname = re.sub("^http(s?)://", "", goname)

+     goname = re.sub(r"^http(s?)://", r"", goname)

      # remove eventual .git suffix

-     goname = re.sub("\.git/*", "", goname)

+     goname = re.sub(r"\.git/*", r"", goname)

      # remove eventual git. prefix

-     goname = re.sub("^git\.", "", goname)

+     goname = re.sub(r"^git\.", r"", goname)

      # remove FQDN root (.com, .org, etc)

      # will also remove vanity FQDNs such as "tools"

-     goname = re.sub("^([^/]+)\.([^\./]+)/", "\g<1>/", goname)

+     goname = re.sub(r"^([^/]+)\.([^\./]+)/", r"\g<1>/", goname)

      # add golang prefix

      goname = "golang-" + goname

      # special-case x.y.z number-strings as that’s an exception in our naming

      # guidelines

-     while re.search("(\d)\.(\d)", goname):

-         goname = re.sub("(\d)\.(\d)", "\g<1>:\g<2>", goname)

+     while re.search(r"(\d)\.(\d)", goname):

+         goname = re.sub(r"(\d)\.(\d)", r"\g<1>:\g<2>", goname)

      # replace various separators rpm does not like with -

-     goname = re.sub("[\._/\-]+", "-", goname)

+     goname = re.sub(r"[\._/\-]+", r"-", goname)

      # because of the Azure sdk

-     goname = re.sub("\-for\-go\-", "-", goname)

+     goname = re.sub(r"\-for\-go\-", r"-", goname)

      # Tokenize along - separators and remove duplicates to avoid

      # golang-foo-foo-bar-foo names

      result = ""

      tokens = {}

      tokens["go"] = True

-     pattern = re.compile("[^\-]+")

      for token in goname.split('-'):

          if token not in tokens:

              result = result + "-" + token

              tokens[token] = True

      # reassemble the string, restore x.y.z runs, convert the vx.y.z

      # Go convention to x.y.z as prefered in rpm naming

-     result = re.sub("^-", "", result)

-     result = re.sub("-$", "", result)

-     result = re.sub(":", ".", result)

+     result = re.sub(r"^-", r"", result)

+     result = re.sub(r"-$", r"", result)

+     result = re.sub(r":", r".", result)

      # some projects have a name that end up in a number, and *also* add release

      # numbers on top of it, keep a - prefix before version strings

-     result = re.sub("\-v([\.\d])", "-\g<1>", result)

+     result = re.sub(r"\-v([\.\d])", r"-\g<1>", result)

      return result

  

  

@@ -131,7 +130,15 @@ 

      license_files = []

      path = os.path.join(GIT_CACHEDIR, *get_repo_name(goipath))

      exclude = set(['vendor', 'example', 'examples', 'internal', 'Godeps', 'testdata', '_testdata', '.github'])

-     matcher = re.compile("(COPYING|COPYING[\.\-].*|COPYRIGHT|COPYRIGHT[\.\-].*|EULA|EULA[\.\-].*|licen[cs]e|licen[cs]e.*|LICEN[CS]E|LICEN[CS]E[\.\-].*|.*[\.\-]LICEN[CS]E.*|NOTICE|NOTICE[\.\-].*|PATENTS|PATENTS[\.\-].*|UNLICEN[CS]E|UNLICEN[CS]E[\.\-].*|agpl[\.\-].*|gpl[\.\-].*|lgpl[\.\-].*|AGPL-.*[0-9].*|APACHE-.*[0-9].*|BSD-.*[0-9].*|CC-BY-.*|GFDL-.*[0-9].*|GNU-.*[0-9].*|GPL-.*[0-9].*|LGPL-.*[0-9].*|MIT-.*[0-9].*|MPL-.*[0-9].*|OFL-.*[0-9].*)")

+     matcher = re.compile(

+         r"(COPYING|COPYING[\.\-].*|COPYRIGHT|COPYRIGHT[\.\-].*|"

+         r"EULA|EULA[\.\-].*|licen[cs]e|licen[cs]e.*|LICEN[CS]E|"

+         r"LICEN[CS]E[\.\-].*|.*[\.\-]LICEN[CS]E.*|NOTICE|NOTICE[\.\-].*|"

+         r"PATENTS|PATENTS[\.\-].*|UNLICEN[CS]E|UNLICEN[CS]E[\.\-].*|"

+         r"agpl[\.\-].*|gpl[\.\-].*|lgpl[\.\-].*|AGPL-.*[0-9].*|"

+         r"APACHE-.*[0-9].*|BSD-.*[0-9].*|CC-BY-.*|GFDL-.*[0-9].*|"

+         r"GNU-.*[0-9].*|GPL-.*[0-9].*|LGPL-.*[0-9].*|MIT-.*[0-9].*|"

+         r"MPL-.*[0-9].*|OFL-.*[0-9].*)")

      for root, dirs, files in os.walk(path, topdown=True):

          dirs[:] = [d for d in dirs if d not in exclude]

          for f in files:

@@ -144,8 +151,19 @@ 

      doc_files = []

      path = os.path.join(GIT_CACHEDIR, *get_repo_name(goipath))

      exclude = set(['vendor', 'example', 'examples', 'internal', 'Godeps', 'testdata', '_testdata', '.github'])

-     matcher = re.compile("(.*\.md|.*\.markdown|.*\.mdown|.*\.mkdn|.*\.rst|.*\.txt|AUTHORS|AUTHORS[\.\-].*|CONTRIBUTORS|CONTRIBUTORS[\.\-].*|README|README[\.\-].*|CHANGELOG|CHANGELOG[\.\-].*|TODO|TODO[\.\-].*)", re.IGNORECASE)

-     licensesex = re.compile("(COPYING|COPYING[\.\-].*|COPYRIGHT|COPYRIGHT[\.\-].*|EULA|EULA[\.\-].*|licen[cs]e|licen[cs]e.*|LICEN[CS]E|LICEN[CS]E[\.\-].*|.*[\.\-]LICEN[CS]E.*|NOTICE|NOTICE[\.\-].*|PATENTS|PATENTS[\.\-].*|UNLICEN[CS]E|UNLICEN[CS]E[\.\-].*|agpl[\.\-].*|gpl[\.\-].*|lgpl[\.\-].*|AGPL-.*[0-9].*|APACHE-.*[0-9].*|BSD-.*[0-9].*|CC-BY-.*|GFDL-.*[0-9].*|GNU-.*[0-9].*|GPL-.*[0-9].*|LGPL-.*[0-9].*|MIT-.*[0-9].*|MPL-.*[0-9].*|OFL-.*[0-9].*)")

+     matcher = re.compile(

+         r"(.*\.md|.*\.markdown|.*\.mdown|.*\.mkdn|.*\.rst|.*\.txt|AUTHORS|"

+         r"AUTHORS[\.\-].*|CONTRIBUTORS|CONTRIBUTORS[\.\-].*|README|"

+         r"README[\.\-].*|CHANGELOG|CHANGELOG[\.\-].*|TODO|TODO[\.\-].*)",

+         re.IGNORECASE)

+     licensesex = re.compile(

+         r"(COPYING|COPYING[\.\-].*|COPYRIGHT|COPYRIGHT[\.\-].*|EULA|"

+         r"EULA[\.\-].*|licen[cs]e|licen[cs]e.*|LICEN[CS]E|LICEN[CS]E[\.\-].*|"

+         r".*[\.\-]LICEN[CS]E.*|NOTICE|NOTICE[\.\-].*|PATENTS|PATENTS[\.\-].*|"

+         r"UNLICEN[CS]E|UNLICEN[CS]E[\.\-].*|agpl[\.\-].*|gpl[\.\-].*|"

+         r"lgpl[\.\-].*|AGPL-.*[0-9].*|APACHE-.*[0-9].*|BSD-.*[0-9].*|CC-BY-.*|"

+         r"GFDL-.*[0-9].*|GNU-.*[0-9].*|GPL-.*[0-9].*|LGPL-.*[0-9].*|"

+         r"MIT-.*[0-9].*|MPL-.*[0-9].*|OFL-.*[0-9].*)")

      for root, dirs, files in os.walk(path, topdown=True):

          dirs[:] = [d for d in dirs if d not in exclude]

          for f in files:

@@ -194,7 +212,7 @@ 

          description = description.capitalize()

      else:

          return None

-     if not re.search("(\.|!)$", description):

+     if not re.search(r"(\.|!)$", description):

          description = description + "."

      return description

  

@@ -348,10 +366,11 @@ 

      if args.goipath is None:

          parser.error("required import path argument missing")

      else:

-         goipath = re.sub("^http(s?)://", "", args.goipath)

+         goipath = re.sub(r"^http(s?)://", r"", args.goipath)

          goipath = goipath.strip('/')

  

-     if not re.search("^(github.com|gitlab.com|bitbucket.org)", goipath) and args.forge is None:

+     if (not re.search(r"^(github.com|gitlab.com|bitbucket.org)", goipath)

+             and args.forge is None):

          parser.error("forge URL is required for import path other than github, gitlab and bitbucket")

  

      if args.forge is None:

These invalid escape sequences will break with Python 3.8.

Pull-Request has been merged by eclipseo

10 months ago
Metadata