diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml new file mode 100644 index 0000000..6db0773 --- /dev/null +++ b/.github/workflows/python-publish.yml @@ -0,0 +1,53 @@ +# This workflow will upload a Python Package using Twine when a release is created +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries + +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +name: Upload Python Package + +on: [push] + +permissions: + contents: read + +jobs: + testing: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v3 + with: + python-version: '3.x' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + - name: Run tests + run: python tests.py + + deploy: + runs-on: ubuntu-latest + needs: testing + + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v3 + with: + python-version: '3.x' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + - name: Build package + run: python setup.py sdist bdist_wheel + - name: Publish package + uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29 + with: + user: __token__ + password: ${{ secrets.PYPI_API_TOKEN }} \ No newline at end of file diff --git a/.gitignore b/.gitignore index d6f58ee..ca24950 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,8 @@ config.json temp public media -__pycache__ \ No newline at end of file +__pycache__ + +build +*.egg-info +dist \ No newline at end of file diff --git a/chessencryption/__init__.py b/chessencryption/__init__.py new file mode 100644 index 0000000..dbdf5ab --- /dev/null +++ b/chessencryption/__init__.py @@ -0,0 +1,11 @@ +from .encode import encode +from .decode import decode +from .util import to_binary_string +from .util import get_pgn_games + +### +### As the different methods are stored in separate files, +### this file is a wrapper for both. +### Using this, you have to call chessencryption.encode() +### instead of chessencryption.encode.encode() +### \ No newline at end of file diff --git a/decode.py b/chessencryption/decode.py similarity index 98% rename from decode.py rename to chessencryption/decode.py index 7528e56..6f39849 100644 --- a/decode.py +++ b/chessencryption/decode.py @@ -1,7 +1,7 @@ from time import time from math import log2 from chess import pgn, Board -from util import get_pgn_games +from .util import get_pgn_games ### diff --git a/encode.py b/chessencryption/encode.py similarity index 98% rename from encode.py rename to chessencryption/encode.py index b3bf36d..ae28712 100644 --- a/encode.py +++ b/chessencryption/encode.py @@ -1,7 +1,7 @@ from time import time from math import log2 from chess import pgn, Board -from util import to_binary_string +from .util import to_binary_string ### diff --git a/util.py b/chessencryption/util.py similarity index 100% rename from util.py rename to chessencryption/util.py diff --git a/requirements.txt b/requirements.txt index 0cc1d12..c3ce250 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,5 @@ chess -flask \ No newline at end of file +flask +setuptools +wheel +twine \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..c6df034 --- /dev/null +++ b/setup.py @@ -0,0 +1,16 @@ +from setuptools import setup, find_packages + +with open("readme.md", "r") as f: + description = f.read() + +setup( + name='chessencryption', + version='1.1', + packages=find_packages(), + install_requires=[ + 'chess', + 'flask' + ], + long_description=description, + long_description_content_type="text/markdown" +) \ No newline at end of file diff --git a/tests.py b/tests.py new file mode 100644 index 0000000..53a5ddd --- /dev/null +++ b/tests.py @@ -0,0 +1,46 @@ +import chessencryption +import os + +### +### This file will be run by +### GitHub actions to test if the +### program is working correctly. +### + +testing_string = "BUY GOLD!" + +try: + os.mkdir("temp") + print("new directory /temp has been created") +except FileExistsError: + print("directory /temp already exists") + +with open("temp/text.txt", "w") as text_file: + text_file.write(testing_string) + print("text.txt has been written") + text_file.close() + +encoded_pgn = chessencryption.encode(file_path="temp/text.txt") + +if (encoded_pgn == None): + print("ERROR: encoded pgn file is empty") + raise ValueError + +chessencryption.decode(pgn_string=encoded_pgn, output_file_path="temp/decoded.txt") + +decoded_file = open("temp/decoded.txt", "r") +decoded_text = decoded_file.read() +decoded_file.close() + +print("\nOriginal:", testing_string) +print("Decoded:", decoded_text) + +if (decoded_text == None): + print("\nERROR: error when decoding pgn\n") + raise ValueError + +if (decoded_text != testing_string): + print("\nERROR: values don't match, encryption failed\n") + raise ValueError + +print("\nSUCCESS: values match accordingly") \ No newline at end of file