Skip to content

Commit

Permalink
Feat: deps management via poetry
Browse files Browse the repository at this point in the history
  • Loading branch information
solarw committed Sep 13, 2022
1 parent 24c570b commit ad5d554
Show file tree
Hide file tree
Showing 14 changed files with 2,844 additions and 407 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: pip install tox==3.25.1
run: pip install tox==3.25.1 poetry==1.2.0rc1
- name: Code style check
run: |
tox -e black-check
Expand Down Expand Up @@ -80,7 +80,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.7", "3.8", "3.9", "3.10"]
python-version: ["3.8", "3.9", "3.10"]

timeout-minutes: 30

Expand All @@ -90,7 +90,7 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: pip install tox==3.25.1
run: pip install tox==3.25.1 poetry==1.2.0rc1
- name: Unit Tests
run: |
tox -e test-unit
Expand All @@ -117,7 +117,7 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: pip install tox==3.25.1
run: pip install tox==3.25.1 poetry==1.2.0rc1
- name: Integration Tests
run: |
tox -e test-integration
37 changes: 19 additions & 18 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
include *.txt
include Pipfile
include strategy.ini
include tox.ini
include *.md
include *.yml
include *.json
include .firebaserc
include mkdocs.yml
recursive-include contracts *.wasm
recursive-include contracts *.txt
recursive-include docs *
recursive-include examples *.py
recursive-include scripts *.py
recursive-include scripts *.sh
recursive-include cosmpy *.py
recursive-include tests *.py
recursive-include tests *.wasm
recursive-excludecosmpy *.py

exclude *.in
exclude *.json
exclude *.lock
exclude *.md
exclude *.txt
exclude *.yml
exclude strategy.ini
exclude tox.ini
exclude .firebaserc
recursive-exclude contracts *.txt
recursive-exclude contracts *.wasm
recursive-exclude docs *.*
recursive-exclude docs *
recursive-exclude examples *.py
recursive-exclude scripts *.py
recursive-exclude scripts *.sh
recursive-exclude tests *.py
46 changes: 18 additions & 28 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,19 @@ $(IBCGO_DIR): Makefile

.PHONY: black-check
black-check:
black --check --verbose $(PYCOSM_SRC_DIR) $(PYCOSM_TESTS_DIR) $(PYCOSM_EXAMPLES_DIR) setup.py --exclude $(OUTPUT_FOLDER)
black --check --verbose $(PYCOSM_SRC_DIR) $(PYCOSM_TESTS_DIR) $(PYCOSM_EXAMPLES_DIR) --exclude $(OUTPUT_FOLDER)

.PHONY: isort-check
isort-check:
isort --check-only --verbose $(PYCOSM_SRC_DIR) $(PYCOSM_TESTS_DIR) $(PYCOSM_EXAMPLES_DIR) setup.py
isort --check-only --verbose $(PYCOSM_SRC_DIR) $(PYCOSM_TESTS_DIR) $(PYCOSM_EXAMPLES_DIR)

.PHONY: flake
flake:
flake8 $(PYCOSM_SRC_DIR) $(PYCOSM_TESTS_DIR) $(PYCOSM_EXAMPLES_DIR) setup.py
flake8 $(PYCOSM_SRC_DIR) $(PYCOSM_TESTS_DIR) $(PYCOSM_EXAMPLES_DIR)

.PHONY: vulture
vulture:
vulture $(PYCOSM_SRC_DIR) $(PYCOSM_TESTS_DIR) $(PYCOSM_EXAMPLES_DIR) setup.py --exclude '*_pb2.py,*_pb2_grpc.py' --min-confidence 100
vulture $(PYCOSM_SRC_DIR) $(PYCOSM_TESTS_DIR) $(PYCOSM_EXAMPLES_DIR) --exclude '*_pb2.py,*_pb2_grpc.py' --min-confidence 100

####################
### Security & Safety
Expand All @@ -118,11 +118,11 @@ safety:

.PHONY: mypy
mypy:
mypy $(PYCOSM_SRC_DIR) $(PYCOSM_TESTS_DIR) $(PYCOSM_EXAMPLES_DIR) setup.py
mypy $(PYCOSM_SRC_DIR) $(PYCOSM_TESTS_DIR) $(PYCOSM_EXAMPLES_DIR)

.PHONY: pylint
pylint:
pylint $(PYCOSM_SRC_DIR) $(PYCOSM_TESTS_DIR) $(PYCOSM_EXAMPLES_DIR) setup.py
pylint $(PYCOSM_SRC_DIR) $(PYCOSM_TESTS_DIR) $(PYCOSM_EXAMPLES_DIR)

####################
### Tests
Expand Down Expand Up @@ -152,7 +152,8 @@ coverage-report:

