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

Add black, isort build tooling and simplify build #22

Merged
merged 1 commit into from
Feb 13, 2024
Merged
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
13 changes: 6 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ jobs:
- name: Checkout
uses: actions/checkout@v2

- name: Install package in dev mode
run: pip install -e .

- name: Install test requirements
run: pip install -r requirements_test.txt
- name: Install the project
run: make install
env:
TERM: xterm-256color

- name: Build
run: ./build.sh
- name: Run the build
run: make build
env:
TERM: xterm-256color
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
build: fmt
build: test

fmt:
black . && flake8 . && isort .

test:
pytest --cov=s3_browser


install:
pip install -e .
pip install -r requirements_test.txt
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,16 @@ And then run with `s3-browser`.

### Running tests

Install the project into your virtualenv in development mode:
This project uses `make` for ease of use. You can install the project in development mode,
and install the test requirements, using the `install` target:

```bash
pip install -e .
make install
```

Then install the test requirements:
It's recommended to create and activate a virtual environment first. There are a number of ways
to do that; I like [virtualenvwrapper](https://virtualenvwrapper.readthedocs.io/en/latest/).

```bash
pip install -r requirements_test.txt
```

and finally run `./build.sh` to run the full build.
Use `make` to run the full build.

[usage-1]: readme-resources/usage-1.png "Usage example"
32 changes: 0 additions & 32 deletions build.sh

This file was deleted.

4 changes: 3 additions & 1 deletion requirements_test.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
flake8>=3.7.0
black==24.2.0
flake8==7.0.0
isort==5.13.2
coverage>=4.5.0
pytest>=7.2.0
pytest-cov>=4.0.0
1 change: 1 addition & 0 deletions s3_browser/argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class ArgumentParser(argparse.ArgumentParser):
When we would normally exit safely, such as with --help, we'll add an extra
flag to the parser so that the caller can determine it shouldn't proceed.
"""

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.exited = False
Expand Down
29 changes: 12 additions & 17 deletions s3_browser/bookmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


class BookmarkManager(object):
KEY_REGEX = re.compile('^[a-zA-Z0-9_][a-zA-Z0-9_-]{0,15}$')
KEY_REGEX = re.compile("^[a-zA-Z0-9_][a-zA-Z0-9_-]{0,15}$")

def __init__(self, bookmark_file):
self.bookmark_file = bookmark_file
Expand All @@ -30,10 +30,7 @@ def add_bookmark(self, name, path):
if bookmarks is None:
return False

bookmarks[name] = Bookmark(
path=str(path),
created_on=datetime.datetime.now()
)
bookmarks[name] = Bookmark(path=str(path), created_on=datetime.datetime.now())
self._bookmarks = bookmarks
self.save()

Expand All @@ -57,7 +54,7 @@ def validate_key(cls, k):
return bool(cls.KEY_REGEX.match(k))

def clean_data(self, data):
bookmarks = data.get('bookmarks', {})
bookmarks = data.get("bookmarks", {})
return {k: Bookmark(**v) for k, v in bookmarks.items()}

def load(self):
Expand All @@ -73,33 +70,31 @@ def load(self):
# Don't try to read something we know isn't present; it's not an error
# though, we'll try to save an initial copy when we add some bookmarks
if not os.path.exists(ff):
logger.debug('No bookmark file %s, setting empty', ff)
logger.debug("No bookmark file %s, setting empty", ff)
self._bookmarks = {}
return True

try:
with open(ff, 'r') as f:
with open(ff, "r") as f:
data = self.clean_data(json.load(f))
except IOError:
logger.exception('Error reading bookmark file %s', ff)
logger.exception("Error reading bookmark file %s", ff)
except ValueError:
logger.exception('Error reading contents of bookmark file %s', ff)
logger.exception("Error reading contents of bookmark file %s", ff)
except AttributeError:
logger.exception('Error with bookmark file format (%s)', ff)
logger.exception("Error with bookmark file format (%s)", ff)
else:
logger.debug('Successfully read %d bookmarks', len(data))
logger.debug("Successfully read %d bookmarks", len(data))

self._bookmarks = data
return data is not None

def save(self):
"""Save bookmark data to file"""
data = {
'bookmarks': {k: v.__dict__ for k, v in self.bookmarks.items()}
}
data = {"bookmarks": {k: v.__dict__ for k, v in self.bookmarks.items()}}
data = json.dumps(data)

with open(self.bookmark_file, 'w') as f:
with open(self.bookmark_file, "w") as f:
f.write(data)


Expand All @@ -111,7 +106,7 @@ def __init__(self, path, created_on=None, *args, **kwargs):
if isinstance(created_on, str):
self.created_on = created_on
else:
self.created_on = created_on.strftime('%Y-%m-%dT%H:%M:%SZ')
self.created_on = created_on.strftime("%Y-%m-%dT%H:%M:%SZ")

def __str__(self):
return self.path
Loading
Loading