Skip to content

Commit

Permalink
bug: fix install from pypi source release (#1064)
Browse files Browse the repository at this point in the history
* fix

Signed-off-by: Jinjing.Zhou <allenzhou@tensorchord.ai>

* lint

Signed-off-by: Jinjing.Zhou <allenzhou@tensorchord.ai>

* lint2

Signed-off-by: Jinjing.Zhou <allenzhou@tensorchord.ai>

* address comment

Signed-off-by: Jinjing.Zhou <allenzhou@tensorchord.ai>

* fix

Signed-off-by: Jinjing.Zhou <allenzhou@tensorchord.ai>

* fix

Signed-off-by: Jinjing.Zhou <allenzhou@tensorchord.ai>

* fix

Signed-off-by: Jinjing.Zhou <allenzhou@tensorchord.ai>

Signed-off-by: Jinjing.Zhou <allenzhou@tensorchord.ai>
  • Loading branch information
VoVAllen authored Oct 20, 2022
1 parent 9d0afc4 commit 672bcd7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ build-release:
-X $(ROOT)/pkg/version.gitTag=$(GIT_TAG)" \
$(CMD_DIR)/$${target}; \
done
@[[ ! -z "$(GIT_TAG)" ]] && echo "$(GIT_TAG)" > .GIT_TAG_INFO
@$(MAKE) generate-git-tag-info

generate-git-tag-info:
[[ ! -z "$(GIT_TAG)" ]] && echo "$(GIT_TAG)" > .GIT_TAG_INFO || true

help: ## Display this help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z0-9_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
Expand Down
21 changes: 18 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import distutils.command.sdist
import os
import shutil
from setuptools import setup, Extension, find_packages
Expand All @@ -24,16 +25,19 @@


def build_envd_if_not_found():
if not os.path.exists("bin/envd"):
if not os.path.isfile("bin/envd"):
logging.info("envd not found. Build from scratch")
try:
with open(".GIT_TAG_INFO") as f:
logging.info("Use build_tag from envd._version")
logging.info("Use build_tag from .GIT_TAG_INFO")
tag = f.read().strip()
logging.info("start building envd from source")
errno = subprocess.call(
["make", "build-release", "GIT_TAG={}".format(tag)]
)
except:
logging.warning(".GIT_TAG_INFO not found")
logging.info("start building envd from source")
errno = subprocess.call(["make", "build-release"])
assert errno == 0, "Failed to build envd"

Expand All @@ -53,6 +57,17 @@ def build_extension(self, ext: Extension) -> None:
shutil.copy("bin/envd", bin_path)


class SdistCommand(distutils.command.sdist.sdist):
def run(self):
errno = subprocess.call(["make", "generate-git-tag-info"])
assert errno == 0, "Failed to generate git tag info"
if not os.path.isfile(".GIT_TAG_INFO"):
logging.warning(".GIT_TAG_INFO not found")
else:
logging.info(".GIT_TAG_INFO generated")
super().run()


def get_version():
# Remove prefix v in versioning
build_envd_if_not_found()
Expand Down Expand Up @@ -103,5 +118,5 @@ def get_version():
ext_modules=[
EnvdExtension(name="envd", sources=["cmd/*"]),
],
cmdclass=dict(build_ext=EnvdBuildExt),
cmdclass=dict(build_ext=EnvdBuildExt, sdist=SdistCommand),
)

0 comments on commit 672bcd7

Please sign in to comment.