Skip to content

Commit a5a1c8c

Browse files
committed
Modernize project to support install with uv
1 parent 393947e commit a5a1c8c

File tree

9 files changed

+1492
-90
lines changed

9 files changed

+1492
-90
lines changed

.github/workflows/lint_python.yml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@ jobs:
1111
name: Check Python linting
1212
runs-on: ubuntu-latest
1313
steps:
14-
- uses: actions/setup-python@v5
14+
- name: Install the latest version of uv.
15+
uses: astral-sh/setup-uv@v5
1516
with:
16-
python-version: '3.13'
17+
python-version: "3.13"
18+
1719
- uses: actions/checkout@v4
18-
- run: pip install -q uv && uv pip install --system ruff==0.4.3 isort
19-
- run: ruff format --check --diff .
20-
- run: ruff check
21-
- run: isort -c --diff nle/
20+
with:
21+
submodules: true
22+
- run: uv sync
23+
- run: uv run ruff format --check --diff .
24+
- run: uv run ruff check
25+
- run: uv run isort -c --diff nle/

.github/workflows/test_and_deploy.yml

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ jobs:
1616
os: [ubuntu-latest, macos-latest]
1717
fail-fast: false
1818
steps:
19-
- name: Setup Python ${{ matrix.python-version }} env
20-
uses: actions/setup-python@v5
19+
- name: Install the latest version of uv.
20+
uses: astral-sh/setup-uv@v5
2121
with:
2222
python-version: ${{ matrix.python-version }}
23-
- name: Ensure latest pip, wheel & setuptools
24-
run: python -m pip install -q --upgrade pip wheel setuptools
25-
- name: Install dependencies
23+
- name: Install the latest version of uv.
24+
uses: astral-sh/setup-uv@v5
25+
with:
26+
python-version: ${{ matrix.python-version }}
27+
- name: Install non-python build dependencies
2628
run: |
2729
if [ "$RUNNER_OS" == "Linux" ]; then
2830
sudo apt-get update && sudo apt-get install -yq \
@@ -36,10 +38,11 @@ jobs:
3638
software-properties-common
3739
fi
3840
- uses: actions/checkout@v4
39-
- name: Install from repo in test mode
40-
run: pip install -e '.[dev]'
41-
- name: Run tests
42-
run: python -m pytest --import-mode=append -svx nle/tests
41+
- name: Install package using uv
42+
run: uv sync
43+
- name: Run tests using uv
44+
run: uv run --no-sync pytest --import-mode=append -svx
45+
4346
test_sdist_3_10:
4447
name: Test sdist on MacOS w/ Py3.10
4548
needs: test_repo
@@ -51,6 +54,9 @@ jobs:
5154
python-version: '3.10'
5255
- name: Ensure latest pip, wheel & setuptools
5356
run: python -m pip install -q --upgrade pip wheel setuptools
57+
- name: Install dependencies
58+
run: |
59+
brew install cmake
5460
- uses: actions/checkout@v4
5561
- name: Generate sdist
5662
run: |
@@ -77,6 +83,9 @@ jobs:
7783
python-version: 3.13
7884
- name: Ensure latest pip, wheel & setuptools
7985
run: python -m pip install -q --upgrade pip wheel setuptools
86+
- name: Install dependencies
87+
run: |
88+
brew install cmake
8089
- uses: actions/checkout@v4
8190
- name: Generate sdist
8291
run: |

nle/agent/agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104

105105
logging.basicConfig(
106106
format=(
107-
"[%(levelname)s:%(process)d %(module)s:%(lineno)d %(asctime)s] " "%(message)s"
107+
"[%(levelname)s:%(process)d %(module)s:%(lineno)d %(asctime)s] %(message)s"
108108
),
109109
level=logging.INFO,
110110
)

nle/dataset/populate_db.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def add_altorg_directory(path, name, filename=nld.db.DB):
151151
game_gen = game_data_generator(xlogfile, separator=sep)
152152
insert_sql = f"""
153153
INSERT INTO games
154-
VALUES (NULL, {','.join('?' for _ in XLOGFILE_COLUMNS)} )
154+
VALUES (NULL, {",".join("?" for _ in XLOGFILE_COLUMNS)} )
155155
"""
156156
c.executemany(insert_sql, game_gen)
157157

