Skip to content

Commit cfe5cdb

Browse files
authored
Merge pull request #11 from Garcia6l20/devel
Devel
2 parents 4687f4c + 9db09dd commit cfe5cdb

Some content is hidden

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

56 files changed

+1204
-304
lines changed

.github/workflows/publish.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Publish to PyPI.org
2+
on:
3+
release:
4+
types: [published]
5+
jobs:
6+
pypi:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Checkout
10+
uses: actions/checkout@v3
11+
- run: python3 -m pip install --upgrade build && python3 -m build
12+
- name: Publish package
13+
uses: pypa/gh-action-pypi-publish@release/v1
14+
with:
15+
password: ${{ secrets.PYPI_API_KEY }}

README.md

Lines changed: 124 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,28 @@
44
55
_dan_ is a build system inspired from _GNU make_, _cmake_, _meson_, ... but only in python.
66

7+
It is mostly designed to be easy to use, it comes with its [vscode extension](https://github.com/Garcia6l20/dan-vscode) available on the [marketplace](https://marketplace.visualstudio.com/items?itemName=garcia6l20.dan).
8+
9+
It also provide a packaging system called [dan.io](https://github.com/Garcia6l20/dan.io),
10+
that will fetch and build 3rd party libraries.
11+
12+
## Install
13+
14+
_dan_ is available on pip:
15+
16+
```bash
17+
pip install dan-build
18+
```
19+
720
## Features
821

9-
- Generators:
22+
### Generators
1023

1124
Generators are python functions that generates an output:
25+
1226
```python
27+
from dan import generator
28+
1329
@generator(output='hello.txt', dependencies=['source.jinja'])
1430
def hello(self):
1531
env = jinja2.Environment(loader=jinja2.FileSystemLoader(self.source_path))
@@ -18,6 +34,7 @@ def hello(self):
1834
```
1935

2036
They can be async:
37+
2138
```python
2239
@generator(output='hello-cpy.txt', dependencies=[hello])
2340
async def hello_cpy(self):
@@ -27,8 +44,62 @@ async def hello_cpy(self):
2744
await dst.write(await src.read())
2845
```
2946

47+
### C/CXX
48+
49+
#### Libraries/Executables
50+
51+
```python
52+
from dan.cxx import Library, Executable
53+
class MyLib(Library):
54+
name = 'my-lib'
55+
sources = ['src/my-lib.cpp']
56+
public_includes = ['include']
57+
58+
class MyExe(Executable):
59+
name = 'my-exe'
60+
sources = ['src/main.cpp']
61+
dependencies = [MyLib]
62+
63+
```
64+
65+
#### Packages
66+
67+
[dan.io](https://github.com/Garcia6l20/dan.io) is the main (default) package source repository (custom repositories are supported by editting _~/.dan/repositories.json_), documentation comming soon.
68+
69+
```python
70+
class MyExe(Executable):
71+
name = 'my-exe'
72+
sources = ['src/main.cpp']
73+
dependencies = ['boost:headers@dan.io >= 1.82']
74+
```
75+
76+
## `dan` cli usage
3077

31-
## Cli usage:
78+
`dan` is the main executable to build your project, it can build, test, list targets/test, ...
79+
80+
```bash
81+
dan --help
82+
Usage: dan [OPTIONS] COMMAND [ARGS]...
83+
84+
Options:
85+
--version Show the version and exit.
86+
-q, --quiet Dont print informations (errors only)
87+
-v, --verbose Pring debug informations
88+
-j, --jobs INTEGER Maximum jobs
89+
--help Show this message and exit.
90+
91+
Commands:
92+
build Build targets
93+
clean Clean generated stuff
94+
code VS-Code specific commands
95+
configure Configure dan project
96+
install Install targets
97+
ls Inspect stuff
98+
run Run executable(s)
99+
scan-toolchains Scan system toolchains
100+
test Run tests
101+
uninstall Uninstall previous installation
102+
```
32103

33104
### Toolchain scan
34105

@@ -50,7 +121,7 @@ dan build [-B <build_path>] [-v] [--for-install] [TARGETS]...
50121

51122
### Install
52123

53-
Install targets marked with `self.install(...)` to the *install.destination* setting.
124+
Install targets marked with `install = True` property to the *install.destination* setting.
54125

55126
```bash
56127
dan install [-B <build_path>] [TARGETS]... [user|dev]
@@ -63,3 +134,53 @@ Settings:
63134
- *install.includes_prefix*: Includes installation prefix (default: include).
64135
- *install.data_prefix*: Data files installation prefix (default: share).
65136
- *install.project_prefix*: !!! NOT USED YET !!! Project prefix (default: None).
137+
138+
## `dan-io` cli usage
139+
140+
`dan-io` is a secondary utility to interract with package management system.
141+
142+
```bash
143+
$ dan-io --help
144+
Usage: dan-io [OPTIONS] COMMAND [ARGS]...
145+
146+
Options:
147+
--help Show this message and exit.
148+
149+
Commands:
150+
ls Inspect stuff
151+
search Search for NAME in repositories
152+
```
153+
154+
```bash
155+
$ dan-io ls --help
156+
Usage: dan-io ls [OPTIONS] COMMAND [ARGS]...
157+
158+
Inspect stuff
159+
160+
Options:
161+
--help Show this message and exit.
162+
163+
Commands:
164+
libraries List available libraries
165+
repositories List available repositories
166+
versions Get LIBRARY's available versions
167+
```
168+
169+
170+
## Auto completion
171+
172+
_bash_ and _zsh_ completions are currently supported:
173+
174+
- _bash_:
175+
```bash
176+
for script in ~/.local/etc/bash_completion.d/*.sh; do
177+
source ${script}
178+
done
179+
```
180+
181+
- _ksh_:
182+
```ksh
183+
for script in ~/.local/etc/ksh_completion.d/*.sh; do
184+
source ${script}
185+
done
186+
```

completion/bash/dan-io.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
_dan_io_completion() {
2+
local IFS=$'\n'
3+
local response
4+
5+
response=$(env COMP_WORDS="${COMP_WORDS[*]}" COMP_CWORD=$COMP_CWORD _DAN_IO_COMPLETE=bash_complete $1)
6+
7+
for completion in $response; do
8+
IFS=',' read type value <<< "$completion"
9+
10+
if [[ $type == 'dir' ]]; then
11+
COMPREPLY=()
12+
compopt -o dirnames
13+
elif [[ $type == 'file' ]]; then
14+
COMPREPLY=()
15+
compopt -o default
16+
elif [[ $type == 'plain' ]]; then
17+
COMPREPLY+=($value)
18+
fi
19+
done
20+
21+
return 0
22+
}
23+
24+
_dan_io_completion_setup() {
25+
complete -o nosort -F _dan_io_completion dan-io
26+
}
27+
28+
_dan_io_completion_setup;
29+

completion/bash/dan.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
_dan_completion() {
2+
local IFS=$'\n'
3+
local response
4+
5+
response=$(env COMP_WORDS="${COMP_WORDS[*]}" COMP_CWORD=$COMP_CWORD _DAN_COMPLETE=bash_complete $1)
6+
7+
for completion in $response; do
8+
IFS=',' read type value <<< "$completion"
9+
10+
if [[ $type == 'dir' ]]; then
11+
COMPREPLY=()
12+
compopt -o dirnames
13+
elif [[ $type == 'file' ]]; then
14+
COMPREPLY=()
15+
compopt -o default
16+
elif [[ $type == 'plain' ]]; then
17+
COMPREPLY+=($value)
18+
fi
19+
done
20+
21+
return 0
22+
}
23+
24+
_dan_completion_setup() {
25+
complete -o nosort -F _dan_completion dan
26+
}
27+
28+
_dan_completion_setup;
29+

completion/zsh/dan-io.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#compdef dan-io
2+
3+
_dan_io_completion() {
4+
local -a completions
5+
local -a completions_with_descriptions
6+
local -a response
7+
(( ! $+commands[dan-io] )) && return 1
8+
9+
response=("${(@f)$(env COMP_WORDS="${words[*]}" COMP_CWORD=$((CURRENT-1)) _DAN_IO_COMPLETE=zsh_complete 'dan-io')}")
10+
11+
for type key descr in ${response}; do
12+
if [[ "$type" == "plain" ]]; then
13+
if [[ "$descr" == "_" ]]; then
14+
completions+=("$key")
15+
else
16+
completions_with_descriptions+=("$key":"$descr")
17+
fi
18+
elif [[ "$type" == "dir" ]]; then
19+
_path_files -/
20+
elif [[ "$type" == "file" ]]; then
21+
_path_files -f
22+
fi
23+
done
24+
25+
if [ -n "$completions_with_descriptions" ]; then
26+
_describe -V unsorted completions_with_descriptions -U
27+
fi
28+
29+
if [ -n "$completions" ]; then
30+
compadd -U -V unsorted -a completions
31+
fi
32+
}
33+
34+
compdef _dan_io_completion dan-io;
35+

completion/zsh/dan.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#compdef dan
2+
3+
_dan_completion() {
4+
local -a completions
5+
local -a completions_with_descriptions
6+
local -a response
7+
(( ! $+commands[dan] )) && return 1
8+
9+
response=("${(@f)$(env COMP_WORDS="${words[*]}" COMP_CWORD=$((CURRENT-1)) _DAN_COMPLETE=zsh_complete dan)}")
10+
11+
for type key descr in ${response}; do
12+
if [[ "$type" == "plain" ]]; then
13+
if [[ "$descr" == "_" ]]; then
14+
completions+=("$key")
15+
else
16+
completions_with_descriptions+=("$key":"$descr")
17+
fi
18+
elif [[ "$type" == "dir" ]]; then
19+
_path_files -/
20+
elif [[ "$type" == "file" ]]; then
21+
_path_files -f
22+
fi
23+
done
24+
25+
if [ -n "$completions_with_descriptions" ]; then
26+
_describe -V unsorted completions_with_descriptions -U
27+
fi
28+
29+
if [ -n "$completions" ]; then
30+
compadd -U -V unsorted -a completions
31+
fi
32+
}
33+
34+
compdef _dan_completion dan;
35+

dan/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from dan.cli import main
1+
from dan.cli.main import main
22

33

44
if __name__ == '__main__':

dan/cli/__init__.py

Whitespace-only changes.

dan/cli/click.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from click import *
2+
3+
import inspect
4+
import asyncio
5+
6+
from dan import logging
7+
8+
class AsyncContext(Context):
9+
def invoke(__self, __callback, *args, **kwargs):
10+
ret = super().invoke(__callback, *args, **kwargs)
11+
if inspect.isawaitable(ret):
12+
loop = asyncio.get_event_loop()
13+
if loop.is_running():
14+
return ret # must be awaited
15+
return loop.run_until_complete(ret)
16+
else:
17+
return ret
18+
19+
20+
BaseCommand.context_class = AsyncContext
21+
22+
logger = logging.getLogger('cli')

0 commit comments

Comments
 (0)