mddj 0.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mddj/__init__.py +3 -0
- mddj/builder.py +34 -0
- mddj/cli.py +59 -0
- mddj/readers.py +21 -0
- mddj-0.0.1.dist-info/LICENSE.txt +9 -0
- mddj-0.0.1.dist-info/METADATA +68 -0
- mddj-0.0.1.dist-info/RECORD +10 -0
- mddj-0.0.1.dist-info/WHEEL +5 -0
- mddj-0.0.1.dist-info/entry_points.txt +2 -0
- mddj-0.0.1.dist-info/top_level.txt +1 -0
mddj/__init__.py
ADDED
mddj/builder.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import contextlib
|
|
2
|
+
import pathlib
|
|
3
|
+
import subprocess
|
|
4
|
+
import sys
|
|
5
|
+
import tempfile
|
|
6
|
+
import typing as t
|
|
7
|
+
|
|
8
|
+
import click
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@contextlib.contextmanager
|
|
12
|
+
def ephemeral_sdist(*, capture_build_output: bool = True) -> t.Iterator[pathlib.Path]:
|
|
13
|
+
with tempfile.TemporaryDirectory() as tmpdir:
|
|
14
|
+
try:
|
|
15
|
+
subprocess.run(
|
|
16
|
+
[sys.executable, "-m", "build", "--sdist", "-o", tmpdir],
|
|
17
|
+
check=True,
|
|
18
|
+
capture_output=capture_build_output,
|
|
19
|
+
)
|
|
20
|
+
except subprocess.CalledProcessError as e:
|
|
21
|
+
if capture_build_output:
|
|
22
|
+
click.secho(
|
|
23
|
+
"Encountered errors in build. "
|
|
24
|
+
"Use --no-build-capture to see full details.",
|
|
25
|
+
fg="red",
|
|
26
|
+
err=True,
|
|
27
|
+
)
|
|
28
|
+
click.get_current_context().exit(e.returncode)
|
|
29
|
+
|
|
30
|
+
# now we have an sdist, so let's find it.
|
|
31
|
+
# the package version will be in the name, so we sniff for any .tar.gz file
|
|
32
|
+
# there will only be one file
|
|
33
|
+
sdist_path = next(pathlib.Path(tmpdir).glob("*.tar.gz"))
|
|
34
|
+
yield sdist_path
|
mddj/cli.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import click
|
|
2
|
+
|
|
3
|
+
from .builder import ephemeral_sdist
|
|
4
|
+
from .readers import read_from_sdist
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@click.group("mddj")
|
|
8
|
+
@click.help_option("-h", "--help")
|
|
9
|
+
def main() -> None:
|
|
10
|
+
"""MetaData DJ"""
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@main.group("read")
|
|
14
|
+
@click.help_option("-h", "--help")
|
|
15
|
+
def read() -> None:
|
|
16
|
+
"""Read metadata from the current project."""
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@read.command("requires-python")
|
|
20
|
+
@click.help_option("-h", "--help")
|
|
21
|
+
@click.option(
|
|
22
|
+
"--lower-bound",
|
|
23
|
+
is_flag=True,
|
|
24
|
+
help="Show a lower bound rather than the full Requires-Python data.",
|
|
25
|
+
)
|
|
26
|
+
@click.option(
|
|
27
|
+
"--no-build-capture",
|
|
28
|
+
is_flag=True,
|
|
29
|
+
help="Disable capturing of the internal package build output and errors.",
|
|
30
|
+
)
|
|
31
|
+
def read_requires_python(*, lower_bound: bool, no_build_capture: bool) -> None:
|
|
32
|
+
"""
|
|
33
|
+
Read the 'Requires-Python' data.
|
|
34
|
+
"""
|
|
35
|
+
with ephemeral_sdist(capture_build_output=not no_build_capture) as sdist_path:
|
|
36
|
+
requires_python = read_from_sdist(sdist_path, "Requires-Python")
|
|
37
|
+
|
|
38
|
+
if lower_bound:
|
|
39
|
+
click.echo(find_lower_bound(requires_python))
|
|
40
|
+
else:
|
|
41
|
+
click.echo(requires_python)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def find_lower_bound(req: str) -> str:
|
|
45
|
+
reqs = req.split(",")
|
|
46
|
+
lower_bounds = []
|
|
47
|
+
for r in reqs:
|
|
48
|
+
if r.startswith(">="):
|
|
49
|
+
lower_bounds.append(r[2:])
|
|
50
|
+
elif r.startswith(">"):
|
|
51
|
+
raise RuntimeError(
|
|
52
|
+
"Found a > requirement, rejecting as invalid (use '>=' instead)"
|
|
53
|
+
)
|
|
54
|
+
if len(lower_bounds) > 1:
|
|
55
|
+
raise RuntimeError("Found multiple lower bounds, cannot choose one")
|
|
56
|
+
elif len(lower_bounds) == 0:
|
|
57
|
+
raise RuntimeError("Found no lower bounds")
|
|
58
|
+
else:
|
|
59
|
+
return lower_bounds[0]
|
mddj/readers.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import pathlib
|
|
2
|
+
import tarfile
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def read_from_sdist(sdist_path: pathlib.Path, key: str) -> str:
|
|
6
|
+
"""
|
|
7
|
+
Read a key from the PKG-INFO file in an sdist.
|
|
8
|
+
"""
|
|
9
|
+
dist_name = sdist_path.name.rsplit(".", 2)[0]
|
|
10
|
+
with tarfile.open(sdist_path, "r:gz") as tf:
|
|
11
|
+
pkg_info_fp = tf.extractfile(f"{dist_name}/PKG-INFO")
|
|
12
|
+
if pkg_info_fp is None:
|
|
13
|
+
raise RuntimeError("Could not find and read PKG-INFO in sdist")
|
|
14
|
+
pkg_info = pkg_info_fp.read().decode()
|
|
15
|
+
try:
|
|
16
|
+
data_line = next(
|
|
17
|
+
line for line in pkg_info.splitlines() if line.startswith(f"{key}:")
|
|
18
|
+
)
|
|
19
|
+
except IndexError:
|
|
20
|
+
raise RuntimeError(f"Could not find '{key}' in PKG-INFO")
|
|
21
|
+
return data_line.partition(":")[2].strip()
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023-present Stephen Rosen <sirosen@globus.org>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: mddj
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: A CLI for extracting python metadata from packages
|
|
5
|
+
Author-email: Stephen Rosen <sirosen@globus.org>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: source, https://github.com/sirosen/mddj
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Programming Language :: Python
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
16
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
17
|
+
Requires-Python: >=3.8
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE.txt
|
|
20
|
+
Requires-Dist: importlib-metadata
|
|
21
|
+
Requires-Dist: build
|
|
22
|
+
Requires-Dist: click
|
|
23
|
+
|
|
24
|
+
# mddj
|
|
25
|
+
|
|
26
|
+
Your DJ of MetaData.
|
|
27
|
+
|
|
28
|
+
[](https://pypi.org/project/mddj)
|
|
29
|
+
[](https://pypi.org/project/mddj)
|
|
30
|
+
|
|
31
|
+
-----
|
|
32
|
+
|
|
33
|
+
**Table of Contents**
|
|
34
|
+
|
|
35
|
+
- [Overview](#overview)
|
|
36
|
+
- [Installation](#installation)
|
|
37
|
+
- [Usage](#usage)
|
|
38
|
+
- [License](#license)
|
|
39
|
+
|
|
40
|
+
## Overview
|
|
41
|
+
|
|
42
|
+
A CLI for interacting with your python package metadata.
|
|
43
|
+
|
|
44
|
+
Supports multiple packaging backends via a uniform interface.
|
|
45
|
+
|
|
46
|
+
## Installation
|
|
47
|
+
|
|
48
|
+
```console
|
|
49
|
+
pipx install mddj
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Usage
|
|
53
|
+
|
|
54
|
+
### `mddj read`
|
|
55
|
+
|
|
56
|
+
Read metadata from your package by building it to an sdist and then inspecting
|
|
57
|
+
that `sdist`.
|
|
58
|
+
|
|
59
|
+
#### `mddj read requires-python`
|
|
60
|
+
|
|
61
|
+
Show the `Requires-Python` data. Supports specialized options for parsing data
|
|
62
|
+
like `--lower-bound`.
|
|
63
|
+
|
|
64
|
+
See `--help` for details.
|
|
65
|
+
|
|
66
|
+
## License
|
|
67
|
+
|
|
68
|
+
`flake8-typing-as-t` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
mddj/__init__.py,sha256=OfphfIZmR_DmABiXa3DXcRfXLST90jfBFFneUaOd8eY,43
|
|
2
|
+
mddj/builder.py,sha256=CI-QQIf5ezsmh703PeejQ9Taj5OaEP4vmi51DS1ZPq0,1123
|
|
3
|
+
mddj/cli.py,sha256=j1IYI7seU6oTghQsRXS5IPRz4LeNVyhOZgThEFnEgdU,1635
|
|
4
|
+
mddj/readers.py,sha256=oWdJDxwSC4FPt0yC1JtcqOuvl11XHG6IJT9RLfyMnN4,741
|
|
5
|
+
mddj-0.0.1.dist-info/LICENSE.txt,sha256=NWsEzuxCFDzCdEkuNpvMKdrwyxZ92lF7cn0FDUjGNGQ,1099
|
|
6
|
+
mddj-0.0.1.dist-info/METADATA,sha256=WezfYIbK4zNxstpzag6Pt8AEVOWJBU0s7AXl1dBOclY,1817
|
|
7
|
+
mddj-0.0.1.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
|
|
8
|
+
mddj-0.0.1.dist-info/entry_points.txt,sha256=gV7sA85o8GVLnTrsJHSjoI5Nb-8fZvxJAgAVOKnxBds,39
|
|
9
|
+
mddj-0.0.1.dist-info/top_level.txt,sha256=zAO8fKfxE0sxxywO34ryw0QBJJnNaLtAE1vUMPLd7FU,5
|
|
10
|
+
mddj-0.0.1.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
mddj
|