From 24728e760a9d5e8ee3885fe280c8cf8127bd2cc0 Mon Sep 17 00:00:00 2001 From: joanferrecid098 <6hpd15h0-github@tigelcid.es> Date: Fri, 6 Sep 2024 21:14:46 +0200 Subject: [PATCH 1/5] feat: module creation --- .gitignore | 6 +++++- chessencryption/__init__.py | 11 +++++++++++ decode.py => chessencryption/decode.py | 2 +- encode.py => chessencryption/encode.py | 2 +- util.py => chessencryption/util.py | 0 requirements.txt | 5 ++++- setup.py | 11 +++++++++++ 7 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 chessencryption/__init__.py rename decode.py => chessencryption/decode.py (98%) rename encode.py => chessencryption/encode.py (98%) rename util.py => chessencryption/util.py (100%) create mode 100644 setup.py 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..0787e28 --- /dev/null +++ b/setup.py @@ -0,0 +1,11 @@ +from setuptools import setup, find_packages + +setup( + name='chessencryption', + version='1.0', + packages=find_packages(), + install_requires=[ + 'chess', + 'flask' + ] +) \ No newline at end of file From 98149e16cb345c603bf5c0c8b8dc7ea2e7e247ca Mon Sep 17 00:00:00 2001 From: joanferrecid098 <6hpd15h0-github@tigelcid.es> Date: Sat, 7 Sep 2024 00:27:50 +0200 Subject: [PATCH 2/5] feat: add github actions, add description to pypi --- .github/workflows/python-publish.yml | 37 ++++++++++++++++++++++++++++ setup.py | 7 +++++- 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/python-publish.yml diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml new file mode 100644 index 0000000..a523b4e --- /dev/null +++ b/.github/workflows/python-publish.yml @@ -0,0 +1,37 @@ +# 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: + deploy: + + 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: 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/setup.py b/setup.py index 0787e28..011b12b 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,8 @@ from setuptools import setup, find_packages +with open("readme.md", "r") as f: + description = f.read() + setup( name='chessencryption', version='1.0', @@ -7,5 +10,7 @@ install_requires=[ 'chess', 'flask' - ] + ], + long_description=description, + long_description_content_type="text/markdown" ) \ No newline at end of file From df92842d818a30f108dafffdc954d791a1f63f34 Mon Sep 17 00:00:00 2001 From: joanferrecid098 <6hpd15h0-github@tigelcid.es> Date: Sat, 7 Sep 2024 01:15:10 +0200 Subject: [PATCH 3/5] feat: automated testing --- .github/workflows/python-publish.yml | 59 +++++++++++++++++----------- tests.py | 46 ++++++++++++++++++++++ 2 files changed, 83 insertions(+), 22 deletions(-) create mode 100644 tests.py diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index a523b4e..464fac7 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -11,27 +11,42 @@ name: Upload Python Package on: [push] permissions: - contents: read + contents: read jobs: - deploy: - - 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: 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 + 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 + + 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/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 From e5304c49435ad23e2c5f10e78a765c4a757fad9c Mon Sep 17 00:00:00 2001 From: joanferrecid098 <6hpd15h0-github@tigelcid.es> Date: Sat, 7 Sep 2024 01:18:03 +0200 Subject: [PATCH 4/5] fix: github actions dependency --- .github/workflows/python-publish.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index 464fac7..6db0773 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -32,6 +32,7 @@ jobs: deploy: runs-on: ubuntu-latest + needs: testing steps: - uses: actions/checkout@v4 From 92a1cb8d4b75830f8ec729cb63bb54a46aac9678 Mon Sep 17 00:00:00 2001 From: joanferrecid098 <6hpd15h0-github@tigelcid.es> Date: Sat, 7 Sep 2024 01:20:17 +0200 Subject: [PATCH 5/5] fix: update package version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 011b12b..c6df034 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setup( name='chessencryption', - version='1.0', + version='1.1', packages=find_packages(), install_requires=[ 'chess',