From 1c1468354fa07a8cb588942a95e5f76e16a07b34 Mon Sep 17 00:00:00 2001 From: Kazuki Suzuki Przyborowski Date: Tue, 22 Oct 2024 17:55:39 -0500 Subject: [PATCH] Small update --- .github/workflows/pylint.yml | 23 +++++++++++++++ .github/workflows/pythonpackage.yml | 33 ++++++++++++++++++++++ .github/workflows/pythonpublish.yml | 26 +++++++++++++++++ setup.py | 43 +++++++++++++++++++++-------- 4 files changed, 113 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/pylint.yml create mode 100644 .github/workflows/pythonpackage.yml create mode 100644 .github/workflows/pythonpublish.yml diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml new file mode 100644 index 0000000..383e65c --- /dev/null +++ b/.github/workflows/pylint.yml @@ -0,0 +1,23 @@ +name: Pylint + +on: [push] + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.8", "3.9", "3.10"] + steps: + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install pylint + - name: Analysing the code with pylint + run: | + pylint $(git ls-files '*.py') diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml new file mode 100644 index 0000000..b5b7c9d --- /dev/null +++ b/.github/workflows/pythonpackage.yml @@ -0,0 +1,33 @@ +name: Python package + +on: [push] + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + max-parallel: 5 + matrix: + python-version: [3.7, 3.8, 3.9, 3.10, 3.11, 3.12] + + steps: + - uses: actions/checkout@v1 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v1 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + - name: Lint with flake8 + run: | + pip install flake8 + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Test with pytest + run: | + pip install pytest + pytest diff --git a/.github/workflows/pythonpublish.yml b/.github/workflows/pythonpublish.yml new file mode 100644 index 0000000..21f2f01 --- /dev/null +++ b/.github/workflows/pythonpublish.yml @@ -0,0 +1,26 @@ +name: Upload Python Package + +on: + release: + types: [created] + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Set up Python + uses: actions/setup-python@v1 + with: + python-version: '3.x' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install setuptools wheel twine + - name: Build and publish + env: + TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} + TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} + run: | + python setup.py sdist bdist_wheel + twine upload dist/* diff --git a/setup.py b/setup.py index 21c37bd..e384860 100644 --- a/setup.py +++ b/setup.py @@ -25,19 +25,38 @@ import pkg_resources from setuptools import setup, find_packages +# Open and read the version info file in a Python 2/3 compatible way verinfofilename = os.path.realpath("."+os.path.sep+os.path.sep+"gm2kenc.py") -verinfofile = open(verinfofilename, "r") -verinfodata = verinfofile.read() -verinfofile.close() -setuppy_verinfo_esc = re.escape("__version_info__ = (")+"(.*)"+re.escape(");") -setuppy_verinfo = re.findall(setuppy_verinfo_esc, verinfodata)[0] -setuppy_verinfo_exp = [vergetspt.strip().replace("\"", "") - for vergetspt in setuppy_verinfo.split(',')] -setuppy_dateinfo_esc = re.escape( - "__version_date_info__ = (")+"(.*)"+re.escape(");") -setuppy_dateinfo = re.findall(setuppy_dateinfo_esc, verinfodata)[0] -setuppy_dateinfo_exp = [vergetspt.strip().replace("\"", "") - for vergetspt in setuppy_dateinfo.split(',')] + +# Use `with` to ensure the file is properly closed after reading +# In Python 2, open defaults to text mode; in Python 3, it’s better to specify encoding +open_kwargs = {'encoding': 'utf-8'} if sys.version_info[0] >= 3 else {} +with open(verinfofilename, "r", **open_kwargs) as verinfofile: + verinfodata = verinfofile.read() + +# Define the regex pattern for extracting version info +# We ensure the pattern works correctly in both Python 2 and 3 by escaping the strings properly +version_pattern = "__version_info__ = \(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*['\"]([\w\s]+)['\"]\s*,\s*(\d+)\s*\)" +setuppy_verinfo = re.findall(version_pattern, verinfodata)[0] + +# If version info is found, process it; handle the case where no match is found +if setuppy_verinfo: + setuppy_verinfo_exp = setuppy_verinfo +else: + print("Version info not found.") + setuppy_verinfo_exp = None # Handle missing version info gracefully + +# Define the regex pattern for extracting version date info +date_pattern = "__version_date_info__ = \(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*['\"]([\w\s]+)['\"]\s*,\s*(\d+)\s*\)" +setuppy_dateinfo = re.findall(date_pattern, verinfodata)[0] + +# If date info is found, process it; handle the case where no match is found +if setuppy_dateinfo: + setuppy_dateinfo_exp = setuppy_dateinfo +else: + print("Date info not found.") + setuppy_dateinfo_exp = None # Handle missing date info gracefully + pymodule = {} pymodule['version'] = str(setuppy_verinfo_exp[0])+"." + \ str(setuppy_verinfo_exp[1])+"."+str(setuppy_verinfo_exp[2])