Skip to content

Commit

Permalink
Merge pull request #322 from GC-repeat/iss313_pylinting
Browse files Browse the repository at this point in the history
Fix #313
  • Loading branch information
GC-repeat authored Aug 24, 2022
2 parents 36bcb90 + 3b89fd4 commit 90d4063
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 24 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/python_linter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
find . -type f -name "*.py" |
xargs pylint
--max-line-length=120
--disable=C0103,C0114,C0115,C0116,C0201,C0206,C0301,C0303,C0325,C0411
--disable=C0103,C0114,C0115,C0116,C0201,C0206,C0325,C0411
--disable=E0611
--disable=R0402,R0801,R0903,R0912,R0914,R0915,R1702,R1705,R1720,R1721,R1724
--disable=W0212,W0511,W0611,W0612,W0622,W1309,W1203,W1512,W1514
Expand All @@ -48,4 +48,4 @@ jobs:
path: "."
max-line-length: 120
update-pip: TRUE
ignore: E121,E203,E226,E231,E251,E265,E302,E305,E501,F401,F403,F541,W291,W503
ignore: E121,F401,F403,F541,W503
6 changes: 4 additions & 2 deletions scripts/scriptutils/conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ def convert_package_sbol2_files(package: str) -> dict[str, str]:
mappings = {}

# import SBOL2
for file in itertools.chain(*(glob.glob(os.path.join(package, f'*{ext}')) for ext in GENETIC_DESIGN_FILE_TYPES['SBOL2'])):
for file in itertools.chain(
*(glob.glob(os.path.join(package, f'*{ext}')) for ext in GENETIC_DESIGN_FILE_TYPES['SBOL2'])
):
print(f'Attempting to convert SBOL2 file {file}')
file3 = os.path.splitext(file)[0]+'.nt' # make an SBOL3 version of the file name
file3 = os.path.splitext(file)[0] + '.nt' # make an SBOL3 version of the file name
doc2 = sbol2.Document()
doc2.read(file) # confirm that it is, in fact, an SBOL2 file
doc3 = convert2to3(file)
Expand Down
12 changes: 6 additions & 6 deletions scripts/scriptutils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def vector_to_insert(component: sbol3.Component) -> sbol3.Component:
if len(subvectors) == 0 and not is_plasmid(component):
return component
# otherwise, if there's precisely one non-vector subcomponent, return the Component it points to
inserts = {f for f in set(component.features)-subvectors if isinstance(f, sbol3.SubComponent)}
inserts = {f for f in set(component.features) - subvectors if isinstance(f, sbol3.SubComponent)}
if len(inserts) == 1:
return inserts.pop().instance_of.lookup()
elif len(inserts) == 0:
Expand Down Expand Up @@ -54,11 +54,11 @@ def remove_duplicate_prefix(name: str) -> str:
"""
components = name.split('_')
# check from largest possible repeated block to smallest
for i in reversed(range(1, math.floor(len(components)/2)+1)):
for i in reversed(range(1, math.floor(len(components) / 2) + 1)):
# Check if there is a repeated block at the front
if components[0:i] == components[i:(2*i)]:
if components[2*i] == 'ins': # also remove insertion markers
ins_less = "_".join(name.split("_")[0:i] + [name.split("_", (2*i)+1)[-1]])
if components[0:i] == components[i:(2 * i)]:
if components[2 * i] == 'ins': # also remove insertion markers
ins_less = "_".join(name.split("_")[0:i] + [name.split("_", (2 * i) + 1)[-1]])
return ins_less
else:
return name.split('_', i)[-1]
Expand All @@ -77,7 +77,7 @@ def truncate_by_underscores(name: str, max_len: int) -> str:
if len(components) > 1:
name = components[-1]
else:
name = name[(len(name)-max_len):]
name = name[(len(name) - max_len):]
return name


Expand Down
3 changes: 2 additions & 1 deletion scripts/scriptutils/package_specification.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ def export_sbol(package: str) -> sbol3.Document:
"""
# get workbook and perform conversion
excel_file = package_excel(package)
sbol3.set_namespace(package_stem(package)) # TODO: update after resolution of https://github.com/SynBioDex/pySBOL3/issues/288
sbol3.set_namespace(package_stem(package)) # TODO: update after resolution of https://github.com/SynBioDex/pySBOL3/issues/288 # pylint: disable=C0301 # noqa: E501

