Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/pip/monty-2025.1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-janssen authored Jan 21, 2025
2 parents 4fb06a2 + ee61bed commit 9316aee
Show file tree
Hide file tree
Showing 21 changed files with 220 additions and 231 deletions.
14 changes: 7 additions & 7 deletions .ci_support/environment-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ dependencies:
- myst-parser
- conda =24.7.1
- conda_subprocess =0.0.5
- cloudpickle =3.1.0
- cloudpickle =3.1.1
- gitpython =3.1.44
- h5io_browser =0.1.5
- h5io_browser =0.1.6
- h5py =3.12.1
- jinja2 =3.1.5
- monty =2025.1.9
- numpy =2.2.1
- numpy =2.2.2
- pandas =2.2.3
- pint =0.24.4
- psutil =6.1.1
- pyfileindex =0.0.32
- pyfileindex =0.0.33
- pyiron_dataclasses =0.0.1
- pyiron_snippets =0.1.4
- executorlib =0.0.7
- executorlib =0.0.8
- pysqa =0.2.3
- pytables =3.10.1
- sqlalchemy =2.0.36
- pytables =3.10.2
- sqlalchemy =2.0.37
- tqdm =4.67.1
- traitlets =5.14.3
- jupyter-book =1.0.0
14 changes: 7 additions & 7 deletions .ci_support/environment-mini.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
channels:
- conda-forge
dependencies:
- cloudpickle =3.1.0
- h5io_browser =0.1.5
- cloudpickle =3.1.1
- h5io_browser =0.1.6
- h5py =3.12.1
- monty =2025.1.9
- numpy =2.2.1
- numpy =2.2.2
- pandas =2.2.3
- psutil =6.1.1
- pyfileindex =0.0.32
- pyfileindex =0.0.33
- pyiron_dataclasses =0.0.1
- pyiron_snippets =0.1.3
- executorlib =0.0.7
- executorlib =0.0.8
- pysqa =0.2.3
- pytables =3.10.1
- sqlalchemy =2.0.36
- pytables =3.10.2
- sqlalchemy =2.0.37
- tqdm =4.67.1
- traitlets =5.14.3
- setuptools
14 changes: 7 additions & 7 deletions .ci_support/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ dependencies:
- codacy-coverage
- conda =24.7.1
- conda_subprocess =0.0.5
- cloudpickle =3.1.0
- cloudpickle =3.1.1
- gitpython =3.1.44
- h5io_browser =0.1.5
- h5io_browser =0.1.6
- h5py =3.12.1
- jinja2 =3.1.5
- monty =2025.1.9
- numpy =2.2.1
- numpy =2.2.2
- pandas =2.2.3
- pint =0.24.4
- psutil =6.1.1
- pyfileindex =0.0.32
- pyfileindex =0.0.33
- pyiron_dataclasses =0.0.1
- pyiron_snippets =0.1.4
- executorlib =0.0.7
- executorlib =0.0.8
- pysqa =0.2.3
- pytables =3.10.1
- sqlalchemy =2.0.36
- pytables =3.10.2
- sqlalchemy =2.0.37
- tqdm =4.67.1
- traitlets =5.14.3
4 changes: 0 additions & 4 deletions .github/workflows/unittests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ jobs:
- operating-system: ubuntu-latest
python-version: '3.11'
label: linux-64-py-3-11

- operating-system: ubuntu-latest
python-version: '3.10'
label: linux-64-py-3-10

steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.6
rev: v0.9.2
hooks:
- id: ruff
name: ruff lint
Expand Down
7 changes: 4 additions & 3 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
version: 2

build:
os: "ubuntu-22.04"
os: "ubuntu-24.04"
tools:
python: "mambaforge-22.9"
python: "mambaforge-23.11"
jobs:
pre_build:
# Generate the Sphinx configuration for this Jupyter Book so it builds.
Expand All @@ -21,10 +21,11 @@ build:
# Build documentation in the docs/ directory with Sphinx
sphinx:
builder: html
configuration: docs/conf.py

# Optionally build your docs in additional formats such as PDF and ePub
formats: []

