Skip to content

Commit 095a271

Browse files
authored
feat: 🎸 support Python 3.12 (#38)
Closes: #35
1 parent 71c3897 commit 095a271

File tree

9 files changed

+38
-30
lines changed

9 files changed

+38
-30
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
fail-fast: false
2121
matrix:
2222
os: [ubuntu-20.04, macos-12, windows-2022]
23-
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11"]
23+
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
2424
runs-on: ${{ matrix.os }}
2525
steps:
2626
- uses: actions/checkout@v4
@@ -31,9 +31,7 @@ jobs:
3131
- name: Install dependencies
3232
run: |
3333
pip install --upgrade pip
34-
pip install setuptools==57.5.0
35-
pip install -r dev-requirement.txt
36-
pip install .
34+
pip install .[dev]
3735
3836
- name: Lint with flake8
3937
run: |

dev-requirement.txt

Lines changed: 0 additions & 6 deletions
This file was deleted.

pyencrypt/cli.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
{__description__}
2626
2727
VERSION {__version__}
28-
"""
28+
""" # noqa: E221,E222
2929

3030
KEY_OPTION_HELP = """
3131
Your encryption key.If you don't specify key,
@@ -52,8 +52,8 @@
5252
Encryption completed {SUCCESS_ANSI}.
5353
Please copy {LOADER_FILE_NAME} into your encrypted directory.
5454
And then remove `encrypted` directory.
55-
Finally, add `import loader` at the top of your entry file.\
56-
"""
55+
Finally, add `import loader` at the top of your entry file.\n
56+
""" # noqa: W604
5757

5858
FINISH_DECRYPT_MSG = f"""
5959
Decryption completed {SUCCESS_ANSI}. Your origin source code has be put: {{work_dir}}
@@ -197,7 +197,7 @@ def encrypt_command(
197197
if key is None:
198198
key = generate_aes_key().decode()
199199
click.echo(
200-
f'Your randomly encryption 🔑 is {click.style(key,underline=True, fg="yellow")}'
200+
f'Your randomly encryption 🔑 is {click.style(key, underline=True, fg="yellow")}'
201201
)
202202

203203
if before > after:

pyencrypt/encrypt.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
import os
2-
import sys
32
import re
3+
import sys
44
from pathlib import Path
55
from typing import Optional
66

7-
import python_minifier
7+
try:
8+
import python_minifier
9+
except ImportError as exc:
10+
if sys.version_info.minor < 12:
11+
raise ImportError("Couldn't import python_minifier.") from exc
12+
13+
python_minifier = None
814

915
from pyencrypt.aes import aes_encrypt
1016
from pyencrypt.generate import generate_rsa_number
@@ -93,10 +99,12 @@ def generate_so_file(
9399
f"{decrypt_source}\n{loader_source}", encoding="utf-8"
94100
)
95101

96-
loader_file_path.write_text(
97-
python_minifier.minify(loader_origin_file_path.read_text(encoding="utf-8")),
98-
encoding="utf-8",
99-
)
102+
minified_code = loader_origin_file_path.read_text(encoding="utf-8")
103+
104+
if python_minifier:
105+
minified_code = python_minifier.minify(minified_code)
106+
107+
loader_file_path.write_text(minified_code, encoding="utf-8")
100108

101109
from setuptools import setup # isort:skip
102110
from Cython.Build import cythonize

pyencrypt/license.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def get_signature(data: bytes) -> str:
3535

3636

3737
def _combine_data(data: dict) -> bytes:
38-
return "*".join(map(lambda x: f"{x}:{data[x]}", FIELDS)).encode()
38+
return "*".join(map(lambda x: f"{x}:{data[x]}", FIELDS)).encode() # noqa: E231
3939

4040

4141
def generate_license_file(

pyencrypt/loader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ def find_spec(
7878
) -> ModuleSpec:
7979
if path:
8080
if isinstance(path, _NamespacePath):
81-
file_path = Path(path._path[0]) / f'{fullname.rsplit(".",1)[-1]}.pye'
81+
file_path = Path(path._path[0]) / f'{fullname.rsplit(".", 1)[-1]}.pye'
8282
else:
83-
file_path = Path(path[0]) / f'{fullname.rsplit(".",1)[-1]}.pye'
83+
file_path = Path(path[0]) / f'{fullname.rsplit(".", 1)[-1]}.pye'
8484
else:
8585
for p in sys.path:
8686
file_path = Path(p) / f"{fullname}.pye"

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[build-system]
22
requires = [
3-
"setuptools >= 42",
3+
"setuptools >= 66.1.0; python_version >= '3.12'",
4+
"setuptools <= 60.9.0; python_version < '3.12'",
45
"wheel"
56
]
67
build-backend = "setuptools.build_meta"

requirement.txt

Lines changed: 0 additions & 4 deletions
This file was deleted.

setup.cfg

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ classifiers =
2020
Programming Language :: Python :: 3.9
2121
Programming Language :: Python :: 3.10
2222
Programming Language :: Python :: 3.11
23+
Programming Language :: Python :: 3.12
2324
Programming Language :: Python :: Implementation :: CPython
2425
Environment :: Console
2526
license_files = LICENSE
@@ -32,13 +33,23 @@ keywords = python-encrypt, import-hook
3233
install_requires =
3334
Cython >= 0.29.30
3435
pycryptodome >= 3.14.1
35-
python-minifier >= 2.6.0
36+
python-minifier >= 2.6.0; python_version < '3.12'
3637
click
37-
python_requires = >=3.6,<3.12
38+
setuptools >= 66.1.0; python_version >= '3.12'
39+
setuptools <= 60.9.0; python_version < '3.12'
40+
python_requires = >=3.6,<3.13
3841
packages = find:
3942
# package_dir =
4043
# = src
4144

45+
[options.extras_require]
46+
dev:
47+
isort
48+
black
49+
pytest
50+
ipython
51+
flake8
52+
4253
[options.packages.find]
4354
# where = src
4455
exclude =

0 commit comments

Comments
 (0)