Skip to content

Commit

Permalink
Streamline setting up the project locally and on CI (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
mataha authored and deathaxe committed Dec 27, 2023
1 parent 615ebf2 commit 4d2291a
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 81 deletions.
3 changes: 0 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,3 @@ indent_size = 4
[*.tmPreferences]
indent_style = tab
indent_size = 4

[Makefile]
indent_style = tab
20 changes: 10 additions & 10 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

# Files and directories with the attribute export-ignore won’t be added to
# archive files. See http://git-scm.com/docs/gitattributes for details.
/.github/ export-ignore
/build/ export-ignore
/icons/svg/ export-ignore
/tests/ export-ignore
/.editorconfig export-ignore
/.flake8 export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/makefile export-ignore
/pyproject.toml export-ignore
/.github/ export-ignore
/build/ export-ignore
/icons/svg/ export-ignore
/tests/ export-ignore
/.editorconfig export-ignore
/.flake8 export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/pyproject.toml export-ignore
/requirements-dev.txt export-ignore
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
<!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->
- [ ] My code follows the code style of this project.
- [ ] My change requires a change to the documentation.
- [ ] I have read the **CONTRIBUTING** document.
- [ ] I have read the [**CONTRIBUTING**](https://github.com/SublimeText/AFileIcon/blob/develop/CONTRIBUTING.md) document.
19 changes: 11 additions & 8 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@ on: [push, pull_request]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: Checkout the latest code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v1
uses: actions/setup-python@v5
with:
python-version: 3.8
- name: Install black
run: pip install black
- name: Check formating
run: black --check .
python-version-file: '.python-version'

- name: Install dependencies
run: python -m pip install -U -r requirements-dev.txt

- name: Check formatting
run: python -m black --check .
65 changes: 40 additions & 25 deletions .github/CONTRIBUTING.md → CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,57 +12,72 @@ We have very precise rules over how our git commit messages can be formatted. Th

We use [**Angular JS commit guidelines**](https://github.com/angular/angular.js/blob/master/CONTRIBUTING.md#-git-commit-guidelines) (except scope notes: we don't need them).

## Building
## Development

## Prerequisites
### Prerequisites

This package provides the `build` python package to create the preferences and icons. In order to add new icons a _python 3_ interpreter is required.
The CairoSVG dependency needs the `cairo` library being present on the system.

The `build` uses [pyPNG](https://pypi.org/project/pypng/) and [CairoSVG](https://pypi.org/project/CairoSVG/) to convert the icons from SVG to PNG. You nee to...
**Linux**

```bash
pip install cairosvg
pip install pypng
sudo apt-get install libcairo2
```

The CairoSVG needs the `cairo` library being present on the system.
**Windows**

**Linux**
You can download the latest release of [`cairo.dll`](https://github.com/preshing/cairo-windows/releases) and place it somewhere Python can load it from.

As a last resort, [Graphviz](https://graphviz.org/) includes `cairo.dll` in its distribution.

### Installation

Navigate to _A File Icon_ root directory and call...

**Linux/MacOS**

```bash
sudo apt-get install libcairo2
python3 -m venv .venv
. .venv/bin/activate
python3 -m pip install -U -r requirements-dev.txt
```

**Windows**

You can download the latest release of the [cairo.dll](https://github.com/preshing/cairo-windows/releases) from https://github.com/preshing/cairo-windows/releases and place it somewhere python can load it from.
```cmd
py -m venv .venv
.venv\Scripts\activate
py -m pip install -U -r requirements-dev.txt
```

### Building

Run the build scripts via makefile:
Navigate to _A File Icon_ root directory, activate python virtual environment and call...

**Linux/MacOS**

```bash
# build all
make all
# build everything
python3 build

# build icons
make icons
# build icons only
python3 build --icons

# build preferences
make preferences
# build preferences only
python3 build --preferences
```

If no make is available run the build scripts directly via python:
**Windows**

```bash
# build all
python -u build --icons --preferences
```cmd
: build everything
py build
# build icons
python -u build --icons
: build icons only
py build --icons
# build preferences
python -u build --preferences
: build preferences only
py build --preferences
```

## Want to add new icons?
Expand Down
9 changes: 5 additions & 4 deletions build/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ def main(argv=None):
"-p", "--preferences", action="store_true", help="create preferences"
)

options = parser.parse_args(argv)
if not options.icons and not options.preferences:
return parser.print_help()

with open(icons_path("icons.json")) as fp:
icons = json.load(fp)

options = parser.parse_args(argv)
if not options.icons and not options.preferences:
options.icons = True
options.preferences = True

if options.icons:
print("building icons...")
create_icons(icons)
Expand Down
20 changes: 2 additions & 18 deletions build/icons.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,10 @@
import cairosvg
import json
import os
import png
import re
import subprocess

try:
import cairosvg
except ImportError:
print(
"Error: CairoSVG not installed!\n"
" Run `pip install cairosvg`!\n"
" Windows users need the cairo.dll from"
" https://github.com/preshing/cairo-windows/releases"
)

try:
import png
except ImportError:
print(
"Error: pyPNG not installed!\n"
" Run `pip install pypng`!"
)


PACKAGE_ROOT = os.path.dirname(os.path.dirname(__file__))

Expand Down
11 changes: 0 additions & 11 deletions makefile

This file was deleted.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ exclude = '''
| \.mypy_cache
| \.tox
| \.venv
| build
| tests
| vendor
)/
'''
8 changes: 8 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
pip

# Build
cairosvg >= 2.7.0
pypng >= 0.20220715.0

# Format
black >= 23.7.0

0 comments on commit 4d2291a

Please sign in to comment.