Skip to content

Commit

Permalink
feat: 🎸 support Python 3.12 (#38)
Browse files Browse the repository at this point in the history
Closes: #35
  • Loading branch information
ZhaoQi99 authored Aug 28, 2024
1 parent 71c3897 commit 095a271
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 30 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: |
Expand Down
6 changes: 0 additions & 6 deletions dev-requirement.txt

This file was deleted.

8 changes: 4 additions & 4 deletions pyencrypt/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
{__description__}
VERSION {__version__}
"""
""" # noqa: E221,E222

KEY_OPTION_HELP = """
Your encryption key.If you don't specify key,
Expand All @@ -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}}
Expand Down Expand Up @@ -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:
Expand Down
20 changes: 14 additions & 6 deletions pyencrypt/encrypt.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyencrypt/license.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions pyencrypt/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
4 changes: 0 additions & 4 deletions requirement.txt

This file was deleted.

15 changes: 13 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 =
Expand Down

0 comments on commit 095a271

Please sign in to comment.