Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package #304

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
51 changes: 51 additions & 0 deletions package.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import os
import jittor as jt
import jittor_utils as jit_utils
package_path = "package"
python = "python"

f = open("tmp.txt", "w")
f.close()
cache_path = os.path.join(jit_utils.home(), ".cache", "jittor")
print("===========delete cache===========")
os.system(f"rm -rf {cache_path}")
print("===========start build===========")
os.system(f"GET_PACKAGE=1 {python} -m jittor.test.test_example")
print("===========make package===========")
datas = open("tmp.txt", "r").readlines()
os.system(f"rm tmp.txt")

if os.path.exists(package_path):
os.system(f"rm -rf {package_path}")
for i in range(len(datas) // 4):
url = datas[i * 4 + 0].rstrip()
filename = datas[i * 4 + 1].rstrip()
root_folder = datas[i * 4 + 2].rstrip()
md5 = datas[i * 4 + 3].rstrip()

target_path = os.path.join(package_path, root_folder[root_folder.find(".cache/jittor"):])
os.makedirs(target_path, exist_ok=True)
os.system(f"cp {os.path.join(root_folder, filename)} {os.path.join(target_path, filename)}")
print("===========download jittor===========")
jittor_path = os.path.join(package_path, "jittor")
os.makedirs(jittor_path)
os.system(f"{python} -m pip download jittor -d {jittor_path}")
print("===========write setup script===========")
f = open(os.path.join(package_path, "setup.py"), "w")
code = """
import os
os.system("rm -rf ~/.cache/jittor")
os.makedirs("~/.cache", exist_ok=True)
os.system("cp -r ./.cache/jittor ~/.cache/jittor")
temp = [i for i in os.listdir("jittor") if i.startswith("jittor-")]
assert(len(temp) == 1)
jittor_file = temp[0]
os.system(f"cd jittor && python -m pip install {jittor_file}")
os.system(f"python -m jittor.test.test_example")
"""
f.write(code)
f.close()
print("===========done===========")
temp = [i for i in os.listdir(os.path.join(package_path, "jittor")) if i.startswith("jittor-")]
jittor_version = temp[0][7:-7]
os.system(f"zip -r jittor-offline-{jittor_version}.zip {package_path}")
7 changes: 4 additions & 3 deletions python/jittor_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ def home():

# LOG.i(f"Use {_home_path} as Jittor Home")

with open(src_path_file,"w") as f:
data['JITTOR_HOME'] = _home_path
json.dump(data,f)
if default_path != _home_path:
with open(src_path_file,"w") as f:
data['JITTOR_HOME'] = _home_path
json.dump(data,f)

_jittor_home = _home_path
return _home_path
Expand Down
11 changes: 11 additions & 0 deletions python/jittor_utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ def bar_update(block_num, block_size, total_size):

@lock.lock_scope()
def download_url_to_local(url, filename, root_folder, md5):
if os.getenv('GET_PACKAGE') == "1":
f = open("tmp.txt", "a")
f.writelines(
[
url + "\n",
filename + "\n",
root_folder + "\n",
md5 + "\n",
]
)
f.close()
ensure_dir(root_folder)
file_path = os.path.join(root_folder, filename)
if check_file_exist(file_path, md5):
Expand Down