Skip to content

Commit

Permalink
Fixing dist packaging.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinzakka committed Mar 19, 2023
1 parent d45eb7d commit 852e268
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 85 deletions.
7 changes: 5 additions & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
recursive-include robopianist/models *.xml
recursive-include robopianist/models/hands/third_party *
recursive-include robopianist/soundfonts *.sf2
recursive-include robopianist/soundfonts *
recursive-include robopianist/music/data *
include robopianist/py.typed
include README.md
include LICENSE
include CITATION.cff
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,14 @@ RoboPianist is supported on both Linux and macOS and can be installed with Pytho
The recommended way to install this package is from source. Start by cloning the repository:

```bash
git clone https://github.com/google-research/robopianist.git
git clone https://github.com/google-research/robopianist.git && cd robopianist
```

Next, install the prerequisite dependencies:

```bash
cd robopianist

bash scripts/install_deps.sh

git submodule init && git submodule update
bash scripts/install_deps.sh
```

Finally, create a new conda environment and install RoboPianist in editable mode:
Expand All @@ -80,7 +77,7 @@ bash scripts/get_soundfonts.sh
First, install the prerequisite dependencies:

```bash
bash <(curl -s https://raw.githubusercontent.com/google-research/robopianist/main/scripts/install_deps.sh)
bash <(curl -s https://raw.githubusercontent.com/google-research/robopianist/main/scripts/install_deps.sh) --no-soundfonts
```

Next, create a new conda environment and install RoboPianist:
Expand Down
2 changes: 1 addition & 1 deletion robopianist/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from pathlib import Path

__version__ = "1.0.3"
__version__ = "1.0.4"

# Path to the root of the project.
_PROJECT_ROOT = Path(__file__).parent.parent
Expand Down
46 changes: 41 additions & 5 deletions scripts/install_deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,26 @@
# limitations under the License.
#
# Install dependencies (macOS and Linux).
# Command line arguments:
# --no-soundfonts: Skip downloading soundfonts.

set -x

SKIP_SOUNDFONTS=false
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
--no-soundfonts)
SKIP_SOUNDFONTS=true
shift
;;
*)
echo "Unknown argument: $key"
exit 1
;;
esac
done

# Install fluidsynth and portaudio.
if [[ $OSTYPE == darwin* ]]; then
# Install homebrew if not installed.
Expand All @@ -34,9 +51,28 @@ else
echo "Unsupported OS"
fi

# Download TimGM6mb.sf2 soundfont.
mkdir -p third_party/soundfonts
LINK=https://sourceforge.net/p/mscore/code/HEAD/tree/trunk/mscore/share/sound/TimGM6mb.sf2?format=raw
if [ ! -f third_party/soundfonts/TimGM6mb.sf2 ]; then
wget $LINK -O third_party/soundfonts/TimGM6mb.sf2
# Install soundfonts.
if [ "$SKIP_SOUNDFONTS" = false ]; then
# Download TimGM6mb.sf2 soundfont.
mkdir -p third_party/soundfonts
LINK=https://sourceforge.net/p/mscore/code/HEAD/tree/trunk/mscore/share/sound/TimGM6mb.sf2?format=raw
if [ ! -f third_party/soundfonts/TimGM6mb.sf2 ]; then
wget $LINK -O third_party/soundfonts/TimGM6mb.sf2
fi

# Copy soundfonts to robopianist.
mkdir -p robopianist/soundfonts
if [ ! -d "third_party/soundfonts" ]; then
echo "third_party/soundfonts does not exist. Run scripts/get_soundfonts.sh first."
exit 1
fi
cp -r third_party/soundfonts/* robopianist/soundfonts

# Copy shadow_hand menagerie model to robopianist.
mkdir -p robopianist/models/hands/third_party/shadow_hand
if [ ! -d "third_party/mujoco_menagerie/shadow_hand" ]; then
echo "third_party/mujoco_menagerie/shadow_hand does not exist. Run git submodule init && git submodule update first."
exit 1
fi
cp -r third_party/mujoco_menagerie/shadow_hand/* robopianist/models/hands/third_party/shadow_hand
fi
72 changes: 1 addition & 71 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,12 @@
# limitations under the License.

import re
import shutil
from distutils import cmd
from pathlib import Path

from setuptools import find_packages, setup
from setuptools.command.build_ext import build_ext
from setuptools.command.build_py import build_py

_here = Path(__file__).resolve().parent

_soundfont_dir = _here / "third_party" / "soundfonts"
_menagerie_dir = _here / "third_party" / "mujoco_menagerie"
_hand_dir = _here / "robopianist" / "models" / "hands" / "third_party"

name = "robopianist"

# Reference: https://github.com/patrick-kidger/equinox/blob/main/setup.py
Expand Down Expand Up @@ -86,62 +78,6 @@

keywords = "reinforcement-learning mujoco bimanual dexterous-manipulation piano"


class _CopyMenagerieModels(cmd.Command):
"""Copy the menagerie models to robopianist/models/hands/third_party/."""

def initialize_options(self) -> None:
pass

def finalize_options(self) -> None:
pass

def run(self) -> None:
if not _menagerie_dir.exists() or not list(_menagerie_dir.iterdir()):
raise RuntimeError(
"The menagerie directory is empty. Please run git submodule init &&"
"git submodule update to download the menagerie models."
)
if _hand_dir.exists():
shutil.rmtree(_hand_dir)
shutil.copytree(_menagerie_dir / "shadow_hand", _hand_dir / "shadow_hand")


class _CopySoundfonts(cmd.Command):
"""Copy the soundfonts to robopianist/soundfonts/."""

def initialize_options(self) -> None:
pass

def finalize_options(self) -> None:
pass

def run(self) -> None:
if not _soundfont_dir.exists() or not list(_soundfont_dir.iterdir()):
raise RuntimeError(
"The soundfont directory is empty. Please run "
"bash scripts/install_deps.sh to download the basic soundfont."
)
_package_soundfonts_dir = _here / "robopianist" / "soundfonts"
if _package_soundfonts_dir.exists():
shutil.rmtree(_package_soundfonts_dir)
shutil.copytree(_soundfont_dir, _package_soundfonts_dir)


class _BuildExt(build_ext):
def run(self) -> None:
self.run_command("copy_menagerie_models")
self.run_command("copy_soundfonts")
build_ext.run(self)


class _BuildPy(build_py):
def run(self) -> None:
self.run_command("copy_menagerie_models")
self.run_command("copy_soundfonts")
build_py.run(self)


setup(
name=name,
version=version,
Expand All @@ -157,18 +93,12 @@ def run(self) -> None:
license="Apache License 2.0",
license_files=("LICENSE",),
packages=find_packages(exclude=["examples"]),
include_package_data=True,
python_requires=">=3.8, <3.11",
install_requires=core_requirements,
classifiers=classifiers,
extras_require={
"test": test_requirements,
"dev": dev_requirements,
},
cmdclass={
"build_ext": _BuildExt,
"build_py": _BuildPy,
"copy_menagerie_models": _CopyMenagerieModels,
"copy_soundfonts": _CopySoundfonts,
},
zip_safe=False,
)

0 comments on commit 852e268

Please sign in to comment.