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

Apply black formatting #109

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions abcd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@classmethod
def from_config(cls, config):
# Factory method
url = config['url']
url = config["url"]

Check warning on line 17 in abcd/__init__.py

View check run for this annotation

Codecov / codecov/patch

abcd/__init__.py#L17

Added line #L17 was not covered by tests
return ABCD.from_url(url)

@classmethod
Expand All @@ -23,35 +23,38 @@
r = parse.urlparse(url)
logger.info(r)

if r.scheme == 'mongodb':
if r.scheme == "mongodb":

conn_settings = {
'host': r.hostname,
'port': r.port,
'username': r.username,
'password': r.password,
'authSource': 'admin',
"host": r.hostname,
"port": r.port,
"username": r.username,
"password": r.password,
"authSource": "admin",
}

db = r.path.split('/')[1] if r.path else None
db = db if db else 'abcd'
db = r.path.split("/")[1] if r.path else None
db = db if db else "abcd"

from abcd.backends.atoms_pymongo import MongoDatabase

return MongoDatabase(db_name=db, **conn_settings, **kwargs)

elif r.scheme == 'http' or r.scheme == 'https':
raise NotImplementedError('http not yet supported! soon...')
elif r.scheme == 'ssh':
raise NotImplementedError('ssh not yet supported! soon...')
elif r.scheme == "http" or r.scheme == "https":
raise NotImplementedError("http not yet supported! soon...")
elif r.scheme == "ssh":
raise NotImplementedError("ssh not yet supported! soon...")

Check warning on line 46 in abcd/__init__.py

View check run for this annotation

Codecov / codecov/patch

abcd/__init__.py#L43-L46

Added lines #L43 - L46 were not covered by tests
else:
raise NotImplementedError('Unable to recognise the type of connection. (url: {})'.format(url))
raise NotImplementedError(

Check warning on line 48 in abcd/__init__.py

View check run for this annotation

Codecov / codecov/patch

abcd/__init__.py#L48

Added line #L48 was not covered by tests
"Unable to recognise the type of connection. (url: {})".format(url)
)


if __name__ == '__main__':
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)

# url = 'mongodb://mongoadmin:secret@localhost:27017'
url = 'mongodb://mongoadmin:secret@localhost:27017/abcd_new'
url = "mongodb://mongoadmin:secret@localhost:27017/abcd_new"

Check warning on line 57 in abcd/__init__.py

View check run for this annotation

Codecov / codecov/patch

abcd/__init__.py#L57

Added line #L57 was not covered by tests
abcd = ABCD.from_url(url)
abcd.print_info()

Expand Down
35 changes: 20 additions & 15 deletions abcd/backends/atoms_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,25 @@


class Atoms(ase.Atoms):

@classmethod
def from_dict(cls, data):
return cls(numbers=data['numbers'], positions=data['positions'])
return cls(numbers=data["numbers"], positions=data["positions"])

Check warning on line 18 in abcd/backends/atoms_http.py

View check run for this annotation

Codecov / codecov/patch

abcd/backends/atoms_http.py#L18

Added line #L18 was not covered by tests


class HttpDatabase(Database):
"""client/local interface"""

def __init__(self, url='http://localhost'):
def __init__(self, url="http://localhost"):

Check warning on line 24 in abcd/backends/atoms_http.py

View check run for this annotation

Codecov / codecov/patch

abcd/backends/atoms_http.py#L24

Added line #L24 was not covered by tests
super().__init__()

self.url = url

def push(self, atoms: ase.Atoms):
# todo: list of Atoms, metadata(user, project, tags)

message = requests.put(self.url + '/calculation', json=DictEncoder().encode(atoms))
message = requests.put(

Check warning on line 32 in abcd/backends/atoms_http.py

View check run for this annotation

Codecov / codecov/patch

abcd/backends/atoms_http.py#L32

Added line #L32 was not covered by tests
self.url + "/calculation", json=DictEncoder().encode(atoms)
)
# message = json.dumps(atoms)
# message_hash = hashlib.md5(message.encode('utf-8')).hexdigest()
logger.info(message)
Expand All @@ -44,29 +45,33 @@
pass

def search(self, query_string: str) -> List[str]:
results = requests.get(self.url + '/calculation').json()
results = requests.get(self.url + "/calculation").json()

Check warning on line 48 in abcd/backends/atoms_http.py

View check run for this annotation

Codecov / codecov/patch

abcd/backends/atoms_http.py#L48

Added line #L48 was not covered by tests
return results

def get_atoms(self, id: str) -> Atoms:
data = requests.get(self.url + '/calculation/{}'.format(id)).json()
data = requests.get(self.url + "/calculation/{}".format(id)).json()

Check warning on line 52 in abcd/backends/atoms_http.py

View check run for this annotation

Codecov / codecov/patch

abcd/backends/atoms_http.py#L52

Added line #L52 was not covered by tests
atoms = Atoms.from_dict(data)
return atoms

def __repr__(self):
return 'ABCD(type={}, url={}, ...)'.format(self.__class__.__name__, self.url)
return "ABCD(type={}, url={}, ...)".format(self.__class__.__name__, self.url)

Check warning on line 57 in abcd/backends/atoms_http.py

View check run for this annotation

Codecov / codecov/patch

abcd/backends/atoms_http.py#L57

Added line #L57 was not covered by tests

def _repr_html_(self):
"""jupyter notebook representation"""
return '<b>ABCD database</b>'
return "<b>ABCD database</b>"

Check warning on line 61 in abcd/backends/atoms_http.py

View check run for this annotation

Codecov / codecov/patch

abcd/backends/atoms_http.py#L61

Added line #L61 was not covered by tests

def print_info(self):
"""shows basic information about the connected database"""

out = linesep.join([
'{:=^50}'.format(' ABCD Database '),
'{:>10}: {}'.format('type', 'remote (http/https)'),
linesep.join('{:>10}: {}'.format(k, v) for k, v in self.db.info().items())
])
out = linesep.join(

Check warning on line 66 in abcd/backends/atoms_http.py

View check run for this annotation

Codecov / codecov/patch

abcd/backends/atoms_http.py#L66

Added line #L66 was not covered by tests
[
"{:=^50}".format(" ABCD Database "),
"{:>10}: {}".format("type", "remote (http/https)"),
linesep.join(
"{:>10}: {}".format(k, v) for k, v in self.db.info().items()
),
]
)

print(out)

Expand All @@ -80,6 +85,6 @@
pass


if __name__ == '__main__':
abcd = HttpDatabase(url='http://localhost:8080/api')
if __name__ == "__main__":
abcd = HttpDatabase(url="http://localhost:8080/api")

Check warning on line 89 in abcd/backends/atoms_http.py

View check run for this annotation

Codecov / codecov/patch

abcd/backends/atoms_http.py#L88-L89

Added lines #L88 - L89 were not covered by tests
abcd.print_info()
Loading