Skip to content

Commit d4800a1

Browse files
authored
Merge pull request #92 from csdms/mcflugen/remove-prettier
Remove black and isort dependencies
2 parents 51fb527 + f18ae42 commit d4800a1

32 files changed

+647
-287
lines changed

.pre-commit-config.yaml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,6 @@ repos:
6666
- id: forbid-new-submodules
6767
- id: trailing-whitespace
6868

69-
- repo: https://github.com/PyCQA/pydocstyle
70-
rev: 6.3.0
71-
hooks:
72-
- id: pydocstyle
73-
files: babelizer/.*\.py$
74-
args:
75-
- --convention=numpy
76-
- --add-select=D417
77-
exclude: ^babelizer/data
78-
additional_dependencies: [".[toml]"]
79-
8069
- repo: https://github.com/pre-commit/mirrors-mypy
8170
rev: v1.8.0
8271
hooks:

README.rst

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ Read all about them in the `Basic Model Interface`_ documentation.
9494
Requirements
9595
------------
9696

97-
The *babelizer* requires Python >=3.9.
97+
The *babelizer* requires Python >=3.10.
9898

9999

100100
Apart from Python, the *babelizer* has a number of other requirements, all of which
@@ -396,23 +396,13 @@ called *hydrotrend*.
396396
python_version = ["3.7", "3.8", "3.9"]
397397
os = ["linux", "mac", "windows"]
398398
399-
You can use the ``babelize generate`` command to generate *babel.toml* files.
400-
For example the above *babel.toml* can be generated with the following,
399+
You can use the ``babelize sample-config`` command to generate
400+
a sample *babel.toml* file to get you started. For example,
401+
the above *babel.toml* can be generated with the following,
401402

402403
.. code:: bash
403404
404-
$ babelize generate \
405-
--package=pymt_hydrotrend \
406-
--summary="PyMT plugin for hydrotrend" \
407-
--language=c \
408-
--library=bmi_hydrotrend \
409-
--header=bmi_hydrotrend.h \
410-
--entry-point=register_bmi_hydrotrend \
411-
--name=Hydrotrend \
412-
--requirement=hydrotrend \
413-
--os-name=linux,mac,windows \
414-
--python-version=3.7,3.8,3.9 > babel.toml
415-
405+
babelize sample-config
416406
417407
Use
418408
---
@@ -422,13 +412,13 @@ sending output to the current directory
422412

423413
.. code:: bash
424414
425-
$ babelize init babel.toml
415+
babelize init babel.toml
426416
427417
Update an existing repository
428418

429419
.. code:: bash
430420
431-
$ babelize update
421+
babelize update
432422
433423
For a complete example of using the *babelizer*
434424
to wrap a C library exposing a BMI,

babelizer/_datadir.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import sys
2+
3+
if sys.version_info >= (3, 12): # pragma: no cover (PY12+)
4+
import importlib.resources as importlib_resources
5+
else: # pragma: no cover (<PY312)
6+
import importlib_resources
7+
8+
9+
def get_datadir() -> str:
10+
return str(importlib_resources.files("babelizer") / "data")

