Skip to content

Commit ec36f45

Browse files
committed
Added CLI support
1 parent a9d6e65 commit ec36f45

132 files changed

Lines changed: 2273 additions & 40 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

find-project-root/docs/README.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121

2222
**find-project-root** is a lightweight utility that traverses up from a given path until it finds a project marker.
2323

24-
- Minimal dependencies — only uses [project-markers][project-markers-gh] (~4 KB module)
24+
- Lightweight — < 100 KB
2525
- Path flexibility — accepts strings, `Path` objects, or current working dir
2626
- Customizable markers — provide your own or use defaults
27-
- Multi-Python support — from Python 2.6 thru 3.15+
27+
- Multi-env support — use via [API](#api-usage) or [CLI](#command-line-usage)
2828

2929
<hr>
3030

@@ -84,6 +84,24 @@ root = find_project_root(path='src', max_depth=5, markers=['manifest.json'])
8484

8585
<hr>
8686

87+
## Command line usage
88+
89+
```bash
90+
find-project-root # or projectroot
91+
# e.g. => 'e:\python\utils\translate-messages'
92+
```
93+
94+
CLI options:
95+
96+
| Option | Description
97+
| ------------------- | ------------------------------------
98+
| `-h`, `--help` | Show help screen
99+
| `-v`, `--version` | Show version
100+
| `--docs` | Open docs URL
101+
102+
<hr>
103+
104+
87105
## MIT License
88106

89107
Copyright © 2026 [Adam Lui](https://github.com/adamlui)

find-project-root/noxfile.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1+
from pathlib import Path
12
import sys
3+
from types import SimpleNamespace as sn
24

35
import nox
46

57
py_cmd = 'py' if sys.platform.startswith('win') else 'python3'
8+
pkg = sn(dir=Path(__file__).parent.name)
9+
pkg.name = pkg.dir.replace('-', '_')
610

711
def session(func) : return nox.session(venv_backend='none', name=func.__name__.replace('_', '-'))(func)
812

913
@session
10-
def dev(session) : session.run('pip', 'install', '-e', '.')
14+
def dev(session) : session.run('pip', 'install', '-e', '.') ; session.run(pkg.dir, '--help', *session.posargs)
15+
@session
16+
def debug(session) : session.run(py_cmd, '-m', pkg.name, '--debug', *session.posargs, env={ 'PYTHONPATH': 'src' })
1117
@session
1218
def test_py26(session):
1319
from pathlib import Path

find-project-root/pyproject.toml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,14 @@ license-files = [
1818
"docs/LICENSE.md",
1919
]
2020
dependencies = [
21+
"colorama>=0.4.6,<1 ; platform_system == 'Windows'",
22+
"is-unicode-supported>=1.2.1,<2",
23+
"json5>=0.14.0,<1",
24+
"non-latin-locales>=1.0.5,<2",
2125
"project-markers>=1.0.4,<2",
26+
"sys-lang>=1.0.1,<2",
2227
]
23-
requires-python = ">=2.6,<4"
28+
requires-python = ">=3.8,<4"
2429
keywords = [
2530
"detect",
2631
"detection",
@@ -71,10 +76,20 @@ Issues = "https://github.com/adamlui/python-utils/issues"
7176
Releases = "https://github.com/adamlui/python-utils/releases"
7277
Repository = "https://github.com/adamlui/python-utils"
7378

79+
[project.scripts]
80+
project-root = "find_project_root.cli.__main__:main"
81+
get-project-root = "find_project_root.cli.__main__:main"
82+
find-project-root = "find_project_root.cli.__main__:main"
83+
projectroot = "find_project_root.cli.__main__:main"
84+
getprojectroot = "find_project_root.cli.__main__:main"
85+
findprojectroot = "find_project_root.cli.__main__:main"
86+
7487
[project.optional-dependencies]
7588
dev = [
7689
"nox>=2026.4.10",
7790
"pre-commit>=4.5.1,<5",
91+
"remove-json-keys>=1.10.1,<2",
7892
"tomli>=2.4.1,<3",
7993
"tomli-w>=1.2.0,<2",
94+
"translate-messages>=1.10.1,<2",
8095
]
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import sys
2-
31
from .api import find_project_root
42

5-
sys.modules[__name__] = find_project_root # type: ignore
3+
__all__ = ['find_project_root']

find-project-root/src/find_project_root/cli/__init__.py

Whitespace-only changes.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import sys
2+
3+
from ..api import find_project_root
4+
from .lib import init, settings
5+
6+
def main():
7+
cli = init.cli()
8+
9+
# Process early-exit args (e.g. --help, --version)
10+
for ctrl_name, ctrl in vars(settings.controls).items():
11+
if getattr(ctrl, 'exit', False) and getattr(cli.config, ctrl_name, False):
12+
if hasattr(ctrl, 'handler') : ctrl.handler(cli)
13+
sys.exit(0)
14+
15+
print(find_project_root())
16+
17+
if __name__ == '__main__' : main()
File renamed without changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from . import csv, file, json, sns
2+
3+
__all__ = ['csv', 'file', 'json', 'sns']
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from typing import List
2+
3+
def parse(val: str) -> List[str]:
4+
if not val : return []
5+
return [item.strip() for item in val.split(',') if item.strip()]
File renamed without changes.

0 commit comments

Comments
 (0)