@@ -293,7 +293,7 @@ def add_nledata_directory(path, name, filename=nld.db.DB):
293293
game_gen = game_data_generator(xlogfile, filter=_filter)
294294
insert_sql = f"""
295295
INSERT INTO games
296-
VALUES (NULL, {','.join('?' for _ in XLOGFILE_COLUMNS)} )
296+
VALUES (NULL, {",".join("?" for _ in XLOGFILE_COLUMNS)} )
297297
"""
298298
c.executemany(insert_sql, game_gen)
299299
gameids = nld.db.get_most_recent_games(c.rowcount, conn=c)

nle/scripts/ttyrec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"-1",
1616
"--no_input",
1717
action="store_true",
18-
help=("Save in ttyrec (not ttyrec2) format, " "without input data"),
18+
help=("Save in ttyrec (not ttyrec2) format, without input data"),
1919
)
2020
parser.add_argument(
2121
"-e", "--execute", metavar="CMD", help="command to run (default: /bin/sh)"

nle/tests/test_converter.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,38 @@
99
from nle.dataset import Converter
1010

1111
# From
12-
# https://alt.org/nethack/trd/?file=https://s3.amazonaws.com/altorg/ttyrec/Anarchos/2020-10-03.17:27:10.ttyrec.bz2 # noqa: B950
12+
# https://alt.org/nethack/trd/?file=https://s3.amazonaws.com/altorg/ttyrec/Anarchos/2020-10-03.17:27:10.ttyrec.bz2
1313
TTYREC_2020 = "2020-10-03.17_27_10.ttyrec.bz2"
1414
COLSROWS = "2020-10-03.17_27_10.rowscols.txt"
1515
TIMESTAMPS = "2020-10-03.17_27_10.timestamps.txt.bz2"
1616
FINALFRAME = "2020-10-03.17_27_10.finalframe.txt"
1717
FINALFRAMECOLORS = "2020-10-03.17_27_10.finalframe.colors.txt"
1818

1919
# From
20-
# https://alt.org/nethack/trd/?file=https://s3.amazonaws.com/altorg/ttyrec/Qvazzler/2009-02-05.10:33:51.ttyrec.bz2 # noqa: B950
20+
# https://alt.org/nethack/trd/?file=https://s3.amazonaws.com/altorg/ttyrec/Qvazzler/2009-02-05.10:33:51.ttyrec.bz2
2121
# This ttyrec uses IBMGraphics (code page 437)
2222
TTYREC_IBMGRAPHICS = "2009-02-05.10_33_51.ttyrec.bz2"
2323
TTYREC_IBMGRAPHICS_FRAME_10 = "2009-02-05.10_33_51.frame.10.txt"
2424

2525
# From
26-
# https://alt.org/nethack/trd/?file=https://s3.amazonaws.com/altorg/ttyrec/moo22/2018-09-27.00:20:39.ttyrec.bz2 # noqa: B950
26+
# https://alt.org/nethack/trd/?file=https://s3.amazonaws.com/altorg/ttyrec/moo22/2018-09-27.00:20:39.ttyrec.bz2
2727
TTYREC_2018 = "2018-09-27.00_20_39.ttyrec.bz2"
2828

2929
# From
30-
# https://alt.org/nethack/trd/?file=https://s3.amazonaws.com/altorg/ttyrec/mackeyth/2017-07-28.18:44:17.ttyrec.bz2 # noqa: B950
30+
# https://alt.org/nethack/trd/?file=https://s3.amazonaws.com/altorg/ttyrec/mackeyth/2017-07-28.18:44:17.ttyrec.bz2
3131
# This ttyrec uses DECGraphics (https://en.wikipedia.org/wiki/DEC_Special_Graphics)
3232
TTYREC_DECGRAPHICS = "2017-07-28.18_44_17.ttyrec.bz2"
3333
TTYREC_DECGRAPHICS_FRAME_10 = "2017-07-28.18_44_17.frame.10.txt"
3434

3535
# From
36-
# https://alt.org/nethack/trd/?file=https://s3.amazonaws.com/altorg/ttyrec/waIrus/2019-11-18.08:52:15.ttyrec.bz2 # noqa: B950
37-
# This ttyrec uses unknown control sequences - it looks like maybe VT420 with rectangle control. `ESC [ %d ; %d ; %d ; %d z` # noqa: B950
36+
# https://alt.org/nethack/trd/?file=https://s3.amazonaws.com/altorg/ttyrec/waIrus/2019-11-18.08:52:15.ttyrec.bz2
37+
# This ttyrec uses unknown control sequences - it looks like maybe VT420 with rectangle control. `ESC [ %d ; %d ; %d ; %d z`
3838
TTYREC_UNKGRAPHICS = "2019-11-18.08_52_15.ttyrec.bz2"
3939
TTYREC_UNKGRAPHICS_FRAME_10 = "2019-11-18.08_52_15.frame.10.txt"
4040

4141
# From
42-
# https://alt.org/nethack/trd/?file=https://s3.amazonaws.com/altorg/ttyrec/fare/2012-02-16.21:09:51.ttyrec.bz2 # noqa: B950
43-
# This ttyrec uses SHIFT IN and SHIFT OUT ASCII control sequences toggle DEC graphics set. # noqa: B950
42+
# https://alt.org/nethack/trd/?file=https://s3.amazonaws.com/altorg/ttyrec/fare/2012-02-16.21:09:51.ttyrec.bz2
43+
# This ttyrec uses SHIFT IN and SHIFT OUT ASCII control sequences toggle DEC graphics set.
4444
TTYREC_SHIFTIN = "2012-02-16.21_09_51.ttyrec.bz2"
4545
TTYREC_SHIFTIN_FRAME_10 = "2012-02-16.21_09_51.frame.10.txt"
4646

pyproject.toml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,69 @@
1+
[project]
2+
name = "nle"
3+
description = "The NetHack Learning Environment (NLE): a reinforcement learning environment based on NetHack"
4+
readme = "README.md"
5+
authors = [ { name = "The NLE Dev Team" } ]
6+
requires-python = ">=3.10"
7+
dynamic = ["classifiers", "version"]
8+
dependencies = [
9+
"pybind11>=2.2",
10+
"numpy>=1.16",
11+
"gymnasium==1.2.0"
12+
]
13+
14+
[project.license]
15+
file = "LICENSE"
16+
17+
[project.urls]
18+
Homepage = "https://github.com/NetHack-LE/nle"
19+
20+
[build-system]
21+
requires = ["setuptools", "pybind11>=2.2"]
22+
build-backend = "setuptools.build_meta"
23+
24+
[tool.setuptools.packages]
25+
find = { include = [
26+
"nle",
27+
"nle.dataset",
28+
"nle.env",
29+
"nle.nethack",
30+
"nle.agent",
31+
"nle.scripts",
32+
"nle.tests"
33+
]}
34+
35+
[project.scripts]
36+
nle-play = "nle.scripts.play:main"
37+
nle-ttyrec = "nle.scripts.ttyrec:main"
38+
nle-ttyplay = "nle.scripts.ttyplay:main"
39+
nle-ttyplay2 = "nle.scripts.ttyplay2:main"
40+
nle-read-tty = "nle.scripts.read_tty:main"
41+
42+
[dependency-groups]
43+
dev = [
44+
"nle[dev]",
45+
]
46+
47+
[project.optional-dependencies]
48+
agent = [
49+
"torch>=1.3.1"
50+
]
51+
dev = [
52+
"pre-commit>=2.0.1",
53+
"isort>=5.13.2",
54+
"cmake_format>=0.6.10",
55+
"memory-profiler>=0.60.0",
56+
"pytest>=6.2.5",
57+
"pytest-benchmark>=3.4.1",
58+
"sphinx>=2.4.4",
59+
"sphinx-rtd-theme>=0.4.3",
60+
"setuptools>=69.5.1",
61+
"ruff>=0.4.3",
62+
]
63+
all = [
64+
"nle[agent,dev]"
65+
]
66+
167
[tool.black]
268
line-length = 88
369
target-version = ['py38']
@@ -68,3 +134,6 @@ manylinux-aarch64-image = "manylinux2014"
68134
[tool.cibuildwheel.macos]
69135
# For macOS wheels, we only need to install cmake
70136
before-all = "rm -rf {project}/build {project}/*.so {project}/CMakeCache.txt && brew install cmake"
137+
138+
[tool.pytest.ini_options]
139+
testpaths = ["nle/tests"]

setup.py

Lines changed: 1 addition & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
#
55
# List of environment variables used:
66
#
7-
# NLE_PACKAGE_NAME
8-
# Prefix of the generated package (defaults to "nle").
9-
#
107
# NLE_BUILD_RELEASE
118
# If set, builds wheel (s)dist such as to prepare it for upload to PyPI.
129
#
@@ -71,48 +68,7 @@ def build_extension(self, ext):
7168
sys.exit(1)
7269

7370

74-
packages = [
75-
"nle",
76-
"nle.dataset",
77-
"nle.env",
78-
"nle.nethack",
79-
"nle.agent",
80-
"nle.scripts",
81-
"nle.tests",
82-
]
83-
84-
entry_points = {
85-
"console_scripts": [
86-
"nle-play = nle.scripts.play:main",
87-
"nle-ttyrec = nle.scripts.ttyrec:main",
88-
"nle-ttyplay = nle.scripts.ttyplay:main",
89-
"nle-ttyplay2 = nle.scripts.ttyplay2:main",
90-
"nle-read-tty = nle.scripts.read_tty:main",
91-
]
92-
}
93-
94-
95-
extras_deps = {
96-
"dev": [
97-
"pre-commit>=2.0.1",
98-
"isort>=5.13.2",
99-
"cmake_format>=0.6.10",
100-
"memory-profiler>=0.60.0",
101-
"pytest>=6.2.5",
102-
"pytest-benchmark>=3.4.1",
103-
"sphinx>=2.4.4",
104-
"sphinx-rtd-theme>=0.4.3",
105-
"setuptools>=69.5.1",
106-
"ruff>=0.4.3",
107-
],
108-
"agent": ["torch>=1.3.1"],
109-
}
110-
111-
extras_deps["all"] = [item for group in extras_deps.values() for item in group]
112-
113-
11471
if __name__ == "__main__":
115-
package_name = os.getenv("NLE_PACKAGE_NAME", "nle")
11672
cwd = os.path.dirname(os.path.abspath(__file__))
11773
version = open("version.txt", "r").read().strip()
11874
sha = "Unknown"
@@ -128,36 +84,18 @@ def build_extension(self, ext):
12884

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

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

138-
with open("README.md") as f:
139-
long_description = f.read()
140-
14195
setuptools.setup(
142-
name=package_name,
14396
version=version,
144-
description=(
145-
"The NetHack Learning Environment (NLE): "
146-
"a reinforcement learning environment based on NetHack"
147-
),
148-
long_description=long_description,
149-
long_description_content_type="text/markdown",
150-
author="The NLE Dev Team",
151-
url="https://github.com/NetHack-LE/nle",
152-
license="NetHack General Public License",
153-
entry_points=entry_points,
154-
packages=packages,
15597
ext_modules=[setuptools.Extension("nle", sources=[])],
15698
cmdclass={"build_ext": CMakeBuild},
157-
setup_requires=["pybind11>=2.2"],
158-
install_requires=["pybind11>=2.2", "numpy>=1.16", "gymnasium==1.2.0"],
159-
extras_require=extras_deps,
160-
python_requires=">=3.10",
16199
classifiers=[
162100
"License :: OSI Approved :: Nethack General Public License",
163101
"Development Status :: 5 - Production/Stable",

0 commit comments

Comments
 (0)