diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 03e43d245..4f5fc4ea0 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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 diff --git a/spdx/parsers/parse_anything.py b/spdx/parsers/parse_anything.py index 329ea6944..906337fff 100644 --- a/spdx/parsers/parse_anything.py +++ b/spdx/parsers/parse_anything.py @@ -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"): @@ -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) diff --git a/spdx/writers/write_anything.py b/spdx/writers/write_anything.py index 5e479ef6e..63a4f4c3b 100644 --- a/spdx/writers/write_anything.py +++ b/spdx/writers/write_anything.py @@ -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"): @@ -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)