Skip to content

Commit

Permalink
Merge pull request #151 from marshall-lab/add-setup
Browse files Browse the repository at this point in the history
Make titan installable
  • Loading branch information
mcmcgrath13 authored Jan 20, 2021
2 parents e9350e1 + 371c66c commit f2b6147
Show file tree
Hide file tree
Showing 24 changed files with 194 additions and 265 deletions.
54 changes: 0 additions & 54 deletions scripts/bs_Core.sh

This file was deleted.

73 changes: 73 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import setuptools
import subprocess

# ========= FROM https://github.com/vivin/better-setuptools-git-version/blob/master/better_setuptools_git_version.py with edits =========
def get_latest_tag():
return subprocess.getoutput(
"git describe --tags `git rev-list --tags --max-count=1`"
)


def get_tag_commit_sha(tag):
"""Return the commit that the tag is pointing to."""
return subprocess.getoutput("git rev-list -n 1 {tag}".format(tag=tag))


def get_head_sha():
"""Return the sha key of HEAD."""
return subprocess.getoutput("git rev-parse HEAD")


def is_head_at_tag(tag):
"""Return True or False depending on whether the given tag is pointing to HEAD"""
return get_head_sha() == get_tag_commit_sha(tag)


def get_version():
"""
Return the full git version using the given template. If there are no annotated tags, the version specified by
starting_version will be used. If HEAD is at the tag, the version will be the tag itself. If there are commits ahead
of the tag, the first 8 characters of the sha of the HEAD commit will be included.
In all of the above cases, if the working tree is also dirty or contains untracked files, a "+dirty" suffix will be
appended to the version.
Returns:
the formatted version based on tags in the git repository.
"""
template = "{tag}.dev{sha}"
tag = get_latest_tag()
if is_head_at_tag(tag):
version = tag
else:
sha = get_head_sha()[:8]
version = template.format(tag=tag, sha=sha)

return version


# add the readme as the description
with open("README.md", "r", encoding="utf-8") as fh:
long_description = fh.read()

# make the requirements.txt be installed (not good practice for general packaging, good for current oscar set up)
with open("requirements.txt") as f:
required = f.read().splitlines()

setuptools.setup(
name="titan", # Replace with your own username,
version=get_version(),
# author="Example Author",
# author_email="[email protected]",
description="TITAN Agent Based Model",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/marshall-lab/TITAN",
packages=setuptools.find_packages(),
install_requires=required,
classifiers=[
"Programming Language :: Python :: 3",
"Operating System :: OS Independent",
],
python_requires=">=3.6",
package_data={"titan": ["params/*.yml", "settings/*/*.yml"]},
entry_points={"console_scripts": ["run_titan=titan:script_init"]},
)
189 changes: 0 additions & 189 deletions subTitan.sh

This file was deleted.

33 changes: 28 additions & 5 deletions tests/integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ def _make_model_integration():

@pytest.mark.integration_deterministic
def test_model_runs():
f = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "run_titan.py")
f = os.path.join(
os.path.dirname(os.path.abspath(__file__)), "..", "titan", "run_titan.py"
)
param_file = os.path.join(
os.path.dirname(os.path.abspath(__file__)), "params", "basic.yml"
)
Expand All @@ -39,11 +41,26 @@ def test_model_runs():
assert True


@pytest.mark.integration_deterministic
def test_model_runs_sweep():
f = os.path.join(
os.path.dirname(os.path.abspath(__file__)), "..", "titan", "run_titan.py"
)
param_file = os.path.join(
os.path.dirname(os.path.abspath(__file__)), "params", "basic.yml"
)

subprocess.check_call([f, f"-p {param_file}", "-w model.seed.run:1:3"])
assert True


@pytest.mark.integration_deterministic
def test_model_reproducible(tmpdir):
path_a = tmpdir.mkdir("result_a")
path_b = tmpdir.mkdir("result_b")
f = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "run_titan.py")
f = os.path.join(
os.path.dirname(os.path.abspath(__file__)), "..", "titan", "run_titan.py"
)
param_file = os.path.join(
os.path.dirname(os.path.abspath(__file__)), "params", "basic_seeded.yml"
)
Expand Down Expand Up @@ -80,7 +97,9 @@ def test_model_reproducible(tmpdir):
@pytest.mark.integration_deterministic
def test_model_pop_write_read(tmpdir):
path_a = tmpdir.mkdir("a")
f = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "run_titan.py")
f = os.path.join(
os.path.dirname(os.path.abspath(__file__)), "..", "titan", "run_titan.py"
)
param_file = os.path.join(
os.path.dirname(os.path.abspath(__file__)), "params", "basic.yml"
)
Expand All @@ -99,13 +118,17 @@ def test_model_pop_write_read(tmpdir):

@pytest.mark.integration_deterministic
def test_model_settings_run(tmpdir):
f = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "run_titan.py")
f = os.path.join(
os.path.dirname(os.path.abspath(__file__)), "..", "titan", "run_titan.py"
)
param_file = os.path.join(
os.path.dirname(os.path.abspath(__file__)), "params", "integration_base.yml"
)

for item in os.listdir(
os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "settings")
os.path.join(
os.path.dirname(os.path.abspath(__file__)), "..", "titan", "settings"
)
):
if "__" not in item and item != "base":
path = tmpdir.mkdir(item)
Expand Down
Loading

0 comments on commit f2b6147

Please sign in to comment.