babelizer/_files/bmi_py.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import os
2+
3+
4+
def render(plugin_metadata) -> str:
5+
"""Render _bmi.py."""
6+
languages = {
7+
library["language"] for library in plugin_metadata._meta["library"].values()
8+
}
9+
assert len(languages) == 1
10+
language = languages.pop()
11+
12+
if language == "python":
13+
return _render_bmi_py(plugin_metadata)
14+
else:
15+
return _render_bmi_c(plugin_metadata)
16+
17+
18+
def _render_bmi_c(plugin_metadata) -> str:
19+
"""Render _bmi.py for a non-python library."""
20+
languages = [
21+
library["language"] for library in plugin_metadata._meta["library"].values()
22+
]
23+
language = languages[0]
24+
assert language in ("c", "c++", "fortran")
25+
26+
imports = [
27+
f"from {plugin_metadata.get('package', 'name')}.lib import {cls}"
28+
for cls in plugin_metadata._meta["library"]
29+
]
30+
31+
names = [
32+
f" {cls!r},".replace("'", '"') for cls in plugin_metadata._meta["library"]
33+
]
34+
35+
return f"""\
36+
{os.linesep.join(sorted(imports))}
37+
38+
__all__ = [
39+
{os.linesep.join(sorted(names))}
40+
]\
41+
"""
42+
43+
44+
def _render_bmi_py(plugin_metadata) -> str:
45+
"""Render _bmi.py for a python library."""
46+
languages = [
47+
library["language"] for library in plugin_metadata._meta["library"].values()
48+
]
49+
language = languages[0]
50+
assert language == "python"
51+
52+
header = """\
53+
import sys
54+
55+
if sys.version_info >= (3, 12): # pragma: no cover (PY12+)
56+
import importlib.resources as importlib_resources
57+
else: # pragma: no cover (<PY312)
58+
import importlib_resources
59+
"""
60+
61+
imports = [
62+
f"from {component['library']} import {component['entry_point']} as {cls}"
63+
for cls, component in plugin_metadata._meta["library"].items()
64+
]
65+
66+
rename = [
67+
f"""\
68+
{cls}.__name__ = {cls!r}
69+
{cls}.METADATA = str(importlib_resources.files(__name__) / "data/{cls}")
70+
""".replace(
71+
"'", '"'
72+
)
73+
for cls in plugin_metadata._meta["library"]
74+
]
75+
76+
names = [
77+
f" {cls!r},".replace("'", '"') for cls in plugin_metadata._meta["library"]
78+
]
79+
80+
return f"""\
81+
{header}
82+
{os.linesep.join(sorted(imports))}
83+
84+
{os.linesep.join(sorted(rename))}
85+
86+
__all__ = [
87+
{os.linesep.join(sorted(names))}
88+
]\
89+
"""

babelizer/_files/gitignore.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import os
2+
3+
4+
def render(plugin_metadata) -> str:
5+
"""Render a .gitignore file."""
6+
package_name = plugin_metadata["package"]["name"]
7+
8+
languages = {library["language"] for library in plugin_metadata["library"].values()}
9+
ignore = {
10+
"*.egg-info/",
11+
"*.py[cod]",
12+
".coverage",
13+
".nox/",
14+
"__pycache__/",
15+
"build/",
16+
"dist/",
17+
}
18+
19+
if "python" not in languages:
20+
ignore |= {"*.o", "*.so"} | {
21+
f"{package_name}/lib/{cls.lower()}.c" for cls in plugin_metadata["library"]
22+
}
23+
24+
if "fortran" in languages:
25+
ignore |= {"*.mod", "*.smod"}
26+
27+
return f"{os.linesep.join(sorted(ignore))}"

babelizer/_files/init_py.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import os
2+
3+
4+
def render(plugin_metadata) -> str:
5+
"""Render __init__.py."""
6+
package_name = plugin_metadata.get("package", "name")
7+
8+
imports = [f"from {package_name}._version import __version__"]
9+
imports += [
10+
f"from {package_name}._bmi import {cls}"
11+
for cls in plugin_metadata._meta["library"]
12+
]
13+
14+
names = [
15+
f" {cls!r},".replace("'", '"') for cls in plugin_metadata._meta["library"]
16+
]
17+
18+
return f"""\
19+
{os.linesep.join(sorted(imports))}
20+
21+
__all__ = [
22+
"__version__",
23+
{os.linesep.join(sorted(names))}
24+
]\
25+
"""

babelizer/_files/lib_init_py.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import os
2+
3+
4+
def render(plugin_metadata) -> str:
5+
"""Render lib/__init__.py."""
6+
package_name = plugin_metadata.get("package", "name")
7+
imports = [
8+
f"from {package_name}.lib.{cls.lower()} import {cls}"
9+
for cls in plugin_metadata._meta["library"]
10+
]
11+
12+
names = [
13+
f" {cls!r},".replace("'", '"') for cls in plugin_metadata._meta["library"]
14+
]
15+
16+
return f"""\
17+
{os.linesep.join(sorted(imports))}
18+
19+
__all__ = [
20+
{os.linesep.join(sorted(names))}
21+
]\
22+
"""

