Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As this tool is made to be used as a module, I had the idea of making it a package and using GitHub actions to publish it automatically it to PyPI. You can review all of the changed code and decide if implementing it is worth it or not.
Btw, excuse me for my English, it's not my native language.
Here I have written a documentation for the changes and (if you choose to) how to implement it to your repository.
Changes
Firstly, the directory tree has changed to accomodate for the Python package publication.
setup.py
This file containes the module's information, such as its name, the description, and the version (note about it here).
It uses
setuptools
for setting up the build information andopen
to include readme.md as the description in PyPI.tests.py
To test the code's functionality, this file can be useful as it encrypts a set string to PGN and later decrypts it. This checks if the two strings match, and if it fails it will raise an exception.
Note: don't write files to the
/temp
directory, as this script may overwrite the contents.requirements.txt
Three new dependencies were added to it, and the three are required to build the Python module. These are
setuptools
,wheel
andtwine
..gitignore
Three build-related directories were added to the file to not accidentaly push the repository with the built package.
__init__.py
This is a standard file for Python modules that includes the available methods. The ones currently added are:
encode
from encode.pydecode
from decode.pyto_binary_string
from util.pyget_pgn_games
from util.pydecode.py/encode.py
Few changes were made to the files, only updated the util.py imports as follows:
This is due to the files being in a different directory instead of the same as the user's (take the tests.py file, for example).
python-publish.yml
Lastly, this is the GitHub actions file that will automatically run tests and publish the package to PyPI. It is currently set to run every time the repository is pushed, but you can change it to your liking using the
on:
parameter. I recommend seeing the official page for triggers.It consists of two jobs consecutively, a testing phase and a publishing phase. The publishing will only run if the tests have deemed successful.
The testing will run the tests.py file and will only succeed if no exceptions are thrown (if the strings don't match, for example).
The publishing will build the package and use this action to publish it to your PyPI account using a set token.
Implementation
Now, if you do wish to implement this there are a few steps you'll have to do so you can use it at its fullest.
PYPI_API_TOKEN
and insert the one created previously.Steps 3-6 are only required if you want to publish the package automatically using GH Actions.
Manual Build
If you prefer to manually build the package, that is an option too. Just install the new requirements and run the following command:
This will create the required directories and files. The final build file is the one called
chessencryption-*.whl
.Version Note
One of the only minor downsides using this configuration is that if you commit changes to the repository and want to publish the new version of the package, you are required to update the
version:
parameter in setup.py to able to publish it without errors.But this can be sometimes useful if the only thing you did was update something like a README file and don't need to publish the package. If you don't change the version the tests will still be run but the publishing will fail (which is the intended outcome in this scenario).
Usage
Here is an example of the syntax for the package.
Final Notes
I understand if you don't think its worth it to implement this, I mostly did it for the fun of it. If you do decide to implement this, tell me and I'll unoccupate the package name
chessencryption
in PyPI. For any doubts, don't hesitate to reach out.Good luck in your development/editing career!