From 5ed748aa03878184db8db4442b7f58b76aa5427b Mon Sep 17 00:00:00 2001 From: Henrique Gemignani Passos Lima Date: Fri, 14 Jul 2023 15:36:37 +0300 Subject: [PATCH 01/10] Declare everything in __init__.py --- dolphin_memory_engine/__init__.py | 42 ++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/dolphin_memory_engine/__init__.py b/dolphin_memory_engine/__init__.py index 9761645..b953984 100644 --- a/dolphin_memory_engine/__init__.py +++ b/dolphin_memory_engine/__init__.py @@ -1 +1,41 @@ -from _dolphin_memory_engine import * +from _dolphin_memory_engine import ( + MemWatch, + assert_hooked, + follow_pointers, + + hook, + un_hook, + is_hooked, + + read_byte, + read_bytes, + read_double, + read_float, + read_word, + write_byte, + write_bytes, + write_double, + write_float, + write_word, +) + +__all__ = [ + 'MemWatch', + 'assert_hooked', + 'follow_pointers', + + 'hook', + 'un_hook', + 'is_hooked', + + 'read_byte', + 'read_bytes', + 'read_double', + 'read_float', + 'read_word', + 'write_byte', + 'write_bytes', + 'write_double', + 'write_float', + 'write_word', +] From 87777bc03f79ca5e76f716f8fc11feafbf86a974 Mon Sep 17 00:00:00 2001 From: Henrique Gemignani Passos Lima Date: Fri, 14 Jul 2023 15:49:01 +0300 Subject: [PATCH 02/10] Move code to python_src --- .../dolphin_memory_engine}/__init__.py | 0 setup.cfg | 8 +++++++- 2 files changed, 7 insertions(+), 1 deletion(-) rename {dolphin_memory_engine => python_src/dolphin_memory_engine}/__init__.py (100%) diff --git a/dolphin_memory_engine/__init__.py b/python_src/dolphin_memory_engine/__init__.py similarity index 100% rename from dolphin_memory_engine/__init__.py rename to python_src/dolphin_memory_engine/__init__.py diff --git a/setup.cfg b/setup.cfg index 6ba941b..df1fe8c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -19,9 +19,15 @@ classifiers = Programming Language :: Python :: 3.11 [options] -packages = dolphin_memory_engine install_requires = include_package_data = True zip_safe = False python_requires = >=3.7 + +packages = find: +package_dir = + = python_src + +[options.packages.find] +where = python_src \ No newline at end of file From edb365bdf57b861e48ffeedd9cb6e9d7d5e948c5 Mon Sep 17 00:00:00 2001 From: Henrique Gemignani Passos Lima Date: Fri, 14 Jul 2023 15:49:12 +0300 Subject: [PATCH 03/10] Rename tests --- .github/workflows/python.yml | 1 - {test => tests}/test_native.py | 0 2 files changed, 1 deletion(-) rename {test => tests}/test_native.py (100%) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 8904390..6046ccc 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -143,7 +143,6 @@ jobs: - name: test run: python -m pytest - working-directory: test pypi: runs-on: 'ubuntu-latest' diff --git a/test/test_native.py b/tests/test_native.py similarity index 100% rename from test/test_native.py rename to tests/test_native.py From b6ca395031f4cb632428a1a4c67f8aa5bdacc509 Mon Sep 17 00:00:00 2001 From: Henrique Gemignani Passos Lima Date: Fri, 14 Jul 2023 15:51:40 +0300 Subject: [PATCH 04/10] Move to pyproject.toml --- pyproject.toml | 33 +++++++++++++++++++++++++++++++-- setup.cfg | 26 -------------------------- 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 09652c0..031443f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,35 @@ [build-system] -requires = ["setuptools>=60.0.0", "Cython>=0.29.21", "setuptools_scm[toml]>=6.4"] +requires = [ + "setuptools>=61.2", + "Cython>=0.29.21", + "setuptools_scm[toml]>=6.4" +] build-backend = "setuptools.build_meta" +[project] +name = "dolphin-memory-engine" +description = "Hooks into the memory of a running Dolphin processes, allowing access to the game memory." +authors = [{name = "Henrique Gemignani"}] +classifiers = [ + "License :: OSI Approved :: MIT License", + "Development Status :: 3 - Alpha", + "Intended Audience :: Developers", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", +] +requires-python = ">=3.7" +dependencies = [] +dynamic = ["version"] + +[project.readme] +file = "README.md" +content-type = "text/markdown" + +[project.urls] +Homepage = "https://github.com/henriquegemignani/py-dolphin-memory-engine" + [tool.setuptools_scm] -local_scheme = "no-local-version" \ No newline at end of file +local_scheme = "no-local-version" diff --git a/setup.cfg b/setup.cfg index df1fe8c..ea8f3e0 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,30 +1,4 @@ -[metadata] -name = dolphin-memory-engine -description = Hooks into the memory of a running Dolphin processes, allowing access to the game memory. -long_description = file: README.md -long_description_content_type = text/markdown -url = https://github.com/henriquegemignani/py-dolphin-memory-engine -author = Henrique Gemignani -license_files = - LICENSE - -classifiers = - License :: OSI Approved :: MIT License - Development Status :: 3 - Alpha - Intended Audience :: Developers - Programming Language :: Python :: 3.7 - Programming Language :: Python :: 3.8 - Programming Language :: Python :: 3.9 - Programming Language :: Python :: 3.10 - Programming Language :: Python :: 3.11 - [options] -install_requires = - -include_package_data = True -zip_safe = False -python_requires = >=3.7 - packages = find: package_dir = = python_src From 8feb5ed40b8e856653b3458fa0ad1b84e0f98c02 Mon Sep 17 00:00:00 2001 From: Henrique Gemignani Passos Lima Date: Fri, 14 Jul 2023 15:53:41 +0300 Subject: [PATCH 05/10] Modernize setup.py --- python_src/dolphin_memory_engine/__init__.py | 2 +- setup.py | 108 ++++++++++--------- 2 files changed, 59 insertions(+), 51 deletions(-) diff --git a/python_src/dolphin_memory_engine/__init__.py b/python_src/dolphin_memory_engine/__init__.py index b953984..47c6ebd 100644 --- a/python_src/dolphin_memory_engine/__init__.py +++ b/python_src/dolphin_memory_engine/__init__.py @@ -1,4 +1,4 @@ -from _dolphin_memory_engine import ( +from dolphin_memory_engine._dolphin_memory_engine import ( MemWatch, assert_hooked, follow_pointers, diff --git a/setup.py b/setup.py index e4a2c24..d7224e7 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ import re import subprocess import sys -from distutils.version import LooseVersion +from pathlib import Path from Cython.Build import cythonize from Cython.Build.Dependencies import default_create_extension @@ -13,92 +13,103 @@ is_windows = platform.system() == "Windows" -file_dir = os.path.dirname(__file__) +file_dir = Path(__file__).parent.relative_to(Path().absolute()) class CMakeExtension(Extension): def __init__(self, name, sources, cmake_options, *args, **kw): super().__init__(name, sources, *args, **kw) - cmake_options["dir"] = os.path.abspath(cmake_options["dir"]) + cmake_options["dir"] = os.fspath(Path(cmake_options["dir"]).resolve()) self.cmake_options = cmake_options class CMakeBuild(build_ext): def run(self): try: - out = subprocess.run(['cmake', '--version'], - stdout=subprocess.PIPE, check=True, - universal_newlines=True) + out = subprocess.run( + ["cmake", "--version"], stdout=subprocess.PIPE, check=True, text=True + ) except (FileNotFoundError, subprocess.CalledProcessError): - raise RuntimeError("CMake must be installed to build the following extensions: " + - ", ".join(e.name for e in self.extensions)) + raise RuntimeError( + "CMake must be installed to build the following extensions: " + + ", ".join(e.name for e in self.extensions) + ) if is_windows: - cmake_version = LooseVersion(re.search(r'version\s*([\d.]+)', out.stdout).group(1)) - if cmake_version < '3.1.0': + cmake_version = tuple( + int(d) + for d in re.search(r"version\s*([\d.]+)", out.stdout) + .group(1) + .split(".") + ) + if cmake_version < (3, 26, 2): raise RuntimeError("CMake >= 3.1.0 is required on Windows") super().run() def build_extension(self, ext): cmake_options = ext.cmake_options - extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name))) - cmake_args = ['-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY=' + extdir, - '-DPYTHON_EXECUTABLE=' + sys.executable, - '-DCMAKE_POSITION_INDEPENDENT_CODE=YES'] + extdir = Path(self.get_ext_fullpath(ext.name)).parent.resolve() + cmake_args = [ + f"-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY={extdir}", + f"-DPYTHON_EXECUTABLE={sys.executable}", + "-DCMAKE_POSITION_INDEPENDENT_CODE=YES", + ] library_output_dir = extdir - - cfg = 'Debug' if self.debug else 'Release' - build_args = ['--config', cfg] + + cfg = "Debug" if self.debug else "Release" + build_args = ["--config", cfg] if self.verbose: build_args.append("--verbose") - + if is_windows: - cmake_args += ['-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_{}={}'.format(cfg.upper(), extdir)] - if sys.maxsize > 2 ** 32: - cmake_args += ['-A', 'x64'] - build_args += ['--', '/m', '/verbosity:minimal'] + cmake_args += [f"-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_{cfg.upper()}={extdir}"] + if sys.maxsize > 2**32: + cmake_args += ["-A", "x64"] + build_args += ["--", "/m", "/verbosity:minimal"] library_name_format = "{}.lib" else: - cmake_args += ['-DCMAKE_BUILD_TYPE=' + cfg] - build_args += ['--', '-j2'] + cmake_args += ["-DCMAKE_BUILD_TYPE=" + cfg] + build_args += ["--", "-j2"] library_name_format = "lib{}.a" - + env = os.environ.copy() - env['CXXFLAGS'] = '{} -DVERSION_INFO=\\"{}\\"'.format(env.get('CXXFLAGS', ''), - self.distribution.get_version()) - if not os.path.exists(self.build_temp): - os.makedirs(self.build_temp) - + env["CXXFLAGS"] = '{} -DVERSION_INFO=\\"{}\\"'.format( + env.get("CXXFLAGS", ""), self.distribution.get_version() + ) + Path(self.build_temp).mkdir(parents=True, exist_ok=True) + subprocess.run( - ['cmake', cmake_options["dir"]] + cmake_args, + ["cmake", cmake_options["dir"]] + cmake_args, cwd=self.build_temp, env=env, - check=True + check=True, ) if self.force: subprocess.run( - ['cmake', '--build', '.', '--target', 'clean'] + build_args, + ["cmake", "--build", ".", "--target", "clean"] + build_args, cwd=self.build_temp, - check=True + check=True, ) for target, target_output in cmake_options["targets"].items(): if self.verbose: - print(['cmake', '--build', '.', '--target', target] + build_args) + print(["cmake", "--build", ".", "--target", target] + build_args) subprocess.run( - ['cmake', '--build', '.', '--target', target] + build_args, + ["cmake", "--build", ".", "--target", target] + build_args, cwd=self.build_temp, - check=True + check=True, ) ext.extra_objects.append( - os.path.join(library_output_dir, library_name_format.format(target)) + os.fspath( + library_output_dir.joinpath(library_name_format.format(target)) + ) ) super().build_extension(ext) -cpp_code_dir = os.path.join(os.path.dirname(__file__), "Source") +cpp_code_dir = os.fspath(file_dir.joinpath("Source")) custom_include_paths = [ cpp_code_dir, ] @@ -114,9 +125,9 @@ def build_extension(self, ext): ext_modules = [ CMakeExtension( - "_dolphin_memory_engine", + "dolphin_memory_engine._dolphin_memory_engine", [ - os.path.join(file_dir, "_dolphin_memory_engine.pyx"), + os.fspath(file_dir.joinpath("_dolphin_memory_engine.pyx")), ], cmake_options={ "dir": cpp_code_dir, @@ -124,10 +135,9 @@ def build_extension(self, ext): "dolphin-memory-engine": "lib", }, }, - language='c++', + language="c++", extra_compile_args=extra_compile_args, - extra_objects=[ - ], + extra_objects=[], ) ] @@ -142,8 +152,8 @@ def create_extension(template, kwds): ext_modules, include_path=custom_include_paths, compiler_directives={ - 'embedsignature': True, - 'language_level': '3', + "embedsignature": True, + "language_level": "3", }, create_extension=create_extension, ) @@ -151,12 +161,10 @@ def create_extension(template, kwds): for ext_module in cythonized_ext_modules: ext_module.include_dirs = custom_include_paths + setup( - use_scm_version={ - "local_scheme": "no-local-version", - }, cmdclass={ - 'build_ext': CMakeBuild, + "build_ext": CMakeBuild, }, ext_modules=cythonized_ext_modules, ) From 1bb2579af476756f417d345e0aeb95719d3d31bb Mon Sep 17 00:00:00 2001 From: Henrique Gemignani Passos Lima Date: Fri, 14 Jul 2023 15:56:13 +0300 Subject: [PATCH 06/10] Update gitignore --- .gitignore | 45 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 7e8a751..656df46 100644 --- a/.gitignore +++ b/.gitignore @@ -16,13 +16,44 @@ Source/.vs/ Source/.vscode/ /Source/out -*.pyc +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class -/.eggs -/build -/venv +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ /linux-venv -/dist + +# Cython /_dolphin_memory_engine.cpp -/dolphin_memory_engine.egg-info -/*.pyd + +# Project +/python_src/dolphin_memory_engine/version.py \ No newline at end of file From b1fa73006dfed69c95ac4f00c8ad1062b158f821 Mon Sep 17 00:00:00 2001 From: Henrique Gemignani Passos Lima Date: Fri, 14 Jul 2023 15:56:23 +0300 Subject: [PATCH 07/10] Include version --- pyproject.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 031443f..0ce56e1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,4 +32,6 @@ content-type = "text/markdown" Homepage = "https://github.com/henriquegemignani/py-dolphin-memory-engine" [tool.setuptools_scm] +version_scheme = "guess-next-dev" local_scheme = "no-local-version" +write_to = "python_src/dolphin_memory_engine/version.py" From 927830073334921bcac02591d919da1eaa635d57 Mon Sep 17 00:00:00 2001 From: Henrique Gemignani Passos Lima Date: Fri, 14 Jul 2023 15:58:19 +0300 Subject: [PATCH 08/10] Add dependabot --- .github/dependabot.yml | 21 +++++++++++++++++++++ .github/workflows/dependabot.yml | 23 +++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..9c8d871 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,21 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: "pip" # See documentation for possible values + directory: "/" # Location of package manifests + schedule: + interval: "weekly" + labels: + - "dependencies" + open-pull-requests-limit: 2 + + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" + labels: + - "dependencies" diff --git a/.github/workflows/dependabot.yml b/.github/workflows/dependabot.yml new file mode 100644 index 0000000..eaa5591 --- /dev/null +++ b/.github/workflows/dependabot.yml @@ -0,0 +1,23 @@ +name: Dependabot auto-merge +on: pull_request + +permissions: + contents: write + pull-requests: write + +jobs: + dependabot: + runs-on: ubuntu-latest + if: ${{ github.actor == 'dependabot[bot]' }} + steps: + - name: Dependabot metadata + id: metadata + uses: dependabot/fetch-metadata@v1 + with: + github-token: "${{ secrets.GITHUB_TOKEN }}" + + - name: Enable auto-merge for Dependabot PRs + run: gh pr merge --auto --merge "$PR_URL" + env: + PR_URL: ${{github.event.pull_request.html_url}} + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} \ No newline at end of file From 9e45cb66b5e52a32395444025c691d9968a9614f Mon Sep 17 00:00:00 2001 From: Henrique Gemignani Passos Lima Date: Fri, 14 Jul 2023 16:00:13 +0300 Subject: [PATCH 09/10] Minor CI improvements --- .github/workflows/python.yml | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 6046ccc..894b497 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -21,7 +21,7 @@ jobs: - '3.8' - '3.9' - '3.10' - - '3.11-dev' + - '3.11' runs-on: ${{ matrix.os }} name: Wheel for ${{ matrix.os }} (${{ matrix.python }}) @@ -42,11 +42,7 @@ jobs: run: python -m pip install --upgrade build pip - name: build wheel - run: python -m build --wheel - - - name: build sdist - run: python -m build --sdist - if: ${{ matrix.os == 'macos-latest' && matrix.python == '3.10' }} + run: python -m build - name: Store the packages uses: actions/upload-artifact@v3 @@ -82,10 +78,10 @@ jobs: - run: /opt/python/${{ matrix.python }}/bin/python -m venv .venv - name: Install Python packages - run: .venv/bin/python -m pip install --upgrade build pip auditwheel + run: .venv/bin/python -m pip install --upgrade build pip auditwheel setuptools - - name: build wheel - run: .venv/bin/python -m build --wheel + - name: build + run: .venv/bin/python -m build - name: multilinux stuff run: | @@ -117,7 +113,7 @@ jobs: - {version: '3.8', wheel: 'cp38-cp38'} - {version: '3.9', wheel: 'cp39-cp39'} - {version: '3.10', wheel: 'cp310-cp310'} - - {version: '3.11-dev', wheel: 'cp311-cp311'} + - {version: '3.11', wheel: 'cp311-cp311'} steps: - name: Checkout @@ -158,10 +154,10 @@ jobs: - name: Publish 📦 to TestPyPI if: ${{ github.ref == 'refs/heads/main' }} - uses: pypa/gh-action-pypi-publish@master + uses: pypa/gh-action-pypi-publish@release/v1 with: password: ${{ secrets.testpypi_password }} - repository_url: https://test.pypi.org/legacy/ + repository-url: https://test.pypi.org/legacy/ - name: Publish 📦 to PyPI if: ${{ startsWith(github.ref, 'refs/tags/') }} From 200f2d8a085d702aa6d674002f9a390912a62413 Mon Sep 17 00:00:00 2001 From: Henrique Gemignani Passos Lima Date: Fri, 14 Jul 2023 16:01:12 +0300 Subject: [PATCH 10/10] Declare pytest as test dependency --- .github/workflows/python.yml | 4 ++-- pyproject.toml | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 894b497..46b63e4 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -131,10 +131,10 @@ jobs: path: dist/ - name: Install Python packages - run: python -m pip install --upgrade pip pytest + run: python -m pip install --upgrade pip - name: install built wheel - run: python -m pip install dist/*-${{ matrix.python.wheel }}-*${{ matrix.os.wheel }}.whl + run: python -m pip install "$(ls dist/*-${{ matrix.python.wheel }}-*${{ matrix.os.wheel }}.whl)[test]" shell: bash - name: test diff --git a/pyproject.toml b/pyproject.toml index 0ce56e1..bfb5f4f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,6 +31,11 @@ content-type = "text/markdown" [project.urls] Homepage = "https://github.com/henriquegemignani/py-dolphin-memory-engine" +[project.optional-dependencies] +test = [ + "pytest", +] + [tool.setuptools_scm] version_scheme = "guess-next-dev" local_scheme = "no-local-version"