Skip to content

Commit 99937fe

Browse files
committed
WIP: testing pypi building wheel ci
1 parent 9d52542 commit 99937fe

File tree

12 files changed

+673
-11
lines changed

12 files changed

+673
-11
lines changed

.github/workflows/pypi-build.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: "pypi-build"
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
pull_request:
7+
branches: ["main"]
8+
9+
10+
env:
11+
BUILD_TYPE: Release
12+
VCPKG_FILE: c:/vcpkg/scripts/buildsystems/vcpkg.cmake
13+
14+
jobs:
15+
pypi_build:
16+
runs-on: windows-latest
17+
18+
steps:
19+
- uses: actions/checkout@v4
20+
21+
- name: Setup conda environment
22+
uses: conda-incubator/setup-miniconda@v2
23+
with:
24+
auto-update-conda: true
25+
python-version: 3.9.1
26+
27+
- name: Cmake Configure
28+
run: ${{github.workspace}}/cmake/config.bat
29+
- name: CMake Build
30+
run: ${{github.workspace}}/cmake/build.bat
31+
32+
- name: Install CPython
33+
run: |
34+
choco install python --version=3.9.10
35+
36+
- name: Build wheel
37+
run: |
38+
cd src/gh/diffCheck/
39+
python setup.py bdist_wheel
40+
cd ../../..
41+
42+
- name: Upload wheel
43+
uses: actions/upload-artifact@v2
44+
with:
45+
name: wheel
46+
path: src/gh/diffCheck/dist/

README.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<p align="center">
55
<img src="https://github.com/diffCheckOrg/diffCheck/actions/workflows/win-build.yml/badge.svg">
66
<img src="https://github.com/diffCheckOrg/diffCheck/actions/workflows/gh-build.yml/badge.svg">
7+
<img src="https://github.com/diffCheckOrg/diffCheck/actions/workflows/pypi-build.yml/badge.svg">
78
<img src="https://img.shields.io/pypi/v/diffCheck" href="https://pypi.org/project/diffCheck/">
89
<img src="https://badges.frapsoft.com/os/v2/open-source.svg?v=103" href="https://github.com/ellerbrock/open-source-badges/">
910
</p>
@@ -72,9 +73,3 @@ To prototype:
7273

