setuptools-tiedostot 0.1__tar.gz
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.
- setuptools_tiedostot-0.1/PKG-INFO +9 -0
- setuptools_tiedostot-0.1/pyproject.toml +18 -0
- setuptools_tiedostot-0.1/setup.cfg +4 -0
- setuptools_tiedostot-0.1/setuptools_tiedostot.egg-info/PKG-INFO +9 -0
- setuptools_tiedostot-0.1/setuptools_tiedostot.egg-info/SOURCES.txt +9 -0
- setuptools_tiedostot-0.1/setuptools_tiedostot.egg-info/dependency_links.txt +1 -0
- setuptools_tiedostot-0.1/setuptools_tiedostot.egg-info/entry_points.txt +2 -0
- setuptools_tiedostot-0.1/setuptools_tiedostot.egg-info/historia.json +7 -0
- setuptools_tiedostot-0.1/setuptools_tiedostot.egg-info/requires.txt +2 -0
- setuptools_tiedostot-0.1/setuptools_tiedostot.egg-info/top_level.txt +1 -0
- setuptools_tiedostot-0.1/setuptools_tiedostot.py +137 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: setuptools-tiedostot
|
|
3
|
+
Version: 0.1
|
|
4
|
+
Summary: Riippuvuuksineen asennettu tiedostolista paketin metadatassa
|
|
5
|
+
Author-email: Antti Hautaniemi <antti.hautaniemi@me.com>
|
|
6
|
+
Project-URL: Homepage, https://github.com/an7oine/setuptools-tiedostot.git
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
Requires-Dist: pip
|
|
9
|
+
Requires-Dist: setuptools>=70.1
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["git-versiointi>=1.7rc4", "setuptools"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
authors = [{name = "Antti Hautaniemi", email = "antti.hautaniemi@me.com"}]
|
|
7
|
+
dependencies = ["pip", "setuptools>=70.1"]
|
|
8
|
+
description = "Riippuvuuksineen asennettu tiedostolista paketin metadatassa"
|
|
9
|
+
dynamic = ["version"]
|
|
10
|
+
name = "setuptools-tiedostot"
|
|
11
|
+
requires-python = ">= 3.10"
|
|
12
|
+
urls = {Homepage = "https://github.com/an7oine/setuptools-tiedostot.git"}
|
|
13
|
+
|
|
14
|
+
[project.entry-points."egg_info.writers"]
|
|
15
|
+
"asennetut-tiedostot.txt" = "setuptools_tiedostot:kirjoita_asennetut_tiedostot"
|
|
16
|
+
|
|
17
|
+
[tool.setuptools]
|
|
18
|
+
py-modules = ["setuptools_tiedostot"]
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: setuptools-tiedostot
|
|
3
|
+
Version: 0.1
|
|
4
|
+
Summary: Riippuvuuksineen asennettu tiedostolista paketin metadatassa
|
|
5
|
+
Author-email: Antti Hautaniemi <antti.hautaniemi@me.com>
|
|
6
|
+
Project-URL: Homepage, https://github.com/an7oine/setuptools-tiedostot.git
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
Requires-Dist: pip
|
|
9
|
+
Requires-Dist: setuptools>=70.1
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
pyproject.toml
|
|
2
|
+
setuptools_tiedostot.py
|
|
3
|
+
setuptools_tiedostot.egg-info/PKG-INFO
|
|
4
|
+
setuptools_tiedostot.egg-info/SOURCES.txt
|
|
5
|
+
setuptools_tiedostot.egg-info/dependency_links.txt
|
|
6
|
+
setuptools_tiedostot.egg-info/entry_points.txt
|
|
7
|
+
setuptools_tiedostot.egg-info/historia.json
|
|
8
|
+
setuptools_tiedostot.egg-info/requires.txt
|
|
9
|
+
setuptools_tiedostot.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
setuptools_tiedostot
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
from pathlib import Path, PurePosixPath
|
|
5
|
+
import tempfile
|
|
6
|
+
import zipfile
|
|
7
|
+
|
|
8
|
+
try:
|
|
9
|
+
import tomllib
|
|
10
|
+
except ModuleNotFoundError:
|
|
11
|
+
import tomli as tomllib
|
|
12
|
+
|
|
13
|
+
from setuptools.errors import SetupError
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def kirjoita_asennetut_tiedostot(cmd, basename, filename):
|
|
17
|
+
'''
|
|
18
|
+
Kirjoita riippuvuuswheelien tiedostopolut egg-info-metadataan.
|
|
19
|
+
Ilman pyproject.toml-dependencies-listaa tiedostoa ei kirjoiteta,
|
|
20
|
+
jotta sama ympäristö voi rakentaa muitakin paketteja.
|
|
21
|
+
'''
|
|
22
|
+
argname = os.path.splitext(basename)[0]
|
|
23
|
+
tiedostolistaus = kokoa_tiedostolistaus(
|
|
24
|
+
projektin_juuri(cmd), cmd.distribution,
|
|
25
|
+
)
|
|
26
|
+
if tiedostolistaus is None:
|
|
27
|
+
cmd.write_or_delete_file(argname, filename, None)
|
|
28
|
+
return
|
|
29
|
+
cmd.write_or_delete_file(
|
|
30
|
+
argname, filename, "\n".join(tiedostolistaus),
|
|
31
|
+
)
|
|
32
|
+
# def kirjoita_asennetut_tiedostot
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def projektin_juuri(cmd) -> Path:
|
|
36
|
+
''' Hakemisto, jossa rakennettavan projektin pyproject.toml on. '''
|
|
37
|
+
juuri = getattr(cmd.distribution, "src_root", None) or os.curdir
|
|
38
|
+
return Path(juuri).resolve()
|
|
39
|
+
# def projektin_juuri
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def kokoa_tiedostolistaus(juuri: Path, jakelu) -> list[str] | None:
|
|
43
|
+
'''
|
|
44
|
+
Hae pyproject.toml-riippuvuuksien wheelit ja palauta niiden
|
|
45
|
+
tiedostopolut ilman metadatahakemistoja.
|
|
46
|
+
'''
|
|
47
|
+
vaatimukset = pakettivaatimukset(juuri, jakelu)
|
|
48
|
+
if not vaatimukset:
|
|
49
|
+
return None
|
|
50
|
+
with tempfile.TemporaryDirectory(
|
|
51
|
+
prefix="setuptools-tiedostot-",
|
|
52
|
+
) as tila:
|
|
53
|
+
hakemisto = Path(tila)
|
|
54
|
+
hae_wheelit(vaatimukset, hakemisto)
|
|
55
|
+
return tiedostot_paketeista(hakemisto)
|
|
56
|
+
# with tempfile.TemporaryDirectory
|
|
57
|
+
# def kokoa_tiedostolistaus
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def pakettivaatimukset(juuri: Path, jakelu) -> list[str]:
|
|
61
|
+
'''
|
|
62
|
+
Staattinen tai dynaaminen ``[project] dependencies``.
|
|
63
|
+
Setuptools on ratkaissut listan jakelun install_requires-kenttään.
|
|
64
|
+
Tyhjä, kun dependencies-listaa ei ole määritelty.
|
|
65
|
+
'''
|
|
66
|
+
if not dependencies_maaritetty(juuri):
|
|
67
|
+
return []
|
|
68
|
+
return [
|
|
69
|
+
str(vaatimus)
|
|
70
|
+
for vaatimus in (getattr(jakelu, "install_requires", None) or [])
|
|
71
|
+
]
|
|
72
|
+
# def pakettivaatimukset
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def dependencies_maaritetty(juuri: Path) -> bool:
|
|
76
|
+
'''
|
|
77
|
+
True, jos pyproject.toml määrittelee [project] dependencies
|
|
78
|
+
-listan staattisesti tai dynamic-kentässä.
|
|
79
|
+
'''
|
|
80
|
+
polku = juuri / "pyproject.toml"
|
|
81
|
+
if not polku.is_file():
|
|
82
|
+
return False
|
|
83
|
+
with polku.open("rb") as tiedosto:
|
|
84
|
+
projekti = tomllib.load(tiedosto).get("project") or {}
|
|
85
|
+
# with polku.open
|
|
86
|
+
if "dependencies" in projekti:
|
|
87
|
+
return True
|
|
88
|
+
return "dependencies" in list(projekti.get("dynamic") or [])
|
|
89
|
+
# def dependencies_maaritetty
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def hae_wheelit(vaatimukset: list[str], kohde: Path) -> None:
|
|
93
|
+
'''
|
|
94
|
+
Sama haku kuin `pip wheel --wheel-dir kohde <vaatimukset>`,
|
|
95
|
+
pipin konsoliskriptin Python-kutsuna. Vaatimukset ovat
|
|
96
|
+
rakennettavan projektin pyproject.toml-dependencies.
|
|
97
|
+
'''
|
|
98
|
+
from pip._internal.cli.main import main
|
|
99
|
+
|
|
100
|
+
koodi = main([
|
|
101
|
+
"wheel",
|
|
102
|
+
"--wheel-dir", str(kohde),
|
|
103
|
+
*vaatimukset,
|
|
104
|
+
])
|
|
105
|
+
if koodi:
|
|
106
|
+
raise SetupError(f"pip wheel päättyi koodiin {koodi}")
|
|
107
|
+
# def hae_wheelit
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def tiedostot_paketeista(hakemisto: Path) -> list[str]:
|
|
111
|
+
''' Yhdistä hakemiston wheel-pakettien tiedostopolut. '''
|
|
112
|
+
polut: set[str] = set()
|
|
113
|
+
for wheel in sorted(hakemisto.glob("*.whl")):
|
|
114
|
+
polut.update(tiedostot_wheelista(wheel))
|
|
115
|
+
return sorted(polut)
|
|
116
|
+
# def tiedostot_paketeista
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def tiedostot_wheelista(wheel: Path) -> list[str]:
|
|
120
|
+
'''
|
|
121
|
+
Listaa wheelin zip-jäsenet. Metadatahakemisto
|
|
122
|
+
`nimi-versio.dist-info` jätetään pois.
|
|
123
|
+
'''
|
|
124
|
+
with zipfile.ZipFile(wheel) as paketti:
|
|
125
|
+
return [
|
|
126
|
+
nimi for nimi in paketti.namelist()
|
|
127
|
+
if not nimi.endswith("/") and not on_metadata(nimi)
|
|
128
|
+
]
|
|
129
|
+
# with zipfile.ZipFile
|
|
130
|
+
# def tiedostot_wheelista
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def on_metadata(polku: str) -> bool:
|
|
134
|
+
''' Wheelin ensimmäinen polun osa on jakelun dist-info-hakemisto. '''
|
|
135
|
+
osat = PurePosixPath(polku).parts
|
|
136
|
+
return bool(osat) and osat[0].endswith(".dist-info")
|
|
137
|
+
# def on_metadata
|