.PHONY: liccheck
liccheck:
liccheck -s strategy.ini -r requirements.txt -l PARANOID
poetry export > tmp-requirements.txt
liccheck -s strategy.ini -r tmp-requirements.txt -l PARANOID

.PHONY: copyright-check
copyright-check:
Expand Down Expand Up @@ -217,9 +218,8 @@ v := $(shell pip -V | grep virtualenvs)
new_env: clean
if [ -z "$v" ];\
then\
pipenv --rm;\
pipenv install --python 3.9;\
echo "Enter virtual environment with all development dependencies now: 'pipenv shell'.";\
poetry install --only main --sync;\
echo "Enter virtual environment with all development dependencies now: 'poetry shell'.";\
else\
echo "In a virtual environment! Exit first: 'exit'.";\
fi
Expand All @@ -228,9 +228,8 @@ new_env: clean
new_env_dev: clean
if [ -z "$v" ];\
then\
pipenv --rm;\
pipenv install --python 3.9 --dev --skip-lock --clear;\
echo "Enter virtual environment with all development dependencies now: 'pipenv shell'.";\
poetry install --with main, dev, test, docs --sync;\
echo "Enter virtual environment with all development dependencies now: 'poetry shell'.";\
else\
echo "In a virtual environment! Exit first: 'exit'.";\
fi
Expand All @@ -241,10 +240,10 @@ new_env_dev: clean

.PHONY: lint
lint:
black $(PYCOSM_SRC_DIR) $(PYCOSM_TESTS_DIR) $(PYCOSM_EXAMPLES_DIR) setup.py --exclude $(OUTPUT_FOLDER)
isort $(PYCOSM_SRC_DIR) $(PYCOSM_TESTS_DIR) $(PYCOSM_EXAMPLES_DIR) setup.py
flake8 $(PYCOSM_SRC_DIR) $(PYCOSM_TESTS_DIR) $(PYCOSM_EXAMPLES_DIR) setup.py
vulture $(PYCOSM_SRC_DIR) $(PYCOSM_TESTS_DIR) $(PYCOSM_EXAMPLES_DIR) setup.py --exclude '*_pb2.py,*_pb2_grpc.py' --min-confidence 100
black $(PYCOSM_SRC_DIR) $(PYCOSM_TESTS_DIR) $(PYCOSM_EXAMPLES_DIR) --exclude $(OUTPUT_FOLDER)
isort $(PYCOSM_SRC_DIR) $(PYCOSM_TESTS_DIR) $(PYCOSM_EXAMPLES_DIR)
flake8 $(PYCOSM_SRC_DIR) $(PYCOSM_TESTS_DIR) $(PYCOSM_EXAMPLES_DIR)
vulture $(PYCOSM_SRC_DIR) $(PYCOSM_TESTS_DIR) $(PYCOSM_EXAMPLES_DIR) --exclude '*_pb2.py,*_pb2_grpc.py' --min-confidence 100

.PHONY: security
security:
Expand All @@ -267,17 +266,8 @@ check:
$(MAKE) copyright-check
$(MAKE) test

Pipfile.lock: Pipfile setup.py
pipenv lock --dev

requirements.txt: Pipfile.lock
pipenv requirements > $@

requirements-dev.txt: Pipfile.lock
pipenv requirements --dev> $@

.PHONY: requirements
requirements: $(REQUIREMENTS_FILES)
poetry.lock: pyproject.toml
poetry lock

debug:
$(info SOURCES_REGEX_TO_EXCLUDE: $(SOURCES_REGEX_TO_EXCLUDE))
Expand Down
17 changes: 0 additions & 17 deletions Pipfile

This file was deleted.

61 changes: 61 additions & 0 deletions install_packages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# ------------------------------------------------------------------------------
#
# Copyright 2018-2022 Fetch.AI Limited
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http:https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# ------------------------------------------------------------------------------

"""The install packages script"""
import re
import subprocess
import sys
from pathlib import Path
from typing import List

import toml


def _load_groups():
data = toml.loads(Path("pyproject.toml").read_text())
return list(data["tool"]["poetry"]["group"].keys())


def _load_dependencies() -> List[str]:
groups = ",".join(_load_groups())
text = subprocess.check_output(
f"poetry export --with {groups}", shell=True, text=True
)
text = text.replace("\\\n", " ")
lines = text.splitlines()
lines = [i.split(" ")[0] for i in lines]
return lines


RE = re.compile("(.*)[=><]")

if __name__ == "__main__":
packages = sys.argv[1:]
requirements = _load_dependencies()

to_install = []
for package in packages:
for requirement in requirements:
if re.match(f"^{package}([<>=].*)?$", requirement):
to_install.append(requirement.strip())
if not to_install:
raise ValueError("No packages found to install")
print("installing", ", ".join(to_install))
subprocess.check_call([sys.executable, "-m", "pip", "install", *to_install])
Loading

0 comments on commit ad5d554

Please sign in to comment.