Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update pytest #36

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6, 3.7, 3.8, 3.9]
python-version: [3.7, 3.8, 3.9]

steps:
- uses: actions/checkout@v2
Expand Down
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,15 @@ usage: alacritty-colorscheme [-c configuration file] [-C colorscheme directory]
REPO="https://github.com/aaron-williamson/base16-alacritty.git"
DEST="$HOME/.aarors-williamson-colorschemes"

# Get colorschemes
# Get colorschemes
git clone $REPO $DEST

# Make sure the config directory exits
mkdir "$HOME/.config/alacritty/" -p

# Make sure the config file exists
touch -a "$HOME/.config/alacritty/alacritty.yml"

# Create symlink at default colors location (optional)
ln -s "$DEST/colors" "$HOME/.config/alacritty/colors"
```
Expand All @@ -40,8 +47,16 @@ usage: alacritty-colorscheme [-c configuration file] [-C colorscheme directory]
```bash
REPO=https://github.com/eendroroy/alacritty-theme.git
DEST="$HOME/.eendroroy-colorschemes"

# Make sure the config directory exits
mkdir "$HOME/.config/alacritty/" -p

# Make sure the config file exists
touch -a "$HOME/.config/alacritty/alacritty.yml"

# Get colorschemes
git clone $REPO $DEST

# Create symlink at default colors location (optional)
ln -s "$DEST/themes" "$HOME/.config/alacritty/colors"
```
Expand Down
22 changes: 10 additions & 12 deletions alacritty_colorscheme/cli.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#!/usr/bin/env python3

import os

from tap import Tap
from os.path import expanduser, isfile, join
from pathlib import Path
from os.path import expanduser, isdir, join
from typing import List, Optional, cast
try:
from typing import Literal # type: ignore
Expand Down Expand Up @@ -92,15 +91,14 @@ def create_parser() -> TypedArgumentParser:

def get_files_in_directory(path: str) -> Optional[List[str]]:
expanded_path = expanduser(path)
if not isdir(expanded_path):
return None
try:
onlyfiles = []
for root, _dirs, files in os.walk(expanded_path, followlinks=True):
for file in files:
full_path = join(root, file)
if file.endswith(('.yml', '.yaml')) and isfile(full_path):
onlyfiles.append(full_path.removeprefix(expanded_path))
onlyfiles.sort()
return onlyfiles
# NOTE: joining path with empty string to add a trailing slash to dir
onlyfiles = [str(x).removeprefix(join(expanded_path, ''))
for x in list(Path(expanded_path).rglob("*.yml"))]
sortedfiles = sorted(onlyfiles)
return sortedfiles
except OSError:
return None

Expand All @@ -109,7 +107,7 @@ def handle_args(args: TypedArgumentParser) -> None:
if args._subparser_name == 'list':
files = get_files_in_directory(args.colorscheme_dir)
if files is None:
raise RuntimeError(f'Could not find directory: {args.colorscheme_dir}')
raise RuntimeError(f'Could not find colorscheme directory: {args.colorscheme_dir}')
for file in files:
print(file)
elif args._subparser_name == 'status':
Expand Down
10 changes: 6 additions & 4 deletions alacritty_colorscheme/colorscheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ def get_applied_colorscheme(config_path: str) -> Optional[str]:
has_comment = _has_comment_token(config_yaml['colors'].ca.comment)
except KeyError:
return None
except TypeError:
return None

if not has_comment:
return None
Expand Down Expand Up @@ -70,13 +72,13 @@ def replace_colorscheme(
try:
# NOTE: update method doesn't read the first comment
config_yaml['colors'].update(colors_yaml['colors'])
# NOTE: We get a KeyError when accessing colors if colors does not exist
except KeyError:
config_yaml['colors'] = colors_yaml['colors']
# NOTE: config_yaml is None when config_file is an empty yml file
# We get a TypeError when accessing colors from None
except TypeError:
if not config_yaml:
config_yaml = {'colors': colors_yaml['colors']}
else:
raise
config_yaml = {'colors': colors_yaml['colors']}

new_comment_token = CommentToken(
f'# COLORSCHEME: {colorscheme}\n',
Expand Down
Loading