setuptools-tiedostot 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.
@@ -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,7 @@
1
+ setuptools_tiedostot.py,sha256=x4SEonRDVn5qg4EXLT_GxBoWgkoOYofGA5x-GWblAJc,3909
2
+ setuptools_tiedostot-0.1.dist-info/METADATA,sha256=T6lCnG1iaLyom-Ye5MsNpH5Y9S0wpPVKlI9sptL7GLE,339
3
+ setuptools_tiedostot-0.1.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
4
+ setuptools_tiedostot-0.1.dist-info/entry_points.txt,sha256=Bz-vC209SvJgT1esJWMch6jzVagZ9M6PeIUj7cvirjw,95
5
+ setuptools_tiedostot-0.1.dist-info/historia.json,sha256=8g3-e6DUfYGQFP4mtIETC7obP-8Ue5CEz38mzG-t5-8,125
6
+ setuptools_tiedostot-0.1.dist-info/top_level.txt,sha256=PfvFHqoUzS73wQao1cwx-3OBmGkbZT1eg-drRwjTePE,21
7
+ setuptools_tiedostot-0.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [egg_info.writers]
2
+ asennetut-tiedostot.txt = setuptools_tiedostot:kirjoita_asennetut_tiedostot
@@ -0,0 +1,7 @@
1
+ [
2
+ {
3
+ "revisio": "1044428f04af3207f0e856cf7552cffa5bd0050e",
4
+ "versio": "0.1",
5
+ "kuvaus": "Alustava toteutus"
6
+ }
7
+ ]
@@ -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