# Install pyiron from conda
conda:
environment: .ci_support/environment-docs.yml
environment: .ci_support/environment-docs.yml
14 changes: 7 additions & 7 deletions binder/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ dependencies:
- python
- conda =24.7.1
- conda_subprocess =0.0.5
- cloudpickle =3.1.0
- cloudpickle =3.1.1
- gitpython =3.1.44
- h5io_browser =0.1.5
- h5io_browser =0.1.6
- h5py =3.12.1
- jinja2 =3.1.5
- monty =2025.1.9
- numpy =2.2.1
- numpy =2.2.2
- pandas =2.2.3
- pint =0.24.4
- psutil =6.1.1
- pyfileindex =0.0.32
- pyfileindex =0.0.33
- pyiron_dataclasses =0.0.1
- pyiron_snippets =0.1.4
- executorlib =0.0.7
- executorlib =0.0.8
- pysqa =0.2.3
- pytables =3.10.1
- sqlalchemy =2.0.36
- pytables =3.10.2
- sqlalchemy =2.0.37
- tqdm =4.67.1
- traitlets =5.14.3
2 changes: 1 addition & 1 deletion pyiron_base/cli/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def main() -> None:
mod.register(sub_parser)
except AttributeError:
warnings.warn(
"module '{}' does not define main or register " "function, ignoring"
"module '{}' does not define main or register function, ignoring"
)

