1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
--- a/mathlibtools/lib.py
+++ b/mathlibtools/lib.py
@@ -21,7 +21,8 @@
import requests
from tqdm import tqdm # type: ignore
-import toml
+import tomli
+import tomli_w
import yaml
from git import (Repo, Commit, InvalidGitRepositoryError, # type: ignore
GitCommandError, BadName, RemoteReference) # type: ignore
@@ -84,7 +85,7 @@ def mathlib_lean_version() -> VersionTuple:
"""Return the latest Lean release supported by mathlib"""
resp = requests.get("https://raw.githubusercontent.com/leanprover-community/mathlib/master/leanpkg.toml")
assert resp.status_code == 200
- conf = toml.loads(resp.text)
+ conf = tomli.loads(resp.text)
return parse_version(conf['package']['lean_version'])
def set_download_url(url: str = AZURE_URL) -> None:
@@ -441,7 +442,8 @@ def from_path(cls, path: Path, cache_url: str = '',
except ValueError:
rev = ''
directory = find_root(path)
- config = toml.load(directory/'leanpkg.toml')
+ with (directory/'leanpkg.toml').open('rb') as pkgtoml:
+ config = tomli.load(pkgtoml)
return cls(repo, is_dirty, rev, directory,
config['package'], config['dependencies'],
@@ -456,7 +458,8 @@ def user_wide(cls, cache_url: str = '',
version of Lean supported by mathlib."""
directory = Path.home()/'.lean'
try:
- config = toml.load(directory/'leanpkg.toml')
+ with (directory/'leanpkg.toml').open('rb') as pkgtoml:
+ config = tomli.load(pkgtoml)
except FileNotFoundError:
directory.mkdir(exist_ok=True)
version = mathlib_lean_version()
@@ -469,8 +472,8 @@ def user_wide(cls, cache_url: str = '',
pkg = { 'name': '_user_local_packages',
'version': '1',
'lean_version': version_str }
- with (directory/'leanpkg.toml').open('w') as pkgtoml:
- toml.dump({'package': pkg}, pkgtoml)
+ with (directory/'leanpkg.toml').open('wb') as pkgtoml:
+ tomli_w.dump({'package': pkg}, pkgtoml)
config = { 'package': pkg, 'dependencies': dict() }
return cls(None, False, '', directory,
@@ -534,7 +537,8 @@ def mathlib_repo(self) -> Repo:
def read_config(self) -> None:
try:
- config = toml.load(self.directory/'leanpkg.toml')
+ with (self.directory/'leanpkg.toml').open('rb') as pkgtoml:
+ config = tomli.load(pkgtoml)
except FileNotFoundError:
raise InvalidLeanProject('Missing leanpkg.toml')
@@ -551,7 +555,7 @@ def write_config(self) -> None:
# for dependencies.
with (self.directory/'leanpkg.toml').open('w') as cfg:
cfg.write('[package]\n')
- cfg.write(toml.dumps(self.pkg_config))
+ cfg.write(tomli_w.dumps(self.pkg_config))
cfg.write('\n[dependencies]\n')
for dep, val in self.deps.items():
nval = str(val).replace("'git':", 'git =').replace(
--- a/setup.py
+++ b/setup.py
@@ -28,7 +28,7 @@
"License :: OSI Approved :: Apache Software License",
"Operating System :: OS Independent" ],
python_requires='>=3.6',
- install_requires=['toml>=0.10.0', 'PyGithub', 'certifi', 'gitpython>=2.1.11', 'requests',
+ install_requires=['tomli', 'tomli-w', 'PyGithub', 'certifi', 'gitpython>=2.1.11', 'requests',
'Click', 'tqdm', 'networkx', 'pydot',
'PyYAML>=3.13', 'atomicwrites', "dataclasses; python_version=='3.6'"]
)
|