Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix path.py deprecation problems #114

Merged
merged 10 commits into from
Aug 1, 2024
10 changes: 5 additions & 5 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.6, 3.7, 3.8, 3.9, "3.10", "3.11"]
python-version: [3.6, 3.7, 3.8, 3.9, "3.10", "3.11", "3.12"]
dependencies: [minimal, latest]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand Down Expand Up @@ -53,9 +53,9 @@ jobs:
if: ${{ github.event_name == 'push' }}
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python 3.7
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: 3.7
- name: Install dependencies
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.6, 3.7, 3.8, 3.9, "3.10", "3.11"]
python-version: [3.6, 3.7, 3.8, 3.9, "3.10", "3.11", "3.12"]
dependencies: [minimal, latest]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand Down Expand Up @@ -53,9 +53,9 @@ jobs:
needs: [ build ]
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python 3.7
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: 3.7
- name: Install dependencies
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/weekly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.6, 3.7, 3.8, 3.9, "3.10", "3.11"]
python-version: [3.6, 3.7, 3.8, 3.9, "3.10", "3.11", "3.12"]
dependencies: [minimal, latest]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand Down
10 changes: 5 additions & 5 deletions cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@
from subprocess import call
from watchdog.events import FileSystemEventHandler
from watchdog.observers import Observer
from path import Path
from pathlib import Path
import time
import os
import yaml
import logging
import logging.config


here = Path(__file__).abspath().dirname()
here = Path(__file__).absolute().parent

logging.config.dictConfig(yaml.load((here / 'log.yaml').open(), Loader=yaml.FullLoader))
logger = logging.getLogger(__name__)


os.environ['PYTHONPATH'] = Path.getcwd()
os.environ['PYTHONPATH'] = str(Path.cwd())


def sh(cmd, all=False, **kwargs):
Expand All @@ -35,7 +35,7 @@ def cli():
@cli.command()
def antlr():
"""generate a new parser based on the grammar using antlr"""
cwd = str(Path('qface/idl/parser').abspath())
cwd = str(Path('qface/idl/parser').absolute())
sh('antlr4 -Dlanguage=Python3 -Werror -package qface.idl.parser -o . -listener -visitor T.g4', cwd=cwd)


Expand All @@ -56,7 +56,7 @@ def test_ci():
@cli.command()
def install(editable):
"""install the script onto the system using pip3"""
script_dir = str(Path(__file__).parent.abspath())
script_dir = str(Path(__file__).parent.absolute())
click.secho(script_dir, fg='blue')
if editable:
sh('pip3 install --editable {0} --upgrade'.format(script_dir))
Expand Down
2 changes: 1 addition & 1 deletion docs/extending.rst
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ The `RuleGenerator` allows you to extract the documentation rules into an extern
.. code-block:: python

from qface.generator import FileSystem, RuleGenerator
from path import Path
from pathlib import Path

here = Path(__file__).dirname()

Expand Down
2 changes: 1 addition & 1 deletion qface/__about__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
__title__ = "qface"
__summary__ = "A generator framework based on a common modern IDL"
__url__ = "https://pelagicore.github.io/qface/"
__version__ = "2.0.8"
__version__ = "2.0.9"
__author__ = "JRyannel"
__author_email__ = ""
__copyright__ = "2019 Pelagicore"
2 changes: 1 addition & 1 deletion qface/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import sys
import click
import logging
from path import Path
from pathlib import Path
from qface.generator import FileSystem, RuleGenerator
from qface.watch import monitor
from qface.utils import load_filters
Expand Down
2 changes: 1 addition & 1 deletion qface/cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys
import click
from path import Path
from pathlib import Path
from qface.generator import FileSystem, RuleGenerator
from qface.watch import monitor

Expand Down
2 changes: 1 addition & 1 deletion qface/contrib/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
import logging.config
import coloredlogs
from path import Path
from pathlib import Path
import os


Expand Down
2 changes: 1 addition & 1 deletion qface/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def load_filters(path):
return {}

