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

add deployment scripts #31

Merged
merged 10 commits into from
Feb 22, 2024
Merged
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
6 changes: 0 additions & 6 deletions .flake8

This file was deleted.

48 changes: 48 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: deploy to pypi

on:
workflow_dispatch:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'

jobs:
test:
uses: ./.github/workflows/test.yml

deploy:
name: deploy
needs: test
permissions:
id-token: write
environment: release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.11

- name: install build dependencies
run: python3 -m pip install build

- name: build package
run: python3 -m build --sdist --wheel --outdir dist/

- name: upload package
uses: actions/upload-artifact@v4
with:
name: package
path: dist/

- name: publish package (pypi)
if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') }}
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: "https://pypi.org/legacy/"

- name: publish package (test.pypi)
if: ${{ github.event_name == 'workflow_dispatch' }}
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: "https://test.pypi.org/legacy/"
22 changes: 8 additions & 14 deletions .github/workflows/ci-test.yml → .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
name: Run CI tests
name: run CI test

on:
push:
branches:
- main
- master
branches: [devel, main, master, wip]
pull_request:
workflow_call:

env:
FORCE_COLOR: "3"
Expand All @@ -17,23 +16,18 @@ jobs:
strategy:
fail-fast: false
matrix:
os: ['ubuntu-latest', 'macos-latest', 'windows-latest']
os: [ubuntu-latest, macos-latest, windows-latest]

steps:
- name: "checkout repository"
uses: actions/checkout@v3

- name: "setup python 3.9"
uses: actions/setup-python@v4
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.9

- name: "setup python 3.11"
uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: 3.11

- name: install nox
- name: install requirements
run: python -m pip install nox

- name: run tests
Expand Down
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Changes

## v1.0.0
## v0.1.0

