Skip to content

Commit

Permalink
Merge pull request #420 from jacobkahn/fix_max_order
Browse files Browse the repository at this point in the history
Swap --max-order to use an environment variable given PEP 517 and 518
  • Loading branch information
kpu authored Mar 5, 2023
2 parents 9af679c + fa98633 commit 716251e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
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

0 comments on commit 716251e

Please sign in to comment.