Skip to content

Commit

Permalink
Update version identifier regex
Browse files Browse the repository at this point in the history
  • Loading branch information
amazimbe committed Sep 19, 2024
1 parent a4fae36 commit 49a1514
Showing 1 changed file with 32 additions and 40 deletions.
72 changes: 32 additions & 40 deletions python/lib/dependabot/python/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,50 +16,42 @@ class Version < Dependabot::Version
attr_reader :post_release_version

# See https://peps.python.org/pep-0440/#appendix-b-parsing-version-strings-with-regular-expressions
# VERSION_PATTERN = 'v?([1-9][0-9]*!)?[0-9]+[0-9a-zA-Z]*(?>\.[0-9a-zA-Z]+)*' \
# '(-[0-9A-Za-z]+(\.[0-9a-zA-Z]+)*)?' \
# '(\+[0-9a-zA-Z]+(\.[0-9a-zA-Z]+)*)?'

VERSION_PATTERN = %r{(?:\+(?(<local>[a-z0-9])+(?:[-_\.]([a-z0-9])+)*))? # local version}x

# VERSION_PATTERN = <<~TEXT
# v?
# # (?:
# # (?:(?P<epoch>[0-9]+)!)? # epoch
# # (?P<release>[0-9]+(?:\.[0-9]+)*) # release segment
# # (?P<pre> # pre-release
# # [-_\.]?
# # (?P<pre_l>alpha|a|beta|b|preview|pre|c|rc)
# # [-_\.]?
# # (?P<pre_n>[0-9]+)?
# # )?
# # (?P<post> # post release
# # (?:-(?P<post_n1>[0-9]+))
# # |
# # (?:
# # [-_\.]?
# # (?P<post_l>post|rev|r)
# # [-_\.]?
# # (?P<post_n2>[0-9]+)?
# # )
# # )?
# # (?P<dev> # dev release
# # [-_\.]?
# # (?P<dev_l>dev)
# # [-_\.]?
# # (?P<dev_n>[0-9]+)?
# # )?
# # )
# (?:\+(?P<local>[a-z0-9]+(?:[-_\.][a-z0-9]+)*))? # local version
# TEXT

# ANCHORED_VERSION_PATTERN = /\A\s*(#{VERSION_PATTERN})?\s*\z/
ANCHORED_VERSION_PATTERN = /#{VERSION_PATTERN}/
VERSION_PATTERN = /
v?
(?:
(?:(?<epoch>[0-9]+)!)? # epoch
(?<release>[0-9]+(?:\.[0-9]+)*) # release
(?<pre> # prerelease
[-_\.]?
(?<pre_l>(a|b|c|rc|alpha|beta|pre|preview))
[-_\.]?
(?<pre_n>[0-9]+)?
)?
(?<post> # post release
(?:-(?<post_n1>[0-9]+))
|
(?:
[-_\.]?
(?<post_l>post|rev|r)
[-_\.]?
(?<post_n2>[0-9]+)?
)
)?
(?<dev> # dev release
[-_\.]?
(?<dev_l>dev)
[-_\.]?
(?<dev_n>[0-9]+)?
)?
)
(?:\+(?<local>[a-z0-9]+(?:[-_\.][a-z0-9]+)*))? # local version
/ix

ANCHORED_VERSION_PATTERN = /\A\s*#{VERSION_PATTERN}\s*\z/

def self.correct?(version)
return false if version.nil?

debugger
version.to_s.match?(ANCHORED_VERSION_PATTERN)
end

Expand Down

0 comments on commit 49a1514

Please sign in to comment.