Skip to content

Commit 48329e0

Browse files
authored
Merge pull request #40 from CycloneDX/fix/issue-39-windows-UnicodeEncodeError
FIX: Resolve file encoding issues on Windows
2 parents eea3598 + 350c097 commit 48329e0

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

.github/workflows/poetry.yml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,25 @@ jobs:
4444
run: poetry run tox -e flake8
4545

4646
build-and-test:
47-
name: Build & Test (Python ${{ matrix.python-version }}
48-
runs-on: ubuntu-latest
47+
name: Build & Test Python ${{ matrix.python-version }} on ${{ matrix.os }}
48+
runs-on: ${{ matrix.os }}
4949
env:
5050
REPORTS_ARTIFACT: tests-reports
5151
strategy:
5252
fail-fast: false
5353
matrix:
54+
os: [ubuntu-latest, windows-latest, macos-latest]
5455
python-version:
5556
- "3.9" # highest supported
5657
- "3.8"
5758
- "3.7"
5859
- "3.6" # lowest supported
5960
timeout-minutes: 30
6061
steps:
62+
- name: Disabled Git auto EOL CRLF transforms
63+
run: |
64+
git config --global core.autocrlf false
65+
git config --global core.eol lf
6166
- name: Checkout
6267
# see https://github.com/actions/checkout
6368
uses: actions/checkout@v2
@@ -69,6 +74,8 @@ jobs:
6974
with:
7075
python-version: ${{ matrix.python-version }}
7176
architecture: 'x64'
77+
- name: Validate Python Environment
78+
run: echo "import sys; print('Python %s on %s in %s' % (sys.version, sys.platform, sys.getdefaultencoding()))" | python
7279
- name: Install poetry
7380
# see https://github.com/marketplace/actions/setup-poetry
7481
uses: Gr1N/setup-poetry@v7
@@ -77,7 +84,7 @@ jobs:
7784
- uses: actions/cache@v2
7885
with:
7986
path: ~/.cache/pypoetry/virtualenvs
80-
key: ${{ runner.os }}-poetry-${{ hashFiles('poetry.lock') }}
87+
key: ${{ runner.os }}}-${{ matrix.python-version }}-poetry-${{ hashFiles('poetry.lock') }}
8188
- name: Install dependencies
8289
run: poetry install
8390
- name: Ensure build successful
@@ -87,7 +94,7 @@ jobs:
8794
- name: Generate coverage reports
8895
run: >
8996
poetry run coverage report &&
90-
poetry run coverage xml -o ${{ env.REPORTS_DIR }}/coverage.xml &&
97+
poetry run coverage xml -o ${{ env.REPORTS_DIR }}/coverage-${{ matrix.os }}-${{ matrix.python-version }}.xml &&
9198
poetry run coverage html -d ${{ env.REPORTS_DIR }}
9299
- name: Artifact reports
93100
if: ${{ ! cancelled() }}

cyclonedx/model/__init__.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,9 @@ def sha1sum(filename: str) -> str:
3939
SHA-1 hash
4040
"""
4141
h = hashlib.sha1()
42-
b = bytearray(128 * 1024)
43-
mv = memoryview(b)
44-
with open(filename, 'rb', buffering=0) as f:
45-
for n in iter(lambda: f.readinto(mv), 0):
46-
h.update(mv[:n])
42+
with open(filename, 'rb') as f:
43+
for byte_block in iter(lambda: f.read(4096), b""):
44+
h.update(byte_block)
4745
return h.hexdigest()
4846

4947

cyclonedx/output/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def output_to_file(self, filename: str, allow_overwrite: bool = False):
7070
raise FileExistsError
7171

7272
with open(output_filename, mode='w') as f_out:
73-
f_out.write(self.output_as_string())
73+
f_out.write(self.output_as_string(), encoding='utf-8')
7474

7575
f_out.close()
7676

0 commit comments

Comments
 (0)