Skip to content

Commit

Permalink
Merge pull request #28 from paulsaxe/main
Browse files Browse the repository at this point in the history
Protected against corrupt job_data.json files.
  • Loading branch information
seamm authored Mar 12, 2024
2 parents b09187b + d8c1c4e commit 162ff82
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 58 deletions.
20 changes: 9 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,28 +57,28 @@ format: ## reformat with black
black --extend-exclude '_version.py' $(MODULE)

typing: ## check typing
pytype seamm_datastore
pytype $(MODULE)

test: ## run tests quickly with the default Python
pytest -rP seamm_datastore/tests
pytest -rP $(MODULE)/tests

test-all: ## run tests on every Python version with tox
tox

coverage: ## check code coverage quickly with the default Python
coverage run --source seamm_datastore -m pytest
coverage run --source $(MODULE) -m pytest
coverage report -m
coverage html
$(BROWSER) htmlcov/index.html

docs: ## generate Sphinx HTML documentation, including API docs
rm -f docs/seamm_datastore.rst
rm -f docs/$(MODULE).rst
rm -f docs/modules.rst
sphinx-apidoc -o docs/ seamm_datastore
sphinx-apidoc -o docs/ $(MODULE)
$(MAKE) -C docs clean
$(MAKE) -C docs html
$(BROWSER) docs/_build/html/index.html
rm -f docs/seamm_datastore.rst
rm -f docs/$(MODULE).rst
rm -f docs/modules.rst

