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

Lint Python scripts and add GitHub Action #232

Merged
merged 7 commits into from
Feb 19, 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
27 changes: 27 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,33 @@ on:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "lint"
lint:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3

# Install python
- uses: actions/setup-python@v3
with:
python-version: '3.x'

# Install isort and black for linting
- name: Install isort and black
run: pip install isort black

# Run isort
- name: Run isort
run: isort --check-only --profile black .

# Run black
- name: Run black
run: black --check --color --diff .

# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
Expand Down
15 changes: 15 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,21 @@ For that last one, you'll need to specify the location of the server at `tools/s

One more thing. While changing scripts, you can run the command `/reload` ingame to reload them, without having to exit and enter the world.

### Linting

#### Python

The `isort` and `black` packages found in the `requirements.txt` file are responsible for automatically formatting your Python code!

Simply run these commands locally at the root of the repository to automatically format the Python code:
``` bash
# Sort package imports.
isort --profile black .

# Auto-format Python code.
black .
```

## Translations

Speak another language? Help the addon become more localized by going to the addon's [Crowdin page](https://crowdin.com/project/worldedit-for-bedrock). Choose a language you're good with, and start contributing in places that don't have a translation.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# WorldEdit: Bedrock Edition
![Build Workflow](https://github.com/SIsilicon/WorldEdit-BE/actions/workflows/main.yml/badge.svg)
[![Documentation Status](https://readthedocs.org/projects/ansicolortags/badge/?version=latest)](http://worldedit-be-docs.readthedocs.io/?badge=latest)
[![Python code style: black](https://img.shields.io/badge/python%20code%20style-black-000000.svg)](https://github.com/psf/black)
[![Python Imports: isort](https://img.shields.io/badge/python%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/)
[![Support me on Patreon](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Fshieldsio-patreon.vercel.app%2Fapi%3Fusername%3DSIsilicon%26type%3Dpatrons&style=flat)](https://patreon.com/SIsilicon)
[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=XXXJ5ETNT5PSN)
[![Twitter Follow](https://img.shields.io/twitter/follow/iSiliconS?style=social)](https://twitter.com/iSiliconS)
Expand Down
24 changes: 15 additions & 9 deletions app/addons/gdnative_data/leveldb/build.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

from distutils.command.build import build
import os
from distutils.command.build import build
from pathlib import Path


Expand All @@ -10,15 +9,22 @@ def execute(args):
target_file_path = args["target_file_path"]
build_target = "Debug" if args["target"] == "debug" else "Release"

run_command(str(source_path / "build"), [
"cmake", "--build", ".", "--target", "leveldb", "--config", build_target
])

run_command(
str(source_path / "build"),
["cmake", "--build", ".", "--target", "leveldb", "--config", build_target],
)

if os.path.exists(target_file_path + ".exp"):
os.remove(target_file_path + ".exp")
if os.path.exists(target_file_path + ".lib"):
os.remove(target_file_path + ".lib")

os.rename(source_path / f"build/{build_target}/leveldb.dll", target_file_path + ".dll")
os.rename(source_path / f"build/{build_target}/leveldb.exp", target_file_path + ".exp")
os.rename(source_path / f"build/{build_target}/leveldb.lib", target_file_path + ".lib")
os.rename(
source_path / f"build/{build_target}/leveldb.dll", target_file_path + ".dll"
)
os.rename(
source_path / f"build/{build_target}/leveldb.exp", target_file_path + ".exp"
)
os.rename(
source_path / f"build/{build_target}/leveldb.lib", target_file_path + ".lib"
)
61 changes: 35 additions & 26 deletions app/addons/silicon.util.gdnative_helper/main_build.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,45 @@
import os, sys, json
import json
import os
import sys
from pathlib import Path

sys.path.append(sys.argv[1])

from build_project import execute

with open("addons/silicon.util.gdnative_helper/build_config.json", 'r') as config:
args = json.load(config)
args["library_name"] = sys.argv[2]
args["target_file_path"] = sys.argv[3]
args["source_path"] = sys.argv[4]
args["library_extension"] = sys.argv[5]
args["platform"] = sys.argv[6]
args["arch"] = sys.argv[7]
args["target"] = sys.argv[8]
args["gd_settings_dir"] = str(Path(sys.argv[1], "../..").resolve())
with open("addons/silicon.util.gdnative_helper/build_config.json", "r") as config:
args = json.load(config)
args["library_name"] = sys.argv[2]
args["target_file_path"] = sys.argv[3]
args["source_path"] = sys.argv[4]
args["library_extension"] = sys.argv[5]
args["platform"] = sys.argv[6]
args["arch"] = sys.argv[7]
args["target"] = sys.argv[8]
args["gd_settings_dir"] = str(Path(sys.argv[1], "../..").resolve())

os.chdir(sys.argv[1])
os.chdir(sys.argv[1])

# Get older dll out of the way on Windows.
lib_name = "%s.%s" % (args["target_file_path"], args["library_extension"])
try:
if os.path.exists(lib_name) and args["platform"] == "windows" and os.name == "nt":
# if os.path.exists(lib_name + ".old"):
# os.remove(lib_name + ".old")
os.replace(lib_name, lib_name + ".old")
except OSError as e:
raise OSError("Cannot delete Windows DLL at \"%s\"! Please delete it manually." % lib_name)
# Get older dll out of the way on Windows.
lib_name = "%s.%s" % (args["target_file_path"], args["library_extension"])
try:
if (
os.path.exists(lib_name)
and args["platform"] == "windows"
and os.name == "nt"
):
# if os.path.exists(lib_name + ".old"):
# os.remove(lib_name + ".old")
os.replace(lib_name, lib_name + ".old")
except OSError as e:
raise OSError(
'Cannot delete Windows DLL at "%s"! Please delete it manually.' % lib_name
)

# Create directory for library files to reside
try:
os.makedirs(Path(args["target_file_path"]).parent)
except: pass
# Create directory for library files to reside
try:
os.makedirs(Path(args["target_file_path"]).parent)
except:
pass

execute(args)
execute(args)
Loading
Loading