Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ Here's the process to make changes to the codebase:
2. Review [open pull requests](https://github.com/spdx/tools-python/pulls) before committing time to a substantial
revision. Work along similar lines may already be in progress.

3. Create a new branch:
3. Create a new branch and set up environment:
```sh
git checkout -b fix-or-improve-something
python -m venv ./venv
./venv/bin/activate
pip install -e .
```
4. Make some changes and commit them to the branch:
```sh
Expand Down
5 changes: 3 additions & 2 deletions spdx/parsers/parse_anything.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
from spdx.parsers.builderexceptions import FileTypeError


def parse_file(fn):
def parse_file(fn, encoding="utf-8"):
builder_module = jsonyamlxmlbuilders
read_data = False
if fn.endswith(".rdf") or fn.endswith(".rdf.xml"):
encoding = None
parsing_module = rdf
builder_module = rdfbuilders
elif fn.endswith(".tag") or fn.endswith(".spdx"):
Expand All @@ -43,7 +44,7 @@ def parse_file(fn):
p = parsing_module.Parser(builder_module.Builder(), StandardLogger())
if hasattr(p, "build"):
p.build()
with open(fn) as f:
with open(fn, "r", encoding=encoding) as f:
if read_data:
data = f.read()
return p.parse(data)
Expand Down
5 changes: 3 additions & 2 deletions spdx/writers/write_anything.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
from spdx.parsers.builderexceptions import FileTypeError


def write_file(doc, fn, validate=True):
def write_file(doc, fn, validate=True, encoding="utf-8"):
out_mode = "w"
if fn.endswith(".rdf") or fn.endswith(".rdf.xml"):
writer_module = rdf
out_mode = "wb"
encoding = None
elif fn.endswith(".tag") or fn.endswith(".spdx"):
writer_module = tagvalue
elif fn.endswith(".json"):
Expand All @@ -34,5 +35,5 @@ def write_file(doc, fn, validate=True):
else:
raise FileTypeError("FileType Not Supported")

with open(fn, out_mode) as out:
with open(fn, out_mode, encoding=encoding) as out:
p = writer_module.write_document(doc, out, validate)