Skip to content

Commit

Permalink
Replace os.path with pathlib.Path where used
Browse files Browse the repository at this point in the history
  • Loading branch information
17o2 authored and laurierloi committed Jan 19, 2023
1 parent c1494db commit 0192f6d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import os
from pathlib import Path
from setuptools import setup, find_packages

from src.wireviz import __version__, CMD_NAME, APP_URL
Expand All @@ -11,15 +11,15 @@
# README file and 2) it's easier to type in the README file than to put a raw
# string in below ...
def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname)).read()
return open(Path(__file__).parent / fname).read()

setup(
name=CMD_NAME,
version=__version__,
author='Daniel Rojas',
#author_email='',
description='Easily document cables and wiring harnesses',
long_description=read(os.path.join(os.path.dirname(__file__), 'docs/README.md')),
long_description=read(Path(__file__).parent / 'docs/README.md'),
long_description_content_type='text/markdown',
install_requires=[
'pyyaml',
Expand Down
4 changes: 2 additions & 2 deletions src/wireviz/build_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# -*- coding: utf-8 -*-

import argparse
import sys
import os
from pathlib import Path
import sys

script_path = Path(__file__).absolute()

Expand Down Expand Up @@ -94,7 +94,7 @@ def clean_generated(groupkeys):
for filename in collect_filenames('Cleaning', key, generated_extensions):
if filename.is_file():
print(f' rm "{filename}"')
os.remove(filename)
Path(filename).unlink()


def compare_generated(groupkeys, branch = '', include_graphviz_output = False):
Expand Down
26 changes: 13 additions & 13 deletions src/wireviz/wireviz.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
# -*- coding: utf-8 -*-

import argparse
import os
from pathlib import Path
import sys
from typing import Any, Tuple

import yaml

if __name__ == '__main__':
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
sys.path.insert(0, str(Path(__file__).parent.parent))

from wireviz import __version__
from wireviz.DataClasses import Metadata, Options, Tweak
Expand Down Expand Up @@ -287,13 +286,15 @@ def alternate_type(): # flip between connector and cable/arrow


def parse_file(yaml_file: str, file_out: (str, Path) = None) -> None:
yaml_file = Path(yaml_file)
with open_file_read(yaml_file) as file:
yaml_input = file.read()

if not file_out:
fn, fext = os.path.splitext(yaml_file)
file_out = fn
file_out = os.path.abspath(file_out)
if file_out:
file_out = Path(file_out)
else:
file_out = yaml_file.parent / yaml_file.stem
file_out = file_out.resolve()

parse(yaml_input, file_out=file_out)

Expand All @@ -314,28 +315,27 @@ def main():

args = parse_cmdline()

if not os.path.exists(args.input_file):
if not Path(args.input_file).exists():
print(f'Error: input file {args.input_file} inaccessible or does not exist, check path')
sys.exit(1)

with open_file_read(args.input_file) as fh:
yaml_input = fh.read()

if args.prepend_file:
if not os.path.exists(args.prepend_file):
if not Path(args.prepend_file).exists():
print(f'Error: prepend input file {args.prepend_file} inaccessible or does not exist, check path')
sys.exit(1)
with open_file_read(args.prepend_file) as fh:
prepend = fh.read()
yaml_input = prepend + yaml_input

if not args.output_file:
file_out = args.input_file
pre, _ = os.path.splitext(file_out)
file_out = pre # extension will be added by graphviz output function
file_out = Path(args.input_file)
file_out = file_out.parent / file_out.stem # extension will be added by graphviz output function
else:
file_out = args.output_file
file_out = os.path.abspath(file_out)
file_out = Path(args.output_file)
file_out = file_out.resolve()

parse(yaml_input, file_out=file_out)

Expand Down

0 comments on commit 0192f6d

Please sign in to comment.