Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swap --max-order to use an environment variable given PEP 517 and 518 #420

Merged
merged 2 commits into from
Mar 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ Contributed by Victor Chahuneau.
pip install https://github.com/kpu/kenlm/archive/master.zip
```

When installing pip, the `MAX_ORDER` environment variable controls the max order with which KenLM was built.

### Basic Usage
```python
import kenlm
Expand Down
8 changes: 7 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@ def compile_test(header, library):
command = "bash -c \"g++ -include " + header + " -l" + library + " -x c++ - <<<'int main() {}' -o " + dummy_path + " >/dev/null 2>/dev/null && rm " + dummy_path + " 2>/dev/null\""
return os.system(command) == 0

max_order = "6"
# Use an environment variable
max_order = os.getenv("MAX_ORDER", "6")

# Try to get from --config-settings, if present
is_max_order = [s for s in sys.argv if "--max_order" in s]
for element in is_max_order:
max_order = re.split('[= ]',element)[1]
sys.argv.remove(element)

print(f"Will build with KenLM max_order set to {max_order}")

FILES = glob.glob('util/*.cc') + glob.glob('lm/*.cc') + glob.glob('util/double-conversion/*.cc') + glob.glob('python/*.cc')
FILES = [fn for fn in FILES if not (fn.endswith('main.cc') or fn.endswith('test.cc'))]

Expand Down Expand Up @@ -70,6 +75,7 @@ def run(self):
"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=" + ext_dir,
"-DBUILD_SHARED_LIBS=ON",
"-DBUILD_PYTHON_STANDALONE=ON",
f"-DKENLM_MAX_ORDER={max_order}",
]
cfg = "Debug" if self.debug else "Release"
build_args = ["--config", cfg]
Expand Down