pyven 102__tar.gz → 104__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.
Files changed (38) hide show
  1. {pyven-102 → pyven-104}/PKG-INFO +1 -1
  2. {pyven-102 → pyven-104}/pyven/bdist.py +8 -6
  3. {pyven-102 → pyven-104}/pyven/checks.py +20 -27
  4. pyven-104/pyven/files.py +54 -0
  5. {pyven-102 → pyven-104}/pyven/licheck.py +9 -9
  6. {pyven-102 → pyven-104}/pyven/minreqs.py +2 -3
  7. {pyven-102 → pyven-104}/pyven/nlcheck.py +1 -1
  8. {pyven-102 → pyven-104}/pyven/pipify.py +15 -11
  9. {pyven-102 → pyven-104}/pyven/projectinfo.py +29 -29
  10. {pyven-102 → pyven-104}/pyven/release.py +15 -18
  11. {pyven-102 → pyven-104}/pyven/tasks.py +6 -5
  12. {pyven-102 → pyven-104}/pyven/tryinstall.py +1 -2
  13. {pyven-102 → pyven-104}/pyven/util.py +12 -8
  14. {pyven-102 → pyven-104}/pyven.egg-info/PKG-INFO +1 -1
  15. {pyven-102 → pyven-104}/setup.py +1 -1
  16. pyven-102/pyven/files.py +0 -61
  17. {pyven-102 → pyven-104}/README.md +0 -0
  18. {pyven-102 → pyven-104}/pyven/README.md.aridt +0 -0
  19. {pyven-102 → pyven-104}/pyven/__init__.py +0 -0
  20. {pyven-102 → pyven-104}/pyven/divcheck.py +0 -0
  21. {pyven-102 → pyven-104}/pyven/execcheck.py +0 -0
  22. {pyven-102 → pyven-104}/pyven/functions.py +0 -0
  23. {pyven-102 → pyven-104}/pyven/mainmodules.py +0 -0
  24. {pyven-102 → pyven-104}/pyven/patchpolicy.py +0 -0
  25. {pyven-102 → pyven-104}/pyven/projectinfo.arid +0 -0
  26. {pyven-102 → pyven-104}/pyven/pyproject.toml.aridt +0 -0
  27. {pyven-102 → pyven-104}/pyven/release.arid +0 -0
  28. {pyven-102 → pyven-104}/pyven/setup.cfg.aridt +0 -0
  29. {pyven-102 → pyven-104}/pyven/setup.py.aridt +0 -0
  30. {pyven-102 → pyven-104}/pyven/setuptools.arid +0 -0
  31. {pyven-102 → pyven-104}/pyven/sourceinfo.py +0 -0
  32. {pyven-102 → pyven-104}/pyven/tests/__init__.py +0 -0
  33. {pyven-102 → pyven-104}/pyven.egg-info/SOURCES.txt +0 -0
  34. {pyven-102 → pyven-104}/pyven.egg-info/dependency_links.txt +0 -0
  35. {pyven-102 → pyven-104}/pyven.egg-info/entry_points.txt +0 -0
  36. {pyven-102 → pyven-104}/pyven.egg-info/requires.txt +0 -0
  37. {pyven-102 → pyven-104}/pyven.egg-info/top_level.txt +0 -0
  38. {pyven-102 → pyven-104}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pyven
3
- Version: 102
3
+ Version: 104
4
4
  Summary: Manage development of multiple Python projects
5
5
  Home-page: https://pypi.org/project/pyven/
6
6
  Author: Homsar
@@ -1,7 +1,9 @@
1
1
  from argparse import ArgumentParser
2
2
  from glob import iglob
3
+ from shutil import copy2, rmtree
4
+ from subprocess import CalledProcessError, check_call
3
5
  from tempfile import mkdtemp
4
- import logging, os, shutil, subprocess
6
+ import logging, os
5
7
 
6
8
  log = logging.getLogger(__name__)
7
9
  distdir = 'dist'
@@ -18,19 +20,19 @@ def main():
18
20
  compatibility = pip.split(os.sep)[3]
19
21
  log.info("Make wheel(s) for implementation-ABI: %s", compatibility)
20
22
  try:
21
- subprocess.check_call([pip, '--no-cache-dir', 'wheel', '--no-deps', '-w', holder, '.'])
22
- except subprocess.CalledProcessError:
23
+ check_call([pip, '--no-cache-dir', 'wheel', '--no-deps', '-w', holder, '.'])
24
+ except CalledProcessError:
23
25
  log.warning('Skip compatibility:', exc_info = True)
24
26
  continue
25
27
  wheelpath, = (os.path.join(holder, n) for n in os.listdir(holder))
26
- subprocess.check_call(['auditwheel', 'repair', '--plat', args.plat, '-w', distdir, wheelpath])
28
+ check_call(['auditwheel', 'repair', '--plat', args.plat, '-w', distdir, wheelpath])
27
29
  plaintarget = os.path.join(distdir, os.path.basename(wheelpath))
28
30
  if os.path.exists(plaintarget):
29
31
  log.info("Replace plain wheel: %s", plaintarget)
30
- shutil.copy2(wheelpath, distdir)
32
+ copy2(wheelpath, distdir)
31
33
  os.remove(wheelpath)
32
34
  finally:
33
- shutil.rmtree(holder)
35
+ rmtree(holder)
34
36
 
35
37
  if ('__main__' == __name__):
36
38
  main()
@@ -8,14 +8,16 @@ from aridity.config import ConfigCtrl
8
8
  from aridity.util import NoSuchPathException, openresource
9
9
  from diapyr.util import singleton
10
10
  from itertools import chain
11
- from lagoon import diff
12
- from lagoon.program import NOEOL, partial
11
+ from lagoon import diff, docker, id, pydoc_markdown
12
+ from lagoon.program import NOEOL, partial, Program
13
13
  from pathlib import Path
14
14
  from setuptools import find_packages
15
- from shutil import copytree, ignore_patterns
15
+ from shutil import copy2, copytree, ignore_patterns
16
16
  from tempfile import NamedTemporaryFile
