From ab9dec7a943a77f03bcb02da6d6f0277bf02aa38 Mon Sep 17 00:00:00 2001 From: Ross Allen Date: Wed, 15 May 2024 13:23:32 -0700 Subject: [PATCH] migrating to pyproject package management --- CHANGELOG.md | 5 +++++ README.md | 1 + environment.yml | 3 +-- pyproject.toml | 34 ++++++++++++++++++++++++++++++++++ requirements.txt | 1 - setup.py | 25 ------------------------- src/kspdg/__init__.py | 5 +++++ src/kspdg/version.py | 8 -------- 8 files changed, 46 insertions(+), 36 deletions(-) create mode 100644 pyproject.toml delete mode 100644 requirements.txt delete mode 100644 setup.py delete mode 100644 src/kspdg/version.py diff --git a/CHANGELOG.md b/CHANGELOG.md index d4f6f8a..14be871 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,14 +9,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- `pyproject.toml` for package and dependency management + ### Fixed ### Changed +- Updated `setup.py` to delegate most package management to `pyproject.toml`; maintains the get_version functionality - Updated copyright year in headers ### Removed +- `setup.py` and `version.py` since single-source version moved to `pyproject.toml` and `kspdg/__init__.py`. See https://packaging.python.org/en/latest/guides/single-sourcing-package-version/ +- `requirements.txt` since there are no "pinned" or "concrete" dependencies as kspdg is not (yet?) intended to be released as a stand-alone app. For further information about the intended role of requirements.txt, see and [setup vs requirements](https://caremad.io/posts/2013/07/setup-vs-requirement/) and [use of requirements w/ pyproject](https://stackoverflow.com/questions/74508024/is-requirements-txt-still-needed-when-using-pyproject-toml) - KSPDG Challenge announcement from README ## [v0.5.1] - 2024.01.09 diff --git a/README.md b/README.md index 1a8d73f..5ce62a5 100644 --- a/README.md +++ b/README.md @@ -205,6 +205,7 @@ _Future Work_ ### Verify Installation +__TODO:__ Update install instructions to reflect testing w/ new `pyproject.toml` and `optional-dependencies` __NOTE:__ Because the KSPDG environments are inexorably linked to the KSP game engine, many of the library's unit/integration test can only be run when a particular game mission file has been loaded and running. This means that verifying installation and testing during code development is a bit more involved than just a single `pytest` call __Serverless Tests:__ Quick test to run without KSP game engine running nor kRPC server connection diff --git a/environment.yml b/environment.yml index 4752b60..98c3d54 100644 --- a/environment.yml +++ b/environment.yml @@ -4,7 +4,6 @@ channels: dependencies: - python=3 - ipython - - pytest - pip - pip: - - -r requirements.txt + - -e . diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..f1b0bdc --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,34 @@ +# New way to specify project dependencies +# Ref: +# https://peps.python.org/pep-0518/ +# Example: https://github.com/Farama-Foundation/Gymnasium/blob/main/pyproject.toml +# Example: https://github.com/pypa/sampleproject/blob/main/pyproject.toml +# Guide (user-friendly): https://packaging.python.org/en/latest/guides/writing-pyproject-toml/ +# Specification (technical, formal): https://packaging.python.org/en/latest/specifications/pyproject-toml/ + +[build-system] +requires = ["setuptools >= 61.0.0"] # to 61 or greater support single-source versioning +build-backend = "setuptools.build_meta" + +[project] +name = "kspdg" +description = "Non-cooperative satellite operations challenge problems implemented in the Kerbal Space Program game engine" +readme = "README.md" +requires-python = ">=3" + +dependencies = [ + "krpc", + "numpy", + "gymnasium", + "astropy" +] + +# single source versioning (see tool.setuptools.dynamic table +# https://packaging.python.org/en/latest/guides/single-sourcing-package-version/ +dynamic = ["version"] + +[tool.setuptools.dynamic] +version = {attr = "kspdg.__version__"} + +[project.optional-dependencies] +testing = ["pytest"] diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 2edd125..0000000 --- a/requirements.txt +++ /dev/null @@ -1 +0,0 @@ --e . # deconflicting setup.py and requirements.txt, see https://caremad.io/posts/2013/07/setup-vs-requirement/ \ No newline at end of file diff --git a/setup.py b/setup.py deleted file mode 100644 index f512942..0000000 --- a/setup.py +++ /dev/null @@ -1,25 +0,0 @@ -from setuptools import setup, find_packages - -def get_version(): - path = "src/kspdg/version.py" - with open(path) as file: - lines = file.readlines() - - for line in lines: - if line.startswith("VERSION"): - return line.strip().split("=")[-1].strip().strip('"') - raise RuntimeError("bad version data in __init__.py") - -setup(name="kspdg", - version=get_version(), - packages=find_packages('src'), - package_dir={'': 'src'}, - python_requires=">=3", - install_requires=[ - "setuptools", - "krpc", - "numpy", - "gymnasium", - "astropy" - ] - ) diff --git a/src/kspdg/__init__.py b/src/kspdg/__init__.py index 9c8f680..728701e 100644 --- a/src/kspdg/__init__.py +++ b/src/kspdg/__init__.py @@ -2,6 +2,11 @@ # Subject to FAR 52.227-11 – Patent Rights – Ownership by the Contractor (May 2014). # SPDX-License-Identifier: MIT +# Single-sourcing package version +# https://packaging.python.org/guides/single-sourcing-package-version/ + +__version__ = "0.6.0" + # these imports make the individual environments accessible at the top-level # of the library and assign an environment version number # If the underlying environment changes, then the version number should be diff --git a/src/kspdg/version.py b/src/kspdg/version.py deleted file mode 100644 index 462a0e2..0000000 --- a/src/kspdg/version.py +++ /dev/null @@ -1,8 +0,0 @@ -# Copyright (c) 2024, MASSACHUSETTS INSTITUTE OF TECHNOLOGY -# Subject to FAR 52.227-11 – Patent Rights – Ownership by the Contractor (May 2014). -# SPDX-License-Identifier: MIT - -# Single-sourcing package version -# https://packaging.python.org/guides/single-sourcing-package-version/ - -VERSION = "0.5.1"