Skip to content

Commit 6580073

Browse files
committed
ci: Add basic check that all dependencies are declared
1 parent 16108b0 commit 6580073

File tree

4 files changed

+89
-0
lines changed

4 files changed

+89
-0
lines changed

.gitlab-ci.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,31 @@ mustache_example_manual:
237237
rules:
238238
- if: $CI_PIPELINE_SOURCE != "schedule"
239239

240+
.basic_usage_example_base:
241+
stage: test
242+
extends: .test
243+
script:
244+
- poetry build --verbose --no-interaction
245+
- cd examples/basic_usage
246+
- python3 -m venv .examplevenv
247+
- source .examplevenv/bin/activate
248+
- pip install ../../dist/deepl-*.tar.gz
249+
- set -o pipefail
250+
- python . 2>&1 | tee basic_usage_result.txt
251+
- grep -q "Success" basic_usage_result.txt
252+
253+
basic_usage_example_scheduled:
254+
extends: .basic_usage_example_base
255+
rules:
256+
- if: $CI_PIPELINE_SOURCE == "schedule"
257+
retry: 2
258+
259+
basic_usage_example_manual:
260+
stage: test
261+
extends: .basic_usage_example_base
262+
rules:
263+
- if: $CI_PIPELINE_SOURCE != "schedule"
264+
240265
# stage: publish -------------------------
241266

242267
pypi upload:

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77

8+
## [Unreleased]
9+
### Added
10+
* Added basic usage example of the library
11+
12+
813
## [1.16.1] - 2023-11-07
914
### Fixed
1015
* Fixed typo in error message when no auth key is provided.
@@ -273,6 +278,7 @@ Version increased to avoid conflicts with old packages on PyPI.
273278
Initial version.
274279

275280

281+
[Unreleased]: https://github.com/DeepLcom/deepl-python/compare/v1.16.1...HEAD
276282
[1.16.1]: https://github.com/DeepLcom/deepl-python/compare/v1.16.0...v1.16.1
277283
[1.16.0]: https://github.com/DeepLcom/deepl-python/compare/v1.15.0...v1.16.0
278284
[1.15.0]: https://github.com/DeepLcom/deepl-python/compare/v1.14.0...v1.15.0

examples/basic_usage/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Example: Basic usage
2+
3+
An example showing how to translate with the `deepl` python package, showcasing various features.
4+
It is also used to test the package, preventing regressions.

examples/basic_usage/__main__.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Copyright 2023 DeepL SE (https://www.deepl.com)
2+
# Use of this source code is governed by an MIT
3+
# license that can be found in the LICENSE file.
4+
5+
import io
6+
import deepl
7+
import os
8+
9+
env_auth_key = "DEEPL_AUTH_KEY"
10+
env_server_url = "DEEPL_SERVER_URL"
11+
12+
13+
def main():
14+
auth_key = os.getenv(env_auth_key)
15+
server_url = os.getenv(env_server_url)
16+
if auth_key is None:
17+
raise Exception(
18+
f"Please provide authentication key via the {env_auth_key} "
19+
"environment variable or --auth_key argument"
20+
)
21+
22+
# Create a Translator object, and call get_usage() to validate connection
23+
translator = deepl.Translator(auth_key, server_url=server_url)
24+
translator.get_usage()
25+
26+
# Use most translation features of the library
27+
translator.translate_text(
28+
["I am an example sentence", "I am another sentence"],
29+
source_lang="EN",
30+
target_lang="FR",
31+
formality=deepl.Formality.DEFAULT,
32+
tag_handling=None,
33+
)
34+
ginfo = translator.create_glossary(
35+
"Test Glossary", "DE", "FR", {"Hallo": "Bonjour"}
36+
)
37+
with io.BytesIO() as output_file:
38+
translator.translate_document(
39+
"My example document",
40+
output_file,
41+
source_lang="DE",
42+
target_lang="FR",
43+
filename="example.txt",
44+
glossary=ginfo,
45+
)
46+
translator.translate_text_with_glossary(
47+
["Ich bin ein Beispielsatz.", "Ich bin noch ein Satz."], glossary=ginfo
48+
)
49+
50+
print("Success")
51+
52+
53+
if __name__ == "__main__":
54+
main()

0 commit comments

Comments
 (0)