args = parser.parse_args()
Expand Down
2 changes: 1 addition & 1 deletion pyiron_base/database/filetable.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def get_items_dict(
return_all_columns (bool): return all columns or only the 'id' - still the format stays the same.
Returns:
list: the function returns a list of dicts like get_items_sql, but it does not format datetime:
list: the function returns a list of dicts, but it does not format datetime:
[{'chemicalformula': u'Ni108',
'computer': u'mapc157',
'hamilton': u'LAMMPS',
Expand Down
132 changes: 29 additions & 103 deletions pyiron_base/database/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def _job_dict(
element_lst (list): list of elements required in the chemical formular - by default None
Returns:
list: the function returns a list of dicts like get_items_sql, but it does not format datetime:
list: the function returns a list of dicts, but it does not format datetime:
[{'chemicalformula': u'Ni108',
'computer': u'mapc157',
'hamilton': u'LAMMPS',
Expand Down Expand Up @@ -312,10 +312,30 @@ def _job_dict(
'username': u'test'},.......]
"""
if not self._sql_lite:

def escape(s, escape_char="\\", special_chars="_%"):
"""Insert escape_char in front of special_chars, unless present.
Handles the cases where s already contains escaped characters,
including the escape character itself.
Defaults for LIKE in SQL statements."""
for c in special_chars:
if c in s:
s = s.replace(escape_char + c, c)
s = s.replace(c, escape_char + c)
return s

else:

def escape(s, escape_char="\\", special_chars="_%"):
return s

dict_clause = {}
# FOR GET_ITEMS_SQL: clause = []
if user is not None:
dict_clause["username"] = str(user)
dict_clause["username"] = escape(str(user))
# FOR GET_ITEMS_SQL: clause.append("username = '" + self.user + "'")
if sql_query is not None:
# FOR GET_ITEMS_SQL: clause.append(self.sql_query)
Expand All @@ -329,18 +349,18 @@ def _job_dict(
{str(element.split()[0]): element.split()[2] for element in cl_split}
)
if job is not None:
dict_clause["job"] = str(job)
dict_clause["job"] = escape(str(job))

if project_path == "./":
project_path = ""
if recursive:
dict_clause["project"] = str(project_path) + "%"
dict_clause["project"] = escape(str(project_path)) + "%"
else:
dict_clause["project"] = str(project_path)
dict_clause["project"] = escape(str(project_path))
if sub_job_name is None:
dict_clause["subjob"] = None
elif sub_job_name != "%":
dict_clause["subjob"] = str(sub_job_name)
dict_clause["subjob"] = escape(str(sub_job_name))
if element_lst is not None:
dict_clause["element_lst"] = element_lst

Expand Down Expand Up @@ -502,100 +522,6 @@ def change_column_type(
else:
raise PermissionError("Not avilable in viewer mode.")

def get_items_sql(
self, where_condition: Optional[str] = None, sql_statement: Optional[str] = None
) -> List[dict]:
"""
Submit an SQL query to the database
Args:
where_condition (str): SQL where query, query like: "project LIKE 'lammps.phonons.Ni_fcc%'"
sql_statement (str): general SQL query, normal SQL statement
Returns:
list: get a list of dictionaries, where each dictionary represents one item of the table like:
[{u'chemicalformula': u'BO',
u'computer': u'localhost',
u'hamilton': u'VAMPS',
u'hamversion': u'1.1',
u'id': 1,
u'job': u'testing',
u'masterid': None,
u'parentid': 0,
u'project': u'database.testing',
u'projectpath': u'/TESTING',
u'status': u'KAAAA',
u'subjob': u'testJob',
u'timestart': u'2016-05-02 11:31:04.253377',
u'timestop': u'2016-05-02 11:31:04.371165',
u'totalcputime': 0.117788,
u'username': u'User'},
{u'chemicalformula': u'BO',
u'computer': u'localhost',
u'hamilton': u'VAMPS',
u'hamversion': u'1.1',
u'id': 2,
u'job': u'testing',
u'masterid': 0,
u'parentid': 0,
u'project': u'database.testing',
u'projectpath': u'/TESTING',
u'status': u'KAAAA',
u'subjob': u'testJob',
u'timestart': u'2016-05-02 11:31:04.253377',
u'timestop': u'2016-05-02 11:31:04.371165',
u'totalcputime': 0.117788,
u'username': u'User'}.....]
"""

if where_condition:
where_condition = (
where_condition.replace("like", "similar to")
if self._engine.dialect.name == "postgresql"
else where_condition
)
try:
query = "select * from " + self.table_name + " where " + where_condition
query.replace("%", "%%")
result = self.conn.execute(text(query))
except Exception as except_msg:
print("EXCEPTION in get_items_sql: ", except_msg)
raise ValueError("EXCEPTION in get_items_sql: ", except_msg)
elif sql_statement:
sql_statement = (
sql_statement.replace("like", "similar to")
if self._engine.dialect.name == "postgresql"
else sql_statement
)
# TODO: make it save against SQL injection
result = self.conn.execute(text(sql_statement))
else:
result = self.conn.execute(text("select * from " + self.table_name))
row = result.mappings().all()
if not self._keep_connection:
self.conn.close()

# change the date of str datatype back into datetime object
output_list = []
for col in row:
# ensures working with db entries, which are camel case
timestop_index = [item.lower() for item in col.keys()].index("timestop")
timestart_index = [item.lower() for item in col.keys()].index("timestart")
tmp_values = list(col.values())
if (tmp_values[timestop_index] and tmp_values[timestart_index]) is not None:
# changes values
try:
tmp_values[timestop_index] = datetime.strptime(
str(tmp_values[timestop_index]), "%Y-%m-%d %H:%M:%S.%f"
)
tmp_values[timestart_index] = datetime.strptime(
str(tmp_values[timestart_index]), "%Y-%m-%d %H:%M:%S.%f"
)
except ValueError:
print("error in: ", str(col))
output_list += [dict(zip(col.keys(), tmp_values))]
return output_list

def _check_chem_formula_length(self, par_dict: dict) -> dict:
"""
performs a check whether the length of chemical formula exceeds the defined limit
Expand Down Expand Up @@ -900,7 +826,7 @@ def get_items_dict(
return_all_columns (bool): return all columns or only the 'id' - still the format stays the same.
Returns:
list: the function returns a list of dicts like get_items_sql, but it does not format datetime:
list: the function returns a list of dicts, but it does not format datetime:
[{'chemicalformula': u'Ni108',
'computer': u'mapc157',
'hamilton': u'LAMMPS',
Expand Down Expand Up @@ -974,10 +900,10 @@ def get_items_dict(
self.conn.connection.create_function("like", 2, self.regexp)

result = self.conn.execute(query)
row = result.fetchall()
results = [row._asdict() for row in result.fetchall()]
if not self._keep_connection:
self.conn.close()
return [dict(zip(col._mapping.keys(), col._mapping.values())) for col in row]
return results

def get_job_status(self, job_id: int) -> Union[str, None]:
try:
Expand Down
1 change: 1 addition & 0 deletions pyiron_base/jobs/job/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,7 @@ def _internal_copy_to(
_copy_database_entry(
new_job_core=new_job_core,
job_copied_id=self.job_id,
username=state.settings.login_user,
)
else:
new_job_core.reset_job_id(job_id=None)
Expand Down
Loading

0 comments on commit 9316aee

Please sign in to comment.