art-vasilyev / demo-source-protect

10 stars 3 forks source link

can we use .so file instead of wheel ? #1

Open krunaldodiya opened 8 months ago

krunaldodiya commented 8 months ago

Hi there,

I am also using the same approach to protect my python source code, I am using cython to build shared object file .so, for each python file it's create .so file, and put it right beside the actual file and then i build python package only using .so file and not actual file

can you please validate that this approach will work or any chances to leak source code ?

i have to manage two repository for that

1) repository 1

my_package
           - __init__.py
           - main.py
           - another_file.py

first i cythonize it to create .so file for each python file

my_package
           - __init__.py
           - main.py
           - main.cpython-311-x86_64-linux-gnu.so
           - another_file.py
           - another_file.cpython-311-x86_64-linux-gnu.so

2) repository 2 now i only take .so file with init.py

my_package
           - __init__.py
           - main.cpython-311-x86_64-linux-gnu.so
           - another_file.cpython-311-x86_64-linux-gnu.so

and then create a python package to distribute

so that user can do

from my_package.main import something

thanks

krunaldodiya commented 8 months ago

here is the setup.py


import os

from setuptools import setup, Extension, find_packages
from Cython.Build import cythonize

def get_ext(package: str, package_path: str, file: str) -> Extension:
    name = f"{package}.{file}".replace(".py", "")
    file = os.path.join(package_path, file)

    return Extension(name=name, sources=[file], language="c++")

packages = find_packages(exclude=["some_directory_to_exclude"])

ext_modules = []

for package in packages:
    package_path = package.replace(".", os.path.sep)

    ext_modules.extend(
        [
            get_ext(package, package_path, file)
            for file in os.listdir(package_path)
            if file.endswith(".py") and file != "__init__.py"
        ]
    )

setup(
    name="my_package",
    ext_modules=cythonize(ext_modules),
)