Skip to content

Commit

Permalink
fix ReleaseCreator
Browse files Browse the repository at this point in the history
  • Loading branch information
sebdelsol committed Feb 24, 2024
1 parent f62cbfc commit e12db03
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 82 deletions.
43 changes: 17 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
[^1]: External EPG doesn't work with **local** m3u accounts.
# Download
[<img src="https://custom-icon-badges.demolab.com/badge/Sfvip All v1.4.12.30 x64-informational.svg?logo=download-cloud&logoSource=feather&logoColor=white&style=flat-square" height="29"><img src="https://custom-icon-badges.demolab.com/badge/clean-brightgreen.svg?logo=shield-check&logoColor=white&style=flat-square" height="29">](https://github.com/sebdelsol/sfvip-all/releases/download/Sfvip.All.1.4.12.30/Install.Sfvip.All.1.4.12.30.x64.exe)
<sup><sup>_by MS Defender • 1.1.24010.10 • 1.405.474.0_</sup></sup>
<sup><sup>_by MS Defender • 1.1.24010.10 • 1.405.524.0_</sup></sup>

[<img src="https://custom-icon-badges.demolab.com/badge/Sfvip All v1.4.12.30 x86-informational.svg?logo=download-cloud&logoSource=feather&logoColor=white&style=flat-square" height="29"><img src="https://custom-icon-badges.demolab.com/badge/clean-brightgreen.svg?logo=shield-check&logoColor=white&style=flat-square" height="29">](https://github.com/sebdelsol/sfvip-all/releases/download/Sfvip.All.1.4.12.30/Install.Sfvip.All.1.4.12.30.x86.exe)
<sup><sup>_by MS Defender • 1.1.24010.10 • 1.405.474.0_</sup></sup>
<sup><sup>_by MS Defender • 1.1.24010.10 • 1.405.524.0_</sup></sup>

Check the [***changelog***](build/changelog.md) and ***notes***[^2].
[***Sfvip Player***](https://github.com/K4L4Uz/SFVIP-Player/tree/master) will be automatically installed if missing.
Expand All @@ -27,7 +27,7 @@ _On **old systems** you might need to install [**vc redist**](https://learn.micr
[![Python](https://img.shields.io/badge/Python-3.11.8-fbdf79?logo=python&logoColor=fbdf79)](https://www.python.org/downloads/release/python-3118/)
[![mitmproxy](https://custom-icon-badges.demolab.com/badge/Mitmproxy-10.2.2-informational.svg?logo=mitmproxy)](https://mitmproxy.org/)
[![Style](https://custom-icon-badges.demolab.com/badge/Style-Black-000000.svg?logo=file-code&logoColor=a0a0a0)](https://black.readthedocs.io/en/stable/)
[![Sloc](https://custom-icon-badges.demolab.com/badge/Sloc-7783-000000.svg?logo=file-code&logoColor=a0a0a0)](https://api.codetabs.com/v1/loc/?github=sebdelsol/sfvip-all)
[![Sloc](https://custom-icon-badges.demolab.com/badge/Sloc-7813-000000.svg?logo=file-code&logoColor=a0a0a0)](https://api.codetabs.com/v1/loc/?github=sebdelsol/sfvip-all)

[![Nuitka](https://custom-icon-badges.demolab.com/badge/Nuitka-2.0.3-informational.svg?logo=tools&logoColor=61dafb)](https://nuitka.net/)
<sup><sub>**or**</sub></sup>
Expand All @@ -38,11 +38,21 @@ _On **old systems** you might need to install [**vc redist**](https://learn.micr
[***NSIS***](https://nsis.sourceforge.io/Download) will be automatically installed if missing.
Check the [***build config***](build_config.py).

### Create the _x64_ environments
You need [***Python 3.11 x64***](https://www.python.org/ftp/python/3.11.8/python-3.11.8-amd64.exe) and [***Rust***](https://www.rust-lang.org/fr).
### Create the environments
You need [***Rust***](https://www.rust-lang.org/fr), [***Python 3.11 x64***](https://www.python.org/ftp/python/3.11.8/python-3.11.8-amd64.exe) and [***x86***](https://www.python.org/ftp/python/3.11.8/python-3.11.8.exe).
```console
rustup target add i686-pc-windows-msvc
py -3.11-64 -m dev.create
py -3.11-32 -m dev.create
```
Get a [***Github token***](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#personal-access-tokens-classic) and a [***DeepL API key***](https://www.deepl.com/en/docs-api/).
Store those in `api_keys.py`:
```python3
# api_keys.py
GITHUB_TOKEN=your_github_token
DEEPL_KEY=your_deepl_api_key
```

### Activate the _x64_ environment
```console
.sfvip64\scripts\activate
Expand Down Expand Up @@ -70,12 +80,6 @@ You need [**Visual Studio**](https://www.visualstudio.com/en-us/downloads/downlo

<img src="resources/VS.png">

### Create the _x86_ environment
You need [***Python 3.11 x86***](https://www.python.org/ftp/python/3.11.8/python-3.11.8.exe) and `i686-pc-windows-msvc` for rust.
```console
rustup target add i686-pc-windows-msvc
py -3.11-32 -m dev.create
```
### Build a specific version
```console
python -m dev.build [--x86 | --x64 | --both] [--pyinstaller | --mingw] [--nobuild | --noinstaller | --readme] [--upgrade] [--publish]
Expand All @@ -85,13 +89,7 @@ It checks for _Nsis_, _Python minor update_ and all _packages dependencies_:
```console
python -m dev.upgrade [--x86 | --x64 | --both] [--noeager] [--clean] [--force]
```
### Publish a release
Get a [***Github token***](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#personal-access-tokens-classic) and set `GITHUB_TOKEN` in `api_keys.py`
```python3
# api_keys.py
GITHUB_TOKEN=your_github_token
```
Publish a release:
### Publish an update
```console
python -m dev.publish [--x86 | --x64 | --both] [--version VERSION] [--info]
```
Expand All @@ -100,14 +98,7 @@ It updates _Microsoft Defender_ engine and signatures before scanning:
```console
python -m dev.scan [--x86 | --x64 | --both]
```

### Translations
Get a [***DeepL API key***](https://www.deepl.com/en/docs-api/) and set `DEEPL_KEY` in `api_keys.py`:
```python3
# api_keys.py
DEEPL_KEY=your_deepl_api_key
```
Translate the [**UI**](translations/loc/texts.py):
### [**UI**](translations/loc/texts.py) Translations
```console
python -m dev.translate [--force] [--language LANGUAGE]
```
21 changes: 10 additions & 11 deletions dev/build.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
from typing import Optional

from build_config import Github, Translations
from translations.loc import LOC

from .tools.builder import Builder
from .tools.publisher import Publisher
from .tools.templater import Templater
from .tools.utils.protocols import CfgBuild, CfgEnvironments, CfgTemplate, CfgTemplates
from .tools.release import ReleaseCreator
from .tools.templater import Templater, get_template_by_name
from .tools.utils.protocols import CfgBuild, CfgEnvironments, CfgTemplates


def do_build(
build: CfgBuild,
environments: CfgEnvironments,
templates: CfgTemplates,
readme: CfgTemplate,
publisher: Optional[Publisher] = None,
publish: bool = False,
) -> None:
LOC.set_tranlastions(Translations.path)
release = ReleaseCreator(build, environments, Github)
publisher = Publisher(build, environments, Github, release) if publish else None
if Builder(build, environments, LOC, publisher).build_all():
Templater(build, environments, Github).create_all(templates)
Templater(build, environments, Github, release).create_all(templates)
if publisher:
publisher.show_versions()
else:
Templater(build, environments, Github).create(readme)
elif readme := get_template_by_name(templates, "Readme"):
Templater(build, environments, Github, release).create(readme)


if __name__ == "__main__":
import build_config

PUBLISHER = Publisher(build_config.Build, build_config.Environments, Github)
do_build(build_config.Build, build_config.Environments, build_config.Templates, build_config.Readme, PUBLISHER)
do_build(build_config.Build, build_config.Environments, build_config.Templates, True)
10 changes: 8 additions & 2 deletions dev/tools/publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,16 @@ def from_update(cls, update: AppUpdate, exe: Path, python_env: PythonEnv) -> Sel
class Publisher:
timeout = 10

def __init__(self, build: CfgBuild, environments: CfgEnvironments, github: CfgGithub) -> None:
def __init__(
self,
build: CfgBuild,
environments: CfgEnvironments,
github: CfgGithub,
release: Optional[ReleaseCreator] = None,
) -> None:
self.build = build
self.dist = Dist(build)
self.release = ReleaseCreator(build, environments, github)
self.release = release or ReleaseCreator(build, environments, github)
self.app_latest_update = AppLatestUpdateLocal(build, github)
self.all_python_envs = PythonEnvs(environments).all
self.environments = environments
Expand Down
45 changes: 30 additions & 15 deletions dev/tools/release.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
from pathlib import Path
from typing import Iterator, NamedTuple, Optional

from github import Auth, Github, GithubException, UnknownObjectException
from github import (
Auth,
BadCredentialsException,
Github,
GithubException,
UnknownObjectException,
)
from github.GitRelease import GitRelease

from api_keys import GITHUB_TOKEN
Expand All @@ -23,23 +29,32 @@ class InstallerRelease(NamedTuple):
class Release:
def __init__(self, dist: Dist, github: CfgGithub) -> None:
self.dist = dist
with Github(auth=Auth.Token(GITHUB_TOKEN)) as git:
user = git.get_user()
assert user.login == github.owner
self.repo = user.get_repo(github.repo)
try:
with Github(auth=Auth.Token(GITHUB_TOKEN)) as git:
user = git.get_user()
assert user.login == github.owner
self.repo = user.get_repo(github.repo)
except BadCredentialsException:
self.repo = None
print(Warn("Can't access github"), Ok(f"{github.owner}/{github.repo}"))

def get(self, version: str) -> Optional[GitRelease]:
tag = f"{self.dist.build_name}.{version}"
try:
release = self.repo.get_release(tag)
print(Title("Update Release"), Ok(tag))
except UnknownObjectException:
if self.repo:
tag = f"{self.dist.build_name}.{version}"
try:
release = self.repo.create_git_release(tag=tag, name=tag, message="", target_commitish="master")
print(Title("Create release"), Ok(tag))
except GithubException:
release = None
print(Warn("Can't create release"), Ok(tag))
release = self.repo.get_release(tag)
print(Title("Update Release"), Ok(tag))
except UnknownObjectException:
try:
release = self.repo.create_git_release(
tag=tag, name=tag, message="", target_commitish="master"
)
print(Title("Create release"), Ok(tag))
except GithubException:
release = None
print(Warn("Can't create release"), Ok(tag))
else:
release = None
return release


Expand Down
19 changes: 15 additions & 4 deletions dev/tools/templater.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ def _get_sloc(path: Path) -> int:
return 0


def _get_exe_args(build: CfgBuild, environments: CfgEnvironments, github: CfgGithub) -> Iterator[tuple[str, str]]:
for installer in ReleaseCreator(build, environments, github).create_all(build.version):
def _get_exe_args(release: ReleaseCreator, build: CfgBuild) -> Iterator[tuple[str, str]]:
for installer in release.create_all(build.version):
yield f"exe_{installer.bitness}_release", installer.url
yield f"exe_{installer.bitness}_engine", installer.scan.engine
yield f"exe_{installer.bitness}_signature", installer.scan.signature
Expand All @@ -57,15 +57,22 @@ def _get_exe_args(build: CfgBuild, environments: CfgEnvironments, github: CfgGit
class Templater:
encoding = "utf-8"

def __init__(self, build: CfgBuild, environments: CfgEnvironments, github: CfgGithub) -> None:
def __init__(
self,
build: CfgBuild,
environments: CfgEnvironments,
github: CfgGithub,
release: Optional[ReleaseCreator] = None,
) -> None:
release = release or ReleaseCreator(build, environments, github)
python_envs = PythonEnvs(environments)
python_version = _version_of(python_envs, "Python")
nuitka_version = _version_of(python_envs, "Nuitka")
pyinstaller_version = _version_of(python_envs, "PyInstaller")
mitmproxy_version = _version_of(python_envs, "mitmproxy")
if python_version and nuitka_version and pyinstaller_version and mitmproxy_version:
self.template_format = dict(
dict(arg for arg in _get_exe_args(build, environments, github)),
dict(arg for arg in _get_exe_args(release, build)),
py_major_version=str(PythonVersion(python_version).major),
py_version_compact=python_version.replace(".", ""),
github_path=f"{github.owner}/{github.repo}",
Expand Down Expand Up @@ -100,3 +107,7 @@ def create(self, template: CfgTemplate) -> None:
def create_all(self, templates: CfgTemplates) -> None:
for template in templates.all:
self.create(template)


def get_template_by_name(templates: CfgTemplates, name: str) -> Optional[CfgTemplate]:
return {template.__name__: template for template in templates.all}.get(name)
37 changes: 14 additions & 23 deletions resources/README_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,21 @@ _On **old systems** you might need to install [**vc redist**](https://learn.micr
[***NSIS***](https://nsis.sourceforge.io/Download) will be automatically installed if missing.
Check the [***build config***](build_config.py).

### Create the _x64_ environments
You need [***Python {py_major_version} x64***](https://www.python.org/ftp/python/{py_version}/python-{py_version}-amd64.exe) and [***Rust***](https://www.rust-lang.org/fr).
### Create the environments
You need [***Rust***](https://www.rust-lang.org/fr), [***Python {py_major_version} x64***](https://www.python.org/ftp/python/{py_version}/python-{py_version}-amd64.exe) and [***x86***](https://www.python.org/ftp/python/{py_version}/python-{py_version}.exe).
```console
rustup target add i686-pc-windows-msvc
py -{py_major_version}-64 -m dev.create
py -{py_major_version}-32 -m dev.create
```
Get a [***Github token***](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#personal-access-tokens-classic) and a [***DeepL API key***](https://www.deepl.com/en/docs-api/).
Store those in `api_keys.py`:
```python3
# api_keys.py
GITHUB_TOKEN=your_github_token
DEEPL_KEY=your_deepl_api_key
```

### Activate the _x64_ environment
```console
{env_x64}\scripts\activate
Expand Down Expand Up @@ -70,12 +80,6 @@ You need [**Visual Studio**](https://www.visualstudio.com/en-us/downloads/downlo

<img src="resources/VS.png">

### Create the _x86_ environment
You need [***Python {py_major_version} x86***](https://www.python.org/ftp/python/{py_version}/python-{py_version}.exe) and `i686-pc-windows-msvc` for rust.
```console
rustup target add i686-pc-windows-msvc
py -{py_major_version}-32 -m dev.create
```
### Build a specific version
```console
python -m dev.build [--x86 | --x64 | --both] [--pyinstaller | --mingw] [--nobuild | --noinstaller | --readme] [--upgrade] [--publish]
Expand All @@ -85,13 +89,7 @@ It checks for _Nsis_, _Python minor update_ and all _packages dependencies_:
```console
python -m dev.upgrade [--x86 | --x64 | --both] [--noeager] [--clean] [--force]
```
### Publish a release
Get a [***Github token***](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#personal-access-tokens-classic) and set `GITHUB_TOKEN` in `api_keys.py`
```python3
# api_keys.py
GITHUB_TOKEN=your_github_token
```
Publish a release:
### Publish an update
```console
python -m dev.publish [--x86 | --x64 | --both] [--version VERSION] [--info]
```
Expand All @@ -100,14 +98,7 @@ It updates _Microsoft Defender_ engine and signatures before scanning:
```console
python -m dev.scan [--x86 | --x64 | --both]
```

### Translations
Get a [***DeepL API key***](https://www.deepl.com/en/docs-api/) and set `DEEPL_KEY` in `api_keys.py`:
```python3
# api_keys.py
DEEPL_KEY=your_deepl_api_key
```
Translate the [**UI**](translations/loc/texts.py):
### [**UI**](translations/loc/texts.py) Translations
```console
python -m dev.translate [--force] [--language LANGUAGE]
```
2 changes: 1 addition & 1 deletion user_proxy_cmd/dev/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ class Environments(MasterEnvironments):


if __name__ == "__main__":
do_build(Build, Environments, Templates, Readme)
do_build(Build, Environments, Templates)

0 comments on commit e12db03

Please sign in to comment.