From eb91ce84f96ed54863121b876d0d8ceaf9da200d Mon Sep 17 00:00:00 2001 From: huangyuxin Date: Mon, 17 Jan 2022 12:52:26 +0000 Subject: [PATCH 1/4] refactor the version --- paddlespeech/__init__.py | 9 +++++++-- setup.py | 16 ++++++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/paddlespeech/__init__.py b/paddlespeech/__init__.py index 5dfc1974c..135ec2187 100644 --- a/paddlespeech/__init__.py +++ b/paddlespeech/__init__.py @@ -11,5 +11,10 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - -__version__ = '0.1.1' +try: + from .version import full_version as __version__ +except ImportError: + import sys + sys.stderr.write( + "Warning: import paddlespeech from source directory without installing, run 'python setup.py install' to install paddlespeech firstly\n" + ) diff --git a/setup.py b/setup.py index 8f68923d9..bc9236830 100644 --- a/setup.py +++ b/setup.py @@ -17,7 +17,6 @@ import io import os import subprocess as sp import sys -import paddlespeech from pathlib import Path from setuptools import Command @@ -28,6 +27,8 @@ from setuptools.command.install import install HERE = Path(os.path.abspath(os.path.dirname(__file__))) +PADDLESPEECH_VERSION = '0.1.1' + requirements = { "install": [ "editdistance", @@ -83,6 +84,15 @@ requirements = { } +def write_version_py(filename='paddlespeech/version.py'): + ver_str = """# THIS FILE IS GENERATED FROM PADDLEPADDLE SETUP.PY +# +full_version = '%(version)s' +""" + with open(filename, 'w') as f: + f.write(ver_str % {'version': PADDLESPEECH_VERSION}) + + @contextlib.contextmanager def pushd(new_dir): old_dir = os.getcwd() @@ -170,10 +180,12 @@ class UploadCommand(Command): sys.exit() +write_version_py() + setup_info = dict( # Metadata name='paddlespeech', - version=paddlespeech.__version__, + version=PADDLESPEECH_VERSION, author='PaddlePaddle Speech and Language Team', author_email='paddlesl@baidu.com', url='https://github.com/PaddlePaddle/PaddleSpeech', From 565a63c5ef766e8e2c4a8034855157955c2f7c50 Mon Sep 17 00:00:00 2001 From: huangyuxin Date: Tue, 18 Jan 2022 02:18:41 +0000 Subject: [PATCH 2/4] refactor the setup in paddleaudio --- paddleaudio/__init__.py | 8 +++++++- paddlespeech/__init__.py | 2 +- setup.py | 2 +- setup_audio.py | 18 ++++++++++++++---- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/paddleaudio/__init__.py b/paddleaudio/__init__.py index b717777d3..8676cfe33 100644 --- a/paddleaudio/__init__.py +++ b/paddleaudio/__init__.py @@ -14,4 +14,10 @@ from .backends import * from .features import * -__version__ = '0.1.0' +try: + from .version import full_version as __version__ +except ImportError: + import sys + sys.stderr.write( + "Warning: import paddlaudio from source directory without installing, run 'python setup_audio.py install' to install paddlespeech firstly\n" + ) diff --git a/paddlespeech/__init__.py b/paddlespeech/__init__.py index 135ec2187..fb855d010 100644 --- a/paddlespeech/__init__.py +++ b/paddlespeech/__init__.py @@ -16,5 +16,5 @@ try: except ImportError: import sys sys.stderr.write( - "Warning: import paddlespeech from source directory without installing, run 'python setup.py install' to install paddlespeech firstly\n" + "Warning: import paddlespeech from source directory without installing, run 'python setup.py install' to install paddlespeech firstly.\n" ) diff --git a/setup.py b/setup.py index bc9236830..75870003e 100644 --- a/setup.py +++ b/setup.py @@ -85,7 +85,7 @@ requirements = { def write_version_py(filename='paddlespeech/version.py'): - ver_str = """# THIS FILE IS GENERATED FROM PADDLEPADDLE SETUP.PY + ver_str = """# THIS FILE IS GENERATED FROM PADDLESPEECH SETUP.PY # full_version = '%(version)s' """ diff --git a/setup_audio.py b/setup_audio.py index 5f0140656..a0c15ae02 100644 --- a/setup_audio.py +++ b/setup_audio.py @@ -13,14 +13,24 @@ # limitations under the License. import setuptools -import paddleaudio - # set the version here -version = paddleaudio.__version__ +PADDLEAUDIO_VERSION = '0.1.0' + + +def write_version_py(filename='paddleaudio/version.py'): + ver_str = """# THIS FILE IS GENERATED FROM SETUP_AUDIO.PY +# +full_version = '%(version)s' +""" + with open(filename, 'w') as f: + f.write(ver_str % {'version': PADDLEAUDIO_VERSION}) + + +write_version_py() setuptools.setup( name="paddleaudio", - version=version, + version=PADDLEAUDIO_VERSION, author="", author_email="", description="PaddleAudio, in development", From 4e31247633c591dbd7d498672a0aff6134671d8a Mon Sep 17 00:00:00 2001 From: huangyuxin Date: Tue, 18 Jan 2022 06:27:59 +0000 Subject: [PATCH 3/4] refacto the code --- paddleaudio/__init__.py | 8 -------- paddlespeech/__init__.py | 7 ------- setup.py | 17 ++++++++--------- setup_audio.py | 17 ++++++++--------- 4 files changed, 16 insertions(+), 33 deletions(-) diff --git a/paddleaudio/__init__.py b/paddleaudio/__init__.py index 8676cfe33..2685cf57c 100644 --- a/paddleaudio/__init__.py +++ b/paddleaudio/__init__.py @@ -13,11 +13,3 @@ # limitations under the License. from .backends import * from .features import * - -try: - from .version import full_version as __version__ -except ImportError: - import sys - sys.stderr.write( - "Warning: import paddlaudio from source directory without installing, run 'python setup_audio.py install' to install paddlespeech firstly\n" - ) diff --git a/paddlespeech/__init__.py b/paddlespeech/__init__.py index fb855d010..185a92b8d 100644 --- a/paddlespeech/__init__.py +++ b/paddlespeech/__init__.py @@ -11,10 +11,3 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -try: - from .version import full_version as __version__ -except ImportError: - import sys - sys.stderr.write( - "Warning: import paddlespeech from source directory without installing, run 'python setup.py install' to install paddlespeech firstly.\n" - ) diff --git a/setup.py b/setup.py index 75870003e..5c6a9e49c 100644 --- a/setup.py +++ b/setup.py @@ -27,7 +27,7 @@ from setuptools.command.install import install HERE = Path(os.path.abspath(os.path.dirname(__file__))) -PADDLESPEECH_VERSION = '0.1.1' +VERSION = '0.1.1' requirements = { "install": [ @@ -84,13 +84,12 @@ requirements = { } -def write_version_py(filename='paddlespeech/version.py'): - ver_str = """# THIS FILE IS GENERATED FROM PADDLESPEECH SETUP.PY -# -full_version = '%(version)s' -""" - with open(filename, 'w') as f: - f.write(ver_str % {'version': PADDLESPEECH_VERSION}) +def write_version_py(filename='paddlespeech/__init__.py'): + import paddlespeech + if hasattr(paddlespeech, "__version__") and paddlespeech.__version__ == VERSION: + return + with open(filename, "a") as f: + f.write(f"\n__version__ = '{VERSION}'\n") @contextlib.contextmanager @@ -185,7 +184,7 @@ write_version_py() setup_info = dict( # Metadata name='paddlespeech', - version=PADDLESPEECH_VERSION, + version=VERSION, author='PaddlePaddle Speech and Language Team', author_email='paddlesl@baidu.com', url='https://github.com/PaddlePaddle/PaddleSpeech', diff --git a/setup_audio.py b/setup_audio.py index a0c15ae02..d6e9e892a 100644 --- a/setup_audio.py +++ b/setup_audio.py @@ -14,23 +14,22 @@ import setuptools # set the version here -PADDLEAUDIO_VERSION = '0.1.0' +VERSION = '0.1.0' -def write_version_py(filename='paddleaudio/version.py'): - ver_str = """# THIS FILE IS GENERATED FROM SETUP_AUDIO.PY -# -full_version = '%(version)s' -""" - with open(filename, 'w') as f: - f.write(ver_str % {'version': PADDLEAUDIO_VERSION}) +def write_version_py(filename='paddleaudio/__init__.py'): + import paddleaudio + if hasattr(paddleaudio, "__version__") and paddleaudio.__version__ == VERSION: + return + with open(filename, "a") as f: + f.write(f"\n__version__ = '{VERSION}'\n") write_version_py() setuptools.setup( name="paddleaudio", - version=PADDLEAUDIO_VERSION, + version=VERSION, author="", author_email="", description="PaddleAudio, in development", From 3ac6386187eeff2f8e4c8a7a2d5256321a8f47af Mon Sep 17 00:00:00 2001 From: huangyuxin Date: Tue, 18 Jan 2022 11:31:10 +0000 Subject: [PATCH 4/4] add remove_version_py --- setup.py | 14 ++++++++++++++ setup_audio.py | 9 +++++++++ 2 files changed, 23 insertions(+) diff --git a/setup.py b/setup.py index 5c6a9e49c..bf5912587 100644 --- a/setup.py +++ b/setup.py @@ -91,6 +91,14 @@ def write_version_py(filename='paddlespeech/__init__.py'): with open(filename, "a") as f: f.write(f"\n__version__ = '{VERSION}'\n") +def remove_version_py(filename='paddlespeech/__init__.py'): + with open(filename, "r") as f: + lines = f.readlines() + with open(filename, "w") as f: + for line in lines: + if "__version__" not in line: + f.write(line) + @contextlib.contextmanager def pushd(new_dir): @@ -247,3 +255,9 @@ setup_info = dict( }) setup(**setup_info) + + +remove_version_py() + + + diff --git a/setup_audio.py b/setup_audio.py index d6e9e892a..4842c1774 100644 --- a/setup_audio.py +++ b/setup_audio.py @@ -24,6 +24,13 @@ def write_version_py(filename='paddleaudio/__init__.py'): with open(filename, "a") as f: f.write(f"\n__version__ = '{VERSION}'\n") +def remove_version_py(filename='paddleaudio/__init__.py'): + with open(filename, "r") as f: + lines = f.readlines() + with open(filename, "w") as f: + for line in lines: + if "__version__" not in line: + f.write(line) write_version_py() @@ -50,3 +57,5 @@ setuptools.setup( 'soundfile >= 0.9.0', 'colorlog', ], ) + +remove_version_py() \ No newline at end of file