Skip to content

Commit

Permalink
Merge branch 'release/v0.2.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
vogt31337 committed Sep 5, 2023
2 parents 6fc6113 + 490fce4 commit 664f0ae
Show file tree
Hide file tree
Showing 26 changed files with 1,783 additions and 523 deletions.
104 changes: 104 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# This workflow will create a Python package and upload it to testPyPi or PyPi
# Then, it installs pandahub from there and all dependencies and runs tests with different Python versions

name: release

# Controls when the action will run.
on:
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
inputs:
upload_server:
description: 'upload server'
required: true
default: 'testpypi'
type: choice
options:
- 'testpypi'
- 'pypi'

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
upload:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3

# Sets up python3
- uses: actions/setup-python@v4
with:
python-version: '3.10'
# Installs and upgrades pip, installs other dependencies and installs the package from setup.py
- name: Install dependencies
run: |
# Upgrade pip
python3 -m pip install --upgrade pip
# Install twine
python3 -m pip install setuptools wheel twine
# Upload to TestPyPI
- name: Build and Upload to TestPyPI
if: inputs.upload_server == 'testpypi'
run: |
python3 setup.py sdist --formats=zip
twine check dist/* --strict
python3 -m twine upload dist/*
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.TESTPYPI }}
TWINE_REPOSITORY: testpypi

# Upload to PyPI
- name: Build and Upload to PyPI
if: inputs.upload_server == 'pypi'
run: |
python3 setup.py sdist --formats=zip
twine check dist/* --strict
python3 -m twine upload dist/*
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI }}
TWINE_REPOSITORY: pypi
# Make sure package is available on pypi
- name: Sleep for 300s to make release available
uses: juliangruber/sleep-action@v1
with:
time: 300s


build:

runs-on: ${{ matrix.os }}
needs: upload
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11']
os: [ ubuntu-latest, windows-latest ]
steps:
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install pytest python-igraph pytest-split
if ${{ matrix.python-version != '3.11' }}; then python -m pip install numba; fi
- name: Install pandahub from TestPyPI
if: ${{ inputs.upload_server == 'testpypi'}}
run: |
pip install --no-cache-dir -i https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple pandahub
- name: Install pandahub from PyPI
if: ${{ inputs.upload_server == 'pypi'}}
run: |
pip install pandahub
- name: List all installed packages
run: |
pip list
- name: Test with pytest
run: |
pytest --pyargs pandahub.test
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,7 @@ ENV/
# Pycharm
.idea

# Credentials
settings.py

!pandahub/lib
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## [0.2.4]
- BREAKING drops index argument from create_variant() function


## [0.2.3]- 2022-08-04

- ADDED version property in project data
Expand Down
23 changes: 23 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Changelog
=============

[XX.XX.XX] - 2023-XX-XX
-------------------------------
- [ADDED]
- [IMPROVED]
- [CHANGED]
- [REMOVED]

[0.23.0] - 2022-08-04
-------------------------------
- [ADDED] version property in project data
- [ADDED] method to migrate projects to latest version
- [ADDED] option to disable registration
- [ADDED] option to use a separate mongodb instance as global database
- [ADDED] geo mode to handle geojson columns
- [ADDED] tutorials
- [IMPROVED] collections for element tables now start with :code:`net_`
- [IMPROVED] project IDs now can be any name
- [IMPROVED] compatibility with python < 3.9
- [IMPROVED] project settings API
- [IMPROVED] timeseries handling
158 changes: 158 additions & 0 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
Get in Touch!
===============

You have found a bug in pandahub or have a suggestion for a new functionality? Then get in touch with us by opening up an issue on the pandahub issue board to discuss possible new developments with the community and the maintainers.


Setup your git repository
==============================

**Note**: *The following setup is just a suggestion of how to setup your repository and is suphosed to make contributing easier, especially for newcomers. If you have a different setup that you are more comfortable with, you do not have to adopt this setup.*

If you want to contribute for the first time, you can set up your environment like this:

#. If you have not done it yet: install git and create a github account
#. Create a fork of the official pandahub repository by clicking on "Fork" in the official pandahub repository (see https://help.github.com/articles/fork-a-repo/)
#. Clone the forked repository to your local machine: ::

git clone https://github.com/YOUR-USERNAME/pandahub.git

#. Copy the following configuration at the bottom of to the pandahub/.git/config file (the .git folder is hidden, so you might have to enable showing hidden folders) and insert your github username: ::

[remote "origin"]
url = https://github.com/e2nIEE/pandahub.git
fetch = +refs/heads/*:refs/remotes/ph/*
pushurl = https://github.com/YOUR-USERNAME/pandahub.git
[remote "ph"]
url = https://github.com/e2nIEE/pandahub.git
fetch = +refs/heads/*:refs/remotes/ph/*
[remote "ph_fork"]
url = https://github.com/YOUR-USERNAME/pandahub.git
fetch = +refs/heads/*:refs/remotes/ph_fork/*
[branch "develop"]
remote = origin
merge = refs/heads/develop
The develop branch is now configured to automatically track the official pandahub develop branch. So if you are on the develop branch and use: ::

git pull
your local repository will be updated with the newest changes in the official pandahub repository.

Since you cannot push directly to the official pandahub repository, if you are on develop and do: ::

git push

your push is by default routed to your own fork instead of the official pandahub repository with the setting as defined above.

If this is to implicit for you, you can always explicitely use the remotes "ph" and "ph_fork" to push and pull from the different repositories: ::

git pull ph develop
git push ph_fork develop

Contribute
=====================================

All contributions to the pandahub repository are made through pull requests to the develop branch. You can either submit a pull request from the develop branch of your fork or create a special feature branch that you keep the changes on. A feature branch is the way to go if you have multiple issues that you are working on in parallel and want to submit with seperate pull requests. If you only have small, one-time changes to submit, you can also use the develop branch to submit your pull request.

**Note**: *The following guide assumes the remotes are set up as described above. If you have a different setup, you will have to adapt the commands accordingly.*

Contribute from your develop branch
------------------------------------

#. Check out the develop branch on your local machine: ::

git checkout develop

#. Update your local copy to the most recent version of the pandpower develop branch: ::

git pull

#. Make changes in the code

#. Add and commit your changes: ::

git add --all
git commit -m"commit message"
If there is an open issue that the commit belongs to, reference the issue in the commit message, for example for issue 3: ::

git commit -m"commit message #3"

#. Push your changes to your fork: ::

git push
#. Put in a Pull request to the main repository: https://help.github.com/articles/creating-a-pull-request-from-a-fork/

#. If you want to amend the pull request (for example because tests are failing in Travis, or because the community/maintainers have asked for modifications), simply push more commits to the branch: ::

git add --all
git commit -m"I have updated the pull request after discussions #3"
git push
The pull request will be automatically updated.

Contribute from a feature branch
------------------------------------

#. Check out the develop branch on your local machine: ::

git checkout develop

#. Update your local copy to the most recent version of the pandahub develop branch: ::

git pull

#. Create a new feature branch: ::

git checkout -b my_branch
#. Make changes in the code

#. Add and commit your change: ::

git add --all
git commit -m"commit message"
If there is an open issue that the commit belongs to, reference the issue in the commit message, for example for issue 3: ::

git commit -m"commit message #3"
#. Push your changes to your fork: ::

git push -u ph_fork my_branch
this pushes the new branch to your fork and also sets up the remote tracking.
#. Put in a Pull request to the official repository (see https://help.github.com/articles/creating-a-pull-request-from-a-fork/)

#. If you want to amend the pull request (for example because tests are failing in Travis, or because the community/maintainers have asked for modifications), simply push more commits to the branch. Since the remote tracking branch has been set up, this is as easy as: ::

git add --all
git commit -m"I have updated the pull request after discussions #3"
git push

#. If the pull request was merged and you don't expect further development on this feature, you can delete the feature branch to keep your repository clean.

Test Suite
================

pandahub uses pytest for automatic software testing.

Making sure you don't break anything
---------------------------------------

If you make changes to pandahub that you plan to submit, first make sure that all tests are still passing. You can do this locally with: ::

import pandahub.test
pandahub.test.run_all_tests()
When you submit a pull request, Travis CI will run the same tests with Python versions 2.7, 3.4, 3.5 and 3.6. In most cases, if tests pass for you locally, they will also pass on Travis. But it can also haphen that the tests pass for you locally, but still fail on Travis, because the new code is not compatible with all Python versions.
In this case you will have to update your pull request until the tests pass in all Python versions. Pull requests that lead to failing tests will not be accepted.


Adding Tests for new functionality
-----------------------------------

If you have added new functionality, you should also add a new function that tests this functionality. pytest automatically detects all functions in the pandahub/test folder that start with 'test' and are located in a file that also starts with 'test' as relevant test cases.
40 changes: 40 additions & 0 deletions VARIANTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Variants

A variant is a version of a power network with changes recorded relative to the base network (element addition and
deletion or paramater value changes). Changes to the base network automatically propagate to variants (see caveats below).

All elements have a field "var_type" with possible values "base", "change" and "addition":

* *base*: base-version of the element
* *change*: variant-version of an element with changes compared to base
* *addition*: element which only exists in a variant

Elements with var_type "base" have an additional array field "not_in_var" holding indices of
variants in which the element has been removed or changed.

Elements with var_types "change" and "addition" have an additional field "variant" referencing the variant index for the change/addition.

`PandaHub.get_variant_filter(variants)` can be used to generate a mongodb query filter mixin which restricts query results to a given variant or variants.

Example variant filter for single variant with index 1:

{"$or": [{"var_type": "base", "not_in_var": {"$ne": 1}},
{"var_type": {"$in": ["change", "addition"]}, "variant": 1}]}

Filter for base variant:

{"$or": [{"var_type": {"$exists": False}},
{"var_type": "base"}]}

## Caveats

### Conflicts

* an element that was changed for a variant is changed in the base variant:
* field(s) changed in variant are changed to different values
* field(s) previously identical with variant are changed
* an element in the base variant is changed breaking the variant:
* net can not be loaded completely - e.g. bus of line added in variant is deleted

### Restrictions
* bulk operations are difficult to implement for variants
2 changes: 1 addition & 1 deletion pandahub/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.2.3"
__version__ = "0.2.4"

from pandahub.lib.PandaHub import PandaHub, PandaHubError
from pandahub.client.PandaHubClient import PandaHubClient
Expand Down
31 changes: 27 additions & 4 deletions pandahub/api/internal/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
from pandahub.api.internal import settings
from pandahub.api.internal.models import AccessToken, UserDB

client = motor.motor_asyncio.AsyncIOMotorClient(
settings.MONGODB_URL, uuidRepresentation="standard"
)
mongo_client_args = {"host": settings.MONGODB_URL, "uuidRepresentation": "standard", "connect": False}
if settings.MONGODB_USER:
mongo_client_args |= {"username": settings.MONGODB_USER, "password": settings.MONGODB_PASSWORD}

client = motor.motor_asyncio.AsyncIOMotorClient(**mongo_client_args)

client.get_io_loop = asyncio.get_event_loop

Expand All @@ -19,8 +21,29 @@


async def get_user_db():
yield MongoDBUserDatabase(UserDB, collection)
if settings.COSMOSDB_COMPAT:
yield MongoDBUserDatabaseCosmos(UserDB, collection)
else:
yield MongoDBUserDatabase(UserDB, collection)


async def get_access_token_db():
yield MongoDBAccessTokenDatabase(AccessToken, access_tokens_collection)

class MongoDBUserDatabaseCosmos(MongoDBUserDatabase):
from typing import Optional
from fastapi_users.models import UD
async def get_by_email(self, email: str) -> Optional[UD]:
await self._initialize()

user = await self.collection.find_one(
{"email": email}
)
return self.user_db_model(**user) if user else None

async def _initialize(self):
if not self.initialized:
if "email_1" not in await self.collection.index_information():
await self.collection.create_index("id", unique=True)
await self.collection.create_index("email", unique=True)
self.initialized = True
Loading

0 comments on commit 664f0ae

Please sign in to comment.