with warnings.catch_warnings():
warnings.simplefilter("ignore", category=UserWarning) # filter the "data validation not supported" warning
wb = openpyxl.open(excel_file, data_only=True)
Expand Down
4 changes: 2 additions & 2 deletions scripts/test/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from scripts.scriptutils import EXPORT_DIRECTORY


def copy_to_tmp(package: list[str] = None, exports: list[str] = None, renames: dict[str,str] = None) -> str:
def copy_to_tmp(package: list[str] = None, exports: list[str] = None, renames: dict[str, str] = None) -> str:
"""Copy test files into a temporary package directory
:param package: list of files to go into the package directory
Expand All @@ -31,6 +31,6 @@ def copy_to_tmp(package: list[str] = None, exports: list[str] = None, renames: d
copy(os.path.join(test_dir, 'test_files', f), tmp_sub)
for f in exports:
copy(os.path.join(test_dir, 'test_files', EXPORT_DIRECTORY, f), tmp_export)
for old_f,new_f in renames.items():
for old_f, new_f in renames.items():
copy(os.path.join(test_dir, 'test_files', old_f), os.path.join(tmp_sub, new_f))
return tmp_sub
7 changes: 4 additions & 3 deletions scripts/test/test_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class Test2To3Conversion(unittest.TestCase):
def test_2to3_package_conversion(self):
"""Test ability to convert parts already in a directory"""
tmpsub = copy_to_tmp(package = ['test_sequence.fasta', 'two_sequences.gb', 'BBa_J23101.xml'])
tmpsub = copy_to_tmp(package=['test_sequence.fasta', 'two_sequences.gb', 'BBa_J23101.xml'])
mappings = scripts.scriptutils.convert_package_sbol2_files(tmpsub)
expected = {os.path.join(tmpsub, 'BBa_J23101.xml'): os.path.join(tmpsub, 'BBa_J23101.nt')}
assert mappings == expected, f'Conversion mappings do not match expected value: {mappings}'
Expand All @@ -21,8 +21,8 @@ def test_2to3_package_conversion(self):

def test_2to3_package_merge(self):
"""Test ability to convert parts already in a directory"""
tmpsub = copy_to_tmp(package = ['test_sequence.fasta', 'two_sequences.gb', 'BBa_J23101.xml'],
renames = {'BBa_J23101_and_J23102.nt': 'BBa_J23101.nt'})
tmpsub = copy_to_tmp(package=['test_sequence.fasta', 'two_sequences.gb', 'BBa_J23101.xml'],
renames={'BBa_J23101_and_J23102.nt': 'BBa_J23101.nt'})
mappings = scripts.scriptutils.convert_package_sbol2_files(tmpsub)
expected = {os.path.join(tmpsub, 'BBa_J23101.xml'): os.path.join(tmpsub, 'BBa_J23101.nt')}
assert mappings == expected, f'Conversion mappings do not match expected value: {mappings}'
Expand All @@ -32,5 +32,6 @@ def test_2to3_package_merge(self):
assert filecmp.cmp(os.path.join(tmpsub, 'BBa_J23101.nt'), comparison_file), \
f'Converted file {comparison_file} is not identical'


if __name__ == '__main__':
unittest.main()
12 changes: 6 additions & 6 deletions scripts/test/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@ def test_duplicate_name_removal(self):
self.assertEqual(helpers.remove_duplicate_prefix('foo_bar_baz'), 'foo_bar_baz')
self.assertEqual(helpers.remove_duplicate_prefix('foo_foo_bar'), 'foo_bar')
self.assertEqual(helpers.remove_duplicate_prefix('foo_foo_bar_baz'), 'foo_bar_baz')
self.assertEqual(helpers.remove_duplicate_prefix('foo_foo_foo_foo_bar_baz'),
self.assertEqual(helpers.remove_duplicate_prefix('foo_foo_foo_foo_bar_baz'),
'foo_foo_bar_baz')
self.assertEqual(helpers.remove_duplicate_prefix('foo_qux_foo_qux_bar_baz'),
self.assertEqual(helpers.remove_duplicate_prefix('foo_qux_foo_qux_bar_baz'),
'foo_qux_bar_baz')
self.assertEqual(helpers.remove_duplicate_prefix('foo_qux_zap_foo_qux_zap_bar_baz'),
self.assertEqual(helpers.remove_duplicate_prefix('foo_qux_zap_foo_qux_zap_bar_baz'),
'foo_qux_zap_bar_baz')
# removing insert markers when appropriate
self.assertEqual(helpers.remove_duplicate_prefix('foo_ins_bar'), 'foo_ins_bar')
self.assertEqual(helpers.remove_duplicate_prefix('foo_ins_bar_baz'), 'foo_ins_bar_baz')
self.assertEqual(helpers.remove_duplicate_prefix('foo_foo_ins_bar'), 'foo_bar')
self.assertEqual(helpers.remove_duplicate_prefix('foo_foo_ins_bar_baz'), 'foo_bar_baz')
self.assertEqual(helpers.remove_duplicate_prefix('foo_foo_foo_foo_ins_bar_baz'),
self.assertEqual(helpers.remove_duplicate_prefix('foo_foo_foo_foo_ins_bar_baz'),
'foo_foo_bar_baz')
self.assertEqual(helpers.remove_duplicate_prefix('foo_qux_foo_qux_ins_bar_baz'),
self.assertEqual(helpers.remove_duplicate_prefix('foo_qux_foo_qux_ins_bar_baz'),
'foo_qux_bar_baz')
self.assertEqual(helpers.remove_duplicate_prefix('foo_qux_zap_foo_qux_zap_ins_bar_baz'),
self.assertEqual(helpers.remove_duplicate_prefix('foo_qux_zap_foo_qux_zap_ins_bar_baz'),
'foo_qux_zap_bar_baz')

def test_name_truncation(self):
Expand Down
5 changes: 3 additions & 2 deletions scripts/test/test_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ def test_all_import_types(self):

# first round of import should obtain all but one missing part
retrieved = part_retrieval.import_parts(tmp_sub)
#assert len(retrieved) == 7 # all but the local file and LCP SynBioHub
github_prefix = 'https://raw.githubusercontent.com/iGEM-Engineering/iGEM-distribution/develop/scripts/test/test_files'
# assert len(retrieved) == 7 # all but the local file and LCP SynBioHub
github_prefix = ('https://raw.githubusercontent.com/'
'iGEM-Engineering/iGEM-distribution/develop/scripts/test/test_files')
expected = ['https://www.ncbi.nlm.nih.gov/nuccore/JWYZ01000115_1', # NCBI
'http://parts.igem.org/BBa_J364007', # iGEM FASTA
'http://parts.igem.org/J23100', # iGEM SynBioHub
Expand Down
1 change: 1 addition & 0 deletions scripts/test/test_markdown_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@ def test_distribution_readme_generation(self):
comparison_file = os.path.join(test_dir, 'test_files', 'distribution', DISTRIBUTION_SUMMARY)
assert filecmp.cmp(generated_file, comparison_file), f'Generated file {generated_file} is not identical'


if __name__ == '__main__':
unittest.main()

0 comments on commit 90d4063

Please sign in to comment.