- create project
16 changes: 8 additions & 8 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ All types of contributions are encouraged and valued. See the [Table of Contents

## Asking Questions

> If you want to ask a question, we assume that you have read the available [Documentation](https://potassco.org/fillname/).
> If you want to ask a question, we assume that you have read the available [Documentation](https://fillname.org/).

Before you ask a question, it is best to search for existing [issues](https://github.com/potassco/fillname/issues) or [messages](https://sourceforge.net/p/potassco/mailman/potassco-users/) in the archive of our mailing list.
Before you ask a question, it is best to search for existing [issues](https://fillname.org/issues) or [messages](https://sourceforge.net/p/potassco/mailman/potassco-users/) in the archive of our mailing list.

If you then still feel the need to ask a question and need clarification, we recommend the following:

- [Subscribe](https://sourceforge.net/projects/potassco/lists/potassco-users) to our mailing list on SourceForge or open an [issue](https://github.com/potassco/fillname/issues/new) on GitHub.
- [Subscribe](https://sourceforge.net/projects/potassco/lists/potassco-users) to our mailing list on SourceForge or open an [issue](https://fillname.org/issues/new) on GitHub.
- Provide as much context as you can about what you're running into.
- We can best help you if you provide executable code showcasing your problem.

Expand All @@ -53,7 +53,7 @@ A good bug report shouldn't leave others needing to chase you up for more inform

- Make sure that you are using the latest version.
- Determine if your bug is really a bug and not an error on your side e.g. using incompatible environment components/versions. If you are looking for support, you might want to check [this section](#i-have-a-question)).
- To see if other users have experienced (and potentially already solved) the same issue you are having, check if there is not already a bug report existing for your bug or error in the [bug tracker](https://github.com/potassco/fillname/issues?q=label%3Abug).
- To see if other users have experienced (and potentially already solved) the same issue you are having, check if there is not already a bug report existing for your bug or error in the [bug tracker](https://fillname.org/issues?q=label%3Abug).
- Collect information about the bug
- Python Version
- Possibly your input and the output
Expand All @@ -65,7 +65,7 @@ A good bug report shouldn't leave others needing to chase you up for more inform

We use GitHub issues to track bugs and errors. If you run into an issue with the project:

- Open an [Issue](https://github.com/potassco/fillname/issues/new).
- Open an [Issue](https://fillname.org/issues/new).
- Explain the behavior you would expect and the actual behavior.
- Please provide as much context as possible and describe the *reproduction steps* that someone else can follow to recreate the issue on their own. This usually includes your code. For good bug reports you should isolate the problem and create a reduced test case.
- Provide the information you collected in the previous section.
Expand All @@ -84,14 +84,14 @@ This section guides you through submitting an enhancement suggestion for fillnam
#### Before Submitting an Enhancement

- Make sure that you are using the latest version.
- Read the [documentation](https://potassco.org/fillname/) carefully and find out if the functionality is already covered, maybe by an individual configuration.
- Perform a [search](https://github.com/potassco/fillname/issues) to see if the enhancement has already been suggested. If it has, add a comment to an existing issue instead of opening a new one.
- Read the [documentation](https://fillname.org/) carefully and find out if the functionality is already covered, maybe by an individual configuration.
- Perform a [search](https://fillname.org/issues) to see if the enhancement has already been suggested. If it has, add a comment to an existing issue instead of opening a new one.
- Find out whether your idea fits with the scope and aims of the project. It's up to you to make a strong case to convince the project's developers of the merits of this feature. Keep in mind that we want features that will be useful to the majority of our users and not just a small subset. If you're just targeting a minority of users, consider writing an add-on/plugin library.

<!-- omit in toc -->
#### How Do I Submit a Good Enhancement Suggestion?

Enhancement suggestions are tracked as [GitHub issues](https://github.com/potassco/fillname/issues).
Enhancement suggestions are tracked as [GitHub issues](https://fillname.org/issues).

- Use a **clear and descriptive title** for the issue to identify the suggestion.
- Provide a **step-by-step description of the suggested enhancement** in as many details as possible.
Expand Down
15 changes: 15 additions & 0 deletions DEPLOYMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## Deployment

Releases are deployed on [pypi] whenever a tag of form `vMajor.Minor.Revision`
is pushed. Furthemore, the deployment workflow can be triggered manually to
deploy test releases on [test.pypi].

For this to work, the workflow has to be granted permission to deploy on the
two services. Please follow this packaging [guide] to setup your accounts
accordingly. We also recommend to setup a github [environment] to restrict which
contributers can deploy packages.

[pypi]: https://pypi.org/
[test.pypi]: https://test.pypi.org/
[guide]: https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/
[environment]: https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment/
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2024 <author>
Copyright (c) 2024 Mister Fillname
Copy link
Member

@MaxOstrowski MaxOstrowski Feb 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Miss Fillname ? @rkaminsk

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about Mx. Fillname ?

Copy link
Member

@sthiele sthiele Feb 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I think <author> was also okay.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's intended. It will be replaced by the init script.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With <author> it might still have worked. But for example with <email> the tests failed because <email> did not have the proper form.

The only reason why I did the change was to give everything a form as it would occur in a real project to be able to test the project. It was not even intended as a joke. I just wanted to have Fillname in here to have unique token to replace. We can also use Fillname Author or similar if you think that is better.

Copy link
Member

@MaxOstrowski MaxOstrowski Feb 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, and now I also understand your comment as you wanted the template to be fit the regular expressions.
But I still don`t get why this could be useful. To test the project-template one would simply choose 4 fake things and then test for them?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, and now I also understand your comment as you wanted the template to be fit the regular expressions. But I still don`t get why this could be useful. To test the project-template one would simply choose 4 fake things and then test for them?

If we use these values, the test workflow will fail because the project template cannot be installed (which is required for testing). The test workflow also runs for the template.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could make the values a bit more consistent:

[email protected]
Author Fillname
https://fillname.org/
fillname

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I tried to replace it the way I suggested in my own project and could see the error you meant. Basically the pyproject.toml isnt able to install a project called "".
https://github.com/MaxOstrowski/test-template/

Not sure this is a bad thing though. It prevents the user from using the project without executing init.py first.
On the other hand it's not looking too nice if the CI test in the template repo fail.
Maybe your more consistent set of names is a good tradeoff.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe your more consistent set of names is a good tradeoff.

I think it is. Having the ci tests running, will ensure that we do not have unnecessary errors in the python code as we continue extending the template.

We could also extend the CI tests to run the init script but that would be a bit cumbersome to implement.

The current approach is an easy workaround with somewhat curios placeholders that is otherwise nice and simple.


Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
6 changes: 3 additions & 3 deletions doc/content/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ $ fillname -h
## Installing with pip


The python fillname package can be found [here](https://pypi.org/project/fillname/).
The python fillname package can be found [here](https://fillname.org/).

```console
$ pip install fillname
Expand All @@ -21,7 +21,7 @@ $ pip install fillname

### Installing from source

The project is hosted on [github](https://github.com/potassco/fillname) and can
The project is hosted on [github](https://fillname.org/) and can
also be installed from source.

```{warning}
Expand All @@ -35,7 +35,7 @@ The `setuptools` package is required to run the commands below.
Execute the following command in the top level fillname directory:

```console
$ git clone https://github.com/potassco/fillname
$ git clone https://fillname.org/
$ cd fillname
$ pip install -e .[all]
```
Empty file removed examples/.gitkeep
Empty file.
45 changes: 38 additions & 7 deletions init.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,65 @@

import os
import re
import subprocess


def read(prompt, regex):
def read(prompt, regex, default):
"""
Read a string from command line.

The string has to match the given regular expression.
"""
if default:
prompt += f" [{default}]"
prompt += ": "

while True:
ret = input(prompt)
if not ret and default:
ret = default
match = re.match(regex, ret)
if match is not None:
return ret
print(f"the project name has to match the regular expression: {regex}")


def git_config_get(attr):
"""
Get a git config value.
"""
try:
return subprocess.check_output(["git", "config", "--get", attr]).decode().strip()
except subprocess.CalledProcessError:
return None

def main():
"""
Rename the project.
"""
project = read("project name: ", r"^[a-z][a-z0-9_]*$")
author = read("author: ", r".+")
email = read("email: ", r".+")

author = git_config_get("user.name")
email = git_config_get("user.email")
origin = git_config_get("remote.origin.url")
url, project = None, None

if origin is not None:
match = re.match(r"^.*[:/]([^:/]*)/([^/]*)(\.git)?$", origin)
if match is not None:
org, project = match.group(1), match.group(2)
url = f"https://github.com/{org}/{project}/"
project = project.replace("-", "_")

project = read("project name", r"^[a-z][a-z0-9_]*$", project)
author = read("author", r".+", author)
email = read("email", r".+", email)
url = read("url", r".+", url)

replacements = {
"[email protected]": email,
"Mister Fillname": author,
"https://fillname.org/": url,
"fillname": project,
"<author-email>": email,
"<author>": author,
}

def replace(filepath):
Expand All @@ -48,8 +79,8 @@ def replace(filepath):
".pre-commit-config.yaml",
"noxfile.py",
"pyproject.toml",
"setup.cfg",
"CONTRIBUTING.md",
"DEPLOYMENT.md",
"DEVELOPMENT.md",
"LICENSE",
"README.md",
Expand Down
32 changes: 32 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,38 @@ requires = [
]
build-backend = "setuptools.build_meta"

[project]
name = "fillname"
authors = [
{ name = "Mister Fillname", email = "[email protected]" }
]
description = "A template project."
requires-python = ">=3.9"
license = {file = "LICENSE"}
dynamic = [ "version" ]
readme = "README.md"

[project.urls]
Hompage = "https://fillname.org/"

[project.optional-dependencies]
format = [ "black", "isort", "autoflake" ]
lint_pylint = [ "pylint" ]
typecheck = [ "types-setuptools", "mypy" ]
test = [ "coverage[toml]" ]
doc = [ "sphinx", "furo", "nbsphinx", "sphinx_copybutton", "myst-parser" ]
dev = [ "fillname[test,typecheck,lint_pylint]" ]

[project.scripts]
fillname = "fillname.__main__:main"

[tool.setuptools.packages.find]
where = ["src"]

[tool.setuptools_scm]
version_scheme = "python-simplified-semver"
local_scheme = "no-local-version"

[tool.isort]
profile = "black"
line_length = 120
Expand Down
45 changes: 0 additions & 45 deletions setup.cfg

This file was deleted.

6 changes: 0 additions & 6 deletions setup.py

This file was deleted.

Empty file removed src/encodings/.gitkeep
Empty file.