Skip to content

Commit

Permalink
version 1.5.5
Browse files Browse the repository at this point in the history
* using colorama shiped in pip
* bug fix
  • Loading branch information
Augus1999 authored Feb 18, 2022
1 parent 0606116 commit 98debf5
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ $ pip install -U mol2chemfigPy3

### Use in command line

> Attention: to render the colours on Windows platform, run it in modern terminals, e.g. ___Windows Terminal___.
> `mol2chemfig` and `python -m mol2chemfigPy3` are equivalent.
#### 1. getting version
Expand Down
16 changes: 8 additions & 8 deletions mol2chemfigPy3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
a python 3 version of mol2chemfig.
mol2chemfig generates chemfig code from mol files.
"""
import os
import re
from typing import Optional
from .main import main
Expand Down Expand Up @@ -48,14 +47,15 @@ def mol2chemfig(content: str,
f'{"c" if show_carbon else ""}{"m" if show_methyl else ""}' \
f' -a {rotate} {"" if marker is None else "-g "+marker}' \
f' {"" if name is None else "-l "+name} {others}'
if os.path.isfile(content):
arg += f' -i file \"{content}\"'
arg = re.sub(r'\s+', ' ', arg).split()
if content.endswith(('.mol', '.smi',)):
arg += ['-i', 'file', content]
else:
if re.match(r'[0-9]+', content).group(0) == content:
arg += f' -i pubchem {content}'
else:
arg += f' -i direct {content}'
arg = re.sub(r'\s+', ' ', arg)
try:
pubchem_id = int(content)
arg += ['-i', 'pubchem', str(pubchem_id)]
except ValueError:
arg += ['-i', 'direct', content]
success, result = process(raw_args=arg, inline=True)
if inline:
return result.render_user() if success else result
Expand Down
2 changes: 1 addition & 1 deletion mol2chemfigPy3/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""
from .options import getParser

program_version = '1.5.3'
program_version = '1.5.5'

# pubchem url for retrieving sdf for numerical IDs
pubchem_url = r"http://pubchem.ncbi.nlm.nih.gov/summary/summary.cgi?cid=%s&disopt=DisplaySDF"
Expand Down
9 changes: 9 additions & 0 deletions mol2chemfigPy3/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
package main
"""
import sys
try:
from pip._vendor import colorama
colour = True
except ImportError:
colour = False
from .processor import process


Expand All @@ -14,8 +19,12 @@ def main(program_name: str = sys.argv[0]) -> None:
:param program_name: program name
:return: None
"""
if colour:
colorama.init()
success, result = process(raw_args=sys.argv[1:], program_name=program_name)
if success:
print(result.render_user())
else:
print(result)
if colour:
colorama.deinit()
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"Programming Language :: Python :: 3.11",
"Topic :: Scientific/Engineering :: Chemistry",
],
keywords=["Chemistry", "chemfig"],
entry_points={
'console_scripts': ['mol2chemfig=mol2chemfigPy3.main:main']
},
Expand Down

0 comments on commit 98debf5

Please sign in to comment.