From 244754fc17e2ac1e28a210b4ec331cf228984610 Mon Sep 17 00:00:00 2001 From: Qi Zhao Date: Tue, 27 Aug 2024 20:30:32 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20support=20Python=203.11?= =?UTF-8?q?=20and=20Python=203.12=20(#36)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ✅ Closes: #35 --- .github/workflows/main.yml | 2 +- pyencrypt/encrypt.py | 20 ++++++++++++++------ pyproject.toml | 2 +- setup.cfg | 11 ++++++++--- 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7329eaa..6565a45 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"] + python-version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11"] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 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/pyproject.toml b/pyproject.toml index a27b3df..f095698 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [build-system] requires = [ - "setuptools >= 42, < 58", + "setuptools >= 42", "wheel" ] build-backend = "setuptools.build_meta" \ No newline at end of file diff --git a/setup.cfg b/setup.cfg index ad41d2f..c4499a4 100644 --- a/setup.cfg +++ b/setup.cfg @@ -19,6 +19,9 @@ classifiers = Programming Language :: Python :: 3.8 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 @@ -29,15 +32,17 @@ keywords = python-encrypt, import-hook [options] install_requires = - Cython >= 0.29.24 + 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.11 +python_requires = >=3.6,<3.13 packages = find: # package_dir = # = src +[options.extras_require] + [options.packages.find] # where = src exclude =