Metadata-Version: 2.4
Name: das-setup-helper
Version: 0.1.0
Summary: Public helper to setup crawlers and manage acquisitions in WIHP (EUROSTAT)
Author: Basile MANGOG
License-Expression: EUPL-1.2
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: boto3<2,>=1.42
Requires-Dist: requests<3,>=2.33
Requires-Dist: pyjwt<3,>=2.11
Requires-Dist: pyyaml<7,>=6.0
Requires-Dist: python-dotenv<2,>=1.1
Requires-Dist: pandas<4,>=3.0
Requires-Dist: aws-secretsmanager-caching<2,>=1.1
Provides-Extra: dev
Requires-Dist: isort<7,>=6.0; extra == "dev"
Requires-Dist: black<27,>=26.1; extra == "dev"
Requires-Dist: pytest<10,>=9.0; extra == "dev"
Requires-Dist: pytest-cov<8,>=7.0; extra == "dev"
Requires-Dist: pytest-asyncio<2,>=1.2; extra == "dev"
Requires-Dist: pre-commit<5,>=4.5; extra == "dev"
Requires-Dist: sphinx<10,>=9.0; extra == "dev"
Requires-Dist: sphinx-rtd-theme<4,>=3.0; extra == "dev"
Requires-Dist: sphinx-autodoc-typehints<4,>=3.9; extra == "dev"
Dynamic: license-file

# DAS Setup Helper

A Python CLI tool to set up crawlers and manage acquisitions in WIHP (EUROSTAT).
It provides three pipelines: creating crawlers, triggering acquisitions, and stopping them.

---

## Requirements