17
+ from urllib.request import urlopen
17
18
  from venvpool import dotpy, initlogging, Pool, Task, TemporaryDirectory
18
- import logging, os, re, shutil, subprocess, sys
19
+ from xml.sax.saxutils import escape as xml_escape
20
+ import logging, os, re, sys
19
21
 
20
22
  log = logging.getLogger(__name__)
21
23
  skip = object()
@@ -75,7 +77,7 @@ class EveryVersion:
75
77
  expected = ''.join(f"{r}\n" for r in self.info.allrequires)
76
78
  if not expected:
77
79
  expected = '# This file blank.\n'
78
- assert expected == Path(self.info.projectdir, 'requirements.txt').read_text()
80
+ assert expected == (self.info.projectdir / 'requirements.txt').read_text()
79
81
  _runcheck('*', reqscheck)
80
82
 
81
83
  def divcheck(self):
@@ -84,12 +86,12 @@ class EveryVersion:
84
86
  def divcheck():
85
87
  if pyversion >= 3:
86
88
  return skip
87
- subprocess.check_call([f"python{pyversion}", scriptpath] + self.files.pypaths)
89
+ Program.text(f"python{pyversion}")[print](scriptpath, *self.files.pypaths)
88
90
  for pyversion in self.info.config.pyversions:
89
91
  _runcheck(pyversion, divcheck)
90
92
 
91
93
  def pyflakes(self):
92
- paths = [path for excludes in [Excludes(self.info.config.flakes.exclude.globs)]
94
+ paths = [str(path) for excludes in [Excludes(self.info.config.flakes.exclude.globs)]
93
95
  for path in self.files.pypaths if os.path.relpath(path, self.files.root) not in excludes]
94
96
  def pyflakes():
95
97
  if paths:
@@ -104,11 +106,11 @@ class EveryVersion:
104
106
  with InstallDeps(self.info, self.siblings, _localrepo() if self.userepo else None) as installdeps:
105
107
  installdeps.add('nose-cov', *self.info.config.test.requires) # TODO: Facility to freeze test requires tree.
106
108
  for pyversion in self.info.config.pyversions:
107
- reportsdir = os.path.join(self.info.projectdir, 'var', str(pyversion))
108
- os.makedirs(reportsdir, exist_ok = True)
109
- xmlpath = os.path.join(reportsdir, 'nosetests.xml')
109
+ reportsdir = self.info.projectdir / 'var' / str(pyversion)
110
+ reportsdir.mkdir(exist_ok = True, parents = True)
111
+ xmlpath = reportsdir / 'nosetests.xml'
110
112
  if self.docker:
111
- coveragepath = os.path.join(self.info.projectdir, '.coverage')
113
+ coveragepath = self.info.projectdir / '.coverage'
112
114
  with bgcontainer('-v', "{0}:{0}".format('/var/run/docker.sock'), '--network', 'host', '-v', f"{os.path.abspath(self.info.projectdir)}:{Container.workdir}", f"python:{pyversiontags[pyversion][0]}") as container:
113
115
  container = Container(container)
114
116
  container.cp(installdeps.workspace, 'installdeps')
@@ -118,7 +120,6 @@ class EveryVersion:
118
120
  for command in ['apt-get', 'update'], ['apt-get', 'install', '-y', 'sudo'] + upstream_devel_packages:
119
121
  container.call(command, check = True, root = True)
120
122
  for script in upstream_devel_scripts:
121
- from lagoon import docker
122
123
  dirpath = docker.exec[NOEOL](container.container, 'mktemp', '-d') # No need to cleanup, will die with container.
123
124
  log.debug("In container dir %s run script: %s", dirpath, script)
124
125
  docker.exec[print]('-w', dirpath, '-t', container.container, 'sh', '-c', script)
@@ -131,7 +132,7 @@ class EveryVersion:
131
132
  '--with-cov', '--cov-report', 'term-missing',
132
133
  ] + sum((['--cov', p] for p in chain(find_packages(self.info.projectdir), self.info.py_modules())), []) + [cpath(p) for p in self.files.testpaths(xmlpath)] + self.noseargs)
133
134
  else:
134
- coveragepath = '.coverage'
135
+ coveragepath = Path('.coverage')
135
136
  with Pool(pyversion).readonlyortransient[self.transient](installdeps) as venv:
