Skip to content
Merged
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: 3 additions & 6 deletions minihack/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import random
import gymnasium as gym
import numpy as np
import pkg_resources
from importlib_resources import files
from typing import Tuple

from nle import _pynethack, nethack
Expand All @@ -17,10 +17,7 @@

PATH_DAT_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "dat")
LIB_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "lib")
PATCH_SCRIPT = os.path.join(
pkg_resources.resource_filename("minihack", "scripts"),
"mh_patch_nhdat.sh",
)
PATCH_SCRIPT = files("minihack.scripts").joinpath("mh_patch_nhdat.sh")
MH_FULL_ACTIONS = list(FULL_ACTIONS)
try:
MH_FULL_ACTIONS.remove(nethack.MiscDirection.UP)
Expand All @@ -38,7 +35,7 @@
)
except AttributeError:
NLE_EXTRA_V081_ACTIONS = ()
HACKDIR = pkg_resources.resource_filename("nle", "nethackdir")
HACKDIR = files("nle").joinpath("nethackdir")

RGB_MAX_VAL = 255
N_TILE_PIXEL = 16
Expand Down
7 changes: 2 additions & 5 deletions minihack/envs/boxohack.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@
import random

import numpy as np
import pkg_resources
from importlib_resources import files
from nle import nethack
from minihack.envs import register
from minihack import LevelGenerator, MiniHackNavigation

LEVELS_PATH = os.path.join(
pkg_resources.resource_filename("minihack", "dat"),
"boxoban-levels-master",
)
LEVELS_PATH = files("minihack.dat").joinpath("boxoban-levels-master")
# The agent can only move towards 4 cardinal directions (instead of default 8)
MOVE_ACTIONS = tuple(nethack.CompassCardinalDirection)

Expand Down
4 changes: 2 additions & 2 deletions minihack/scripts/download_boxoban_levels.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import os
import zipfile
import pkg_resources
from importlib_resources import files

DESTINATION_PATH = pkg_resources.resource_filename("minihack", "dat")
DESTINATION_PATH = files("minihack.dat")
BOXOBAN_REPO_URL = (
"https://github.com/deepmind/boxoban-levels/archive/refs/heads/master.zip"
)
Expand Down
2 changes: 1 addition & 1 deletion minihack/scripts/get_nhwiki_data.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright (c) Facebook, Inc. and its affiliates.

DATA_DIR=$(python -c 'import pkg_resources; print(pkg_resources.resource_filename("nle", "minihack/dat"), end="")')
DATA_DIR=$(python -c 'from importlib_resources import files; print(files("nle").joinpath("minihack").joinpath("dat"), end="")')

wget https://www.dropbox.com/s/6qbfmsr3l89sip0/nethackwikidata.json

Expand Down
7 changes: 2 additions & 5 deletions minihack/tiles/glyph_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from minihack.tiles import glyph2tile, MAXOTHTILE
from nle.nethack import MAX_GLYPH
import numpy as np
import pkg_resources
from importlib_resources import files
import pickle
import os

Expand All @@ -19,10 +19,7 @@ def load_tiles(self):
If it doesn't, call make_tiles.py in win/
"""

tile_rgb_path = os.path.join(
pkg_resources.resource_filename("minihack", "tiles"),
"tiles.pkl",
)
tile_rgb_path = files("minihack.tiles").joinpath("tiles.pkl")

return pickle.load(open(tile_rgb_path, "rb"))

Expand Down
4 changes: 2 additions & 2 deletions minihack/wiki.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from typing import List
from urllib.parse import unquote

import pkg_resources
from importlib_resources import files

try:
import inflect
Expand All @@ -20,7 +20,7 @@
PREPROCESSING_ALLOWED = False
import_error = error

DATA_DIR_PATH = pkg_resources.resource_filename("nle", "minihack/dat")
DATA_DIR_PATH = files("nle").joinpath("minihack").joinpath("dat")

EXCEPTIONS = (
"floor of a room",
Expand Down
7 changes: 6 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@
]
}

install_requires = ["numpy>=1.16", "gymnasium", "setuptools"]
install_requires = [
"numpy>=1.16",
"gymnasium",
"setuptools",
"importlib-resources",
]
if not os.getenv("READTHEDOCS"):
install_requires.append("nle")

Expand Down
Loading