7374
See the [CONTRIBUTING.md](https://github.com/diffCheckOrg/diffCheck/blob/main/CONTRIBUTING.md) for more information on how to prototype with diffCheck (code guidelines, visualizer, utilities, etc).
7475

75-
76-
## TODO:
77-
- [ ] @Andrea: add writing functions for mesh and point cloud
78-
- [ ] @Andrea: refactor `IOManager.hh` with a class `IOManager` and static methods
79-
- [ ] @Andrea: test Rhino exporeted `.ply` files
80-
- [ ] @Andrea: tests suite for IO /pcdmesh / visualizer

invokes/flagerize.py

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
#! python3
2+
3+
import os
4+
import sys
5+
import argparse
6+
import re
7+
8+
import typing
9+
10+
def main(
11+
package: str,
12+
from_manifest: bool,
13+
path_manifest: str,
14+
*args, **kwargs
15+
) -> bool:
16+
# for all the files that are called code.py in the components folder
17+
# stamp on the second line of the file by not overwriting the first line
18+
for root, dirs, files in os.walk("./py/components/"):
19+
for file in files:
20+
if file == "code.py":
21+
path = os.path.join(root, file)
22+
with open(path, "r") as f:
23+
lines = f.readlines()
24+
# check if the line # r: package_name is already in the first 10 lines
25+
if any([re.search(r"# r: .+==", line) for line in lines[:10]]):
26+
print(f"File {path} is already stamped with the package version.")
27+
return False
28+
with open(path, "w") as f:
29+
f.write(lines[0])
30+
f.write(f"# r: {package}=={kwargs['version']}\n")
31+
for line in lines[1:]:
32+
f.write(line)
33+
print("Done stamping components with version number of the pypi package.")
34+
return True
35+
36+
37+
if __name__ == "__main__":
38+
parser = argparse.ArgumentParser(
39+
description="Add the # r : package==version for ghusers components release."
40+
)
41+
parser.add_argument(
42+
"--package",
43+
type=str,
44+
help="The package name."
45+
)
46+
parser.add_argument(
47+
"--source",
48+
type=str,
49+
required=False,
50+
default="./py/components/",
51+
help="The path to component folders."
52+
)
53+
parser.add_argument(
54+
"--from-manifest",
55+
action='store_true',
56+
default=False,
57+
help="Whether to update the version from the manifest file's version."
58+
)
59+
parser.add_argument(
60+
"--path-manifest",
61+
type=str,
62+
required=False,
63+
default="./manifest.yml",
64+
help="The path to the manifest file."
65+
)
66+
parser.add_argument(
67+
"--version",
68+
type=str,
69+
required=False,
70+
help="The version number to update and overwrite in the code base."
71+
)
72+
73+
args = parser.parse_args()
74+
75+
if args.package is None:
76+
parser.print_help()
77+
sys.exit(1)
78+
79+
parse_errors = []
80+
81+
_manifest_version = None
82+
if args.from_manifest:
83+
if not os.path.isfile(args.path_manifest):
84+
parse_errors.append(f"Path to manifest file is invalid: {args.path_manifest}")
85+
with open(args.path_manifest, "r") as f:
86+
manifest = f.read()
87+
match = re.search(r"version: (\d+\.\d+\.\d+)", manifest)
88+
if match:
89+
_manifest_version = match.group(1)
90+
if _manifest_version is None:
91+
parse_errors.append("Could not find the version number in the manifest file.")
92+
args.version = _manifest_version
93+
is_version_ok = True
94+
_version = args.version
95+
if not re.match(r"^\d+\.\d+\.\d+$", _version) \
96+
or _version.count(".") < 2 \
97+
or len(_version) < 5:
98+
is_version_ok = False
99+
parse_errors.append("Version must be in the format: Major.Minor.Patch")
100+
101+
is_source_populated = True
102+
if not os.path.isdir(args.source):
103+
is_source_populated = False
104+
parse_errors.append(f"Path to source folder is invalid: {args.source}")
105+
nbr_pycode_files = 0
106+
for root, dirs, files in os.walk(args.source):
107+
for file in files:
108+
if file == "code.py":
109+
nbr_pycode_files += 1
110+
if nbr_pycode_files == 0:
111+
is_source_populated = False
112+
parse_errors.append(f"Source folder is empty or does not contain components: {args.source}")
113+
114+
print("Flagerizer checks:")
115+
if _manifest_version is not None:
116+
print(f"\t[x] Version from manifest: {_manifest_version}")
117+
else:
118+
print(f"\t[ ] Version from manifest: {_manifest_version}")
119+
if is_version_ok:
120+
print("\t[x] Correct version format")
121+
else:
122+
print(f"\t[ ] Correct version format")
123+
if is_source_populated:
124+
print(f"\t[x] Source folder is populated {args.source} with {nbr_pycode_files} components")
125+
else:
126+
print(f"\t[ ] Source folder is populated")
127+
128+
if parse_errors.__len__() != 0:
129+
for error in parse_errors:
130+
print(error)
131+
sys.exit(1)
132+
133+
print("Stamping components with version number of the pypi package:")
134+
print(f"\t# r: {args.package}=={_version}")
135+
136+
res = main(
137+
package=args.package,
138+
from_manifest=args.from_manifest,
139+
path_manifest=args.path_manifest,
140+
version=_version
141+
)
142+
143+
if res:
144+
print("[x] Done flagerizing components.")
145+
else:
146+
print("[ ] Failed flagerizing components.")
147+
sys.exit(1)

invokes/pypireize.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#! python3
2+
3+
import os
4+
import sys
5+
import argparse
6+
7+
import typing
8+
9+
def main(
10+
setup_path: str,
11+
*args, **kwargs
12+
) -> bool:
13+
setup_dir = os.path.dirname(setup_path)
14+
os.chdir(setup_dir)
15+
try:
16+
os.system(f"python setup.py sdist")
17+
os.system(f"python setup.py bdist_wheel")
18+
except Exception as e:
19+
print(f"Failed to build the package: {e}")
20+
return False
21+
return True
22+
23+
if __name__ == "__main__":
24+
parser = argparse.ArgumentParser(
25+
description="Build the python package and wheel."
26+
)
27+
parser.add_argument(
28+
"--setup-path",
29+
type=str,
30+
required=True,
31+
default="./py/pypi/setup.py",
32+
help="The path to the setup file of the python package."
33+
)
34+
35+
args = parser.parse_args()
36+
parse_errors = []
37+
38+
is_setup_path_correct = True
39+
if not os.path.isfile(args.setup_path):
40+
parse_errors.append(f"Path to setup file is invalid: {args.setup_path}")
41+
is_setup_path_correct = False
42+
43+
print("Pypireize check:")
44+
if is_setup_path_correct:
45+
print(f"\t[x] Setup file path: {args.setup_path}")
46+
else:
47+
print(f"\t[ ] Setup file path: {args.setup_path}")
48+
if parse_errors:
49+
for error in parse_errors:
50+
print(error)
51+
sys.exit(1)
52+
print("Starting the pypireize task...")
53+
54+
res = main(
55+
setup_path=args.setup_path
56+
)
57+
if res:
58+
print("[x] Pypireize task completed.")
59+
else:
60+
print("[ ] Pypireize task failed.")
61+
sys.exit(1)

0 commit comments

Comments
 (0)