diff --git a/.git_archival.txt b/.git_archival.txt new file mode 100644 index 0000000..7c51009 --- /dev/null +++ b/.git_archival.txt @@ -0,0 +1,3 @@ +node: $Format:%H$ +node-date: $Format:%cI$ +describe-name: $Format:%(describe:tags=true,match=*[0-9]*)$ diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..b81df74 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,6 @@ +# Required to provide version information to setuptools_scm if someone downloads +# CoilSnake's code as an archive, instead of cloning with git. See +# https://setuptools-scm.readthedocs.io/en/stable/usage/#builtin-mechanisms-for-obtaining-version-numbers +# for more details. +.git_archival.txt export-subst + diff --git a/.github/workflows/pyinstaller.yaml b/.github/workflows/pyinstaller.yaml index bc5c9f3..f11340b 100644 --- a/.github/workflows/pyinstaller.yaml +++ b/.github/workflows/pyinstaller.yaml @@ -15,12 +15,10 @@ jobs: python-version: '3.8' cache: 'pip' # caching pip dependencies architecture: 'x86' - - name: Install requirements - run: pip install -r requirements.txt - - name: Write build Git commit info - run: python set_git_commit.py --write - name: Build CoilSnake - run: python setup.py install + run: pip install . + - name: Install PyInstaller + run: pip install pyinstaller - name: Build .exe run: python setup_exe.py - name: Rename .exe diff --git a/.gitignore b/.gitignore index a9a6843..d55dafa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ /.idea /build +/coilsnake_venv /dist /*.egg-info /.coverage diff --git a/CoilSnake.spec b/CoilSnake.spec index f690ae2..a5a679b 100644 --- a/CoilSnake.spec +++ b/CoilSnake.spec @@ -13,9 +13,11 @@ run_setup('setup.py', ['build_ext']) debug = False -sys_platform = sys.platform -if sys_platform == 'win32': - sys_platform = sysconfig.get_platform() +# This logic is specific to setuptools. It may change in future versions, as it did in 62.1.0. +plat_specifier = f'.{sysconfig.get_platform()}-{sys.implementation.cache_tag}' +if sysconfig.get_config_var('Py_GIL_DISABLED'): + plat_specifier += 't' + if len(sys.argv) > 1 and sys.argv[1] == 'debug': debug = True @@ -35,9 +37,8 @@ with open(os.path.join("coilsnake", "assets", "modulelist.txt"), "r") as f: pyver = '{}.{}'.format(sys.version_info[0], sys.version_info[1]) binaries = [( - 'build/lib.{}-{}/coilsnake/util/eb/native_comp.cp*'.format( - sys_platform if sys_platform != 'darwin' else 'macosx', - pyver + 'build/lib{}/coilsnake/util/eb/native_comp.cp*'.format( + plat_specifier ), 'coilsnake/util/eb' )] diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 2b83edf..6a3f02c 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -2,19 +2,24 @@ ## Environment -Because Python is notorious for being difficult to maintain a clean installation of, it is recommended to develop either in a Python virtualenv or in an actual virtual machine. +Because Python is notorious for being difficult to maintain a clean installation of, it is recommended to develop either in a Python virtual environment or in an actual virtual machine. -### Using a virtualenv +### Using a virtual environment -1. `sudo pip3 install virtualenv` -1. `virtualenv CoilSnake_virtualenv --no-site-packages` -1. `source CoilSnake_virtualenv/bin/activate` - - The above command sets up your CoilSnake virtual development environment. When you open a new terminal for CoilSnake development, always re-run the above command in order to re-enter the virtual development environment. For more information about how this works, see [virtualenv's documentation](https://pypi.python.org/pypi/virtualenv/1.7). +If you're on Windows, whenever a command begins with `python3` below, use `py` instead. + +1. Install Python through your package manager or via [Python.org](https://www.python.org/downloads/). + - On Debian-based OSes, run `sudo apt install python3-venv` to install the missing virtual environment support. +1. `python3 -m venv coilsnake_venv` +1. Activate the virtual environment. + - On Windows: `coilsnake_venv\Scripts\activate` + - On other platforms: `source coilsnake_venv/bin/activate` + - You'll know that it works if you see `(coilsnake_venv)` at the beginning of the line for your terminal. When you open a new terminal for CoilSnake development, always re-run the above command in order to re-activate the virtual development environment. For more information about how this works, see [`venv`'s documentation](https://docs.python.org/3/library/venv.html). 1. Follow the steps mentioned below for your respective system. ### Using a virtual machine -For Windows, you'll probably want to follow the steps from a fresh virtual machine. You can start up a new Windows 10 VM by the following command: `vagrant up windows` +For Windows, you have the option to instead follow the steps from a fresh virtual machine. You can start up a new Windows 10 VM by the following command: `vagrant up windows` To make a Ubuntu VM, you can follow these instructions: @@ -26,16 +31,16 @@ cd /vagrant Please note that the included Vagrant configuration for Ubuntu does not run a GUI, meaning that you won't be able to test CoilSnake's GUI with it. -After installing a VM, follow the steps mentioned below for your respective system ([Linux](#linux)/[Windows](#windows)). +After installing a VM, follow the steps mentioned below for your respective system ([Linux](#linux)/[macOS](#macos)/[Windows](#windows)). ## Linux 1. Install any system dependencies required by CoilSnake. For Debian-based OSes, simply run: ``` -sudo apt-get install python3-pip python3-dev g++ libyaml-dev \ - python3-tk python3-pil.imagetk \ - libjpeg-dev zlib1g-dev tk8.6-dev tcl8.6-dev +sudo apt install python3-pip python3-dev g++ libyaml-dev \ + python3-tk python3-pil.imagetk \ + libjpeg-dev zlib1g-dev tk8.6-dev tcl8.6-dev ``` @@ -58,40 +63,40 @@ sudo apt-get install python3-pip python3-dev g++ libyaml-dev \ ## Windows 1. Install: - 1. [Python 3.9](https://www.python.org/downloads/release/python-392/) (64-bit version) + 1. [Python 3.8 or later](https://www.python.org/downloads/) 1. [Visual C++ 2019 Build Tools](https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=BuildTools&rel=16) - Select "C++ build tools" under the "Workloads" tab and make sure these are ticked: 1. MSVC v140 - VS 2015 C++ x64/x86 build tools 1. Windows 10 SDK 1. Find a path that exists on your computer similar to `C:\Program Files (x86)\Windows Kits\10\bin\10.0.19041.0\x86` and add it to your system environment variables. 1. Follow the '[Generic](#generic)' instructions below. -1. In commands beginning with `python3` use just `python` instead. +1. In commands beginning with `python3`, use just `py` instead. ## Generic 1. Using your favorite git client, clone the [CoilSnake](https://github.com/pk-hack/CoilSnake) repository. 1. Open the command line and `cd` to your local CoilSnake git repository's main directory. -1. `python3 -m pip install pip==18.1` -1. Install dependencies: - - `python3 setup.py develop` -1. Build additional coilsnake dependencies: - - `python3 setup.py build` +1. `python3 -m pip install --upgrade pip` +1. Use `pip` to install the current package in "editable" or "development" mode: + - `pip3 install -e .` -CoilSnake is now installed in development mode. After making code changes to the source, run your code by launching CoilSnake's GUI or CLI: +CoilSnake is now installed in development mode. After making code changes to the source, run your code by activating the virtual environment (see above) and launching CoilSnake's GUI or CLI: ``` -python3 script/gui.py +coilsnake # or... -python3 script/cli.py +coilsnake-cli ``` -### Creating a standalone executable +There are also scripts to launch the GUI and CLI in the `script` folder, with the virtual environment active. + +### Creating a standalone Windows executable Note: The steps for creating a standalone executable are currently unmaintained and likely broken for systems other than 64-bit Windows. 1. Follow the steps above to build CoilSnake for your system. 1. Install pyinstaller: - - `python3 -m pip install pyinstaller` + - `pip3 install pyinstaller` 1. In the CoilSnake source directory, build the CoilSnake executable: - `python3 setup_exe.py` 1. Run the output file under the 'dist' directory. diff --git a/MANIFEST.in b/MANIFEST.in index 2b1e6f4..37a06eb 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,2 +1,3 @@ include README.md -recursive-include coilsnake/assets * \ No newline at end of file +recursive-include coilsnake/assets * +recursive-include coilsnake/util/eb * \ No newline at end of file diff --git a/coilsnake/ui/information.py b/coilsnake/ui/information.py index 1a3b9d2..8470a93 100644 --- a/coilsnake/ui/information.py +++ b/coilsnake/ui/information.py @@ -1,13 +1,9 @@ +from importlib.metadata import version + from coilsnake.util.common import project -# In case the file was not properly generated or bundled... -try: - from coilsnake.ui.git_commit import GIT_COMMIT -except: - GIT_COMMIT = None -VERSION = project.VERSION_NAMES[project.FORMAT_VERSION] -if GIT_COMMIT: - VERSION = f"{VERSION}-next-{GIT_COMMIT}" +VERSION = version('coilsnake') +PROJECT_VERSION = project.VERSION_NAMES[project.FORMAT_VERSION] RELEASE_DATE = "March 19, 2023" WEBSITE = "http://pk-hack.github.io/CoilSnake" @@ -16,6 +12,7 @@ - Contributions by H.S, Michael1, John Soklaski, João Silva, ShadowOne333, stochaztic, Catador, cooprocks123e, and many others""" +# TODO: add the actual code dependencies here DEPENDENCIES = [ {"name": "CoilSnake logo and icon", "author": "Rydel"}, @@ -35,12 +32,13 @@ "url": "https://github.com/devinacker/exhal"}, {"name": "EB++", "author": "Rufus", - "url": "http://goo.gl/BnNqUM"} + "url": "http://goo.gl/BnNqUM"}, ] def coilsnake_about(): description = f"""CoilSnake {VERSION} - {WEBSITE} +Compatible with projects created by Coilsnake version {PROJECT_VERSION} Created by {AUTHOR} Released on {RELEASE_DATE} """ diff --git a/coilsnake/util/common/project.py b/coilsnake/util/common/project.py index 6ad0acc..4d96de5 100644 --- a/coilsnake/util/common/project.py +++ b/coilsnake/util/common/project.py @@ -12,7 +12,7 @@ # format. Version numbers are necessary because the format of data files may # change between versions of CoilSnake. -FORMAT_VERSION = 12 +FORMAT_VERSION = 13 # Names for each version, corresponding the the CS version VERSION_NAMES = { @@ -28,6 +28,7 @@ 10: "4.0", 11: "4.1", 12: "4.2", + 13: "NEXT" } # The default project filename diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..2a79619 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,31 @@ +[build-system] +# 62.1.0 changes the folder layout for built extensions -- we need the new layout +# (Before that, 61 is the first version supporting pyproject.toml.) +requires = ["setuptools >= 62.1", "setuptools-scm"] +build-backend = "setuptools.build_meta" + +[project] +name = "coilsnake" +dynamic = ["version"] +description = "CoilSnake" +urls = {Homepage = "https://pk-hack.github.io/CoilSnake"} +requires-python = ">=3.8" +dependencies = [ + "Pillow>=3.0.0", + "PyYAML>=3.11", + "CCScriptWriter @ https://github.com/pk-hack/CCScriptWriter/tarball/master", + "ccscript @ https://github.com/charasyn/ccscript_legacy/archive/refs/tags/v1.500.tar.gz", + # ??? CoilSnake hasn't been tested on Mac in a while. Is this still needed? + "pyobjc-framework-Cocoa; platform_system == 'Darwin'", +] + +[project.scripts] +coilsnake-cli = "coilsnake.ui.cli:main" +# Comment out the next line to make CoilSnake launch with a terminal window on Windows +[project.gui-scripts] +coilsnake = "coilsnake.ui.gui:main" + +[tool.setuptools.packages] +find = {} + +[tool.setuptools_scm] diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 324331e..0000000 --- a/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -pip>=19.0 -pyinstaller>=6.3.0 diff --git a/set_git_commit.py b/set_git_commit.py deleted file mode 100755 index d4feb50..0000000 --- a/set_git_commit.py +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env python -import os -import subprocess -import sys - -GITHUB_SHA_ENV_VAR_NAME = 'GITHUB_SHA' -COILSNAKE_GIT_COMMIT_PY_PATH = 'coilsnake/ui/git_commit.py' - -def get_git_commit(): - # Try looking at the GitHub variable - revision = os.environ.get(GITHUB_SHA_ENV_VAR_NAME) - # If it wasn't set, run against head - if not revision: - revision = "HEAD" - # Try to run git rev-parse to get the short hash - try: - print('Getting short hash for Git revision:', revision) - git_commit = subprocess.check_output(['git', 'rev-parse', '--short', revision]) - return git_commit.strip().decode() - except Exception as e: - print('Error when running rev-parse:', e, sep='\n') - # In case of error, return None - return None - -def write_git_commit(git_commit): - # Force git_commit to be a value, or None - git_commit = git_commit or None - git_commit_file_text = f'GIT_COMMIT = {git_commit!r}' - print(f"Writing '{COILSNAKE_GIT_COMMIT_PY_PATH}' with: {git_commit_file_text}") - with open(COILSNAKE_GIT_COMMIT_PY_PATH, 'w') as f: - print(git_commit_file_text, file=f) - -if __name__ == '__main__': - git_commit = get_git_commit() - print('Found Git commit short hash:', git_commit) - if '--write' in sys.argv[1:]: - write_git_commit(git_commit) diff --git a/setup.py b/setup.py index 0b92cc3..c3e1795 100755 --- a/setup.py +++ b/setup.py @@ -1,38 +1,15 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 -import os import platform -from setuptools import setup, find_packages +from setuptools import setup from setuptools.extension import Extension extra_compile_args = [] if platform.system() != "Windows": - extra_compile_args = ["-std=c99"] - -install_requires = [ - "Pillow>=3.0.0", - "PyYAML>=3.11", - "CCScriptWriter>=1.2", - "ccscript>=1.500" -] - -if platform.system() == "Darwin": - install_requires.append("pyobjc-framework-Cocoa") + extra_compile_args.append("-std=c99") setup( - name="coilsnake", - version="4.2", - description="CoilSnake", - url="https://pk-hack.github.io/CoilSnake", - packages=find_packages(), - include_package_data=True, - - install_requires=install_requires, - dependency_links=[ - "https://github.com/Lyrositor/CCScriptWriter/tarball/master#egg=CCScriptWriter-1.2", - "https://github.com/charasyn/ccscript_legacy/archive/refs/tags/v1.500.tar.gz#egg=ccscript-1.500" - ], ext_modules=[ Extension( "coilsnake.util.eb.native_comp", @@ -40,13 +17,6 @@ extra_compile_args=extra_compile_args, ) ], - entry_points={ - "console_scripts": [ - "coilsnake = coilsnake.ui.gui:main", - "coilsnake-cli = coilsnake.ui.cli:main" - ] - }, - test_suite="nose.collector", tests_require=[ "nose>=1.0",