Skip to content

Commit 20f8fc0

Browse files
authored
Initial commit
0 parents  commit 20f8fc0

File tree

12 files changed

+1853
-0
lines changed

12 files changed

+1853
-0
lines changed

.github/workflows/d4g-utils.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Copy File to Organization Repos
2+
3+
on:
4+
push:
5+
paths:
6+
- 'd4g-utils/**' # Trigger the workflow only when changes are made in the d4g-utils directory
7+
branches:
8+
- main
9+
10+
# Allows you to run this workflow manually from the Actions tab
11+
workflow_dispatch:
12+
13+
jobs:
14+
copy:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout template repo
18+
uses: actions/checkout@v2
19+
20+
- name: Set up Git
21+
run: |
22+
git config --global user.email "[email protected]"
23+
git config --global user.name "D4G Tech"
24+
25+
- name: Get organization repositories
26+
id: org_repos
27+
run: |
28+
ORG_NAME="dataforgoodfr"
29+
TEMPLATE_REPO="$ORG_NAME/python_template"
30+
TOKEN=$1
31+
32+
# Fetch repositories from the organization
33+
repos=`gh repo list $ORG_NAME --limit 500 | awk ' {print $1}'`
34+
35+
echo "::set-output name=repos::$repos"
36+
env:
37+
GH_TOKEN: ${{ secrets.D4GTECH_TOKEN }}
38+
39+
- name: Copy files to organization repos
40+
run: |
41+
echo "Searching for repositories generated from template: $template_repo"
42+
for repo in ${{ steps.org_repos.outputs.repos }}; do
43+
repo_info=`gh api repos/$repo`
44+
echo "$repo_info" | jq -r ".template_repository.full_name" | grep "$template_repo" 2>&1 > /dev/null
45+
if [ "$?" -eq "0" ]
46+
then
47+
echo "repo_using_template: $repo"
48+
fi
49+
done
50+
env:
51+
GH_TOKEN: ${{ secrets.D4GTECH_TOKEN }}
52+
53+
54+
# for repo in ${{ steps.org_repos.outputs.repos }}; do
55+
# # Clone the repository
56+
# git clone "https://github.com/$repo" target_repo
57+
58+
# # Copy all files from d4g-utils to target repository d4g-utlis
59+
# rsync -av --exclude='.git' d4g-utils/ target_repo/d4g-utils
60+
61+
# # Commit and push changes
62+
# cd target_repo
63+
# git add .
64+
# git commit -m "Copy files from d4g-utils directory"
65+
# git push origin main
66+
67+
# cd ..
68+
# done

.github/workflows/pre-commit.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: pre-commit
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [main]
7+
8+
jobs:
9+
pre-commit:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
- uses: actions/setup-python@v2
14+
- name: set PY
15+
run: echo "PY=$(python -c 'import hashlib, sys;print(hashlib.sha256(sys.version.encode()+sys.executable.encode()).hexdigest())')" >> $GITHUB_ENV
16+
- uses: actions/cache@v4
17+
with:
18+
path: ~/.cache/pre-commit
19+
key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
20+
- uses: pre-commit/[email protected]

.gitignore

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
# From https://github.com/github/gitignore/blob/main/Python.gitignore
2+
# Byte-compiled / optimized / DLL files
3+
__pycache__/
4+
*.py[cod]
5+
*$py.class
6+
7+
# C extensions
8+
*.so
9+
10+
# Distribution / packaging
11+
bin/
12+
.Python
13+
build/
14+
develop-eggs/
15+
dist/
16+
downloads/
17+
eggs/
18+
.eggs/
19+
lib/
20+
lib64/
21+
lib64
22+
parts/
23+
sdist/
24+
var/
25+
wheels/
26+
share/python-wheels/
27+
*.egg-info/
28+
.installed.cfg
29+
*.egg
30+
MANIFEST
31+
32+
# PyInstaller
33+
# Usually these files are written by a python script from a template
34+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
35+
*.manifest
36+
*.spec
37+
38+
# Installer logs
39+
pip-log.txt
40+
pip-delete-this-directory.txt
41+
42+
# Unit test / coverage reports
43+
htmlcov/
44+
.tox/
45+
.nox/
46+
.coverage
47+
.coverage.*
48+
.cache
49+
nosetests.xml
50+
coverage.xml
51+
*.cover
52+
*.py,cover
53+
.hypothesis/
54+
.pytest_cache/
55+
cover/
56+
57+
# Translations
58+
*.mo
59+
*.pot
60+
61+
# Django stuff:
62+
*.log
63+
local_settings.py
64+
db.sqlite3
65+
db.sqlite3-journal
66+
67+
# Flask stuff:
68+
instance/
69+
.webassets-cache
70+
71+
# Scrapy stuff:
72+
.scrapy
73+
74+
# Sphinx documentation
75+
docs/_build/
76+
77+
# PyBuilder
78+
.pybuilder/
79+
target/
80+
81+
# Jupyter Notebook
82+
.ipynb_checkpoints
83+
84+
# IPython
85+
profile_default/
86+
ipython_config.py
87+
88+
# pyenv
89+
# For a library or package, you might want to ignore these files since the code is
90+
# intended to run in multiple environments; otherwise, check them in:
91+
.python-version
92+
93+
# pipenv
94+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
95+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
96+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
97+
# install all needed dependencies.
98+
#Pipfile.lock
99+
100+
# poetry
101+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
102+
# This is especially recommended for binary packages to ensure reproducibility, and is more
103+
# commonly ignored for libraries.
104+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
105+
#poetry.lock
106+
107+
# pdm
108+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
109+
#pdm.lock
110+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
111+
# in version control.
112+
# https://pdm.fming.dev/#use-with-ide
113+
.pdm.toml
114+
115+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
116+
__pypackages__/
117+
118+
# Celery stuff
119+
celerybeat-schedule
120+
celerybeat.pid
121+
122+
# SageMath parsed files
123+
*.sage.py
124+
125+
# Environments
126+
.env
127+
.env.test
128+
.venv
129+
env/
130+
venv/
131+
ENV/
132+
env.bak/
133+
venv.bak/
134+
135+
# Spyder project settings
136+
.spyderproject
137+
.spyproject
138+
139+
# VS Code
140+
.vscode
141+
142+
# Rope project settings
143+
.ropeproject
144+
145+
# mkdocs documentation
146+
/site
147+
148+
# mypy
149+
.mypy_cache/
150+
.dmypy.json
151+
dmypy.json
152+
153+
# Pyre type checker
154+
.pyre/
155+
156+
# pytype static type analyzer
157+
.pytype/
158+
159+
# Cython debug symbols
160+
cython_debug/
161+
162+
# Precommit hooks: ruff cache
163+
.ruff_cache