servedocs: docs ## compile the docs watching for changes
Expand All @@ -93,12 +93,10 @@ check-release: clean ## check the release for errors
python -m twine check dist/*

dist: clean ## builds source and wheel package
python setup.py sdist
python setup.py bdist_wheel
ls -l dist
python -m build

install: uninstall ## install the package to the active Python's site-packages
python setup.py install
pip install .

uninstall: clean ## uninstall the package
pip uninstall --yes seamm_datastore
pip uninstall --yes $(MODULE)
3 changes: 0 additions & 3 deletions seamm_datastore/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ def __init__(
datastore_location: str = None,
default_project: str = "default",
):

if database_uri.lower() == "sqlite:///:memory:":
initialize = True

Expand Down Expand Up @@ -212,7 +211,6 @@ def add_job(
parameters=None,
status="submitted",
):

warn(
"Deprecation warning: This method will no longer be available",
" in the next version of the seamm datastore.",
Expand All @@ -223,7 +221,6 @@ def add_job(
parameters = {"cmdline": []}

with session_scope(self.Session) as session:

job = self.Job.create(
id,
flowchart_filename,
Expand Down
60 changes: 31 additions & 29 deletions seamm_datastore/database/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,40 +130,42 @@ def import_datastore(session, location, as_json=True):
potential_job = os.path.join(potential_project, potential_job)

if os.path.isdir(potential_job):

# Check for job_data.json - has to have this to be job
check_path = os.path.join(potential_job, "job_data.json")
if os.path.exists(check_path):
job_data = Job.parse_job_data(check_path)

if "command line" in job_data:
parameters = {"cmdline": job_data["command line"]}
else:
parameters = {"cmdline": []}

try:
job = Job.create(
job_data["id"],
potential_job + "/flowchart.flow",
project_names=job_data["project_names"],
path=potential_job,
title=job_data["title"],
description=job_data.get("description", ""),
submitted=job_data.get("submitted", None),
started=job_data.get("started", None),
finished=job_data.get("finished", None),
status=job_data["status"],
parameters=parameters,
)
except Exception:
print(
f"Job {job_data['id']} not imported because it is "
"already in the database."
)
job_data = Job.parse_job_data(check_path)
except Exception as e:
print(f"Could not read the job data {check_path}: {str(e)}")
else:
session.add(job)
session.commit()
jobs.append(job)
if "command line" in job_data:
parameters = {"cmdline": job_data["command line"]}
else:
parameters = {"cmdline": []}

try:
job = Job.create(
job_data["id"],
potential_job + "/flowchart.flow",
project_names=job_data["project_names"],
path=potential_job,
title=job_data["title"],
description=job_data.get("description", ""),
submitted=job_data.get("submitted", None),
started=job_data.get("started", None),
finished=job_data.get("finished", None),
status=job_data["status"],
parameters=parameters,
)
except Exception:
print(
f"Job {job_data['id']} not imported because it is "
"already in the database."
)
else:
session.add(job)
session.commit()
jobs.append(job)

session.commit()

Expand Down
2 changes: 0 additions & 2 deletions seamm_datastore/database/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,6 @@ class Flowchart(Base, Resource):

@classmethod
def create(cls, **flowchart_info):

try:
flowchart = cls.query.filter_by(
sha256_strict=flowchart_info["sha256_strict"]
Expand Down Expand Up @@ -709,7 +708,6 @@ def update(

@classmethod
def create_from_file(cls, job_data_file):

job_data = cls.parse_job_data(job_data_file)

job = Job.create(job_data)
Expand Down
2 changes: 0 additions & 2 deletions seamm_datastore/flask_authorize_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
def generate_association_table(
entity_name, resource_name, entity_tablename=None, resource_tablename=None
):

# Make them plural by adding 's' :)
if not entity_tablename:
entity_tablename = entity_name.lower() + "s"
Expand Down Expand Up @@ -183,7 +182,6 @@ def allowed(self, *args, **kwargs): # pragma: no cover
# must have authorization to proceed.
operation = set(self.permission)
for arg in args:

if not isinstance(arg.__class__, six.class_types):
continue

Expand Down
1 change: 0 additions & 1 deletion seamm_datastore/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def admin_connection(connection):

@pytest.fixture(scope="function")
def filled_db(connection):

# The lazy way to do this for now
import os

Expand Down
1 change: 0 additions & 1 deletion seamm_datastore/tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@


def test_build(connection):

from seamm_datastore.database.models import Flowchart

loc = os.path.abspath(os.path.dirname(__file__))
Expand Down
5 changes: 0 additions & 5 deletions seamm_datastore/tests/test_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@ def test_project_create(connection):


def test_project_exists(connection):

with pytest.raises(ValueError):
connection.Project.create(name="default")


def test_project_no_user(connection):

with pytest.raises(ValueError):
connection.logout()
connection.Project.create(name="test")
Expand All @@ -43,7 +41,6 @@ def test_project_create_group(connection):


def test_flowchart_parse(connection):

this_file = os.path.dirname(os.path.abspath(__file__))
filepath = os.path.join(this_file, "..", "data", "sample_flowchart_v2.flow")

Expand All @@ -59,7 +56,6 @@ def test_flowchart_parse(connection):


def test_flowchart_from_file(connection):

this_file = os.path.dirname(os.path.abspath(__file__))
filepath = os.path.join(this_file, "..", "data", "sample_flowchart_v2.flow")

Expand All @@ -72,7 +68,6 @@ def test_flowchart_from_file(connection):


def test_create_user(connection):

user = connection.User.create(username="test", password="test")

assert user.username == "test"
Expand Down
2 changes: 0 additions & 2 deletions seamm_datastore/tests/test_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,13 @@ def test_get_queries(


def test_job_update_error(filled_db):

from seamm_datastore.database.models import Job

with pytest.raises(ValueError):
Job.update(1, description="This is a new description.")


def test_job_update(filled_db):

from seamm_datastore.database.models import Job

job = Job.update(92, description="This is a new description.")
Expand Down
4 changes: 2 additions & 2 deletions versioneer.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,9 @@ def get_config_from_root(root):
# configparser.NoOptionError (if it lacks "VCS="). See the docstring at
# the top of versioneer.py for instructions on writing your setup.cfg .
setup_cfg = os.path.join(root, "setup.cfg")
parser = configparser.SafeConfigParser()
parser = configparser.ConfigParser()
with open(setup_cfg, "r") as f:
parser.readfp(f)
parser.read_file(f)
VCS = parser.get("versioneer", "VCS") # mandatory

def get(parser, name):
Expand Down

0 comments on commit 162ff82

Please sign in to comment.