Add bare metal Mac installation and run process to remove admin requirements - #109
Add bare metal Mac installation and run process to remove admin requirements#109tarahmarie wants to merge 34 commits into
Conversation
macOS wc outputs leading whitespace, causing .split() to fail on banality_finder.py line 60. Adds sed patch to install script matching the manual fix already applied to the local copy. Third of three upstream macOS compatibility fixes: 1. line_count.py rewrite (non-lz4 branch broken) 2. ulimit increase for large corpora 3. banality_finder.py .strip() before .split()
Mac bare metal
describe mac bare metal process and tag for thesis usage
… pre and sets configs correctly
Installtion and configuration updates. Install script installs needed…
Install.sh script rewrite for a bare metal mac
Install.sh scaffold and config setup
multithread update
text_setup.sh
generate() shelled out via os.system with the output path interpolated unquoted in eleven places, including rm -rf: any output path containing a space word-splits in the shell, failing at best and deleting the wrong path at worst (macOS paths like ~/Library/Mobile Documents contain spaces). Directory setup and cleanup now use shutil.rmtree/os.makedirs; the external-sort index pipeline stays in the shell for performance but shell-quotes every path occurrence. Verified with a functional test on a path containing spaces.
saveAlignmentConfig writes alignment_config.ini by looking up a hardcoded list of field names on matchingParams via reflection. banalNgrams and oneWayMatching no longer exist on the struct, so FieldByName returned the zero Value and every run's provenance record contained '<invalid reflect.Value>' for both. Removed the two stale names; the remaining seventeen all exist on the struct. go build passes.
my_config.ini shipped with a machine-specific source_file_path; it is now blank like the config template, with the path applied at run time. text_setup.sh hardcoded another machine's absolute path in its sed line; it now derives the repo root from the script's own location.
A 4 MB build artifact; it also embeds build-machine paths. The install flow builds it from source, and it now stays untracked via .gitignore. The local copy is untouched.
Upstream fixes
Completes what the generate_ngrams fix started: __main__.py shelled out with unquoted interpolated paths (three rm -rf sites, the full compareNgrams command line, and the batch-merge pipeline), and banality_finder.py chained rm && mv through the shell. Directory removal and moves now use shutil/os.replace (atomic); the compareNgrams command shell-quotes every path-valued argument; the batch-merge pipeline is NUL-delimited (find -print0 | sort -zV | xargs -0) so batch paths with spaces survive. Not covered, deliberately: web_loader.py (web-app deployment) and vector_space_alignment (experimental). Note that full end-to-end support for output paths containing spaces additionally requires a fix in PhiloLogic's Loader.setup_db_dir, which runs rm -rf through the shell unquoted (directly below its own unused shellquote helper); textpair's own code no longer mishandles such paths. Verified: py_compile passes; a 30-document French corpus runs the full pipeline (parse, ngrams, alignment, banality flagging, grouping) with identical results before and after.
…pstream my_config.ini and text_setup.sh are machine-specific run helpers that do not belong in the shared history (local copies untouched, now gitignored). lib/textpair.egg-info/entry_points.txt is generated build metadata; reverted to the upstream version so it carries no diff.
Untrack fork-local run config and setup script; align egg-info with u…
Extend path-space safety to the core alignment pipeline
…un() entry point Conflict resolutions: - config: upstream's sa_config.ini/vsa_config.ini split adopted wholesale (fork's language=en template default dropped to keep upstream defaults) - install.sh: upstream's version kept verbatim; the fork's bare-metal installer ships as the new opt-in install_bare_metal_mac.sh (seed file reference updated to config/sa_config.ini) - entry point: upstream's run() name kept; the fork's macOS RLIMIT_NOFILE raise/restore folded into it; the .xml.xml input-dir renamer dropped (staging-side workaround, mutates user files) - lib/pyproject.toml: entry point follows run()
Sync upstream
The README's macOS section predated the upstream merge: it pointed at the retired mac-bare-metal branch and the old combined install.sh, and described patches (cli_entry wrapper, banality_finder wc fix, psycopg2-binary swap) that now live in the source or upstream. Rewritten around the opt-in install_bare_metal_mac.sh with accurate prerequisites and run instructions; the fork-voice note is gone, with the thesis attribution kept in the macOS section. The installer drops its three now-obsolete self-patching steps (cli_entry append, banality wc sed, psycopg2 swap - upstream ships psycopg2-binary and the source carries the fixes) and gains an lz4 dependency check, since the batch-merge step uses lz4cat. The PhiloLogic line_count patch stays: that package is still broken on macOS.
Update macOS docs and installer for the post-merge layout
|
this changes |
clovis
left a comment
There was a problem hiding this comment.
Thanks for the pull request! Just a few issues to resolve (noted in comments) but otherwise looks good, thanks!
There was a problem hiding this comment.
Could you make the ThreadPoolExecutor code only run under Darwin, and leave the older code which uses multiprocessing on Linux? Something like:
if platform.system() == "Darwin":
# init preprocessor with workers=workers
# for local_metadata in preprocessor.process_texts(files, progress=False) ...
else:
# workers=1, and ThreadPoolExecutor
Hope that makes sense!
There was a problem hiding this comment.
cool thought, good call. just a sec.
|
|
||
|
|
||
| def read_global_config() -> configparser.ConfigParser: | ||
| """Read global_settings.ini from the first location(s) that exist. Missing files are silently skipped.""" |
There was a problem hiding this comment.
This isn't quite right I believe. The second location overrides the first, no? Which is fine btw. Just a nitpick on the comment.
There was a problem hiding this comment.
It does and its a fair nit, This is dug killing run a muck
| @@ -0,0 +1 @@ | |||
| 3.11.15 | |||
There was a problem hiding this comment.
why hardcode to 3.11? The original install.sh lets you choose your Python executable which gives you more flexibility. I'm also planning on actually having uv install python directly (Python 3.12 most likely) to avoid any issues with Python versions.
There was a problem hiding this comment.
Its an issue with the way python is upgrading on different systems, Im game to try some alts.
There was a problem hiding this comment.
yeah, the hardcode will break stuff
| "text_preprocessing @ git+https://github.com/ARTFL-Project/text-preprocessing@v1.1.2#egg=text_preprocessing", | ||
| "fastapi==0.110.3", | ||
| "psycopg2", | ||
| "psycopg2-binary", |
There was a problem hiding this comment.
that's actually not something I'd want in production. Perhaps you could instead add an environment marker in this file to handle the Mac and Linux case? E.g.:
'psycopg2; sys_platform != "darwin"',
'psycopg2-binary; sys_platform == "darwin"',
There was a problem hiding this comment.
Ah, ok. Let me check and see if that is just the name for the package, or i did that to follow another bug.
There was a problem hiding this comment.
Nope - i made this change, adn I don't like it. I'll fix it.
There was a problem hiding this comment.
I wonder if compareNgrams should just be compiled by default. Adding Go as a dependency is not a huge ask anyway.
There was a problem hiding this comment.
I don't remember, i have to get back in and check.
There was a problem hiding this comment.
That's because I made the edit.
This is a multithreaded bare metal Mac version of text-pair that lets someone who may not have admin privileges over their laptop have a decent chance at running text-pair. It repairs some reproducibility issues and does not touch the supported Linux/Docker path.
Before committing this, I tested it, another dev (@karmichand, who also added the multithreading capabilities) tested on bare metal Mac as well, and before the upstream merge, I tested this on before-and-after alignments produced from a given corpus; the two were byte-identical.
The aligner is deterministic and code-stable; differences between runs trace to explicit, documented configuration choices, with a sub-0.1% residue from code evolution.
Below are more details; I hand-wrote much of the code but used Claude to check and handle pro forma fixes.
What's included
macOS support (opt-in)
install_bare_metal_mac.sh: standalone installer for a native macOS setup (pyenv-managed Python 3.11, buildscompareNgramsfrom source since the prebuilt binaries are Linux ELF, patches PhiloLogic'sline_count.py. see note below). Documented in a new README section with prerequisites and known limitations.run()now raisesRLIMIT_NOFILEon Darwin for the duration of the run (macOS defaults to 256 open fds, which PhiloLogic's sort/merge exceeds on large corpora) and restores it afterwards. No-op on Linux.generate_ngrams.py: ngram generation now fans out with aThreadPoolExecutorinstead of relying ontext_preprocessing's internalmultiprocess.Pool. Forking again immediately after the parse stage's pool tears down reliably deadlocks on modern macOS (bpo-33725); threads sidestep this, and throughput is equivalent.read_global_config()checks~/.text-pair/global_settings.iniafter/etc/text-pair/, so a user-level install doesn't need root to write/etc. All existing/etcinstalls behave exactly as before; the three call sites inweb_loader.pythat re-read the file directly now go through this helper.Portability/robustness fixes (benefit all platforms)
generate_ngrams.py,__main__.py, andbanality_finder.pyno longer shells out with unquoted interpolated paths (os.system("rm -rf {path}")etc.). Paths containing spaces previously failed — or worse,rm -rfword-split. Nowshutil/os.replace(atomic for the banality rewrites), with the two remaining shell pipelines (external sort, batch merge) shell-quoted and the merge NUL-delimited (find -print0 | sort -zV | xargs -0).saveAlignmentConfigincompareNgramslisted two field names (banalNgrams,oneWayMatching) that no longer exist onmatchingParams, so every run'salignment_config.inirecorded<invalid reflect.Value>for both. Removed; the remaining fields all exist.Testing
language = frenchpreprocessing path), 8 workers, macOS (Apple Silicon).go buildandbash -npass; branch merges cleanly against current master.Note on PhiloLogic
Full end-to-end support for output paths containing spaces still requires a fix in PhiloLogic itself:
Loader.setup_db_dirrunsrm -rfthrough the shell unquoted (directly below its own unusedshellquotehelper). The macOS installer patches PhiloLogic'sline_count.pyfor a separate issue (the non-lz4 code path and BSDwcoutput format).I am more than happy to file these against PhiloLogic if useful.