forked from sonic-net/sonic-buildimage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[sonic-package-manager] remove make_python_identifier (sonic-net#1801)
#### What I did It is not needed to make a CLI plugin name with valid python identifier. It is also possible that make_python_identifier will return same filename for two different packages. #### How I did it Removed make_python_identifier. #### How to verify it Install package with CLI plugin.
- Loading branch information
1 parent
f738818
commit 6412fea
Showing
3 changed files
with
32 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,5 @@ | ||
#!/usr/bin/env python | ||
|
||
import keyword | ||
import re | ||
|
||
from docker_image.reference import Reference | ||
|
||
DockerReference = Reference | ||
|
||
|
||
def make_python_identifier(string): | ||
""" | ||
Takes an arbitrary string and creates a valid Python identifier. | ||
Identifiers must follow the convention outlined here: | ||
https://docs.python.org/2/reference/lexical_analysis.html#identifiers | ||
""" | ||
|
||
# create a working copy (and make it lowercase, while we're at it) | ||
s = string.lower() | ||
|
||
# remove leading and trailing whitespace | ||
s = s.strip() | ||
|
||
# Make spaces into underscores | ||
s = re.sub('[\\s\\t\\n]+', '_', s) | ||
|
||
# Remove invalid characters | ||
s = re.sub('[^0-9a-zA-Z_]', '', s) | ||
|
||
# Remove leading characters until we find a letter or underscore | ||
s = re.sub('^[^a-zA-Z_]+', '', s) | ||
|
||
# Check that the string is not a python identifier | ||
while s in keyword.kwlist: | ||
if re.match(".*?_\d+$", s): | ||
i = re.match(".*?_(\d+)$", s).groups()[0] | ||
s = s.strip('_'+i) + '_'+str(int(i)+1) | ||
else: | ||
s += '_1' | ||
|
||
return s |
This file was deleted.
Oops, something went wrong.