-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from alkuzad/main
Windows Support
- Loading branch information
Showing
13 changed files
with
285 additions
and
194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,11 +7,11 @@ on: | |
|
||
jobs: | ||
build: | ||
runs-on: ${{ matrix.os[0]}} | ||
runs-on: ${{ matrix.os }} | ||
|
||
strategy: | ||
matrix: | ||
os: [[ubuntu-latest, linux]] | ||
os: [ubuntu-latest, windows-latest] | ||
|
||
steps: | ||
- name: Checkout Code | ||
|
@@ -29,12 +29,46 @@ jobs: | |
- name: Install Poetry Packages | ||
run: poetry install | ||
|
||
- name: Get version | ||
run: | | ||
poetry run python ./build_system/update_version.py | ||
- name: Build Pyinstaller | ||
run: make build | ||
run: | | ||
poetry run python ./build_system/update_version.py | ||
poetry run pyinstaller --onefile ./src/zeal_cli.py --name zeal-cli | ||
- name: 'Upload Artifact' | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: zeal-cli | ||
path: dist/zeal-cli | ||
retention-days: 5 | ||
if: matrix.os == 'ubuntu-latest' | ||
|
||
- name: 'Upload Artifact - Windows' | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: zeal-cli.exe | ||
path: dist/zeal-cli.exe | ||
retention-days: 5 | ||
if: matrix.os == 'windows-latest' | ||
|
||
release: | ||
needs: build | ||
|
||
runs-on: "ubuntu-latest" | ||
|
||
steps: | ||
- name: download artifacts | ||
uses: actions/download-artifact@v3 | ||
with: | ||
path: /home/runner/artifacts | ||
|
||
- name: Upload Executables | ||
uses: softprops/[email protected] | ||
with: | ||
files: | | ||
dist/zeal-cli | ||
dist/zeal-cli.exe | ||
/home/runner/artifacts/**/zeal-cli | ||
/home/runner/artifacts/**/zeal-cli.exe | ||
fail_on_unmatched_files: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
|
||
import git | ||
|
||
|
||
repo = git.Repo(search_parent_directories=True) | ||
version = repo.git.describe("--tags") | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,91 @@ | ||
import logging | ||
import os | ||
import platform | ||
from typing import Any | ||
|
||
if platform.system() == "Windows": | ||
import winreg | ||
|
||
import yaml | ||
from pathlib import Path | ||
|
||
|
||
logger = logging.getLogger(__file__) | ||
|
||
|
||
def get_docset_dir() -> str: | ||
# Set zeal_docset_dir variable. | ||
if platform.system() == "Linux": | ||
return os.path.join(os.path.expanduser("~"), ".local", "share", "Zeal", "Zeal", "docsets") | ||
else: | ||
raise NotImplementedError("Zeal_CLI only supports linux at this time.") | ||
|
||
|
||
def get_cli_data_dir() -> str: | ||
if platform.system() == "Linux": | ||
zeal_cli_dir = os.path.join(os.path.expanduser("~"), ".local", "share", "zeal_cli") | ||
else: | ||
raise NotImplementedError("Zeal_CLI only supports linux at this time.") | ||
|
||
if os.path.isfile(zeal_cli_dir): | ||
logger.warning( | ||
f"The Zeal CLI data directory location ({zeal_cli_dir}) exists and is a file, not a directory. Deleting." | ||
) | ||
os.remove(zeal_cli_dir) | ||
os.makedirs(zeal_cli_dir) | ||
elif os.path.isdir(zeal_cli_dir): | ||
logger.debug(f"The Zeal CLI data directory location ({zeal_cli_dir}) already exists.") | ||
elif not os.path.exists(zeal_cli_dir): | ||
logger.debug( | ||
f"The Zeal CLI data directory location ({zeal_cli_dir}) does not exist. Creating." | ||
) | ||
os.makedirs(zeal_cli_dir) | ||
return zeal_cli_dir | ||
|
||
|
||
def set_default_config(config_path: str) -> dict: | ||
config_dict = {"docset_dir": get_docset_dir()} | ||
if os.path.isfile(config_path): | ||
os.remove(config_path) | ||
with open(config_path, "x") as file: | ||
yaml.safe_dump(config_dict, stream=file) | ||
return config_dict | ||
|
||
|
||
def get_config(config_path: str) -> dict: | ||
if os.path.isfile(config_path): | ||
logger.debug(f"Using config file found at {config_path}.") | ||
with open(config_path, "r") as file: | ||
config_dict = yaml.safe_load(file) | ||
else: | ||
logger.warning(f"Did not find a config file at {config_path}. Creating default.") | ||
config_dict = set_default_config(config_path) | ||
if not config_dict: | ||
logger.warning(f"Config file found at {config_path} is empty. Resetting to defaults.") | ||
config_dict = set_default_config(config_path) | ||
return config_dict | ||
|
||
|
||
def set_config_value(key, value, config_path): | ||
with open(config_path, "r+") as config_file: | ||
config_dict = yaml.safe_load(config_file) | ||
config_dict[key] = value | ||
yaml.safe_dump(config_dict, stream=config_file) | ||
|
||
|
||
cli_data_dir = get_cli_data_dir() | ||
cli_config_path = os.path.join(cli_data_dir, "config.yml") | ||
cli_config = get_config(cli_config_path) | ||
docset_dir = cli_config["docset_dir"] | ||
class Config: | ||
def _get_docset_dir(self) -> Path: | ||
# Set zeal_docset_dir variable. | ||
if platform.system() == "Linux": | ||
return Path("~", ".local", "share", "Zeal", "Zeal", "docsets").expanduser() | ||
elif platform.system() == "Windows": | ||
with winreg.OpenKey(winreg.HKEY_CURRENT_USER, "Software\\Zeal\\Zeal\\docsets") as key: | ||
path, _type = winreg.QueryValueEx(key, "path") | ||
return Path(path).expanduser() | ||
else: | ||
raise RuntimeError("Systems other than Linux and Windows are not supported") | ||
|
||
def _get_cli_data_dir(self) -> Path: | ||
zeal_cli_dir = Path("~", ".local", "share", "zeal_cli").expanduser() | ||
|
||
if zeal_cli_dir.is_file(): | ||
logger.warning( | ||
f"The Zeal CLI data directory location ({zeal_cli_dir}) exists and is a file, not a directory. Deleting." | ||
) | ||
os.remove(zeal_cli_dir) | ||
zeal_cli_dir.mkdir(parents=True) | ||
elif zeal_cli_dir.is_dir(): | ||
logger.debug(f"The Zeal CLI data directory location ({zeal_cli_dir}) already exists.") | ||
elif not zeal_cli_dir.exists(): | ||
logger.debug( | ||
f"The Zeal CLI data directory location ({zeal_cli_dir}) does not exist. Creating." | ||
) | ||
zeal_cli_dir.mkdir(parents=True) | ||
return zeal_cli_dir | ||
|
||
def _set_default_config(self, config_path: Path) -> dict: | ||
config_dict = {"docset_dir": str(self._get_docset_dir().resolve())} | ||
if config_path.is_file(): | ||
os.remove(config_path) | ||
with config_path.open(mode="x") as file: | ||
yaml.safe_dump(config_dict, stream=file) | ||
return config_dict | ||
|
||
def _get_config(self, config_path: Path) -> dict: | ||
if config_path.is_file(): | ||
logger.debug(f"Using config file found at {config_path}.") | ||
with config_path.open() as file: | ||
config_dict = yaml.safe_load(file) | ||
else: | ||
logger.warning(f"Did not find a config file at {config_path}. Creating default.") | ||
config_dict = self._set_default_config(config_path) | ||
if not config_dict: | ||
logger.warning(f"Config file found at {config_path} is empty. Resetting to defaults.") | ||
config_dict = self._set_default_config(config_path) | ||
return config_dict | ||
|
||
def set_config_value(self, key: Any, value: Any, config_path: Path): | ||
with config_path.open(mode="r+") as config_file: | ||
config_dict = yaml.safe_load(config_file) | ||
config_dict[key] = value | ||
yaml.safe_dump(config_dict, stream=config_file) | ||
|
||
@property | ||
def cli_data_dir(self): | ||
return self._get_cli_data_dir() | ||
|
||
@property | ||
def cli_config_path(self): | ||
return Path(self.cli_data_dir, "config.yml") | ||
|
||
@property | ||
def cli_config(self): | ||
return self._get_config(self.cli_config_path) | ||
|
||
@property | ||
def docset_dir(self): | ||
if self.cli_config: | ||
return Path(self.cli_config["docset_dir"]) | ||
|
||
|
||
config = Config() |
Oops, something went wrong.