From 5127206907d974ff0618d930c15627c34f0ec9ff Mon Sep 17 00:00:00 2001 From: Qi Zhao Date: Tue, 27 Aug 2024 20:12:02 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20support=203.12?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/main.yml | 4 ++-- pyencrypt/encrypt.py | 20 ++++++++++++++------ requirement.txt | 2 +- setup.cfg | 8 ++++++-- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6565a45..714b7c6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -20,7 +20,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-20.04, macos-12, windows-2022] - python-version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11"] + python-version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11", "3.12"] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 @@ -31,7 +31,7 @@ jobs: - name: Install dependencies run: | pip install --upgrade pip - pip install setuptools==57.5.0 + pip install setuptools -U pip install -r dev-requirement.txt pip install . diff --git a/pyencrypt/encrypt.py b/pyencrypt/encrypt.py index 8a8c1c4..2d58a70 100644 --- a/pyencrypt/encrypt.py +++ b/pyencrypt/encrypt.py @@ -1,10 +1,16 @@ import os -import sys import re +import sys from pathlib import Path from typing import Optional -import python_minifier +try: + import python_minifier +except ImportError as exc: + if sys.version_info.minor < 12: + raise ImportError("Couldn't import python_minifier.") from exc + + python_minifier = None from pyencrypt.aes import aes_encrypt from pyencrypt.generate import generate_rsa_number @@ -93,10 +99,12 @@ def generate_so_file( f"{decrypt_source}\n{loader_source}", encoding="utf-8" ) - loader_file_path.write_text( - python_minifier.minify(loader_origin_file_path.read_text(encoding="utf-8")), - encoding="utf-8", - ) + minified_code = loader_origin_file_path.read_text(encoding="utf-8") + + if python_minifier: + minified_code = python_minifier.minify(minified_code) + + loader_file_path.write_text(minified_code, encoding="utf-8") from setuptools import setup # isort:skip from Cython.Build import cythonize diff --git a/requirement.txt b/requirement.txt index 112162c..0409ab9 100644 --- a/requirement.txt +++ b/requirement.txt @@ -1,4 +1,4 @@ click==8.0.3 Cython==0.29.24 pycryptodome==3.14.1 -python-minifier==2.9.0 \ No newline at end of file +python-minifier==2.9.0; python_version < '3.12' \ No newline at end of file diff --git a/setup.cfg b/setup.cfg index 737c42b..c4499a4 100644 --- a/setup.cfg +++ b/setup.cfg @@ -20,6 +20,8 @@ classifiers = Programming Language :: Python :: 3.9 Programming Language :: Python :: 3.10 Programming Language :: Python :: 3.11 + Programming Language :: Python :: 3.11 + Programming Language :: Python :: 3.12 Programming Language :: Python :: Implementation :: CPython Environment :: Console license_files = LICENSE @@ -32,13 +34,15 @@ keywords = python-encrypt, import-hook install_requires = Cython >= 0.29.30 pycryptodome >= 3.14.1 - python-minifier >= 2.6.0 + python-minifier >= 2.6.0; python_version < '3.12' click -python_requires = >=3.6,<3.12 +python_requires = >=3.6,<3.13 packages = find: # package_dir = # = src +[options.extras_require] + [options.packages.find] # where = src exclude =