Skip to content

Commit

Permalink
Formats project using ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
marshallmcdonnell committed Aug 16, 2024
1 parent f4d2086 commit bf9297d
Show file tree
Hide file tree
Showing 28 changed files with 1,274 additions and 1,293 deletions.
60 changes: 29 additions & 31 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
#
import os
import sys
sys.path.insert(0, os.path.abspath('..'))

sys.path.insert(0, os.path.abspath(".."))

import ssm_client

Expand All @@ -33,22 +34,22 @@

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.viewcode']
extensions = ["sphinx.ext.autodoc", "sphinx.ext.viewcode"]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'
source_suffix = ".rst"

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# General information about the project.
project = 'ssm-client'
project = "ssm-client"
copyright = "2020, Marshall McDonnell"
author = "Marshall McDonnell"

Expand All @@ -71,10 +72,10 @@
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This patterns also effect to html_static_path and html_extra_path
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
pygments_style = "sphinx"

# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = False
Expand All @@ -85,7 +86,7 @@
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
#html_theme = 'alabaster'
# html_theme = 'alabaster'
html_theme = "sphinx_rtd_theme"
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]

Expand All @@ -98,13 +99,13 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]


# -- Options for HTMLHelp output ---------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = 'ssm_clientdoc'
htmlhelp_basename = "ssm_clientdoc"


# -- Options for LaTeX output ------------------------------------------
Expand All @@ -113,15 +114,12 @@
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',

# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
Expand All @@ -131,21 +129,21 @@
# (source start file, target name, title, author, documentclass
# [howto, manual, or own class]).
latex_documents = [
(master_doc, 'ssm_client.tex',
'ssm-client Documentation',
'Marshall McDonnell', 'manual'),
(
master_doc,
"ssm_client.tex",
"ssm-client Documentation",
"Marshall McDonnell",
"manual",
),
]


# -- Options for manual page output ------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'ssm_client',
'ssm-client Documentation',
[author], 1)
]
man_pages = [(master_doc, "ssm_client", "ssm-client Documentation", [author], 1)]


# -- Options for Texinfo output ----------------------------------------
Expand All @@ -154,13 +152,13 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'ssm_client',
'ssm-client Documentation',
author,
'ssm_client',
'One line description of project.',
'Miscellaneous'),
(
master_doc,
"ssm_client",
"ssm-client Documentation",
author,
"ssm_client",
"One line description of project.",
"Miscellaneous",
),
]



2,108 changes: 1,035 additions & 1,073 deletions pdm.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ license = {text = "BSD 3-Clause License"}
notebooks = [
"jupyter>=1.0.0",
]
":lint" = [
"ruff>=0.6.1",
]

