Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 61 additions & 8 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,79 @@
name: Upload Python Package
name: CI and Publish

on:
push:
branches: [ "typing" ] # тестирование при пуше в ветку typing
pull_request:
branches: [ "main" ] # тестирование при PR в main
release:
types: [published]
types: [published] # публикация только при создании релиза

jobs:
test:
name: Test on Python ${{ matrix.python-version }}
runs-on: ubuntu-22.04
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
# Для тестирования бета/альфа версий можно добавить:
# include:
# - python-version: "3.14-dev" # тестирование на dev версии

steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5 # обновил до v5
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true # разрешает установку pre-release версий (например, 3.14-dev)

- name: Install dependencies
run: |
python -m pip install --upgrade pip
# Устанавливаем pytest для более детальных отчётов
pip install pytest pytest-cov
# Устанавливаем ваш пакет в режиме разработки
pip install -e .
pip install -r requirements.txt

- name: Run tests with pytest
run: |
pytest tests/ --cov=./ --cov-report=xml -v

- name: Upload coverage to Codecov (опционально)
uses: codecov/codecov-action@v4
with:
file: ./coverage.xml
fail_ci_if_error: false

deploy:
needs: test
runs-on: ubuntu-latest
# Публикация только при создании релиза (и после успешных тестов)
if: github.event_name == 'release' && github.event.action == 'published'
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install dependencies

- name: Install build dependencies
run: |
python -m pip install --upgrade pip
pip install build
pip install build twine # twine для дополнительной проверки

- name: Build package
run: python -m build
- name: Publish package

- name: Check package with twine
run: twine check dist/*

- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
# Если хотите тестовую публикацию в Test PyPI:
# repository-url: https://test.pypi.org/legacy/
40 changes: 36 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ Python Telegraph API wrapper

```bash
$ python3 -m pip install telegraph
# with asyncio support
$ python3 -m pip install 'telegraph[aio]'
```

## Example
### Example
```python
from telegraph import Telegraph

Expand All @@ -25,9 +23,23 @@ response = telegraph.create_page(
html_content='<p>Hello, world!</p>'
)
print(response['url'])

telegraph.close()
```

#### Or with context manager
```python

with Telegraph() as telegraph:
telegraph.create_account(short_name='1337')
response = telegraph.create_page(
'Hey',
html_content='<p>Hello, world!</p>'
)
print(response['url'])
```

## Async Example
### Async Example
```python
import asyncio
from telegraph.aio import Telegraph
Expand All @@ -42,6 +54,26 @@ async def main():
)
print(response['url'])

await telegraph.aclose()


asyncio.run(main())
```

#### Or with context manager
```python
import asyncio
from telegraph.aio import Telegraph

async def main():
async with Telegraph() as telegraph:
print(await telegraph.create_account(short_name='1337'))

response = await telegraph.create_page(
'Hey',
html_content='<p>Hello, world!</p>',
)
print(response['url'])

asyncio.run(main())
```
70 changes: 32 additions & 38 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@

import os
import sys
sys.path.insert(0, os.path.abspath('../'))

sys.path.insert(0, os.path.abspath("../"))

from datetime import datetime

Expand All @@ -31,26 +32,23 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.

extensions = ['sphinx.ext.autodoc',
'sphinx.ext.todo',
'sphinx.ext.viewcode']
extensions = ["sphinx.ext.autodoc", "sphinx.ext.todo", "sphinx.ext.viewcode"]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
source_suffix = '.rst'
source_suffix = ".rst"

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# General information about the project.
project = 'telegraph'
project = "telegraph"
copyright = '{:%Y}, <a href="https://python273.pw">{}</a>'.format(
datetime.utcnow(),
telegraph.__author__
datetime.utcnow(), telegraph.__author__
)

author = telegraph.__author__
Expand All @@ -65,15 +63,15 @@
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = 'en'
language = "en"

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This patterns also effect to html_static_path and html_extra_path
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
pygments_style = "sphinx"

# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = True
Expand All @@ -84,31 +82,31 @@
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'alabaster'
html_theme = "alabaster"

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#
html_theme_options = {
'show_powered_by': False,
'github_user': 'python273',
'github_repo': 'telegraph',
'github_banner': True,
'github_type': 'star',
'show_related': False
"show_powered_by": False,
"github_user": "python273",
"github_repo": "telegraph",
"github_banner": True,
"github_type": "star",
"show_related": False,
}

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]


# -- Options for HTMLHelp output ------------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = 'telegraphdoc'
htmlhelp_basename = "telegraphdoc"


# -- Options for LaTeX output ---------------------------------------------
Expand All @@ -117,15 +115,12 @@
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',

# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
Expand All @@ -135,19 +130,15 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'telegraph.tex', 'telegraph Documentation',
'Author', 'manual'),
(master_doc, "telegraph.tex", "telegraph Documentation", "Author", "manual"),
]


# -- Options for manual page output ---------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'telegraph', 'telegraph Documentation',
[author], 1)
]
man_pages = [(master_doc, "telegraph", "telegraph Documentation", [author], 1)]


# -- Options for Texinfo output -------------------------------------------
Expand All @@ -156,13 +147,18 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'telegraph', 'telegraph Documentation',
author, 'telegraph', 'One line description of project.',
'Miscellaneous'),
(
master_doc,
"telegraph",
"telegraph Documentation",
author,
"telegraph",
"One line description of project.",
"Miscellaneous",
),
]



# -- Options for Epub output ----------------------------------------------

# Bibliographic Dublin Core info.
Expand All @@ -181,6 +177,4 @@
# epub_uid = ''

# A list of files that should not be packed into the epub file.
epub_exclude_files = ['search.html']


epub_exclude_files = ["search.html"]
12 changes: 6 additions & 6 deletions generate_async_api.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""Generate async api from sync api"""

from typing import Optional

import libcst as cst
from libcst._nodes.expression import Await
from libcst._nodes.whitespace import SimpleWhitespace


class SyncToAsyncTransformer(cst.CSTTransformer):
Expand Down Expand Up @@ -71,12 +71,14 @@ def leave_Call(self, original_node: cst.FunctionDef, updated_node: cst.FunctionD
# await the call if it's API class method
should_await = (
path[-2:] == ["session", "self"]
or path[-3:] == [
or path[-3:]
== [
"method",
"_telegraph",
"self",
]
or path[-3:] == [
or path[-3:]
== [
"upload_file",
"_telegraph",
"self",
Expand Down Expand Up @@ -104,9 +106,7 @@ def leave_FunctionDef(
return updated_node

# mark fn as async
return updated_node.with_changes(
asynchronous=cst.Asynchronous()
)
return updated_node.with_changes(asynchronous=cst.Asynchronous())


def main():
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
requests
httpx
libcst
Loading