Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
@@ -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 }}
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ config.json
temp
public
media
__pycache__
__pycache__

build
*.egg-info
dist
11 changes: 11 additions & 0 deletions chessencryption/__init__.py
Original file line number Diff line number Diff line change
@@ -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()
###
2 changes: 1 addition & 1 deletion decode.py → chessencryption/decode.py
Original file line number Diff line number Diff line change
@@ -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


###
Expand Down
2 changes: 1 addition & 1 deletion encode.py → chessencryption/encode.py
Original file line number Diff line number Diff line change
@@ -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


###
Expand Down
File renamed without changes.
5 changes: 4 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
chess
flask
flask
setuptools
wheel
twine
16 changes: 16 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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"
)
46 changes: 46 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
@@ -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")