[tool.pdm.dev-dependencies]
test = [
Expand Down
2 changes: 1 addition & 1 deletion src/ssm_client/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Top-level package for ssm-client."""

__author__ = """Marshall McDonnell"""
__email__ = '[email protected]'
__email__ = "[email protected]"


from .ssm_rester import SSMRester
Expand Down
4 changes: 2 additions & 2 deletions src/ssm_client/containers/collection_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

class CollectionContainer:
def __init__(self, **kwargs):
self.__title = kwargs.get('title', None)
self.__uri = kwargs.get('uri', None)
self.__title = kwargs.get("title", None)
self.__uri = kwargs.get("uri", None)

def __eq__(self, other):
"""
Expand Down
4 changes: 2 additions & 2 deletions src/ssm_client/containers/dataset_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

class DatasetContainer:
def __init__(self, **kwargs):
self.__uuid = kwargs.get('uuid', None)
self.__dataset = kwargs.get('dataset', dict())
self.__uuid = kwargs.get("uuid", None)
self.__dataset = kwargs.get("dataset", dict())

def __eq__(self, other):
"""
Expand Down
5 changes: 1 addition & 4 deletions src/ssm_client/io/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from .formats import read, write

__all__ = [
'read',
'write'
]
__all__ = ["read", "write"]
14 changes: 7 additions & 7 deletions src/ssm_client/io/formats.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
from importlib import import_module


_MODULE_BASE = 'ssm_client.io.'
_MODULE_BASE = "ssm_client.io."


class UnknownFileTypeError(Exception):
pass


ioformats = {
'jcamp': 'jcamp',
'rruff': 'rruff',
'scidata-jsonld': 'scidata_jsonld',
'ssm-json': 'ssm_json',
"jcamp": "jcamp",
"rruff": "rruff",
"scidata-jsonld": "scidata_jsonld",
"ssm-json": "ssm_json",
}


Expand All @@ -25,11 +25,11 @@ def _get_ioformat(name):


def _readfunc(module, name):
return getattr(module, 'read_' + name)
return getattr(module, "read_" + name)


def _writefunc(module, name):
return getattr(module, 'write_' + name)
return getattr(module, "write_" + name)


def read(filename, ioformat=None, **kwargs) -> dict:
Expand Down
2 changes: 1 addition & 1 deletion src/ssm_client/io/jcamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def read_jcamp(filename: str) -> dict:
Args:
filename (str): Filename to read from for JCAMP-DX files
Returns:
Returns:
scidata_dict (dict): SciData JSON-LD dictionary
"""
scidata_obj = scidatalib.io.read(filename, ioformat="jcamp")
Expand Down
4 changes: 2 additions & 2 deletions src/ssm_client/io/scidata_jsonld.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def read_scidata_jsonld(filename):
Return:
scidata_dict (dict): SciData JSON-LD dictionary
"""
with open(filename, 'r') as fileobj:
with open(filename, "r") as fileobj:
scidata_dict = json.load(fileobj)
return scidata_dict

Expand All @@ -25,5 +25,5 @@ def write_scidata_jsonld(filename, scidata_dict):
filename (str): Filename for SciData JSON-LD
scidata_dict (dict): SciData JSON-LD dictionary to write out
"""
with open(filename, 'w') as fileobj:
with open(filename, "w") as fileobj:
json.dump(scidata_dict, fileobj, indent=2)
22 changes: 12 additions & 10 deletions src/ssm_client/io/ssm_json.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import json

from scidatalib.scidata import SciData


Expand All @@ -10,7 +12,7 @@ def read_ssm_json(filename: str) -> dict:
Return:
scidata_dict (dict): SciData JSON-LD dictionary
"""
with open(filename, 'r') as fileobj:
with open(filename, "r") as fileobj:
ssm_json_dict = json.load(fileobj)
scidata_obj = _ssm_json_to_scidata(ssm_json_dict)
return scidata_obj.output
Expand Down Expand Up @@ -64,7 +66,7 @@ def _scidata_to_ssm_json(scidata: SciData) -> dict:
# property
properties = sd.get("property", None)
if properties:
properties = ','.join(properties)
properties = ",".join(properties)
output["scidata"]["property"] = properties

# methodology
Expand Down Expand Up @@ -115,7 +117,6 @@ def _scidata_to_ssm_json(scidata: SciData) -> dict:
# dataset
dataset = sd.get("dataset", None)
if dataset:

dataseries_list = dataset.get("dataseries", list())
if dataseries_list:
output_dataseries_list = list()
Expand Down Expand Up @@ -165,10 +166,12 @@ def _scidata_to_ssm_json(scidata: SciData) -> dict:
]

axis = parameter.get("axis", f"axis-{i}")
output_dataseries_list.append({
f'{axis}': {"parameter": output_parameter},
"hasAxisType": axis
})
output_dataseries_list.append(
{
f"{axis}": {"parameter": output_parameter},
"hasAxisType": axis,
}
)

output_dataseries = output_dataseries_list
output["scidata"]["dataseries"] = output_dataseries
Expand All @@ -188,7 +191,7 @@ def _ssm_json_to_scidata(ssm_json: dict) -> SciData:
"""
# Construct UID for SciData document from title
title = ssm_json.get("title", "ssm:dataset")
uid = ssm_json.get("uid", f'scidata:jsonld:{title}')
uid = ssm_json.get("uid", f"scidata:jsonld:{title}")

# Setup SciData object
sd = SciData(uid)
Expand All @@ -204,7 +207,7 @@ def _ssm_json_to_scidata(ssm_json: dict) -> SciData:
sd.sources(sources)

properties = ssm_json.get("scidata").get("property", "").split(",")
sd.meta['@graph']['scidata']['property'] = properties
sd.meta["@graph"]["scidata"]["property"] = properties

description = ssm_json.get("description", "")
sd.description(description)
Expand Down Expand Up @@ -294,4 +297,3 @@ def _ssm_json_to_scidata(ssm_json: dict) -> SciData:
sd.dataseries(output_dataseries_list)

return sd

8 changes: 4 additions & 4 deletions src/ssm_client/services/collection_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ def _endpoint(self, collection: str = "") -> str:
Returns:
endpoint (str): Collection endpoint to use
"""
endpoint = f'{self.uri}/{_COLLECTION_ENDPOINT}'
endpoint = f"{self.uri}/{_COLLECTION_ENDPOINT}"
if collection:
endpoint += f'/{collection}'
endpoint += f"/{collection}"
return endpoint

@property
def uri(self):
"""
URI property for CollectionContainer
"""
return f'{self.hostname}'
return f"{self.hostname}"

def create(self, title: str) -> CollectionContainer:
"""
Expand All @@ -50,7 +50,7 @@ def create(self, title: str) -> CollectionContainer:
response = requests.post(self._endpoint(), json=json)
response.raise_for_status()
return CollectionContainer(**response.json())

def get_collections(self) -> list[CollectionContainer]:
response = requests.get(self._endpoint())
response.raise_for_status()
Expand Down
Loading

0 comments on commit bf9297d

Please sign in to comment.