From c3b595050311093747d95770017d1f284a0ebab4 Mon Sep 17 00:00:00 2001 From: PhoenixBound Date: Wed, 21 Aug 2024 17:26:19 -0500 Subject: [PATCH 1/3] Modernize build methods and instructions So far, this works well enough to install the package "successfully." I haven't tested whether it actually works or not, or whether the git version number integration works properly, or whether you can make an EXE. (I used Python 3.10.6 on Windows 10 for testing so far. I know of issues with the spec file.) While I was here, I tried moving everything I could out of setup.py and into the new file format shared by all build systems. Maybe that was a bit unnecessary... But I figure pyproject.toml is easier to analyze with tools, for people who want to scour GitHub and identify security problems in popular packages and stuff like that. --- DEVELOPMENT.md | 51 ++++++++++++++++++++++++++++---------------------- MANIFEST.in | 3 ++- pyproject.toml | 26 +++++++++++++++++++++++++ setup.py | 37 ++++-------------------------------- 4 files changed, 61 insertions(+), 56 deletions(-) create mode 100644 pyproject.toml diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 2b83edf3..6f175d5c 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 may instead 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` To make a Ubuntu VM, you can follow these instructions: @@ -33,9 +38,9 @@ After installing a VM, follow the steps mentioned below for your respective syst 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,42 @@ 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. Build CoilSnake as a binary distribution in egg format: + - `python3 setup.py bdist_egg` 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 2b1e6f46..37a06ebe 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/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..d031f168 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,26 @@ +[build-system] +requires = ["setuptools >= 61", "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", + "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 = {} diff --git a/setup.py b/setup.py index 0b92cc38..0a78e8b9 100755 --- a/setup.py +++ b/setup.py @@ -1,52 +1,23 @@ -#!/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", ["coilsnake/util/eb/native_comp.c", "coilsnake/util/eb/exhal/compress.c"], + # include_dirs=['coilsnake/util/eb/exhal'], 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", From d1652951be9138ecb588500371ce2ac37519cf94 Mon Sep 17 00:00:00 2001 From: PhoenixBound Date: Fri, 23 Aug 2024 22:42:02 -0500 Subject: [PATCH 2/3] Update CI to match the current build process progress And remove a line of setup.py that I accidentally added while debugging why some headers couldn't be found in the exhal folder... --- .github/workflows/pyinstaller.yaml | 6 +----- requirements.txt | 2 -- setup.py | 1 - 3 files changed, 1 insertion(+), 8 deletions(-) delete mode 100644 requirements.txt diff --git a/.github/workflows/pyinstaller.yaml b/.github/workflows/pyinstaller.yaml index bc5c9f3f..da667453 100644 --- a/.github/workflows/pyinstaller.yaml +++ b/.github/workflows/pyinstaller.yaml @@ -15,12 +15,8 @@ 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: Build .exe run: python setup_exe.py - name: Rename .exe diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 324331ef..00000000 --- a/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -pip>=19.0 -pyinstaller>=6.3.0 diff --git a/setup.py b/setup.py index 0a78e8b9..c3e1795f 100755 --- a/setup.py +++ b/setup.py @@ -14,7 +14,6 @@ Extension( "coilsnake.util.eb.native_comp", ["coilsnake/util/eb/native_comp.c", "coilsnake/util/eb/exhal/compress.c"], - # include_dirs=['coilsnake/util/eb/exhal'], extra_compile_args=extra_compile_args, ) ], From ee645c0f093648ff55677ef15e9b5fb54abc0f94 Mon Sep 17 00:00:00 2001 From: PhoenixBound Date: Mon, 11 Nov 2024 23:30:36 -0600 Subject: [PATCH 3/3] Build EXEs and fix setuptools_scm version junk --- .git_archival.txt | 3 +++ .gitattributes | 6 +++++ .github/workflows/pyinstaller.yaml | 2 ++ .gitignore | 1 + CoilSnake.spec | 13 ++++++----- DEVELOPMENT.md | 6 ++--- coilsnake/ui/information.py | 16 ++++++------- coilsnake/util/common/project.py | 3 ++- pyproject.toml | 7 +++++- set_git_commit.py | 37 ------------------------------ 10 files changed, 36 insertions(+), 58 deletions(-) create mode 100644 .git_archival.txt create mode 100644 .gitattributes delete mode 100755 set_git_commit.py diff --git a/.git_archival.txt b/.git_archival.txt new file mode 100644 index 00000000..7c510094 --- /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 00000000..b81df740 --- /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 da667453..f11340bb 100644 --- a/.github/workflows/pyinstaller.yaml +++ b/.github/workflows/pyinstaller.yaml @@ -17,6 +17,8 @@ jobs: architecture: 'x86' - name: Build CoilSnake 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 a9a68430..d55dafa2 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 f690ae2d..a5a679b2 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 6f175d5c..6a3f02ce 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -19,7 +19,7 @@ If you're on Windows, whenever a command begins with `python3` below, use `py` i ### Using a virtual machine -For Windows, you may instead 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: @@ -31,7 +31,7 @@ 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 @@ -95,8 +95,6 @@ There are also scripts to launch the GUI and CLI in the `script` folder, with th 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. Build CoilSnake as a binary distribution in egg format: - - `python3 setup.py bdist_egg` 1. Install pyinstaller: - `pip3 install pyinstaller` 1. In the CoilSnake source directory, build the CoilSnake executable: diff --git a/coilsnake/ui/information.py b/coilsnake/ui/information.py index 1a3b9d28..8470a93a 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 6ad0acc9..4d96de58 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 index d031f168..2a796199 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,7 @@ [build-system] -requires = ["setuptools >= 61", "setuptools-scm"] +# 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] @@ -13,6 +15,7 @@ dependencies = [ "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'", ] @@ -24,3 +27,5 @@ coilsnake = "coilsnake.ui.gui:main" [tool.setuptools.packages] find = {} + +[tool.setuptools_scm] diff --git a/set_git_commit.py b/set_git_commit.py deleted file mode 100755 index d4feb50c..00000000 --- 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)