- Python >= 3.12
- [uv](https://docs.astral.sh/uv/) — fast Python package and project manager

Install uv (once, globally):
```bash
curl -LsSf https://astral.sh/uv/install.sh | sh
```

---

## Installation

### From PyPI (recommended)

```bash
# Create a project directory
mkdir das-setup-helper && cd das-setup-helper

# Install the package in an isolated environment
uv add das-setup-helper
```

All three CLI commands (`das-setup-crawler`, `das-create-acq`, `das-stop-acq`) are then available via `uv run`.

### From source (contributors)

```bash
# Clone the repository
git clone <repo-url>
cd das-setup-helper

# Install all dependencies including dev tools
make sync
# or directly:
uv sync --extra dev
```

---

## Configuration

Copy the template and fill in your values:
```bash
cp env.sh.template env.sh
# edit env.sh with your settings
```

Key variables:

| Variable | Description |
|---|---|
| `STORAGE_BACKEND` | `local` (default) or `s3` |
| `USE_SECRET_MANAGER` | `false` (default, uses env vars) or `true` (uses AWS Secrets Manager) |
| `AWS_SECRET_MANAGER_NAME` | Secret name in Secrets Manager — only needed if `USE_SECRET_MANAGER=true` |
| `S3_AWS_WIHP_CONFIG_DIRECTORY` | Path to the config directory (local path or S3 prefix) |
| `S3_AWS_WIHP_INPUT_SOURCES_TO_CREATE` | Path to the input CSV file with sources to create |
| `S3_AWS_WHIP_READY_FOR_CRAWLING_DIRECTORY` | Directory where crawler outputs are written |
| `WIHP_API_URL` | WIHP API base URL |
| `WIHP_TOKEN_URL` | WIHP OAuth token endpoint |
| `WIHP_API_KEY` | WIHP API key |
| `WIHP_GROUP` | WIHP group (e.g. `/MNE`) |

### Local storage

When `STORAGE_BACKEND=local`, paths are local filesystem paths.
The `local_storage/` directory mirrors the S3 structure:

```
local_storage/
├── config/                   # input files
├── ready_for_crawling/       # crawler outputs
├── ready_to_export/
├── done/
└── staging/
"" source to create directory"
```

The only input file required to run `das-setup-crawler`:
```
local_storage/MNE/config/dashelper/sources_to_create.csv
```

Format (semicolon-separated):
```csv
mne_name;wikipedia_url
Airbus;https://en.wikipedia.org/wiki/Airbus
TotalEnergies;https://en.wikipedia.org/wiki/TotalEnergies
```

---

## Running the pipelines

Load your environment variables then run a pipeline:

```bash
source env.sh

# 1. Create a crawler from the input CSV
uv run das-setup-crawler
# or: make run-crawler

# 2. Trigger acquisitions for existing crawlers
uv run das-create-acq
# or: make run-acq

# 3. Stop running acquisitions
uv run das-stop-acq
# or: make run-stop
```

Pipeline order: **setup-crawler → create-acq → stop-acq**

---

## Development

```bash
# Run tests
make test

# Format code
make lint

# Refresh dependency lock (without upgrading)
make lock

# Upgrade all dependencies
make lock-upgrade
```

Available `make` targets:
```bash
make info
```

---

## Deployment (prod/staging)

In production (MWAA / Lambda), set:
```bash
USE_SECRET_MANAGER=true
AWS_SECRET_MANAGER_NAME=prod/DASHelper
STORAGE_BACKEND=s3
```

All other variables are loaded automatically from AWS Secrets Manager.
The IAM role must have `secretsmanager:GetSecretValue` permission on the secret.

---

## Release

```bash
# Build the package
make build

# Publish a development build to TestPyPI
make publish-test

# Publish a release build to PyPI
make publish
```

The package version is derived from Git tags and follows Python package versioning conventions (PEP 440):

- Tagged releases use stable versions such as `v1.2.3`.
- Untagged branch builds produce development versions such as `1.2.4.dev5`.

GitLab CI release flow:

- Branch `develop`: manual job `publish-internal` publishes the current branch build to the internal Python repository.
- Branch `test`: manual job `publish-testpypi` publishes the current branch build to TestPyPI.
- Branch `main`: manual jobs `prepare-release-patch`, `prepare-release-minor`, and `prepare-release-major` create the next Git tag.
- Tag pipeline `vX.Y.Z`: manual job `publish-pypi` publishes that tagged release to PyPI.

SonarQube runs in the `quality` stage for merge requests and for the `develop` and `main` branches.

To allow the release-tag job to push tags from CI, define these GitLab CI/CD variables:

- `REPO_PUSH_USER`
- `REPO_PUSH_TOKEN`

Also define the repository tokens used for publishing:

- `DOCKER_REGISTRY_USER`
- `DOCKER_REGISTRY_PASSWORD`
- `TEST_PYPI_TOKEN`
- `PYPI_TOKEN`

For SonarQube, also define:

- `SONAR_TOKEN`

## License

This project is distributed under the European Union Public Licence v1.2
(EUPL-1.2). The full licence text is available in [LICENSE](LICENSE) and on the
European Commission website:
https://commission.europa.eu/about/departments-and-executive-agencies/digital-services/open-source-strategy-history/european-union-public-licence_en

## Test and Deploy

Use the built-in continuous integration in GitLab.

* [Get started with GitLab CI/CD](https://docs.gitlab.com/ci/quick_start/)
* [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/user/application_security/sast/)
* [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/topics/autodevops/requirements/)
* [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/user/clusters/agent/)
* [Set up protected environments](https://docs.gitlab.com/ci/environments/protected_environments/)

***

# Editing this README

When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template.

## Suggestions for a good README

Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.

## Name
Choose a self-explaining name for your project.

## Description
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.

## Badges
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.

## Visuals
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.

## Installation
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.

## Usage
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.

## Support
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.

## Roadmap
If you have ideas for releases in the future, it is a good idea to list them in the README.

## Contributing
State if you are open to contributions and what your requirements are for accepting them.

For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.

You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.

## Authors and acknowledgment
Show your appreciation to those who have contributed to the project.

## License
For open source projects, say how it is licensed.

## Project status
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
