py2docfx 0.1.9.dev1861949__py3-none-any.whl → 0.1.9.dev1865926__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.
py2docfx/__main__.py CHANGED
@@ -1,6 +1,8 @@
1
1
  from __future__ import annotations # Avoid A | B annotation break under <= py3.9
2
+ import asyncio
2
3
  import argparse
3
4
  import os
5
+ import subprocess
4
6
  import sys
5
7
  import time
6
8
 
@@ -222,6 +224,20 @@ def install_required_packages(
222
224
  get_source(package, idx, vststoken=ado_token, githubtoken=github_token)
223
225
  install_package(package)
224
226
 
227
+ async def create_venv_async(venv_dir: os.PathLike, package: PackageInfo) -> None:
228
+ subprocess.run([sys.executable, "-m", "venv", venv_dir], check=True)
229
+ venv_exe = os.path.join(venv_dir, "Scripts", "python.exe")
230
+ subprocess.run([venv_exe, "-m", "pip", "install", "sphinx==6.1.3"], check=True)
231
+ subprocess.run([venv_exe, "-m", "pip", "install", "setuptools"], check=True)
232
+ subprocess.run([venv_exe, "-m", "pip", "install", "pyyaml"], check=True)
233
+ subprocess.run([venv_exe, "-m", "pip", "install", "jinja2==3.0.3"], check=True)
234
+ if package.version:
235
+ pkg_install_str = package.name + "==" + package.version
236
+ else:
237
+ pkg_install_str = package.name
238
+ subprocess.run([venv_exe, "-m", "pip", "install", pkg_install_str], check=True)
239
+ return venv_exe
240
+
225
241
  def donwload_package_generate_documents(
226
242
  package_info_list: list[PackageInfo],
227
243
  output_root: str | os.PathLike | None,
@@ -235,13 +251,16 @@ def donwload_package_generate_documents(
235
251
  end_time = time.time()
236
252
  print(f"<get_source>{package.name},{end_time-start_time}<get_source/>")
237
253
 
238
- start_time = time.time()
239
- install_package(package)
240
- end_time = time.time()
254
+ # start_time = time.time()
255
+ # install_package(package)
256
+ # end_time = time.time()
241
257
  print(f"<install_package>{package.name},{end_time-start_time}<install_package/>")
242
258
 
259
+ venv_dir = os.path.join(PACKAGE_ROOT, "venv", "0")
260
+ venv_exe = asyncio.run(create_venv_async(venv_dir, package))
261
+
243
262
  start_time = time.time()
244
- generate_document(package, output_root)
263
+ generate_document(package, output_root, venv_exe)
245
264
  end_time = time.time()
246
265
  print(f"<generate_document>{package.name},{end_time-start_time}<generate_document/>")
247
266
 
@@ -1,9 +1,8 @@
1
1
  from __future__ import annotations # Avoid A | B annotation break under <= py3.9
2
2
  import os
3
- import subprocess
4
3
  import sys
5
4
  import time
6
- from py2docfx import PACKAGE_ROOT
5
+
7
6
  from py2docfx.convert_prepare.generate_conf import generate_conf
8
7
  from py2docfx.convert_prepare.git import checkout
9
8
  from py2docfx.convert_prepare.package_info import PackageInfo
@@ -12,7 +11,7 @@ from py2docfx.convert_prepare.subpackage import merge_subpackage_files
12
11
 
13
12
  CONF_TEMPLATE_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "conf_templates")
14
13
 
15
- def generate_document(pkg: PackageInfo, output_root: str | os.PathLike):
14
+ def generate_document(pkg: PackageInfo, output_root: str | os.PathLike, executable=sys.executable):
16
15
  start_time = time.time()
17
16
  # Copy manual written RST from target doc repo
18
17
  package_paths = pkg.path
@@ -47,21 +46,8 @@ def generate_document(pkg: PackageInfo, output_root: str | os.PathLike):
47
46
  end_time = time.time()
48
47
  print(f"<generate_conf>{pkg.name},{end_time-start_time}<generate_conf/>")
49
48
 
50
- venv_dir = os.path.join(PACKAGE_ROOT, "venv", "0")
51
- subprocess.run([sys.executable, "-m", "venv", venv_dir], check=True)
52
- venv_exe = os.path.join(venv_dir, "Scripts", "python.exe")
53
- subprocess.run([venv_exe, "-m", "pip", "install", "sphinx==6.1.3"], check=True)
54
- subprocess.run([venv_exe, "-m", "pip", "install", "setuptools"], check=True)
55
- subprocess.run([venv_exe, "-m", "pip", "install", "pyyaml"], check=True)
56
- subprocess.run([venv_exe, "-m", "pip", "install", "jinja2==3.0.3"], check=True)
57
- if pkg.version:
58
- pkg_install_str = pkg.name + "==" + pkg.version
59
- else:
60
- pkg_install_str = pkg.name
61
- subprocess.run([venv_exe, "-m", "pip", "install", pkg_install_str], check=True)
62
-
63
49
  start_time = time.time()
64
- run_converter(package_paths.doc_folder, package_paths.yaml_output_folder, executable=venv_exe)
50
+ run_converter(package_paths.doc_folder, package_paths.yaml_output_folder, executable=executable)
65
51
  end_time = time.time()
66
52
  print(f"<run_converter>{pkg.name},{end_time-start_time}<run_converter/>")
67
53
  subpackages_path_record = {}
@@ -71,7 +57,7 @@ def generate_document(pkg: PackageInfo, output_root: str | os.PathLike):
71
57
  for (subpackage_name, subpackage_path) in subpackages_rst_record.items():
72
58
  subpackage_yaml_path = os.path.join(subpackages_yaml_path, subpackage_name)
73
59
  subpackages_path_record[subpackage_name] = subpackage_yaml_path
74
- run_converter(subpackage_path, subpackage_yaml_path, executable=venv_exe)
60
+ run_converter(subpackage_path, subpackage_yaml_path, executable=executable)
75
61
 
76
62
  merge_subpackage_files(subpackages_path_record, package_paths.yaml_output_folder, pkg.name)
77
63
  end_time = time.time()
@@ -0,0 +1,53 @@
1
+ """
2
+ Test the generate_document function.
3
+ """
4
+ import os
5
+ import sys
6
+ import shutil
7
+ from py2docfx.convert_prepare.generate_document import generate_document
8
+ from py2docfx.convert_prepare.package_info import PackageInfo
9
+ from py2docfx.convert_prepare.source import Source
10
+
11
+ def test_generate_document(tmp_path):
12
+ """
13
+ Test the generate_document function.
14
+ """
15
+ # init test case
16
+ source_code_path = "convert_prepare\\tests\\data\\generate_document"
17
+ output_root = os.path.join(tmp_path, "output")
18
+ shutil.copytree(source_code_path, os.path.join(tmp_path, "source\\0"))
19
+ package = PackageInfo()
20
+ package.name = "azure-dummy-sourcecode"
21
+ package.exclude_path = ["test*", "example*", "sample*", "doc*"]
22
+ package.install_type = PackageInfo.InstallType.PYPI
23
+ package.version = None
24
+ package.build_in_subpackage = False
25
+ package.extra_index_url = None
26
+ package.prefer_source_distribution = False
27
+ source_folder = os.path.join(tmp_path, "source\\0\\azure-dummy-sourcecode")
28
+ yaml_output_folder = os.path.join(tmp_path, "yaml_output")
29
+ package.path = Source(
30
+ source_folder=source_folder, yaml_output_folder=yaml_output_folder, package_name=package.name
31
+ )
32
+
33
+ # add dummy code to python sys path to simulate installation
34
+ os.environ["PYTHONPATH"] = os.path.abspath(source_folder)
35
+ sys.path.insert(0, os.path.abspath(source_folder))
36
+
37
+ # add docfx_yaml to python sys path for sphinx build to import
38
+ sys.path.insert(1, os.path.abspath("docfx_yaml"))
39
+
40
+ # call the function
41
+ generate_document(package, output_root)
42
+
43
+ #assert the result
44
+ yaml_path = os.path.join(yaml_output_folder, "_build\\docfx_yaml")
45
+ assert os.path.exists(yaml_path)
46
+ assert os.path.exists(os.path.join(yaml_path, "azure.dummy.sourcecode.foo.foo.yml"))
47
+ assert os.path.exists(os.path.join(yaml_path, "azure.dummy.sourcecode.boo.boo.yml"))
48
+ assert os.path.exists(os.path.join(yaml_path, "azure.dummy.sourcecode.foo.foo.Foo.yml"))
49
+ assert os.path.exists(os.path.join(yaml_path, "azure.dummy.sourcecode.boo.boo.Boo.yml"))
50
+ assert os.path.exists(os.path.join(yaml_path, "azure.dummy.sourcecode.yml"))
51
+ assert not os.path.exists(os.path.join(yaml_path, "azure.dummy.yml"))
52
+ assert not os.path.exists(os.path.join(yaml_path, "azure.yml"))
53
+ assert os.path.exists(os.path.join(yaml_path, "toc.yml"))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: py2docfx
3
- Version: 0.1.9.dev1861949
3
+ Version: 0.1.9.dev1865926
4
4
  Summary: A package built based on Sphinx which download source code package and generate yaml files supported by docfx.
5
5
  Author: Microsoft Corporation
6
6
  License: MIT License
@@ -1,9 +1,9 @@
1
1
  py2docfx/__init__.py,sha256=kPRhPGPC1JknDotkksG428c1iIgfFr_4_7Jm-llrowY,72
2
- py2docfx/__main__.py,sha256=GqWpjtCsIlKzE9_FDFBV4fJbKvgyFoYUvMYJqUfZBKI,12074
2
+ py2docfx/__main__.py,sha256=E9u8YQ3W4eMm7xg6ELrzih2sfcn0YqxTbxBFP2euhR8,13065
3
3
  py2docfx/convert_prepare/__init__.py,sha256=XxtxrP0kmW3ZBHIAoxsPDEHzcgeC0WSnole8Lk6CjKs,11
4
4
  py2docfx/convert_prepare/environment.py,sha256=AwS4c4OSwVdxlExBLVo310HrVhFMhWQ2Wh9RJPJKH1c,894
5
5
  py2docfx/convert_prepare/generate_conf.py,sha256=wqs6iyElzJarH-20_qEL9zvZvt5xfBMsGXSXPSZy6wg,2295
6
- py2docfx/convert_prepare/generate_document.py,sha256=nZnbThthpCgPu5YGuFnWQSRRiDuJBpVqsTgLKYNj1m8,3879
6
+ py2docfx/convert_prepare/generate_document.py,sha256=cLfFr7od0RHADkXyh2gaPreXZGvKNBUlduBosYTuPbk,3118
7
7
  py2docfx/convert_prepare/get_source.py,sha256=eEIbfLkGdBSOIJElMBTiXkKlkujb_hdFu5g6InNroTg,5851
8
8
  py2docfx/convert_prepare/git.py,sha256=xGJp2nDWLfVljrxyPnFKPoLIqmBh6by-QdITogIuxi0,5893
9
9
  py2docfx/convert_prepare/install_package.py,sha256=hATmgazcSX7k2n4jQXh9sQMyNUc1k1YqHv5K5UMALq4,262
@@ -23,6 +23,7 @@ py2docfx/convert_prepare/post_process/merge_toc.py,sha256=coyae54OB1nGcCkxz9oAu-
23
23
  py2docfx/convert_prepare/subpackage_merge/merge_root_package.py,sha256=uK96qL2asuSfo_3SZaoP8XZaUvjf5mNkr17JNbZR4Lg,1026
24
24
  py2docfx/convert_prepare/subpackage_merge/merge_toc.py,sha256=nkVqe8R0m8D6cyTYV7aIpMDXorvn4-LXfU_vIK_hJBg,1706
25
25
  py2docfx/convert_prepare/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
26
+ py2docfx/convert_prepare/tests/test_generate_document.py,sha256=FpxwyRQFBfEdYUH16tpcJrqTAC0J5mq-Edn-N7Lz0rY,2413
26
27
  py2docfx/convert_prepare/tests/test_get_source.py,sha256=70EVlIZe71aDYDOXMnhqzZclKL8KuIg4t-X0U-pVyhA,7429
27
28
  py2docfx/convert_prepare/tests/test_pack.py,sha256=46JWMNzknIptDVs7D3CuxcmqBr_OKMmaw1br9H7wqco,4134
28
29
  py2docfx/convert_prepare/tests/test_package_info.py,sha256=hdNpAH9hlLF-cX9sKAu3cmiCtphX4USy9G_gWI_iaHo,3883
@@ -5330,7 +5331,7 @@ py2docfx/venv/0/Scripts/rst2s5.py,sha256=qup0-LMkBGLuh6Bj-1n8ucEVc5T8ANpqL0Pscmp
5330
5331
  py2docfx/venv/0/Scripts/rst2xetex.py,sha256=FNBX2UuBN3vqJQss_DdqjMBSU5BQmOFGLOZV8DSNAuk,905
5331
5332
  py2docfx/venv/0/Scripts/rst2xml.py,sha256=7uyNsZb5QOV243R-EQqdsyUKX7t5_9sQd6LYtw1ZyPA,634
5332
5333
  py2docfx/venv/0/Scripts/rstpep2html.py,sha256=p-PYRUWuvD1LWAzofxrQu_Go3SMfIS8q0pmy6HT2Y5E,702
5333
- py2docfx-0.1.9.dev1861949.dist-info/METADATA,sha256=fwvuv5S6J2-6S42KgT8bWHICqOhrLVAI4VGMFmEx5A4,600
5334
- py2docfx-0.1.9.dev1861949.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
5335
- py2docfx-0.1.9.dev1861949.dist-info/top_level.txt,sha256=5dH2uP81dczt_qQJ38wiZ-gzoVWasfiJALWRSjdbnYU,9
5336
- py2docfx-0.1.9.dev1861949.dist-info/RECORD,,
5334
+ py2docfx-0.1.9.dev1865926.dist-info/METADATA,sha256=kY1kthhnWMguDb-mKMpM8MoJV-rjLljUyyH51hAtyRc,600
5335
+ py2docfx-0.1.9.dev1865926.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
5336
+ py2docfx-0.1.9.dev1865926.dist-info/top_level.txt,sha256=5dH2uP81dczt_qQJ38wiZ-gzoVWasfiJALWRSjdbnYU,9
5337
+ py2docfx-0.1.9.dev1865926.dist-info/RECORD,,