Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions .gitmodules

This file was deleted.

60 changes: 40 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,22 @@ message(STATUS "HACKDIR set to: ${HACKDIR}")
set(VARDIR ${HACKDIR})
set(INSTDIR ${HACKDIR})

# pybind11 via FetchContent
include(FetchContent)
FetchContent_Declare(
pybind11
GIT_REPOSITORY https://github.com/pybind/pybind11.git
GIT_TAG v3.0.1)
FetchContent_MakeAvailable(pybind11)
find_package(pybind11 CONFIG REQUIRED)

# de-boost-ified version of boost.context via FetchContent
FetchContent_Declare(
deboost_context
GIT_REPOSITORY https://github.com/septag/deboost.context.git
GIT_HASH "259fc4103bad6bb484d5ff426ace56ac557107a4")
FetchContent_MakeAvailable(deboost_context)

add_compile_definitions(
GCC_WARN
NOCLIPPING
Expand All @@ -78,9 +94,6 @@ set(NLE_DAT_GEN ${nle_BINARY_DIR}/dat)
set(NLE_UTIL_GEN ${nle_BINARY_DIR}/util)

set(CMAKE_INSTALL_MESSAGE LAZY) # Don't tell us about up-to-date files.

# EXCLUDE_FROM_ALL: Don't install this static library into /usr/local.
add_subdirectory(third_party/deboost.context EXCLUDE_FROM_ALL)
add_subdirectory(util)
add_subdirectory(dat)

Expand All @@ -96,17 +109,26 @@ file(
"win/tty/*.c"
"win/rl/winrl.cc")

# static version of bzip2 library
add_library(
bz2_static STATIC
"third_party/bzip2/blocksort.c"
"third_party/bzip2/bzlib.c"
"third_party/bzip2/compress.c"
"third_party/bzip2/crctable.c"
"third_party/bzip2/decompress.c"
"third_party/bzip2/huffman.c"
"third_party/bzip2/randtable.c")
target_link_libraries(bz2_static)
# FetchContent for bzip2
include(FetchContent)
FetchContent_Declare(
bzip2
GIT_REPOSITORY git://sourceware.org/git/bzip2.git
GIT_TAG master)
FetchContent_MakeAvailable(bzip2)

# Manually add bzip2 source files from the downloaded directory
set(BZIP2_SOURCE_DIR ${bzip2_SOURCE_DIR})
set(BZIP2_SRC
${BZIP2_SOURCE_DIR}/blocksort.c
${BZIP2_SOURCE_DIR}/bzlib.c
${BZIP2_SOURCE_DIR}/compress.c
${BZIP2_SOURCE_DIR}/crctable.c
${BZIP2_SOURCE_DIR}/decompress.c
${BZIP2_SOURCE_DIR}/huffman.c
${BZIP2_SOURCE_DIR}/randtable.c)
add_library(bz2_static STATIC ${BZIP2_SRC})
target_include_directories(bz2_static PUBLIC ${BZIP2_SOURCE_DIR})

# terminal emulator library
add_library(tmt STATIC "third_party/libtmt/tmt.c")
Expand All @@ -120,7 +142,7 @@ target_include_directories(
nethack
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include ${NLE_INC_GEN} /usr/local/include
${CMAKE_CURRENT_SOURCE_DIR}/third_party/libtmt
${CMAKE_CURRENT_SOURCE_DIR}/third_party/bzip2)
$<TARGET_PROPERTY:bz2_static,SOURCE_DIR>)
# target_link_directories(nethack PUBLIC /usr/local/lib)

# Careful with -DMONITOR_HEAP: Ironically, it fails to fclose FILE* heaplog.
Expand All @@ -131,9 +153,8 @@ target_link_libraries(nethack PUBLIC m fcontext bz2_static tmt)
# dlopen wrapper library
add_library(nethackdl STATIC "sys/unix/nledl.c")
target_include_directories(
nethackdl
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/third_party/deboost.context/include)
nethackdl PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include
${deboost_context_SOURCE_DIR}/include)
target_link_libraries(nethackdl PUBLIC dl)

# rlmain C++ (test) binary
Expand All @@ -144,7 +165,6 @@ target_include_directories(rlmain PUBLIC ${NLE_INC_GEN})
add_dependencies(rlmain util) # For pm.h.

# pybind11 core python library.
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/third_party/pybind11)
pybind11_add_module(
_pynethack
win/rl/pynethack.cc
Expand All @@ -166,7 +186,7 @@ target_include_directories(
converter
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/third_party/libtmt
${CMAKE_CURRENT_SOURCE_DIR}/third_party/converter
${CMAKE_CURRENT_SOURCE_DIR}/third_party/bzip2)
$<TARGET_PROPERTY:bz2_static,SOURCE_DIR>)
target_link_libraries(converter PUBLIC bz2_static tmt)
if(CMAKE_BUILD_TYPE MATCHES Debug)
target_compile_options(converter PRIVATE -Wall -Wextra -pedantic -Werror)
Expand Down
63 changes: 63 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,63 @@
[project]
name = "nle"
description = "The NetHack Learning Environment (NLE): a reinforcement learning environment based on NetHack"
readme = "README.md"
authors = [ { name = "The NLE Dev Team" } ]
requires-python = ">=3.10"
dynamic = ["classifiers", "version"]
dependencies = [
"pybind11>=2.2",
"numpy>=1.16",
"gymnasium==1.2.0"
]

