Skip to content

Commit

Permalink
Added black stylechecking to circleci (#12)
Browse files Browse the repository at this point in the history
* Added stylecheck to circleci

* Updated black to 18.9b0

* Formatted all source files with black
  • Loading branch information
freundTech authored and naor2013 committed Oct 1, 2018
1 parent feeb68f commit af72cc2
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 26 deletions.
13 changes: 10 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
# Download and cache dependencies
- restore_cache:
keys:
- v1-dependencies-{{ checksum "requirements.txt" }}
- v1-dependencies-{{ checksum "requirements-dev.txt" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-

Expand All @@ -25,19 +25,26 @@ jobs:
command: |
python3 -m venv venv
. venv/bin/activate
pip install -r requirements.txt
pip install -r requirements-dev.txt
- save_cache:
paths:
- ./venv
key: v1-dependencies-{{ checksum "requirements.txt" }}
key: v1-dependencies-{{ checksum "requirements-dev.txt" }}

- run:
name: run tests
command: |
. venv/bin/activate
python -m unittest discover -v -s tests
- run:
name: run stylecheck
command: |
. venv/bin/activate
python -m black --check src
python -m black --check tests
- store_artifacts:
path: test-reports
destination: test-reports
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
Sphinx==1.7.4
sphinx-autodoc-typehints==1.3.0
sphinx_rtd_theme==0.3.1
black==18.4a2
black==18.9b0
PyInstaller==3.4
pre_commit==1.11.1
14 changes: 7 additions & 7 deletions src/formats/anvil/anvil_world.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ def load_chunk(
if not self.load_region(rx, rz):
raise Exception()

cx &= 0x1f
cz &= 0x1f
cx &= 0x1F
cz &= 0x1F

chunk_offset = self._loaded_regions[key]["offsets"][
(cx & 0x1f) + (cz & 0x1f) * 32
(cx & 0x1F) + (cz & 0x1F) * 32
]
if chunk_offset == 0:
raise Exception()

sector_start = chunk_offset >> 8
number_of_sectors = chunk_offset & 0xff
number_of_sectors = chunk_offset & 0xFF

if number_of_sectors == 0:
raise Exception()
Expand Down Expand Up @@ -93,8 +93,8 @@ def load_region(self, rx: int, rz: int) -> bool:
self._loaded_regions[key] = {}

file_size = path.getsize(filename)
if file_size & 0xfff:
file_size = (file_size | 0xfff) + 1
if file_size & 0xFFF:
file_size = (file_size | 0xFFF) + 1
fp.truncate(file_size)

if not file_size:
Expand Down Expand Up @@ -122,7 +122,7 @@ def load_region(self, rx: int, rz: int) -> bool:

for offset in offsets:
sector = offset >> 8
count = offset & 0xff
count = offset & 0xFF

for i in range(sector, sector + count):
if i >= len(free_sectors):
Expand Down
14 changes: 7 additions & 7 deletions src/formats/anvil2/anvil2_world.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ def load_chunk(
if not self.load_region(rx, rz):
raise Exception()

cx &= 0x1f
cz &= 0x1f
cx &= 0x1F
cz &= 0x1F

chunk_offset = self._loaded_regions[key]["offsets"][
(cx & 0x1f) + (cz & 0x1f) * 32
(cx & 0x1F) + (cz & 0x1F) * 32
]
if chunk_offset == 0:
raise Exception()

sector_start = chunk_offset >> 8
number_of_sectors = chunk_offset & 0xff
number_of_sectors = chunk_offset & 0xFF

if number_of_sectors == 0:
raise Exception()
Expand Down Expand Up @@ -91,8 +91,8 @@ def load_region(self, rx: int, rz: int) -> bool:
self._loaded_regions[key] = {}

file_size = path.getsize(filename)
if file_size & 0xfff:
file_size = (file_size | 0xfff) + 1
if file_size & 0xFFF:
file_size = (file_size | 0xFFF) + 1
fp.truncate(file_size)

if not file_size:
Expand Down Expand Up @@ -120,7 +120,7 @@ def load_region(self, rx: int, rz: int) -> bool:

for offset in offsets:
sector = offset >> 8
count = offset & 0xff
count = offset & 0xFF

for i in range(sector, sector + count):
if i >= len(free_sectors):
Expand Down
2 changes: 1 addition & 1 deletion src/utils/world_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def from_nibble_array(arr: ndarray) -> ndarray:
new_arr = zeros((shape[0], shape[1], shape[2] * 2), dtype=uint8)

new_arr[:, :, ::2] = arr
new_arr[:, :, ::2] &= 0xf
new_arr[:, :, ::2] &= 0xF
new_arr[:, :, 1::2] = arr
new_arr[:, :, 1::2] >>= 4

Expand Down
4 changes: 0 additions & 4 deletions tests/test_format_proto_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class TestPrototypeBaseCases:
# Wrapped in another class, so it isn't executed on it's own.

class TestPrototype(unittest.TestCase):

def _setUp(self, version):
self.proto = definition_manager.DefinitionManager(version)

Expand All @@ -29,7 +28,6 @@ def test_get_internal_block(self):
self.assertIsInstance(stone_def, dict)
self.assertEqual("Stone", stone_def["name"])


self.assertIsInstance(granite_def, dict)
self.assertEqual("Granite", granite_def["name"])
self.assertNotEqual(granite_def, stone_def)
Expand All @@ -54,7 +52,6 @@ def test_get_internal_block(self):


class TestPrototype112(TestPrototypeBaseCases.TestPrototype):

def setUp(self):
self._setUp("java_1_12")

Expand All @@ -63,7 +60,6 @@ def test_direct_access(self):


class TestPrototype113(TestPrototypeBaseCases.TestPrototype):

def setUp(self):
self._setUp("java_1_13")

Expand Down
3 changes: 0 additions & 3 deletions tests/test_world.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class WorldTestBaseCases:
# Wrapped in another class, so it isn't executed on it's own.

class WorldTestCase(unittest.TestCase):

def _setUp(self, world_name):
self.world = world_loader.loader.load_world(get_world_path(world_name))

Expand Down Expand Up @@ -108,13 +107,11 @@ def test_fill_operation(self):


class AnvilWorldTestCase(WorldTestBaseCases.WorldTestCase):

def setUp(self):
self._setUp("1.12.2 World")


class Anvil2WorldTestCase(WorldTestBaseCases.WorldTestCase):

def setUp(self):
self._setUp("1.13 World")

Expand Down

0 comments on commit af72cc2

Please sign in to comment.