forked from watertap-org/watertap-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update move entry points file to replace current set of entry points …
…if found, and to use an argument for project name to look for entry points; add math.nist.gov to git ignore
- Loading branch information
1 parent
7e3569d
commit 96d315c
Showing
2 changed files
with
88 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,93 @@ | ||
import sys | ||
import os | ||
import glob | ||
import argparse | ||
|
||
conda_prefix = os.environ['CONDA_PREFIX'] | ||
from pathlib import Path | ||
|
||
print(f'conda_prefix is {conda_prefix}') | ||
def update_entry_points(project): | ||
|
||
try: | ||
if sys.platform == "darwin": | ||
print('darwin') | ||
entrypoints_src_path = f'{conda_prefix}/lib/python*/site-packages/watertap-*info/entry_points.txt' | ||
entrypoints_dst_path = f'{conda_prefix}/lib/python*/site-packages/setuptools-*info/entry_points.txt' | ||
elif sys.platform == "linux": | ||
print('linux') | ||
entrypoints_src_path = f'{conda_prefix}/lib/python*/site-packages/watertap-*info/entry_points.txt' | ||
entrypoints_dst_path = f'{conda_prefix}/lib/python*/site-packages/setuptools-*info/entry_points.txt' | ||
else: | ||
print('windows') | ||
entrypoints_src_path = f'{conda_prefix}/lib/site-packages/watertap-*info/entry_points.txt' | ||
entrypoints_dst_path = f'{conda_prefix}/lib/site-packages/setuptools-*info/entry_points.txt' | ||
except Exception as e: | ||
print(f'unable to get entry points src/dst: {e}') | ||
|
||
print(f'globbing from {entrypoints_src_path} to {entrypoints_dst_path}') | ||
|
||
entrypoints_src = glob.glob(entrypoints_src_path)[0] | ||
entrypoints_dst = glob.glob(entrypoints_dst_path)[0] | ||
|
||
print(f'moving entry points from {entrypoints_src} to {entrypoints_dst}') | ||
|
||
# get entry points from src | ||
with open(entrypoints_src, 'r') as f: | ||
dst = open(entrypoints_dst, 'r') | ||
if not 'watertap.flowsheets' in (dst.read()): | ||
dst.close() | ||
entry_points = f.read() | ||
print(f'found entry points:\n{entry_points}') | ||
dst = open(entrypoints_dst, 'a') | ||
dst.write(f'\n{entry_points}') | ||
dst.close() | ||
conda_prefix = os.environ["CONDA_PREFIX"] | ||
|
||
try: | ||
if sys.platform == "darwin": | ||
print("darwin") | ||
entrypoints_src_path = ( | ||
f"{conda_prefix}/lib/python*/site-packages/{project}-*info/entry_points.txt" | ||
) | ||
entrypoints_dst_path = f"{conda_prefix}/lib/python*/site-packages/setuptools-*info/entry_points.txt" | ||
elif sys.platform == "linux": | ||
print("linux") | ||
entrypoints_src_path = ( | ||
f"{conda_prefix}/lib/python*/site-packages/{project}-*info/entry_points.txt" | ||
) | ||
entrypoints_dst_path = f"{conda_prefix}/lib/python*/site-packages/setuptools-*info/entry_points.txt" | ||
else: | ||
# print("windows") | ||
entrypoints_src_path = ( | ||
f"{conda_prefix}/lib/site-packages/{project}-*info/entry_points.txt" | ||
) | ||
entrypoints_dst_path = ( | ||
f"{conda_prefix}/lib/site-packages/setuptools-*info/entry_points.txt" | ||
) | ||
except Exception as e: | ||
print(f"unable to get entry points src/dst: {e}") | ||
|
||
print(f"globbing from {entrypoints_src_path} to {entrypoints_dst_path}") | ||
|
||
entrypoints_src = glob.glob(entrypoints_src_path)[0] | ||
entrypoints_dst = glob.glob(entrypoints_dst_path)[0] | ||
|
||
entry_points = [] | ||
start_getting_entries = False | ||
with open(entrypoints_src, "r") as f: | ||
for line in f: | ||
if f"[{project}.flowsheets]" in line: | ||
start_getting_entries = True | ||
elif start_getting_entries == True and ("]" in line or line == None or line == "\n"): | ||
print(f"reached end of entry points, breaking") | ||
break | ||
elif start_getting_entries: | ||
entry = line.replace("\n", "") | ||
if line is not None: | ||
entry_points.append(entry) | ||
else: | ||
print(f"line is none, breaking") | ||
|
||
## if entry points for this project exist, remove current set of entry points | ||
entrypoints_dst_str = "" | ||
found_entrypoints = False | ||
with open(entrypoints_dst, "r") as f: | ||
for line in f: | ||
if f"[{project}.flowsheets]" in line: | ||
found_entrypoints = True | ||
elif found_entrypoints == True and (line == None or line == "\n"): | ||
found_entrypoints = False | ||
elif found_entrypoints: | ||
entry = line.replace("\n", "") | ||
else: | ||
entrypoints_dst_str+=line | ||
|
||
## add in entrypoints from the list | ||
entrypoints_dst_str+=f"\n\n[{project}.flowsheets]" | ||
for each in entry_points: | ||
entrypoints_dst_str+=f"\n{each}" | ||
|
||
## write this string to the dst path | ||
with open(entrypoints_dst, "w") as f: | ||
f.write(entrypoints_dst_str) | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("-p", "--project", help="Project to search for entry points. If not provided, default is WaterTAP.") | ||
args = parser.parse_args() | ||
project = args.project | ||
if project is None: | ||
project = "watertap" | ||
elif project.lower() == "idaes": | ||
project = "idaes_pse" | ||
else: | ||
print(f'file already has watertap entry points, no need to add them') | ||
project = project.lower() | ||
update_entry_points(project) | ||
|