[project.license]
file = "LICENSE"

[project.urls]
Homepage = "https://github.com/NetHack-LE/nle"

[build-system]
requires = ["setuptools", "pybind11>=2.2"]
build-backend = "setuptools.build_meta"

[tool.setuptools.packages]
find = { include = [
"nle",
"nle.dataset",
"nle.env",
"nle.nethack",
"nle.agent",
"nle.scripts",
"nle.tests"
]}

[project.scripts]
nle-play = "nle.scripts.play:main"
nle-ttyrec = "nle.scripts.ttyrec:main"
nle-ttyplay = "nle.scripts.ttyplay:main"
nle-ttyplay2 = "nle.scripts.ttyplay2:main"
nle-read-tty = "nle.scripts.read_tty:main"

[dependency-groups]
dev = [
"pre-commit>=2.0.1",
"isort>=5.13.2",
"cmake_format>=0.6.10",
"memory-profiler>=0.60.0",
"pytest>=6.2.5",
"pytest-benchmark>=3.4.1",
"sphinx>=2.4.4",
"sphinx-rtd-theme>=0.4.3",
"setuptools>=69.5.1",
"ruff>=0.4.3",
]
agent = ["torch>=1.3.1"]
all = [
{include-group = "agent"},
{include-group = "dev"},
]

[tool.black]
line-length = 88
target-version = ['py38']
Expand Down Expand Up @@ -68,3 +128,6 @@ manylinux-aarch64-image = "manylinux2014"
[tool.cibuildwheel.macos]
# For macOS wheels, we only need to install cmake
before-all = "rm -rf {project}/build {project}/*.so {project}/CMakeCache.txt && brew install cmake"

[tool.pytest.ini_options]
testpaths = ["nle/tests"]
64 changes: 1 addition & 63 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
#
# List of environment variables used:
#
# NLE_PACKAGE_NAME
# Prefix of the generated package (defaults to "nle").
#
# NLE_BUILD_RELEASE
# If set, builds wheel (s)dist such as to prepare it for upload to PyPI.
#
Expand Down Expand Up @@ -71,48 +68,7 @@ def build_extension(self, ext):
sys.exit(1)


packages = [
"nle",
"nle.dataset",
"nle.env",
"nle.nethack",
"nle.agent",
"nle.scripts",
"nle.tests",
]

entry_points = {
"console_scripts": [
"nle-play = nle.scripts.play:main",
"nle-ttyrec = nle.scripts.ttyrec:main",
"nle-ttyplay = nle.scripts.ttyplay:main",
"nle-ttyplay2 = nle.scripts.ttyplay2:main",
"nle-read-tty = nle.scripts.read_tty:main",
]
}


extras_deps = {
"dev": [
"pre-commit>=2.0.1",
"isort>=5.13.2",
"cmake_format>=0.6.10",
"memory-profiler>=0.60.0",
"pytest>=6.2.5",
"pytest-benchmark>=3.4.1",
"sphinx>=2.4.4",
"sphinx-rtd-theme>=0.4.3",
"setuptools>=69.5.1",
"ruff>=0.4.3",
],
"agent": ["torch>=1.3.1"],
}

extras_deps["all"] = [item for group in extras_deps.values() for item in group]


if __name__ == "__main__":
package_name = os.getenv("NLE_PACKAGE_NAME", "nle")
cwd = os.path.dirname(os.path.abspath(__file__))
version = open("version.txt", "r").read().strip()
sha = "Unknown"
Expand All @@ -128,36 +84,18 @@ def build_extension(self, ext):

if sha != "Unknown" and not os.getenv("NLE_RELEASE_BUILD"):
version += "+" + sha[:7]
package_name = setuptools.find_packages()[0]
print("Building wheel {}-{}".format(package_name, version))

version_path = os.path.join(cwd, "nle", "version.py")
with open(version_path, "w") as f:
f.write("__version__ = '{}'\n".format(version))
f.write("git_version = {}\n".format(repr(sha)))

with open("README.md") as f:
long_description = f.read()

setuptools.setup(
name=package_name,
version=version,
description=(
"The NetHack Learning Environment (NLE): "
"a reinforcement learning environment based on NetHack"
),
long_description=long_description,
long_description_content_type="text/markdown",
author="The NLE Dev Team",
url="https://github.com/NetHack-LE/nle",
license="NetHack General Public License",
entry_points=entry_points,
packages=packages,
ext_modules=[setuptools.Extension("nle", sources=[])],
cmdclass={"build_ext": CMakeBuild},
setup_requires=["pybind11>=2.2"],
install_requires=["pybind11>=2.2", "numpy>=1.16", "gymnasium==1.2.0"],
extras_require=extras_deps,
python_requires=">=3.10",
classifiers=[
"License :: OSI Approved :: Nethack General Public License",
"Development Status :: 5 - Production/Stable",
Expand Down
1 change: 0 additions & 1 deletion third_party/bzip2
Submodule bzip2 deleted from fbc4b1
1 change: 0 additions & 1 deletion third_party/deboost.context
Submodule deboost.context deleted from 259fc4
1 change: 0 additions & 1 deletion third_party/pybind11
Submodule pybind11 deleted from ed5057
Loading