babelizer/_files/license_rst.py

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
from datetime import datetime
2+
3+
4+
def render(plugin_metadata) -> str:
5+
"""Render LICENSE.rst."""
6+
license_name = plugin_metadata["info"]["package_license"]
7+
kwds = {
8+
"full_name": plugin_metadata["info"]["package_author"],
9+
"year": datetime.now().year,
10+
"project_short_description": plugin_metadata["info"]["summary"],
11+
}
12+
13+
return LICENSE[license_name].format(**kwds)
14+
15+
16+
LICENSE = {
17+
"MIT License": """\
18+
MIT License
19+
===========
20+
21+
Copyright (c) *{year}*, *{full_name}*
22+
23+
Permission is hereby granted, free of charge, to any person obtaining a copy
24+
of this software and associated documentation files (the "Software"), to deal
25+
in the Software without restriction, including without limitation the rights
26+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
27+
copies of the Software, and to permit persons to whom the Software is
28+
furnished to do so, subject to the following conditions:
29+
30+
The above copyright notice and this permission notice shall be included in all
31+
copies or substantial portions of the Software.
32+
33+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39+
SOFTWARE.\
40+
""",
41+
"BSD License": """\
42+
BSD License
43+
===========
44+
45+
Copyright (c) *{year}*, *{full_name}*
46+
All rights reserved.
47+
48+
Redistribution and use in source and binary forms, with or without modification,
49+
are permitted provided that the following conditions are met:
50+
51+
* Redistributions of source code must retain the above copyright notice, this
52+
list of conditions and the following disclaimer.
53+
54+
* Redistributions in binary form must reproduce the above copyright notice, this
55+
list of conditions and the following disclaimer in the documentation and/or
56+
other materials provided with the distribution.
57+
58+
* Neither the name of the copyright holder nor the names of its
59+
contributors may be used to endorse or promote products derived from this
60+
software without specific prior written permission.
61+
62+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
63+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
64+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
65+
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
66+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
67+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
68+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
69+
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
70+
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
71+
OF THE POSSIBILITY OF SUCH DAMAGE.
72+
""",
73+
"ISC License": """\
74+
ISC License
75+
===========
76+
77+
Copyright (c) *{year}*, *{full_name}*
78+
79+
Permission to use, copy, modify, and/or distribute this software for any purpose
80+
with or without fee is hereby granted, provided that the above copyright notice
81+
and this permission notice appear in all copies.
82+
83+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
84+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
85+
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
86+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
87+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
88+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
89+
PERFORMANCE OF THIS SOFTWARE.\
90+
""",
91+
"Apache Software License 2.0": """\
92+
Apache Software License 2.0
93+
===========================
94+
95+
Copyright (c) *{year}*, *{full_name}*
96+
97+
Licensed under the Apache License, Version 2.0 (the "License");
98+
you may not use this file except in compliance with the License.
99+
You may obtain a copy of the License at
100+
101+
http://www.apache.org/licenses/LICENSE-2.0
102+
103+
Unless required by applicable law or agreed to in writing, software
104+
distributed under the License is distributed on an "AS IS" BASIS,
105+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
106+
See the License for the specific language governing permissions and
107+
limitations under the License.\
108+
""",
109+
"GNU General Public License v3": """\
110+
GNU GENERAL PUBLIC LICENSE
111+
==========================
112+
113+
Version 3, 29 June 2007
114+
115+
{project_short_description}
116+
Copyright (c) *{year}*, *{full_name}*
117+
118+
This program is free software: you can redistribute it and/or modify
119+
it under the terms of the GNU General Public License as published by
120+
the Free Software Foundation, either version 3 of the License, or
121+
(at your option) any later version.
122+
123+
This program is distributed in the hope that it will be useful,
124+
but WITHOUT ANY WARRANTY; without even the implied warranty of
125+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
126+
GNU General Public License for more details.
127+
128+
You should have received a copy of the GNU General Public License
129+
along with this program. If not, see <http://www.gnu.org/licenses/>.
130+
131+
Also add information on how to contact you by electronic and paper mail.
132+
133+
You should also get your employer (if you work as a programmer) or school,
134+
if any, to sign a "copyright disclaimer" for the program, if necessary.
135+
For more information on this, and how to apply and follow the GNU GPL, see
136+
<http://www.gnu.org/licenses/>.
137+
138+
The GNU General Public License does not permit incorporating your program
139+
into proprietary programs. If your program is a subroutine library, you
140+
may consider it more useful to permit linking proprietary applications with
141+
the library. If this is what you want to do, use the GNU Lesser General
142+
Public License instead of this License. But first, please read
143+
<http://www.gnu.org/philosophy/why-not-lgpl.html>.\
144+
""",
145+
}

0 commit comments

Comments
 (0)