From 095a271a1e3aa405a93255f2f9b46860e73b1213 Mon Sep 17 00:00:00 2001 From: Qi Zhao Date: Wed, 28 Aug 2024 11:50:09 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20support=20Python=203.12?= =?UTF-8?q?=20(#38)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ✅ Closes: #35 --- .github/workflows/main.yml | 6 ++---- dev-requirement.txt | 6 ------ pyencrypt/cli.py | 8 ++++---- pyencrypt/encrypt.py | 20 ++++++++++++++------ pyencrypt/license.py | 2 +- pyencrypt/loader.py | 4 ++-- pyproject.toml | 3 ++- requirement.txt | 4 ---- setup.cfg | 15 +++++++++++++-- 9 files changed, 38 insertions(+), 30 deletions(-) delete mode 100644 dev-requirement.txt delete mode 100644 requirement.txt diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6565a45..6426069 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,9 +31,7 @@ jobs: - name: Install dependencies run: | pip install --upgrade pip - pip install setuptools==57.5.0 - pip install -r dev-requirement.txt - pip install . + pip install .[dev] - name: Lint with flake8 run: | diff --git a/dev-requirement.txt b/dev-requirement.txt deleted file mode 100644 index 1d76b9a..0000000 --- a/dev-requirement.txt +++ /dev/null @@ -1,6 +0,0 @@ --r requirement.txt -isort==5.10.1 -black==22.8.0 -pytest==6.2.5 -ipython==7.16.3 -flake8==4.0.1 \ No newline at end of file diff --git a/pyencrypt/cli.py b/pyencrypt/cli.py index 590a4be..3dd182b 100644 --- a/pyencrypt/cli.py +++ b/pyencrypt/cli.py @@ -25,7 +25,7 @@ {__description__} VERSION {__version__} -""" +""" # noqa: E221,E222 KEY_OPTION_HELP = """ Your encryption key.If you don't specify key, @@ -52,8 +52,8 @@ Encryption completed {SUCCESS_ANSI}. Please copy {LOADER_FILE_NAME} into your encrypted directory. And then remove `encrypted` directory. -Finally, add `import loader` at the top of your entry file.\ -""" +Finally, add `import loader` at the top of your entry file.\n +""" # noqa: W604 FINISH_DECRYPT_MSG = f""" Decryption completed {SUCCESS_ANSI}. Your origin source code has be put: {{work_dir}} @@ -197,7 +197,7 @@ def encrypt_command( if key is None: key = generate_aes_key().decode() click.echo( - f'Your randomly encryption 🔑 is {click.style(key,underline=True, fg="yellow")}' + f'Your randomly encryption 🔑 is {click.style(key, underline=True, fg="yellow")}' ) if before > after: 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/pyencrypt/license.py b/pyencrypt/license.py index 9a31aed..67d326a 100644 --- a/pyencrypt/license.py +++ b/pyencrypt/license.py @@ -35,7 +35,7 @@ def get_signature(data: bytes) -> str: def _combine_data(data: dict) -> bytes: - return "*".join(map(lambda x: f"{x}:{data[x]}", FIELDS)).encode() + return "*".join(map(lambda x: f"{x}:{data[x]}", FIELDS)).encode() # noqa: E231 def generate_license_file( diff --git a/pyencrypt/loader.py b/pyencrypt/loader.py index 4d28cb1..069010e 100644 --- a/pyencrypt/loader.py +++ b/pyencrypt/loader.py @@ -78,9 +78,9 @@ def find_spec( ) -> ModuleSpec: if path: if isinstance(path, _NamespacePath): - file_path = Path(path._path[0]) / f'{fullname.rsplit(".",1)[-1]}.pye' + file_path = Path(path._path[0]) / f'{fullname.rsplit(".", 1)[-1]}.pye' else: - file_path = Path(path[0]) / f'{fullname.rsplit(".",1)[-1]}.pye' + file_path = Path(path[0]) / f'{fullname.rsplit(".", 1)[-1]}.pye' else: for p in sys.path: file_path = Path(p) / f"{fullname}.pye" diff --git a/pyproject.toml b/pyproject.toml index f095698..259506b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,7 @@ [build-system] requires = [ - "setuptools >= 42", + "setuptools >= 66.1.0; python_version >= '3.12'", + "setuptools <= 60.9.0; python_version < '3.12'", "wheel" ] build-backend = "setuptools.build_meta" \ No newline at end of file diff --git a/requirement.txt b/requirement.txt deleted file mode 100644 index 112162c..0000000 --- a/requirement.txt +++ /dev/null @@ -1,4 +0,0 @@ -click==8.0.3 -Cython==0.29.24 -pycryptodome==3.14.1 -python-minifier==2.9.0 \ No newline at end of file diff --git a/setup.cfg b/setup.cfg index 737c42b..159f79b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -20,6 +20,7 @@ classifiers = Programming Language :: Python :: 3.9 Programming Language :: Python :: 3.10 Programming Language :: Python :: 3.11 + Programming Language :: Python :: 3.12 Programming Language :: Python :: Implementation :: CPython Environment :: Console license_files = LICENSE @@ -32,13 +33,23 @@ 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 + setuptools >= 66.1.0; python_version >= '3.12' + setuptools <= 60.9.0; python_version < '3.12' +python_requires = >=3.6,<3.13 packages = find: # package_dir = # = src +[options.extras_require] +dev: + isort + black + pytest + ipython + flake8 + [options.packages.find] # where = src exclude =