Skip to content

Poetry support (Python 3.10) #13

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Checks (pylint,pytest)

on: [push]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi
- name: Analysing the code with pylint
run: |
pylint --fail-under=6 $(git ls-files '*.py')
- name: Run Tests
run: |
pytest

40 changes: 40 additions & 0 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Python package

on:
push:
branches: [ "master", "stable" ]
pull_request:
branches: [ "master", "stable" ]

jobs:
build:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest
43 changes: 43 additions & 0 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# This workflow will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Upload Python Package

on:
release:
types: [published]

permissions:
contents: read

jobs:
deploy:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi
- name: Build package
run: python -m build
- name: Publish package
run: |
python -m site
# uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
# with:
# user: __token__
# password: ${{ secrets.PYPI_API_TOKEN }}
#
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ lib64/
parts/
sdist/
var/
venv/
.vscode/
wheels/
*.egg-info/
.installed.cfg
Expand Down
16 changes: 16 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
setupextras >= 0.1.5
coloredlogs >= 10.0
termcolor >= 1.1.0

colour-runner >= 0.0.5
deepdiff >= 3.3.0
pygments >= 2.2.0
tox >= 3.0.0
coverage >= 4.5.2
codecov >= 2.0.15

flake8
pytest
pylint
black
build
4 changes: 4 additions & 0 deletions requirements-ide.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
python-language-server[all]
pyls-black
pyls-isort
pyls-mypy
10 changes: 0 additions & 10 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1 @@
setupextras >= 0.1.5
six >= 1.11.0
coloredlogs >= 10.0
termcolor >= 1.1.0

colour-runner >= 0.0.5
deepdiff >= 3.3.0
pygments >= 2.2.0
tox >= 3.0.0
coverage >= 4.5.2
codecov >= 2.0.15
14 changes: 7 additions & 7 deletions rootpath/append.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@

# =========================================
# DEPS
# --------------------------------------

import sys
import os

from os import path

CURRENT_PATH = path.abspath(path.dirname(__file__))
ROOT_PATH = path.abspath(path.join(CURRENT_PATH, '..'))
ROOT_PATH = path.abspath(path.join(CURRENT_PATH, ".."))

try:
try:
Expand All @@ -24,13 +22,12 @@

import rootpath


# =========================================
# FUNCTIONS
# --------------------------------------

def append(current_path = None, pattern = None):

def append(current_path=None, pattern=None):
"""
Automatically adds current file's package root to Python load path (i.e. `sys.path`) unless already added.
This makes it possible to always ensure module imports behave same no matter how the file is loaded.
Expand All @@ -44,8 +41,11 @@ def append(current_path = None, pattern = None):
"""
project_root_path = rootpath.detect(current_path, pattern)

if project_root_path is None:
return False, project_root_path

try:
if project_root_path != current_path:
if current_path is not None and project_root_path != current_path:
try:
sys.path.remove(current_path)
except:
Expand All @@ -55,7 +55,7 @@ def append(current_path = None, pattern = None):

return False, project_root_path

except ValueError as error:
except ValueError:
sys.path.append(project_root_path)

return True, project_root_path
24 changes: 12 additions & 12 deletions rootpath/detect.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# =========================================
# IMPORTS
# --------------------------------------
Expand All @@ -10,21 +9,19 @@

from os import path, listdir


# =========================================
# CONSTANTS
# --------------------------------------

DEFAULT_PATH = '.'
DEFAULT_ROOT_FILENAME_MATCH_PATTERN = '.git|requirements.txt'

DEFAULT_PATH = "."
DEFAULT_ROOT_FILENAME_MATCH_PATTERN = ".git|requirements.txt|pyproject.toml"

# =========================================
# FUNCTIONS
# --------------------------------------

def detect(current_path = None, pattern = None):

def detect(current_path=None, pattern=None):
"""
Find project root path from specified file/directory path,
based on common project root file pattern.
Expand All @@ -46,7 +43,7 @@ def detect(current_path = None, pattern = None):
if not path.isdir(current_path):
current_path = path.dirname(current_path)

def find_root_path(current_path, pattern = None):
def find_root_path(current_path, pattern):
if isinstance(pattern, six.string_types):
pattern = re.compile(pattern)

Expand All @@ -59,9 +56,12 @@ def find_root_path(current_path, pattern = None):
file_names = None
root_file_names = None

while (detecting):
file_names = listdir(current_path)
found_more_files = bool(len(file_names) > 0)
while detecting:
try:
file_names = listdir(current_path)
found_more_files = bool(len(file_names) > 0)
except FileNotFoundError:
return None

if not found_more_files:
detecting = False
Expand All @@ -84,13 +84,13 @@ def find_root_path(current_path, pattern = None):
return None

system_root = sys.executable

while os.path.split(system_root)[1]:
system_root = os.path.split(system_root)[0]

if current_path == system_root:
return None

current_path = path.abspath(path.join(current_path, '..'))
current_path = path.abspath(path.join(current_path, ".."))

return find_root_path(current_path, pattern)
3 changes: 2 additions & 1 deletion rootpath/tests/test_append.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ def test__import(self):

def test_rootpath_append_base(self):
try:
sys.path.remove(ROOT_PATH)
while sys.path.count(ROOT_PATH) > 0:
sys.path.remove(ROOT_PATH)
except:
pass

Expand Down
2 changes: 1 addition & 1 deletion rootpath/tests/test_detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def test_rootpath_detect_entry_nested_pattern(self):
self.assertEqual(root_path, None)

def test_system_root(self):
root_path = rootpath.detect(r"\Users\Public\Downloads")
root_path = rootpath.detect(r"/Users/Public/Downloads")

self.assertEqual(root_path, None)

Expand Down
Loading