136
137
  status = venv.run('call', installdeps.localreqs, Task('''import collections
137
138
  try:
@@ -143,10 +144,10 @@ except AttributeError:
143
144
  '--with-doctest', '--doctest-extension', '.md',
144
145
  '--with-xunit', '--xunit-file', xmlpath,
145
146
  '--with-cov', '--cov-report', 'term-missing',
146
- ] + sum((['--cov', p] for p in chain(find_packages(self.info.projectdir), self.info.py_modules())), []) + self.files.testpaths(xmlpath) + self.noseargs)
147
- if os.path.exists(coveragepath):
148
- shutil.copy2(coveragepath, os.path.join(reportsdir, 'coverage')) # Replace whatever the status, as if we configured the location.
149
- os.remove(coveragepath) # Can't simply use rename cross-device in release case.
147
+ ] + sum((['--cov', p] for p in chain(find_packages(self.info.projectdir), self.info.py_modules())), []) + [str(p) for p in self.files.testpaths(xmlpath)] + self.noseargs)
148
+ if coveragepath.exists():
149
+ copy2(coveragepath, reportsdir / 'coverage') # Replace whatever the status, as if we configured the location.
150
+ coveragepath.unlink() # Can't simply use rename cross-device in release case.
150
151
  assert not status
151
152
 
152
153
  def readme(self):
@@ -155,7 +156,6 @@ except AttributeError:
155
156
  return o
156
157
  raise NoSuchPathException('Empty set.')
157
158
  def getpydoc(mainmodules):
158
- from lagoon import pydoc_markdown
159
159
  with TemporaryDirectory() as pydocparent:
160
160
  pydocdir = os.path.join(pydocparent, 'project')
161
161
  copytree(self.info.projectdir, pydocdir, ignore = ignore_patterns('test_*'))
@@ -197,7 +197,7 @@ except AttributeError:
197
197
  with openresource(__name__, 'README.md.aridt') as f:
198
198
  (-config).processtemplate(f, g)
199
199
  g.flush()
200
- completed = diff(g.name, os.path.join(self.info.projectdir, 'README.md'), check = False)
200
+ completed = diff(g.name, self.info.projectdir / 'README.md', check = False)
201
201
  sys.stdout.write(completed.stdout)
202
202
  assert completed.returncode in {0, 1}
203
203
  assert all('<' != l[0] for l in completed.stdout.splitlines())
@@ -216,10 +216,8 @@ except AttributeError:
216
216
  account = self.info.config.linktree.account
217
217
  if account is None:
218
218
  return skip
219
- from urllib.request import urlopen
220
- from xml.sax.saxutils import escape
221
219
  with urlopen(f"https://linktr.ee/{account}") as f: # TODO: Percent-encode.
222
- assert f">{escape(self.info.config.name)} \N{BULLET} {escape(self.info.config.tagline)}<" in f.read().decode('utf-8') # TODO: Deduce encoding, consider lagoon URL.
220
+ assert f">{xml_escape(self.info.config.name)} \N{BULLET} {xml_escape(self.info.config.tagline)}<" in f.read().decode('utf-8') # TODO: Deduce encoding, consider lagoon URL.
223
221
  _runcheck('*', linktree)
224
222
 
225
223
  class Container:
@@ -227,19 +225,16 @@ class Container:
227
225
  workdir = '/io'
228
226
 
229
227
  def __init__(self, container):
230
- from lagoon import id
231
228
  self.uid = int(id._u())
232
229
  self.gid = int(id._g())
233
230
  self.container = container
234
231
 
235
232
  def inituser(self):
236
- from lagoon import docker
237
233
  docker.exec[print](self.container, 'groupadd', '-g', os.stat('/var/run/docker.sock').st_gid, 'docker')
238
234
  docker.exec[print](self.container, 'groupadd', '-g', self.gid, 'pyvengroup')
239
235
  docker.exec[print](self.container, 'useradd', '-g', self.gid, '-G', 'docker', '-u', self.uid, '-m', 'pyvenuser')
240
236
 
241
237
  def initapt(self):
242
- from lagoon import docker
243
238
  initapt(docker.exec[partial, print](self.container))
244
239
 
245
240
  def install(self, args):
@@ -247,11 +242,9 @@ class Container:
247
242
  self.call(['pip', 'install', '--user', *args], check = True)
248
243
 
249
244
  def call(self, args, check = False, root = False):
250
- from lagoon import docker
251
245
  return docker.exec[print]('-w', self.workdir, self.container, *[] if root else ['sudo', '-u', 'pyvenuser', 'PATH=/home/pyvenuser/.local/bin:/usr/local/bin:/usr/bin:/bin', 'env'], *args, check = check)
252
246
 
253
247
  def cp(self, src, dest):
254
- from lagoon import docker
255
248
  docker.cp[print](src, f"{self.container}:{dest}")
256
249
 
257
250
  def main():
@@ -0,0 +1,54 @@
1
+ from collections import defaultdict
2
+ from lagoon import git
3
+ from lagoon.program import partial
4
+ from pathlib import Path
5
+ from venvpool import dotpy
6
+ import xml.dom.minidom as dom, os
7
+
8
+ class Files:
9
+
10
+ @staticmethod
11
+ def _findfiles(walkpath, suffixes, prefixes):
12
+ for dirpath, dirnames, filenames in os.walk(walkpath):
13
+ for name in sorted(filenames):
14
+ if any(name.endswith(suffix) for suffix in suffixes) or any(name.startswith(prefix) for prefix in prefixes):
15
+ yield Path(dirpath, name).relative_to(walkpath)
16
+ dirnames.sort()
17
+
18
+ @classmethod
19
+ def relpaths(cls, root, suffixes, prefixes):
20
+ paths = list(cls._findfiles(root, suffixes, prefixes))
21
+ if paths:
22
+ with git.check_ignore[partial](*paths, check = False, cwd = root) as p:
23
+ ignored = set(p.stdout.read().splitlines())
24
+ assert p.wait() in [0, 1]
25
+ for path in paths:
26
+ if str(path) not in ignored:
27
+ yield path
28
+
29
+ def __init__(self, root):
30
+ srcsuffixes = [x for s in ['.py', '.py3', '.pyx', '.s', '.sh', '.h', '.cpp', '.cxx', '.arid', '.gradle', '.java', '.mk', '.md'] for x in [s, f"{s}.aridt"]]
31
+ self.allsrcpaths = [root / p for p in self.relpaths(root, srcsuffixes, ['Dockerfile', 'Makefile'])]
32
+ self.docpaths = [p for p in self.allsrcpaths if p.name.endswith('.md')]
33
+ self.pypaths = [p for p in self.allsrcpaths if p.name.endswith('.py')]
34
+ self.root = root
35
+
36
+ def testpaths(self, reportpath):
37
+ paths = [p for p in self.pypaths if os.path.basename(p).startswith('test_')] + self.docpaths
38
+ if reportpath.exists():
39
+ with reportpath.open() as f:
40
+ doc = dom.parse(f)
41
+ nametopath = {'.'.join(p.relative_to(self.root).parts)[:-len(dotpy)]: p for p in paths} # FIXME: Correctly handle docpaths.
42
+ pathtotime = defaultdict(int)
43
+ for e in doc.getElementsByTagName('testcase'):
44
+ name = e.getAttribute('classname')
45
+ while True:
46
+ i = name.rfind('.')
47
+ if -1 == i:
48
+ break
49
+ name = name[:i]
50
+ if name in nametopath:
51
+ pathtotime[nametopath[name]] += float(e.getAttribute('time'))
52
+ break
53
+ paths.sort(key = lambda p: pathtotime.get(p, float('inf')))
54
+ return paths
@@ -1,4 +1,4 @@
1
- import hashlib, os, re, shlex, sys
1
+ import hashlib, re, shlex, sys
2
2
 
3
3
  gpltemplate = """# Copyright {years} {author}
4
4
 
@@ -25,9 +25,9 @@ def _hassuffix(name, *suffixes):
25
25
  return name.endswith(suffixes) or name.endswith(tuple(f"{s}.aridt" for s in suffixes))
26
26
 
27
27
  def _checkmd5(info, name, expected):
28
- licpath = os.path.join(info.projectdir, name)
28
+ licpath = info.projectdir / name
29
29
  md5 = hashlib.md5()
30
- with open(licpath) as f:
30
+ with licpath.open() as f:
31
31
  md5.update(f.read().encode('utf_8'))
32
32
  if expected != md5.hexdigest():
33
33
  raise Exception(licpath)
@@ -47,7 +47,7 @@ def licheck(info, paths):
47
47
  name = info.config.name,
48
48
  ))
49
49
  elif 'MIT' == name:
50
- with open(info.mitpath()) as f:
50
+ with info.mitpath().open() as f:
51
51
  sections.append(''.join(('# ' if l.rstrip() else '#') + l for l in f))
52
52
  elif 'UNLICENSE' == name:
53
53
  pass
@@ -55,21 +55,21 @@ def licheck(info, paths):
55
55
  raise Exception(name)
56
56
  master = ''.join(s + '\n' for s in sections) # Check each section ends with 2 newlines.
57
57
  def checkone(path):
58
- with open(path) as f:
58
+ with path.open() as f:
59
59
  text = f.read()
60
60
  if text.startswith('#!'):
61
61
  for _ in range(2):
62
62
  text = text[text.index('\n') + 1:]
63
- if _hassuffix(path, '.s'):
63
+ if _hassuffix(path.name, '.s'):
64
64
  text = re.sub('^;', '#', text, flags = re.MULTILINE)
65
- elif _hassuffix(path, '.h', '.cpp', '.cxx', '.gradle', '.java'):
65
+ elif _hassuffix(path.name, '.h', '.cpp', '.cxx', '.gradle', '.java'):
66
66
  text = re.sub('^//', '#', text, flags = re.MULTILINE)
67
- elif _hassuffix(path, '.arid'):
67
+ elif _hassuffix(path.name, '.arid'):
68
68
  text = re.sub('^:', '#', text, flags = re.MULTILINE)
69
69
  return master == text[:len(master)]
70
70
  badpaths = [p for p in paths if not checkone(p)]
71
71
  if badpaths:
72
- raise Exception(' '.join(map(shlex.quote, badpaths)))
72
+ raise Exception(' '.join(map(shlex.quote, map(str, badpaths))))
73
73
  if 'GPL' in info.config.licenses:
74
74
  _checkmd5(info, 'COPYING', 'd32239bcb673463ab874e80d47fae504')
75
75
  if 'UNLICENSE' in info.config.licenses:
@@ -1,15 +1,14 @@
1
1
  'Pin requires to their minimum allowed versions.'
2
2
  from .projectinfo import ProjectInfo
3
- from pathlib import Path
4
3
  from venvpool import initlogging
5
4
 
6
5
  def main():
7
6
  initlogging()
8
7
  info = ProjectInfo.seek('.')
9
8
  minreqs = [r.minstr() for r in info.parsedrequires()]
10
- with Path(info.projectdir, 'project.arid').open('a') as f:
9
+ with (info.projectdir / 'project.arid').open('a') as f:
11
10
  print(f"requires = $list({' '.join(minreqs)})", file = f)
12
- Path(info.projectdir, 'requirements.txt').write_text(''.join(f"{r}\n" for r in minreqs) if minreqs else '# This file blank.\n')
11
+ (info.projectdir / 'requirements.txt').write_text(''.join(f"{r}\n" for r in minreqs) if minreqs else '# This file blank.\n')
13
12
 
14
13
  if '__main__' == __name__:
15
14
  main()
@@ -4,7 +4,7 @@ class MoreThanOneEolStyleException(Exception): pass
4
4
 
5
5
  def nlcheck(paths):
6
6
  for path in paths:
7
- with open(path, 'rb') as f:
7
+ with path.open('rb') as f:
8
8
  text = f.read().decode()
9
9
  eols = set(re.findall(r'\r\n|[\r\n]', text))
10
10
  if len(eols) > 1:
@@ -3,10 +3,14 @@ from .projectinfo import ProjectInfo, Req, SimpleInstallDeps
3
3
  from argparse import ArgumentParser
4
4
  from aridity.config import ConfigCtrl
5
5
  from diapyr.util import bfs
6
+ from lagoon import git
7
+ from lagoon.program import Program
8
+ from pathlib import Path
6
9
  from pkg_resources import resource_filename
10
+ from shutil import rmtree
7
11
  from tempfile import mkdtemp
8
12
  from venvpool import initlogging, Pool
9
- import logging, os, shutil, subprocess, sys
13
+ import logging, os, sys
10
14
 
11
15
  log = logging.getLogger(__name__)
12
16
 
@@ -58,22 +62,22 @@ console_scripts := $list()
58
62
  cc.printf('" = $(%s)', quote)
59
63
  cc.processtemplate(
60
64
  resource_filename(__name__, template), # TODO LATER: Make aridity get the resource.
61
- os.path.abspath(os.path.join(info.projectdir, name)))
65
+ os.path.abspath(info.projectdir / name))
62
66
 
63
67
  def main():
64
68
  initlogging()
65
69
  parser = ArgumentParser()
66
70
  parser.add_argument('--transient', action = 'store_true')
67
71
  parser.add_argument('--version')
68
- parser.add_argument('projectdir', nargs = '?') # FIXME: When projectdir is passed in its console_scripts are not populated!
72
+ parser.add_argument('projectdir', nargs = '?', type = Path) # FIXME: When projectdir is passed in its console_scripts are not populated!
69
73
  args = parser.parse_args()
70
- info = ProjectInfo.seek('.') if args.projectdir is None else ProjectInfo(args.projectdir, os.path.join(args.projectdir, ProjectInfo.projectaridname))
74
+ info = ProjectInfo.seek('.') if args.projectdir is None else ProjectInfo(args.projectdir, args.projectdir / ProjectInfo.projectaridname)
71
75
  pipify(info, args.version)
72
76
  setupcommand(info, sys.version_info.major, args.transient, 'egg_info')
73
77
 
74
78
  def setupcommand(info, pyversion, transient, *command):
75
79
  def setup(absexecutable):
76
- subprocess.check_call([absexecutable, 'setup.py'] + list(command), cwd = info.projectdir)
80
+ Program.text(absexecutable)[print]('setup.py', *command, cwd = info.projectdir)
77
81
  if {'setuptools', 'wheel'} == set(info.allbuildrequires) and sys.version_info.major == pyversion:
78
82
  setup(sys.executable)
79
83
  else:
@@ -115,7 +119,7 @@ class InstallDeps:
115
119
  continue
116
120
  if self.siblings:
117
121
  siblingpath = r.siblingpath(i.contextworkspace())
118
- if os.path.exists(siblingpath):
122
+ if siblingpath.exists():
119
123
  editableprojects[name] = j = ProjectInfo.seek(siblingpath)
120
124
  yield j, True
121
125
  continue
@@ -125,8 +129,8 @@ class InstallDeps:
125
129
  if self.siblings:
126
130
  log.warning("Not a sibling, install from repo: %s", name)
127
131
  clonepath = os.path.join(self.workspace, name)
128
- subprocess.check_call(['git', 'clone', '--depth', '1', f"file://{repopath}", clonepath])
129
- subprocess.check_call(['git', 'fetch', '--tags'], cwd = clonepath)
132
+ git.clone[print]('--depth', 1, f"file://{repopath}", clonepath)
133
+ git.fetch.__tags[print](cwd = clonepath)
130
134
  volatileprojects[name] = j = ProjectInfo.seek(clonepath)
131
135
  yield j, False
132
136
  continue
@@ -140,7 +144,7 @@ class InstallDeps:
140
144
  return adddeps(*t)
141
145
  for i in volatileprojects.values(): # Assume editables already pipified.
142
146
  pipify(i)
143
- self.localreqs = [i.projectdir for i in editableprojects.values()]
147
+ self.localreqs = [str(i.projectdir) for i in editableprojects.values()]
144
148
  self.volatileprojects = volatileprojects.values()
145
149
  self.fetchreqs = list(Req.published(pypireqs))
146
150
  return self
@@ -149,13 +153,13 @@ class InstallDeps:
149
153
  self.fetchreqs.extend(Req.parselines(requires))
150
154
 
151
155
  def invoke(self, venv):
152
- venv.install([i.projectdir for i in self.volatileprojects] + [r.reqstr for r in self.fetchreqs])
156
+ venv.install([str(i.projectdir) for i in self.volatileprojects] + [r.reqstr for r in self.fetchreqs])
153
157
 
154
158
  def cinvoke(self, container):
155
159
  container.install([f"/installdeps/{os.path.relpath(i.projectdir, self.workspace).replace(os.sep, '/')}" for i in self.volatileprojects] + [r.reqstr for r in self.fetchreqs])
156
160
 
157
161
  def __exit__(self, *exc_info):
158
- shutil.rmtree(self.workspace)
162
+ rmtree(self.workspace)
159
163
 
160
164
  if '__main__' == __name__:
161
165
  main()
@@ -4,12 +4,18 @@ from .util import Seek
4
4
  from aridity.config import ConfigCtrl
5
5
  from aridity.model import Entry, Resource
6
6
  from aridity.util import openresource
7
+ from http import HTTPStatus
7
8
  from inspect import getsource
8
- from pathlib import Path
9
+ from lagoon import git
10
+ from lagoon.binary import tidy
11
+ from lagoon.program import Program
9
12
  from pkg_resources import parse_requirements
10
13
  from setuphacks import getsetupkwargs
14
+ from urllib.error import HTTPError
15
+ from urllib.parse import quote as url_quote
16
+ from urllib.request import Request, urlopen
11
17
  from venvpool import ParsedRequires, TemporaryDirectory
12
- import logging, os, re, subprocess, venvpool
18
+ import xml.dom.minidom as dom, json, logging, os, re, time, venvpool
13
19
 
14
20
  log = logging.getLogger(__name__)
15
21
 
@@ -36,14 +42,10 @@ class Req:
36
42
 
37
43
  @classmethod
38
44
  def published(cls, reqstrs):
39
- from http import HTTPStatus
40
- from urllib.error import HTTPError
41
- from urllib.parse import quote
42
- from urllib.request import Request, urlopen
43
45
  for r in cls.parselines(reqstrs):
44
46
  try:
45
47
  # FIXME: Allow running tests offline.
46
- with urlopen(Request(f"https://pypi.org/simple/{quote(r.namepart, safe = '')}/", method = 'HEAD')):
48
+ with urlopen(Request(f"https://pypi.org/simple/{url_quote(r.namepart, safe = '')}/", method = 'HEAD')):
47
49
  pass
48
50
  yield r
49
51
  except HTTPError as e:
@@ -74,10 +76,10 @@ class Req:
74
76
  return versionstr in self.parsed
75
77
 
76
78
  def siblingpath(self, workspace):
77
- return os.path.join(workspace, self.namepart)
79
+ return workspace / self.namepart
78
80
 
79
81
  def isproject(self, info):
80
- return os.path.exists(self.siblingpath(info.contextworkspace()))
82
+ return self.siblingpath(info.contextworkspace()).exists()
81
83
 
82
84
  def minstr(self):
83
85
  version, = (s.version for s in self.specifierset if s.operator in {'>=', '=='})
@@ -107,10 +109,10 @@ class ProjectInfo:
107
109
 
108
110
  @classmethod
109
111
  def seek(cls, realdir):
110
- path = Seek.seek(realdir, cls.projectaridname)
111
- if path is None:
112
+ seek = Seek.seek(realdir, cls.projectaridname)
113
+ if seek is None:
112
114
  raise ProjectInfoNotFoundException(realdir)
113
- return cls(path.parent, path)
115
+ return cls(seek.parent, seek.path)
114
116
 
115
117
  @classmethod
116
118
  def seekany(cls, realdir):
@@ -118,17 +120,17 @@ class ProjectInfo:
118
120
  return cls.seek(realdir)
119
121
  except ProjectInfoNotFoundException:
120
122
  pass
121
- setuppath = Seek.seek(realdir, 'setup.py')
122
- if setuppath is not None:
123
+ setupseek = Seek.seek(realdir, 'setup.py')
124
+ if setupseek is not None:
123
125
  log.info('Use setuptools mode.')
124
- return _setuptoolsinfo(setuppath)
126
+ return _setuptoolsinfo(setupseek.path)
125
127
  log.info('Use uninstallable mode.')
126
- projectdir = os.path.dirname(Seek.seek(realdir, '.git'))
128
+ projectdir = Seek.seek(realdir, '.git').path.parent
127
129
  with openresource(__name__, 'setuptools.arid') as f:
128
130
  info = cls(projectdir, f)
129
131
  info.config.name = os.path.basename(os.path.abspath(projectdir))
130
132
  try:
131
- info.allrequires.extend((Path(projectdir) / 'requirements.txt').read_text().splitlines())
133
+ info.allrequires.extend((projectdir / 'requirements.txt').read_text().splitlines())
132
134
  except FileNotFoundError:
133
135
  pass
134
136
  return info
@@ -143,10 +145,10 @@ class ProjectInfo:
143
145
  self.projectdir = projectdir
144
146
 
145
147
  def mitpath(self):
146
- return os.path.join(self.projectdir, self.config.MIT.path)
148
+ return self.projectdir / self.config.MIT.path
147
149
 
148
150
  def contextworkspace(self):
149
- return os.path.join(self.projectdir, '..')
151
+ return self.projectdir / '..'
150
152
 
151
153
  def parsedrequires(self):
152
154
  return Req.parselines(self.allrequires)
@@ -155,26 +157,24 @@ class ProjectInfo:
155
157
  return [r.namepart for r in self.parsedrequires() if r.isproject(self)]
156
158
 
157
159
  def nextversion(self): # XXX: Deduce from tags instead?
158
- import urllib.request, urllib.error, re, xml.dom.minidom as dom
159
160
  pattern = re.compile('-([0-9]+)[-.]')
160
161
  try:
161
- with urllib.request.urlopen(f"https://pypi.org/simple/{self.config.name}/") as f:
162
- doc = dom.parseString(subprocess.check_output(['tidy', '-asxml'], input = f.read()))
162
+ with urlopen(f"https://pypi.org/simple/{self.config.name}/") as f:
163
+ doc = dom.parseString(tidy._asxml(input = f.read()))
163
164
  last = max(int(pattern.search(textcontent(a)).group(1)) for a in doc.getElementsByTagName('a'))
164
- except urllib.error.HTTPError as e:
165
+ except HTTPError as e:
165
166
  if 404 != e.code:
166
167
  raise
167
168
  last = 0
168
169
  return str(max(10, last + 1))
169
170
 
170
171
  def descriptionandurl(self):
171
- import urllib.error, urllib.request, json, time
172
172
  urlpath = f"{self.config.github.account}/{self.config.name}"
173
173
  while True:
174
174
  try:
175
- with urllib.request.urlopen(f"https://api.github.com/repos/{urlpath}") as f:
175
+ with urlopen(f"https://api.github.com/repos/{urlpath}") as f:
176
176
  return json.loads(f.read().decode())['description'], f"https://github.com/{urlpath}"
177
- except urllib.error.HTTPError as e:
177
+ except HTTPError as e:
178
178
  if 403 != e.code:
179
179
  raise
180
180
  log.info("Sleep 1 minute due to: %s", e)
@@ -192,14 +192,14 @@ class ProjectInfo:
192
192
  f.write(getsource(mainmodules))
193
193
  with open(os.path.join(tempdir, 'venvpool.py'), 'w') as f:
194
194
  f.write(getsource(venvpool))
195
- for line in subprocess.check_output([f"python{next(iter(self.config.pyversions))}", scriptpath, self.projectdir] + paths).splitlines():
195
+ for line in Program.text(f"python{next(iter(self.config.pyversions))}")(scriptpath, self.projectdir, *paths).splitlines():
196
196
  yield MainModule(eval(line))
197
197
 
198
198
  def console_scripts(self):
199
199
  return [mm.console_script for mm in self.mainmodules()]
200
200
 
201
201
  def devversion(self):
202
- releases = [int(t[1:]) for t in subprocess.check_output(['git', 'tag'], cwd = self.projectdir, universal_newlines = True).splitlines() if 'v' == t[0]]
202
+ releases = [int(t[1:]) for t in git.tag(cwd = self.projectdir).splitlines() if 'v' == t[0]]
203
203
  return f"{(max(releases) if releases else 0) + 1}.dev0"
204
204
 
205
205
  class MainModule:
@@ -210,7 +210,7 @@ class MainModule:
210
210
 
211
211
  def _setuptoolsinfo(setuppath):
212
212
  with openresource(__name__, 'setuptools.arid') as f:
213
- info = ProjectInfo(os.path.dirname(setuppath), f)
213
+ info = ProjectInfo(setuppath.parent, f)
214
214
  setupkwargs = getsetupkwargs(setuppath, ['name', 'install_requires', 'entry_points'])
215
215
  if 'name' in setupkwargs:
216
216
  info.config.name = setupkwargs['name']
@@ -8,11 +8,13 @@ from argparse import ArgumentParser
8
8
  from aridity.config import ConfigCtrl
9
9
  from diapyr.util import singleton
10
10
  from itertools import chain
11
- from lagoon.program import partial, Program
11
+ from lagoon import docker, git
12
+ from lagoon.program import NOEOL, partial, Program
12
13
  from pkg_resources import resource_filename
14
+ from shutil import copy2, copytree, rmtree
13
15
  from tempfile import NamedTemporaryFile
14
16
  from venvpool import dotpy, initlogging, Pip, Pool, TemporaryDirectory
15
- import lagoon, logging, os, re, shutil, sys, sysconfig
17
+ import logging, os, re, sys, sysconfig
16
18
 
17
19
  log = logging.getLogger(__name__)
18
20
  distrelpath = 'dist'
@@ -52,8 +54,6 @@ class Image:
52
54
  self.arch = arch
53
55
 
54
56
  def makewheels(self, info): # TODO: This code would benefit from modern syntax.
55
- from lagoon import docker
56
- from lagoon.program import NOEOL
57
57
  log.info("Make wheels for platform: %s", self.plat)
58
58
  scripts = list(info.config.devel.scripts)
59
59
  packages = list(info.config.devel.packages)
@@ -83,22 +83,19 @@ def main():
83
83
  # XXX: Load info config to a scope in our config?
84
84
  info = ProjectInfo.seek(config.path)
85
85
  config.account = info.config.pypi.account
86
- git = lagoon.git[partial](cwd = info.projectdir)
87
- if git.status.__porcelain():
86
+ srcgit = git[partial](cwd = info.projectdir)
87
+ if srcgit.status.__porcelain():
88
88
  raise Exception('Uncommitted changes!')
89
89
  log.debug('No uncommitted changes.')
90
90
  with TemporaryDirectory() as tempdir:
91
91
  copydir = os.path.join(tempdir, os.path.basename(os.path.abspath(info.projectdir)))
92
92
  log.info("Copying project to: %s", copydir)
93
- shutil.copytree(info.projectdir, copydir)
94
- for relpath in release(config, git, ProjectInfo.seek(copydir)):
93
+ copytree(info.projectdir, copydir)
94
+ for relpath in release(config, srcgit, ProjectInfo.seek(copydir)):
95
95
  log.info("Replace artifact: %s", relpath)
96
- destpath = os.path.join(info.projectdir, relpath)
97
- try:
98
- os.makedirs(os.path.dirname(destpath))
99
- except OSError:
100
- pass
101
- shutil.copy2(os.path.join(copydir, relpath), destpath)
96
+ destpath = info.projectdir / relpath
97
+ destpath.parent.mkdir(exist_ok = True, parents = True)
98
+ copy2(os.path.join(copydir, relpath), destpath)
102
99
 
103
100
  def uploadableartifacts(artifactrelpaths):
104
101
  def acceptplatform(platform):
@@ -127,7 +124,7 @@ def _runsetup(info, commands):
127
124
  venv.run('check_call', ['.'], 'setup', commands, cwd = info.projectdir) # XXX: Should venvpool automatically include current dir?
128
125
 
129
126
  def release(config, srcgit, info):
130
- scrub = lagoon.git.clean._xdi[partial, print](cwd = info.projectdir, input = 'c')
127
+ scrub = git.clean._xdi[partial, print](cwd = info.projectdir, input = 'c')
131
128
  scrub()
132
129
  version = info.nextversion()
133
130
  pipify(info, version)
@@ -138,10 +135,10 @@ def release(config, srcgit, info):
138
135
  if name.startswith('test_'): # TODO LATER: Allow project to add globs to exclude.
139
136
  path = os.path.join(dirpath, name)
140
137
  log.debug("Delete: %s", path)
141
- (os.remove if name.endswith('.py') else shutil.rmtree)(path)
138
+ (os.remove if name.endswith('.py') else rmtree)(path)
142
139
  _warmups(info)
143
140
  pipify(info, version)
144
- shutil.rmtree(os.path.join(info.projectdir, '.git'))
141
+ rmtree(info.projectdir / '.git')
145
142
  setupcommands = []
146
143
  if SourceInfo(info.projectdir).extpaths:
147
144
  for image in _images():
@@ -149,7 +146,7 @@ def release(config, srcgit, info):
149
146
  else:
150
147
  setupcommands.append('bdist_wheel')
151
148
  _runsetup(info, setupcommands + ['sdist'])
152
- artifactrelpaths = [os.path.join(distrelpath, name) for name in sorted(os.listdir(os.path.join(info.projectdir, distrelpath)))]
149
+ artifactrelpaths = [os.path.join(distrelpath, name) for name in sorted(os.listdir(info.projectdir / distrelpath))]
153
150
  if config.upload:
154
151
  srcgit.tag[print](f"v{version}")
155
152
  # TODO LATER: If tag succeeded but push fails, we're left with a bogus tag.
@@ -1,19 +1,20 @@
1
1
  'Show all XX''X/TO''DO/FIX''ME comments in project.'
2
2
  from .files import Files
3
3
  from argparse import ArgumentParser
4
- import subprocess
4
+ from lagoon import ag, git
5
+ from lagoon.program import NOEOL, partial
5
6
 
6
7
  def main():
7
8
  parser = ArgumentParser()
8
9
  parser.add_argument('-q', action = 'count', default = 0)
9
10
  config = parser.parse_args()
10
- root, = subprocess.check_output(['git', 'rev-parse', '--show-toplevel']).decode().splitlines()
11
- agcommand = ['ag', '--noheading', '--nobreak']
11
+ root = git.rev_parse.__show_toplevel[NOEOL]()
12
+ agcommand = ag.__noheading.__nobreak[partial, print](cwd = root, check = False)
12
13
  # XXX: Integrate with declared project resource types?
13
14
  paths = list(Files.relpaths(root, ['.py', '.pyx', '.h', '.cpp', '.ui', '.java', '.kt', '.c', '.s', '.sh', '.arid', '.aridt', '.gradle', '.java', '.mk', '.js'], ['Dockerfile', 'Makefile']))
14
15
  for tag in ['XX''X', 'TO''DO', 'FIX''ME'][config.q:]:
15
- subprocess.call(agcommand + [tag + ' LATER'] + paths, cwd = root)
16
- subprocess.call(agcommand + [tag + '(?! LATER)'] + paths, cwd = root)
16
+ agcommand(f"{tag} LATER", *paths)
17
+ agcommand(f"{tag}(?! LATER)", *paths)
17
18
 
18
19
  if '__main__' == __name__:
19
20
  main()
@@ -2,7 +2,7 @@
2
2
  from .checks import EveryVersion
3
3
  from .projectinfo import ProjectInfo
4
4
  from .util import bgcontainer, initapt, pyversiontags
5
- from lagoon import git
5
+ from lagoon import docker, git
6
6
  from lagoon.program import partial
7
7
  from urllib.request import urlopen
8
8
  from venvpool import initlogging
@@ -11,7 +11,6 @@ import logging, xml.etree.ElementTree as ET
11
11
  log = logging.getLogger(__name__)
12
12
 
13
13
  def main():
14
- from lagoon import docker
15
14
  initlogging()
16
15
  headinfo = ProjectInfo.seek('.')
17
16
  if not headinfo.config.pypi.participant: # XXX: Or look for tags?
@@ -1,4 +1,7 @@
1
1
  from contextlib import contextmanager
2
+ from lagoon import docker
3
+ from lagoon.program import NOEOL
4
+ from pathlib import Path
2
5
  import os, re, sys
3
6
 
4
7
  pyversiontags = {2: ['2'], 3: ['3.9', '3.10', '3.11', '3.12', '3.13']}
@@ -29,24 +32,25 @@ class Excludes:
29
32
  def __contains__(self, relpath):
30
33
  return self.pattern.search(relpath) is not None
31
34
 
32
- class Seek(str):
35
+ class Seek:
33
36
 
34
37
  @classmethod
35
38
  def seek(cls, dirpath, name):
39
+ dirpath = Path(dirpath)
36
40
  while True:
37
- path = cls(os.path.join(dirpath, name))
38
- if os.path.exists(path):
39
- path.parent = dirpath
40
- return path
41
- parent = os.path.join(dirpath, '..')
41
+ path = dirpath / name
42
+ if path.exists():
43
+ seek = cls()
44
+ seek.path = path
45
+ seek.parent = dirpath
46
+ return seek
47
+ parent = dirpath / '..'
42
48
  if os.path.abspath(parent) == os.path.abspath(dirpath):
43
49
  break
44
50
  dirpath = parent
45
51
 
46
52
  @contextmanager
47
53
  def bgcontainer(*dockerrunargs):
48
- from lagoon import docker
49
- from lagoon.program import NOEOL
50
54
  container = docker.run._d[NOEOL](*dockerrunargs + ('sleep', 'inf'))
51
55
  try:
52
56
  yield container
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pyven
3
- Version: 102
3
+ Version: 104
4
4
  Summary: Manage development of multiple Python projects
5
5
  Home-page: https://pypi.org/project/pyven/
6
6
  Author: Homsar
@@ -44,7 +44,7 @@ class SourceInfo:
44
44
  sourceinfo = SourceInfo('.')
45
45
  setup(
46
46
  name = 'pyven',
47
- version = '102',
47
+ version = '104',
48
48
  description = 'Manage development of multiple Python projects',
49
49
  long_description = long_description(),
50
50
  long_description_content_type = 'text/markdown',
pyven-102/pyven/files.py DELETED
@@ -1,61 +0,0 @@
1
- from collections import defaultdict
2
- import os, subprocess, xml.dom.minidom as dom
3
-
4
- class Files:
5
-
6
- @staticmethod
7
- def _findfiles(walkpath, suffixes, prefixes):
8
- def acceptname():
9
- for suffix in suffixes:
10
- if name.endswith(suffix):
11
- return True
12
- for prefix in prefixes:
13
- if name.startswith(prefix):
14
- return True
15
- prefixlen = len(walkpath + os.sep)
16
- for dirpath, dirnames, filenames in os.walk(walkpath):
17
- for name in sorted(filenames):
18
- if acceptname():
19
- yield os.path.join(dirpath, name)[prefixlen:]
20
- dirnames.sort()
21
-
22
- @classmethod
23
- def relpaths(cls, root, suffixes, prefixes):
24
- paths = list(cls._findfiles(root, suffixes, prefixes))
25
- if os.path.exists(os.path.join(root, '.gitmodules')):
26
- for submoduleslash in (l.split(' ', 1)[1] + os.sep for l in subprocess.check_output(['git', 'config', '--file', '.gitmodules', '--get-regexp', '^submodule[.].+[.]path$'], cwd = root).decode().splitlines()):
27
- paths = [p for p in paths if not p.startswith(submoduleslash)]
28
- if paths:
29
- p = subprocess.Popen(['git', 'check-ignore'] + paths, stdout = subprocess.PIPE, cwd = root)
30
- ignored = set(p.communicate()[0].decode().splitlines())
31
- assert p.wait() in [0, 1]
32
- for path in paths:
33
- if path not in ignored:
34
- yield path
35
-
36
- def __init__(self, root):
37
- srcsuffixes = sum(([s, f"{s}.aridt"] for s in ['.py', '.py3', '.pyx', '.s', '.sh', '.h', '.cpp', '.cxx', '.arid', '.gradle', '.java', '.mk', '.md']), [])
38
- self.allsrcpaths = [os.path.join(root, p) for p in self.relpaths(root, srcsuffixes, ['Dockerfile', 'Makefile'])]
39
- self.docpaths = [p for p in self.allsrcpaths if p.endswith('.md')]
40
- self.pypaths = [p for p in self.allsrcpaths if p.endswith('.py')]
41
- self.root = root
42
-
43
- def testpaths(self, reportpath):
44
- paths = [p for p in self.pypaths if os.path.basename(p).startswith('test_')] + self.docpaths
45
- if os.path.exists(reportpath):
46
- with open(reportpath) as f:
47
- doc = dom.parse(f)
48
- nametopath = dict([p[len(self.root + os.sep):-len('.py')].replace(os.sep, '.'), p] for p in paths)
49
- pathtotime = defaultdict(int)
50
- for e in doc.getElementsByTagName('testcase'):
51
- name = e.getAttribute('classname')
52
- while True:
53
- i = name.rfind('.')
54
- if -1 == i:
55
- break
56
- name = name[:i]
57
- if name in nametopath:
58
- pathtotime[nametopath[name]] += float(e.getAttribute('time'))
59
- break
60
- paths.sort(key = lambda p: pathtotime.get(p, float('inf')))
61
- return paths
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes