Skip to content

Commit 4eb787f

Browse files
authored
Merge pull request #86 from StagPython/packaging
Packaging
2 parents fe259ee + 2f7ffb6 commit 4eb787f

35 files changed

+2269
-1962
lines changed

.github/workflows/tox.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
strategy:
1616
fail-fast: false
1717
matrix:
18-
py: ['3.8', '3.9', '3.10']
18+
py: ['3.8', '3.9', '3.10', '3.11']
1919

2020
steps:
2121
- uses: actions/checkout@v3
@@ -28,6 +28,6 @@ jobs:
2828
- name: Update pip
2929
run: python -m pip install -U pip
3030
- name: Install tox-gh
31-
run: python3 -m pip install tox-gh==0.0.4 tox==4.0.0b2
31+
run: python3 -m pip install tox-gh>=1.0.0 tox==4.4.2
3232
- name: Run tox
3333
run: tox run

pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ classifiers = [
2525
"Programming Language :: Python :: 3.8",
2626
"Programming Language :: Python :: 3.9",
2727
"Programming Language :: Python :: 3.10",
28+
"Programming Language :: Python :: 3.11",
2829
]
2930
requires-python = ">=3.8"
3031
dependencies = [
@@ -65,3 +66,7 @@ module = [
6566
"scipy.*",
6667
]
6768
ignore_missing_imports = true
69+
70+
[tool.isort]
71+
profile = "black"
72+
multi_line_output = 3

stagpy/__init__.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"""
1818

1919
from __future__ import annotations
20+
2021
import importlib.resources as imlr
2122
import os
2223
import shutil
@@ -26,20 +27,20 @@
2627

2728
from setuptools_scm import get_version
2829

29-
from . import config, _styles
30+
from . import _styles, config
3031

3132
if typing.TYPE_CHECKING:
32-
from typing import NoReturn, Any, Iterator
33+
from typing import Any, Iterator, NoReturn
3334

3435

3536
def _env(var: str) -> bool:
3637
"""Return whether var is set to True."""
37-
val = os.getenv(var, default='').lower()
38-
return val in ('true', 't', 'yes', 'y', 'on', '1')
38+
val = os.getenv(var, default="").lower()
39+
return val in ("true", "t", "yes", "y", "on", "1")
3940

4041

41-
DEBUG = _env('STAGPY_DEBUG')
42-
ISOLATED = _env('STAGPY_ISOLATED')
42+
DEBUG = _env("STAGPY_DEBUG")
43+
ISOLATED = _env("STAGPY_ISOLATED")
4344

4445

4546
def sigint_handler(*_: Any) -> NoReturn:
@@ -48,7 +49,7 @@ def sigint_handler(*_: Any) -> NoReturn:
4849
It is set when you use StagPy as a command line tool to handle gracefully
4950
keyboard interruption.
5051
"""
51-
print('\nSo long, and thanks for all the fish.')
52+
print("\nSo long, and thanks for all the fish.")
5253
sys.exit()
5354

5455

@@ -61,7 +62,7 @@ def _iter_styles() -> Iterator[str]:
6162
def _check_config() -> None:
6263
"""Create config files as necessary."""
6364
config.CONFIG_DIR.mkdir(parents=True, exist_ok=True)
64-
verfile = config.CONFIG_DIR / '.version'
65+
verfile = config.CONFIG_DIR / ".version"
6566
uptodate = verfile.is_file() and verfile.read_text() == __version__
6667
if not uptodate:
6768
verfile.write_text(__version__)
@@ -75,13 +76,17 @@ def _check_config() -> None:
7576

7677

7778
if DEBUG:
78-
print('StagPy runs in DEBUG mode because the environment variable',
79-
'STAGPY_DEBUG is set to "True"', sep='\n', end='\n\n')
79+
print(
80+
"StagPy runs in DEBUG mode because the environment variable",
81+
'STAGPY_DEBUG is set to "True"',
82+
sep="\n",
83+
end="\n\n",
84+
)
8085
else:
8186
_PREV_INT = signal.signal(signal.SIGINT, sigint_handler)
8287

8388
try:
84-
__version__ = get_version(root='..', relative_to=__file__)
89+
__version__ = get_version(root="..", relative_to=__file__)
8590
except LookupError:
8691
try:
8792
from ._version import version as __version__

stagpy/__main__.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,27 @@ def main() -> None:
1111
"""Implement StagPy entry point."""
1212
if not DEBUG:
1313
signal.signal(signal.SIGINT, sigint_handler)
14-
warnings.simplefilter('ignore')
14+
warnings.simplefilter("ignore")
1515
from . import args, error
16+
1617
try:
1718
args.parse_args()()
1819
except error.StagpyError as err:
1920
if DEBUG:
2021
raise
2122
errtype = type(err).__name__
22-
print('Oops! StagPy encountered the following problem while '
23-
'processing your request.', 'Please check the path to your '
24-
'simulation and the command line arguments.', '',
25-
f'{errtype}: {err}', sep='\n', file=sys.stderr)
23+
print(
24+
"Oops! StagPy encountered the following problem while "
25+
"processing your request.",
26+
"Please check the path to your "
27+
"simulation and the command line arguments.",
28+
"",
29+
f"{errtype}: {err}",
30+
sep="\n",
31+
file=sys.stderr,
32+
)
2633
sys.exit()
2734

2835

29-
if __name__ == '__main__':
36+
if __name__ == "__main__":
3037
main()

stagpy/_helpers.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
from . import conf
1111

1212
if typing.TYPE_CHECKING:
13-
from typing import Optional, Any
13+
from typing import Any, Optional
14+
1415
from matplotlib.figure import Figure
1516
from numpy import ndarray
1617

@@ -31,8 +32,8 @@ def out_name(stem: str, timestep: Optional[int] = None) -> str:
3132
if conf.core.shortname:
3233
return conf.core.outname
3334
if timestep is not None:
34-
stem = f'{stem}{timestep:05d}'
35-
return conf.core.outname + '_' + stem
35+
stem = f"{stem}{timestep:05d}"
36+
return conf.core.outname + "_" + stem
3637

3738

3839
def scilabel(value: float, precision: int = 2) -> str:
@@ -47,13 +48,14 @@ def scilabel(value: float, precision: int = 2) -> str:
4748
Returns:
4849
the scientific notation of the specified value.
4950
"""
50-
man, exps = f'{value:.{precision}e}'.split('e')
51+
man, exps = f"{value:.{precision}e}".split("e")
5152
exp = int(exps)
52-
return fr'{man}\times 10^{{{exp}}}'
53+
return rf"{man}\times 10^{{{exp}}}"
5354

5455

55-
def saveplot(fig: Figure, *name_args: Any, close: bool = True,
56-
**name_kwargs: Any) -> None:
56+
def saveplot(
57+
fig: Figure, *name_args: Any, close: bool = True, **name_kwargs: Any
58+
) -> None:
5759
"""Save matplotlib figure.
5860
5961
You need to provide :data:`stem` as a positional or keyword argument (see
@@ -66,8 +68,9 @@ def saveplot(fig: Figure, *name_args: Any, close: bool = True,
6668
name_kwargs: keyword arguments passed on to :func:`out_name`.
6769
"""
6870
oname = out_name(*name_args, **name_kwargs)
69-
fig.savefig(f'{oname}.{conf.plot.format}',
70-
format=conf.plot.format, bbox_inches='tight')
71+
fig.savefig(
72+
f"{oname}.{conf.plot.format}", format=conf.plot.format, bbox_inches="tight"
73+
)
7174
if close:
7275
plt.close(fig)
7376

@@ -85,9 +88,9 @@ def baredoc(obj: object) -> str:
8588
"""
8689
doc = getdoc(obj)
8790
if not doc:
88-
return ''
91+
return ""
8992
doc = doc.splitlines()[0]
90-
return doc.rstrip(' .').lstrip()
93+
return doc.rstrip(" .").lstrip()
9194

9295

9396
def find_in_sorted_arr(value: Any, array: ndarray, after: bool = False) -> int:

0 commit comments

Comments
 (0)