extra_filters = {}
spec = importlib.util.spec_from_file_location('filters', path.abspath())
spec = importlib.util.spec_from_file_location('filters', path.absolute())
filters_module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(filters_module)
filters_module.get_filters(extra_filters)
Expand Down
16 changes: 8 additions & 8 deletions qface/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from jinja2 import Environment, Template, Undefined, StrictUndefined
from jinja2 import FileSystemLoader, PackageLoader, ChoiceLoader
from jinja2 import TemplateSyntaxError, TemplateNotFound, TemplateError
from path import Path
from pathlib import Path
from antlr4 import InputStream, FileStream, CommonTokenStream, ParseTreeWalker
from antlr4.error import DiagnosticErrorListener, ErrorListener
import shelve
Expand Down Expand Up @@ -195,7 +195,7 @@ def _write(self, file_path: Path, template: str, context: dict, preserve: bool =
force = self.force or force
path = self.resolved_path / Path(self.apply(file_path, context))
if path.parent:
path.parent.makedirs_p()
path.parent.mkdir(parents=True, exist_ok=True)
logger.info('write {0}'.format(path))
data = self.render(template, context)
if self._has_different_content(data, path) or force:
Expand Down Expand Up @@ -324,7 +324,7 @@ def _parse_document(document: Path, system: System = None, profile=EProfile.FULL
logger.debug('parse document: {0}'.format(document))
stream = FileStream(str(document), encoding='utf-8')
system = FileSystem._parse_stream(stream, system, document, profile)
FileSystem.merge_annotations(system, document.stripext() + '.yaml')
FileSystem.merge_annotations(system, os.path.splitext(document)[0] + '.yaml')
return system

@staticmethod
Expand All @@ -351,10 +351,10 @@ def merge_annotations(system, document):
return
meta = FileSystem.load_yaml(document)
if not meta:
click.secho('skipping empty: {0}'.format(document.name), fg='blue')
click.secho('skipping empty: {0}'.format(Path(document).name), fg='blue')
return
else:
click.secho('merge: {0}'.format(document.name), fg='blue')
click.secho('merge: {0}'.format(Path(document).name), fg='blue')
try:
for identifier, data in meta.items():
symbol = system.lookup(identifier)
Expand Down Expand Up @@ -389,11 +389,11 @@ def parse(input, identifier: str = None, use_cache=False, clear_cache=True, patt
system = cache[identifier]
# if domain model not cached generate it
for input in inputs:
path = Path.getcwd() / str(input)
if path.isfile():
path = Path.cwd() / str(input)
if path.is_file():
FileSystem.parse_document(path, system)
else:
for document in path.walkfiles(pattern):
for document in path.rglob(pattern):
FileSystem.parse_document(document, system)

if use_cache:
Expand Down
27 changes: 27 additions & 0 deletions qface/idl/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class System(object):
"""The root entity which consist of modules"""
def __init__(self):
log.debug('System()')
self._tags = dict()
self._moduleMap = OrderedDict() # type: dict[str, Module]

def __unicode__(self):
Expand All @@ -43,6 +44,30 @@ def __unicode__(self):
def __repr__(self):
return '<System>'

@property
def tags(self):
return self._tags

def add_tag(self, tag):
""" add a tag to the tag list """
if tag not in self._tags:
self._tags[tag] = dict()

def add_attribute(self, tag, name, value):
""" add an attribute (nam, value pair) to the named tag """
self.add_tag(tag)
d = self._tags[tag]
d[name] = value

def tag(self, name):
""" return tag by name """
return self._tags[name]

def attribute(self, tag, name):
""" return attribute by tag and attribute name """
if tag in self._tags and name in self._tags[tag]:
return self._tags[tag][name]

@property
def modules(self):
'''returns ordered list of module symbols'''
Expand All @@ -53,6 +78,8 @@ def lookup(self, name: str):
# <module>
if name in self._moduleMap:
return self._moduleMap[name]
if name == 'system':
return self;
# <module>.<Symbol>
(module_name, type_name, fragment_name) = self.split_typename(name)
if not module_name in self._moduleMap:
Expand Down
5 changes: 3 additions & 2 deletions qface/idl/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ def escape_decode(s):
class QFaceListener(TListener):
def __init__(self, system, profile=EProfile.FULL):
super().__init__()
click.secho('qface uses language profile: {}'.format(profile), fg='blue')
if profile != EProfile.FULL:
log.secho('qface uses language profile: {}'.format(profile), fg='blue')
self.lang_features = get_features(profile)
self.system = system or System() # type:System

def check_support(self, feature, report=True):
if feature not in self.lang_features and report:
click.secho('Unsuported language feature: {}'.format(EFeature.IMPORT), fg='red')
log.error('Unsuported language feature: {}'.format(EFeature.IMPORT), fg='red')
return False
return True

Expand Down
4 changes: 3 additions & 1 deletion qface/idl/parser/T4Lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,9 @@ class T4Lexer(Lexer):

def __init__(self, input=None, output:TextIO = sys.stdout):
super().__init__(input, output)
self.checkVersion("4.10")
# Disable the version check for now as although there is a mismatch the Lexer seems to work fine.
# Rely on the weekly CI to make sure this keeps working also with later antlr versions.
# self.checkVersion("4.10")
self._interp = LexerATNSimulator(self, self.atn, self.decisionsToDFA, PredictionContextCache())
self._actions = None
self._predicates = None
Expand Down
4 changes: 3 additions & 1 deletion qface/idl/parser/T4Parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,9 @@ class T4Parser ( Parser ):

def __init__(self, input:TokenStream, output:TextIO = sys.stdout):
super().__init__(input, output)
self.checkVersion("4.10")
# Disable the version check for now as although there is a mismatch the Lexer seems to work fine.
# Rely on the weekly CI to make sure this keeps working also with later antlr versions.
# self.checkVersion("4.10")
self._interp = ParserATNSimulator(self, self.atn, self.decisionsToDFA, self.sharedContextCache)
self._predicates = None

Expand Down
8 changes: 4 additions & 4 deletions qface/watch.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from watchdog.events import FileSystemEventHandler
from watchdog.observers import Observer
import click
from path import Path
from pathlib import Path
import time
from subprocess import call

Expand All @@ -25,7 +25,7 @@ def run(self):
if self.is_running:
return
self.is_running = True
call(self.args, cwd=Path.getcwd())
call(self.args, cwd=Path.cwd())
self.is_running = False


Expand All @@ -34,11 +34,11 @@ def monitor(args, watch):
reloads the script given by argv when src files changes
"""
watch = watch if isinstance(watch, (list, tuple)) else [watch]
watch = [Path(entry).expand().abspath() for entry in watch]
watch = [Path(entry).expand().absolute() for entry in watch]
event_handler = RunScriptChangeHandler(args)
observer = Observer()
for entry in watch:
if entry.isfile():
if entry.is_file():
entry = entry.parent
click.secho('watch recursive: {0}'.format(entry), fg='blue')
observer.schedule(event_handler, entry, recursive=True)
Expand Down
5 changes: 1 addition & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@ antlr4-python3-runtime>=4.7.1
argh>=0.26.2
click>=6.7
coloredlogs>=10.0
humanfriendly>=4.15.1
Jinja2>=2.10.3
MarkupSafe>=1.0
path.py>=11.0.1
pathtools>=0.1.2
PyYAML>=5.1
six>=1.11.0
watchdog>=0.8.3
watchdog>=1.0
pytest>=5.3.5
pytest-cov>=2.8.1
5 changes: 1 addition & 4 deletions requirements_minimal.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@ antlr4-python3-runtime==4.7.1
argh==0.26.2
click==6.7
coloredlogs==10.0
humanfriendly==4.15.1
Jinja2==2.10.3
MarkupSafe==1.1
path.py==11.0.1
pathtools==0.1.2
PyYAML==5.1
six==1.11.0
watchdog==0.8.3
watchdog==1.0
pytest==6.2.5
pytest-cov==2.8.1
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@
'click>=6.7',
'antlr4-python3-runtime>=4.7.1',
'jinja2>=2.10.3',
'path.py>=11.0.1',
'pyyaml>=5.1',
'watchdog>=0.8.3',
'watchdog>=1.0',
'six>=1.11.0',
'coloredlogs>=10.0',
],
Expand Down
3 changes: 3 additions & 0 deletions tests/in/com.pelagicore.ivi.tuner.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
system:
global_option: true

com.pelagicore.ivi.tuner.Tuner:
port: 12345
config:
Expand Down
Loading