.pre-commit-config.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
repos:
2+
- repo: https://github.com/charliermarsh/ruff-pre-commit
3+
# Ruff version.
4+
rev: "v0.2.1"
5+
hooks:
6+
- id: ruff
7+
args: [--fix]
8+
- repo: https://github.com/pre-commit/pre-commit-hooks
9+
rev: v4.3.0
10+
hooks:
11+
- id: check-merge-conflict
12+
- id: mixed-line-ending

LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright (c) 2015-2024 Data4Good
2+
3+
Permission is hereby granted, free of charge, to any person obtaining
4+
a copy of this software and associated documentation files (the
5+
"Software"), to deal in the Software without restriction, including
6+
without limitation the rights to use, copy, modify, merge, publish,
7+
distribute, sublicense, and/or sell copies of the Software, and to
8+
permit persons to whom the Software is furnished to do so, subject to
9+
the following conditions:
10+
11+
The above copyright notice and this permission notice shall be
12+
included in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Template DataForGood
2+
3+
This file will become your README and also the index of your
4+
documentation.
5+
6+
# Contributing
7+
8+
9+
## Installation
10+
11+
- [Installation de Python](#installation-de-python)
12+
13+
Ce projet utilise [uv](https://docs.astral.sh/uv/) pour la gestion des dépendances Python. Il est préréquis pour l'installation de ce projet.
14+
15+
Une fois installé, il suffit de lancer la commande suivante pour installer la version de Python adéquate, créer un environnement virtuel et installer les dépendances du projet.
16+
17+
```bash
18+
uv sync
19+
```
20+
21+
A l'usage, si vous utilisez VSCode, l'environnement virtuel sera automatiquement activé lorsque vous ouvrirez le projet. Sinon, il suffit de l'activer manuellement avec la commande suivante :
22+
23+
```bash
24+
source .venv/bin/activate
25+
```
26+
27+
Ou alors, utilisez la commande `uv run ...` (au lieu de `python ...`) pour lancer un script Python. Par exemple:
28+
29+
```bash
30+
uv run pipelines/run.py run build_database
31+
```
32+
33+
34+
## Lancer les precommit-hook localement
35+
36+
[Installer les precommit](https://pre-commit.com/)
37+
38+
pre-commit run --all-files
39+
40+
## Utiliser Tox pour tester votre code
41+
42+
tox -vv

d4g-utils/install_poetry.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/bash
2+
3+
# Function to check if a command is available
4+
command_exists() {
5+
command -v "$1" &> /dev/null
6+
}
7+
8+
# Check if Poetry is installed
9+
if command_exists poetry && poetry --version &> /dev/null; then
10+
echo "Poetry is already installed. Version: $(poetry --version)"
11+
else
12+
echo "Poetry is not installed. Installing now..."
13+
14+
# Install Poetry
15+
curl -sSL https://install.python-poetry.org | python3 -
16+
17+
# Add poetry to PATH
18+
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
19+
source ~/.bashrc
20+
21+
echo "Poetry has been installed."
22+
fi
23+
24+
echo "Configuring Poetry to use virtual environment in project directory..."
25+
26+
# Configure Poetry to use a virtual environment in the project
27+
poetry config virtualenvs.in-project true
28+
29+
echo "Poetry is now configured to use a virtual environment in the project directory."
30+
31+
# Navigate to the project directory
32+
project_dir=$(pwd)
33+
34+
# Check if the virtual environment exists in the project directory
35+
if [ -d ".venv" ]; then
36+
echo "Virtual environment in project directory exists."
37+
fi
38+
39+
# Analyze project content and create pyproject.toml file if not exists
40+
if [ ! -f pyproject.toml ]; then
41+
echo "Creating pyproject.toml file..."
42+
poetry init --no-interaction
43+
else
44+
echo "pyproject.toml file already exists. Skipping initialization."
45+
fi
46+
47+
# Install project dependencies
48+
echo "Installing project dependencies..."
49+
poetry install
50+
51+
echo "Script execution complete."

0 commit comments

Comments
 (0)