Repository: magenta/magenta

Issue:
Building the pip package shouldn't require installing Magenta dependencies
Currently, building the pip package requires installing Magenta dependencies like pretty_midi because setup.py does an `import magenta` to get the version number. We should move the version number into a separate file (version.py?) that is then referenced by both magenta/__init__.py and setup.py


Discussion:

Resolving patch:
diff --git a/magenta/__init__.py b/magenta/__init__.py
--- a/magenta/__init__.py
+++ b/magenta/__init__.py
@@ -20,19 +20,21 @@
   grep '//magenta' | \
   egrep  -v "/([^:/]+):\1$" | \
   sed -e 's/\/\//import /' -e 's/\//./' -e 's/:/./' -e  's/py_pb2/pb2/' | \
-  sort
+  LANG=C sort
 """
 
-__version__ = '0.1.5'
-
+import magenta.common.concurrency
 import magenta.common.sequence_example_lib
 import magenta.common.testing_lib
 import magenta.common.tf_lib
 import magenta.music.constants
+import magenta.music.encoder_decoder
 import magenta.music.events_lib
 import magenta.music.melodies_lib
+import magenta.music.melody_encoder_decoder
 import magenta.music.midi_io
 import magenta.music.midi_synth
+import magenta.music.model
 import magenta.music.note_sequence_io
 import magenta.music.notebook_utils
 import magenta.music.sequence_generator
@@ -40,8 +42,12 @@
 import magenta.music.sequences_lib
 import magenta.music.testing_lib
 import magenta.pipelines.dag_pipeline
+import magenta.pipelines.melody_pipelines
 import magenta.pipelines.pipeline
 import magenta.pipelines.pipelines_common
 import magenta.pipelines.statistics
 import magenta.protobuf.generator_pb2
 import magenta.protobuf.music_pb2
+import magenta.version
+
+from magenta.version import __version__
diff --git a/magenta/tools/pip/setup.py b/magenta/tools/pip/setup.py
--- a/magenta/tools/pip/setup.py
+++ b/magenta/tools/pip/setup.py
@@ -16,7 +16,11 @@
 from setuptools import find_packages
 from setuptools import setup
 
-import magenta
+# Bit of a hack to parse the version string stored in version.py without
+# executing __init__.py, which will end up requiring a bunch of dependencies to
+# execute (e.g., tensorflow, pretty_midi, etc.).
+# Makes the __version__ variable available.
+execfile('magenta/version.py')
 
 
 REQUIRED_PACKAGES = [
@@ -43,7 +47,7 @@
 
 setup(
     name='magenta',
-    version=magenta.__version__,
+    version=__version__,  # pylint: disable=undefined-variable
     description='Use machine learning to create art and music',
     long_description='',
     url='https://magenta.tensorflow.org/',
diff --git a/magenta/version.py b/magenta/version.py
new file mode 100644
--- /dev/null
+++ b/magenta/version.py
@@ -0,0 +1,22 @@
+# Copyright 2016 Google Inc. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+r"""Separate file for storing the current version of Magenta.
+
+Stored in a separate file so that setup.py can reference the version without
+pulling in all the dependencies in __init__.py.
+"""
+
+__version__ = '0.1.5'
+


Test patch: