Skip to content

Commit 0a929c9

Browse files
committed
updated setup.py tests.yml
1 parent 3e04af6 commit 0a929c9

File tree

5 files changed

+113
-75
lines changed

5 files changed

+113
-75
lines changed

.flake8

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
; [flake8]
2+
; exclude = site-packages, __pycache__, .git, .venv, .eggs, *.egg-info
3+
; max-line-length = 88
14
[flake8]
2-
exclude = site-packages, __pycache__, .git, .venv, .eggs, *.egg-info
3-
max-line-length = 88
5+
max-line-length = 100
6+
exclude = .git,__pycache__,build,dist,*.egg-info
7+
ignore = E203,W503
8+
per-file-ignores = __init__.py:F401

.github/workflows/tests.yml

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,71 +16,73 @@ jobs:
1616
fail-fast: false
1717

1818
steps:
19-
- name: Checkout code
20-
uses: actions/checkout@v4
21-
19+
- uses: actions/checkout@v4
20+
2221
- name: Set up Python ${{ matrix.python-version }}
2322
uses: actions/setup-python@v5
2423
with:
2524
python-version: ${{ matrix.python-version }}
2625

27-
- name: Install build tools (Windows)
26+
- name: Install build dependencies (Windows)
2827
if: runner.os == 'Windows'
2928
run: |
30-
choco install visualstudio2019buildtools --include-optional
31-
choco install windows-sdk-10.0 --include-optional
29+
choco install visualstudio2019buildtools --package-parameters "--add Microsoft.VisualStudio.Component.VC.Tools.x86.x64"
30+
choco install windows-sdk-10.0
3231
33-
- name: Set environment variables (Windows)
32+
- name: Set up MSVC (Windows)
33+
if: runner.os == 'Windows'
34+
uses: microsoft/[email protected]
35+
36+
- name: Build Windows Extension
3437
if: runner.os == 'Windows'
3538
run: |
36-
setx PATH "%PATH%;C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin"
37-
38-
- name: Debug environment
39-
run: |
40-
echo "OS: ${{ matrix.os }}"
41-
echo "Python Version: ${{ matrix.python-version }}"
42-
python -m sysconfig
43-
echo "Python include: $(python -c 'import sysconfig; print(sysconfig.get_path("include"))')"
44-
echo "Python libdir: $(python -c 'import sysconfig; print(sysconfig.get_config_var("LIBDIR"))')"
45-
python --version
46-
pip list
39+
python setup.py build_ext --inplace
40+
mkdir -p optimrl/c_src
41+
Copy-Item build\lib.win-amd64*\optimrl\c_src\libgrpo.dll optimrl\c_src\
4742
48-
- name: Install dependencies
43+
- name: Install package
4944
run: |
50-
python -m pip install --upgrade pip
45+
python -m pip install --upgrade pip setuptools wheel
5146
pip install -e '.[test]'
5247
53-
- name: Run tests with pytest
54-
run: |
55-
pytest tests/ -v
48+
- name: Run tests
49+
run: pytest tests/ -v
5650

5751
lint:
5852
runs-on: ubuntu-latest
5953
steps:
60-
- name: Checkout code
61-
uses: actions/checkout@v4
54+
- uses: actions/checkout@v4
6255

6356
- name: Set up Python
6457
uses: actions/setup-python@v5
6558
with:
6659
python-version: '3.12'
6760

68-
- name: Install linting dependencies
61+
- name: Install linting tools
6962
run: |
7063
python -m pip install --upgrade pip
71-
pip install black isort flake8
64+
pip install black==23.12.1 isort==5.13.2 flake8==7.0.0
7265
73-
- name: Auto-correct formatting issues
66+
- name: Create linting configs
67+
run: |
68+
echo "[flake8]
69+
max-line-length = 100
70+
exclude = .git,__pycache__,build,dist,*.egg-info
71+
ignore = E203,W503
72+
per-file-ignores = __init__.py:F401" > .flake8
73+
74+
echo "[tool.isort]
75+
profile = \"black\"
76+
line_length = 100
77+
skip = [\"site-packages\", \"__pycache__\"]" >> pyproject.toml
78+
79+
- name: Format code
7480
run: |
7581
black optimrl tests
7682
isort optimrl tests
7783
78-
- name: Check code formatting
84+
- name: Check code style
7985
run: |
8086
black --check optimrl tests
8187
isort --check-only optimrl tests
82-
flake8 optimrl tests
83-
84-
- name: Upgrade setuptools
85-
run: python -m pip install --upgrade setuptools wheel
86-
88+
flake8 optimrl tests

optimrl/core.py

Lines changed: 49 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -37,39 +37,58 @@ def __init__(self, epsilon=0.2, beta=0.1):
3737
# Set up C function interfaces
3838
self._setup_functions()
3939

40+
# def _find_library_path(self):
41+
# """Find the path to the compiled library file."""
42+
# # Get the directory of the current file
43+
# current_dir = os.path.dirname(os.path.abspath(__file__))
44+
45+
# # Determine library name based on platform
46+
# if platform.system() == "Darwin":
47+
# lib_name = "libgrpo.dylib"
48+
# elif platform.system() == "Linux":
49+
# lib_name = "libgrpo.so"
50+
# elif platform.system() == "Windows":
51+
# lib_name = "libgrpo.dll"
52+
# else:
53+
# raise OSError(f"Unsupported operating system: {platform.system()}")
54+
55+
# # Possible locations for the library
56+
# possible_paths = [
57+
# os.path.join(current_dir, "c_src", lib_name),
58+
# os.path.join(current_dir, lib_name),
59+
# os.path.join(os.path.dirname(current_dir), "c_src", lib_name),
60+
# os.path.join(sys.prefix, "lib", lib_name),
61+
# ]
62+
63+
# # Find the first existing library file
64+
# for path in possible_paths:
65+
# if os.path.exists(path):
66+
# return path
67+
68+
# paths_str = "\n".join(possible_paths)
69+
# raise FileNotFoundError(
70+
# f"Could not find {lib_name}. Searched in:\n{paths_str}\n"
71+
# "Try reinstalling the package or building the C extension."
72+
# )
4073
def _find_library_path(self):
41-
"""Find the path to the compiled library file."""
42-
# Get the directory of the current file
4374
current_dir = os.path.dirname(os.path.abspath(__file__))
44-
45-
# Determine library name based on platform
46-
if platform.system() == "Darwin":
47-
lib_name = "libgrpo.dylib"
48-
elif platform.system() == "Linux":
49-
lib_name = "libgrpo.so"
50-
elif platform.system() == "Windows":
51-
lib_name = "libgrpo.dll"
52-
else:
53-
raise OSError(f"Unsupported operating system: {platform.system()}")
54-
55-
# Possible locations for the library
56-
possible_paths = [
57-
os.path.join(current_dir, "c_src", lib_name),
58-
os.path.join(current_dir, lib_name),
59-
os.path.join(os.path.dirname(current_dir), "c_src", lib_name),
60-
os.path.join(sys.prefix, "lib", lib_name),
75+
lib_name = {
76+
'Windows': 'libgrpo.dll',
77+
'Darwin': 'libgrpo.dylib',
78+
'Linux': 'libgrpo.so'
79+
}[platform.system()]
80+
81+
search_paths = [
82+
os.path.join(current_dir, "c_src"),
83+
current_dir,
84+
os.path.join(os.path.dirname(current_dir), "c_src"),
85+
os.path.join(sys.prefix, "lib")
6186
]
62-
63-
# Find the first existing library file
64-
for path in possible_paths:
65-
if os.path.exists(path):
66-
return path
67-
68-
paths_str = "\n".join(possible_paths)
69-
raise FileNotFoundError(
70-
f"Could not find {lib_name}. Searched in:\n{paths_str}\n"
71-
"Try reinstalling the package or building the C extension."
72-
)
87+
88+
for path in search_paths:
89+
full_path = os.path.normpath(os.path.join(path, lib_name))
90+
if os.path.exists(full_path):
91+
return full_path
7392

7493
def _load_library(self):
7594
"""Load the compiled C library."""

pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,8 @@ skip = [
1818
"site-packages",
1919
"__pycache__",
2020
]
21+
22+
23+
[tool.mypy]
24+
ignore_missing_imports = true
25+
strict_optional = true

setup.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def build_extensions(self):
2222
print(f"Include dirs: {ext.include_dirs}")
2323
print(f"Library dirs: {ext.library_dirs}")
2424
super().build_extensions()
25-
25+
2626
compiler_type = self.compiler.compiler_type
2727
for ext in self.extensions:
2828
if compiler_type == 'unix':
@@ -89,17 +89,24 @@ def finalize_options(self):
8989

9090
# Define the extension module
9191

92+
# grpo_module = Extension(
93+
# 'optimrl.c_src.libgrpo',
94+
# sources=['optimrl/c_src/grpo.c'],
95+
# include_dirs=[
96+
# 'optimrl/c_src',
97+
# python_include_path
98+
# ],
99+
# library_dirs=[
100+
# python_lib_path # Include the Python library path dynamically
101+
# ],
102+
# libraries=['m'] if platform.system() != 'Windows' else [],
103+
# extra_compile_args=['-O3', '-fPIC'] if platform.system() != 'Windows' else ['/O2'],
104+
# extra_link_args=['-L' + python_lib_path] if platform.system() != 'Windows' else ['/EXPORT:PyInit_libgrpo']
105+
# )
92106
grpo_module = Extension(
93107
'optimrl.c_src.libgrpo',
94108
sources=['optimrl/c_src/grpo.c'],
95-
include_dirs=[
96-
'optimrl/c_src',
97-
python_include_path
98-
],
99-
library_dirs=[
100-
python_lib_path # Include the Python library path dynamically
101-
],
102-
libraries=['m'] if platform.system() != 'Windows' else [],
109+
include_dirs=[...],
103110
extra_compile_args=['-O3', '-fPIC'] if platform.system() != 'Windows' else ['/O2'],
104111
extra_link_args=['-L' + python_lib_path] if platform.system() != 'Windows' else ['/EXPORT:PyInit_libgrpo']
105112
)

0 commit comments

Comments
 (0)