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

Simplify adding mbuild to PYTHONPATH #323

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 2 additions & 11 deletions pysrc/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,8 @@
import datetime

from genutil import *
def find_dir(d):
directory = os.getcwd()
last = ''
while directory != last:
target_directory = os.path.join(directory,d)
if os.path.exists(target_directory):
return target_directory
last = directory
directory = os.path.split(directory)[0]
return None
sys.path.append(find_dir('mbuild'))

add_mbuild_to_path()
try:
import mbuild
except:
Expand Down
13 changes: 2 additions & 11 deletions pysrc/enumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,9 @@
import sys
import re
import codegen
from genutil import add_mbuild_to_path

def find_dir(d):
directory = os.getcwd()
last = ''
while directory != last:
target_dir = os.path.join(directory,d)
if os.path.exists(target_dir):
return target_dir
last = directory
directory = os.path.split(directory)[0]
return None
sys.path.append(find_dir('mbuild'))
add_mbuild_to_path()
try:
import mbuild
except:
Expand Down
39 changes: 0 additions & 39 deletions pysrc/find_dir.py

This file was deleted.

17 changes: 2 additions & 15 deletions pysrc/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,9 @@
import optparse
import collections
from typing import Dict, List
from genutil import add_mbuild_to_path

def find_dir(d):
directory = os.getcwd()
last = ''
while directory != last:
target_directory = os.path.join(directory,d)
if os.path.exists(target_directory):
return target_directory
last = directory
directory = os.path.split(directory)[0]
return None

mbuild_install_path = os.path.join(os.path.dirname(sys.argv[0]), '..', 'mbuild')
if not os.path.exists(mbuild_install_path):
mbuild_install_path = find_dir('mbuild')
sys.path= [mbuild_install_path] + sys.path
add_mbuild_to_path()
try:
import mbuild
except:
Expand Down
29 changes: 28 additions & 1 deletion pysrc/genutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import re
import stat
import platform
from typing import Tuple, Any, List, Dict
from typing import Tuple, Any, List, Dict, Optional

psystem = platform.system()
if (psystem == 'Microsoft' or
Expand Down Expand Up @@ -84,6 +84,33 @@ def warn(msg: str):
msgerr('[WARNING] ' + msg)


def find_dir(d: str) -> Optional[str]:
"""Attempts to find directory `d` in the current directory or any parent directory."""

directory = os.getcwd()
last = ''
while directory != last:
target_directory = os.path.join(directory, d)
if os.path.exists(target_directory):
return target_directory
last = directory
directory = os.path.split(directory)[0]
return None


def add_mbuild_to_path():
"""
Add the mbuild directory to the python path.

This will do nothing if `mbuild` already exists in the python path.
"""

if not any('mbuild' in x for x in sys.path):
mbuild_dir = find_dir('mbuild')
if not mbuild_dir:
die('Could not find mbuild directory.')
sys.path.append(mbuild_dir)

def check_python_version(argmaj: int, argmin: int):
tup = sys.version_info
major: int = tup[0]
Expand Down
19 changes: 2 additions & 17 deletions pysrc/read-encfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,9 @@
import optparse
import stat
import copy
from genutil import add_mbuild_to_path

def find_dir(d):
directory = os.getcwd()
last = ''
while directory != last:
target_directory = os.path.join(directory,d)
if os.path.exists(target_directory):
return target_directory
last = directory
directory = os.path.split(directory)[0]
return None

mbuild_install_path = os.path.join(os.path.dirname(sys.argv[0]),
'..', '..', 'mbuild')

if not os.path.exists(mbuild_install_path):
mbuild_install_path = find_dir('mbuild')
sys.path= [mbuild_install_path] + sys.path
add_mbuild_to_path()
try:
import mbuild
except:
Expand Down