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

Formatting changes, update imports, other minor changes #227

Merged
merged 8 commits into from
Nov 19, 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
1 change: 0 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,4 @@ jobs:
- name: Check that the docs build (linux only)
if: matrix.config.doc == 1
run: |
pip install sphinx
make -j 4 -C doc SPHINXOPTS="-W --keep-going" html
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ refl1d-webview-client*.tgz
/bumps-*
/Refl1D.pdf
/output-*
test-files/

# Build
*.so
Expand Down
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ ROOTDIR = $(shell pwd)
help: ## Print this help message
@perl -nle'print $& if m{^[/a-zA-Z_-]+:.*?## .*$$}' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-25s\033[0m %s\n", $$1, $$2}'

.PHONY: clean
clean: ## Delete some cruft from builds/testing/etc.
rm -f `find . -type f -name '*.py[co]'`
rm -rf `find . -name __pycache__ -o -name "*.egg-info"` \
`find . -name 'output-*'` \
.coverage build dist \
doc/_build doc/api doc/tutorial \
.pytest_cache \
.ruff_cache

.PHONY: test
test: ## Run pytest and doc tests
pytest -v
python check_examples.py --chisq

.PHONY: lint
lint: ## Run ruff linting
Expand Down
6 changes: 3 additions & 3 deletions compareopt/slabs.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from __future__ import print_function

from random import getrandbits

from bumps.parameter import summarize
from numpy.random import uniform

from refl1d.names import *
from bumps.parameter import summarize

num_layers = int(sys.argv[1])
init_file = sys.argv[2] if len(sys.argv) > 2 else "/tmp/problem"
Expand Down
1 change: 1 addition & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
collect_ignore = [
"doc/guide/toffset.py",
# "refl1d/wx_gui/",
"tests/refl1d/Q_probe_oversample.py",
# "tests/refl1d/snsdata_test.py",
]
19 changes: 10 additions & 9 deletions doc/_extensions/wx_directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@

# Note: adapted from matplotlib.sphinxext.plot_directive by Paul Kienzle

from six.moves import StringIO

import sys, os, glob, shutil, hashlib, imp, warnings
import imp
import os
import re
import shutil
import sys
import warnings

from six.moves import StringIO

try:
from hashlib import md5
Expand All @@ -34,16 +38,13 @@
from docutils.parsers.rst.directives.images import Image

align = Image.align
from docutils import nodes
import sphinx

import wx

# Matplotlib helper utilities
import matplotlib.cbook as cbook
import numpy
import png

import sphinx
import wx
from docutils import nodes

sphinx_version = sphinx.__version__.split(".")
# The split is necessary for sphinx beta versions where the string is
Expand Down
3 changes: 2 additions & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

import sys, os
import os
import sys

print("python %s" % sys.executable)

Expand Down
3 changes: 2 additions & 1 deletion doc/examples/distribution/dist-example.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys, os
import os
import sys

sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from refl1d.names import *
Expand Down
11 changes: 5 additions & 6 deletions doc/genmods.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
MODULE_TEMPLATE is the template for each api module.
"""

from __future__ import with_statement, print_function
import inspect
import sys
from os import makedirs
from os.path import abspath, dirname, exists, getmtime
from os.path import join as joinpath

OPTIONS = {
"absolute": False, # True if package.module in table of contents
Expand Down Expand Up @@ -119,11 +123,6 @@
"""
# ===================== Documentation generator =====================

from os import makedirs
from os.path import exists, dirname, getmtime, join as joinpath, abspath
import inspect
import sys


def newer(file1, file2):
return not exists(file1) or (getmtime(file1) < getmtime(file2))
Expand Down
112 changes: 71 additions & 41 deletions doc/getting_started/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ Contributing Changes

.. contents:: :local:


The refl1d package is a community project, and we welcome contributions from anyone.
The package is developed collaboratively on `Github <https://github.com>`_ - if you don't have an account yet, you can sign up for free. For direct write access to the repository, it is required that your accout have `two-factor authentication enabled <https://docs.github.com/en/authentication/securing-your-account-with-two-factor-authentication-2fa>`_.
You may also want to configure your account to use `SSH keys <https://docs.github.com/en/authentication/connecting-to-github-with-ssh>`_ for authentication.

The best way to contribute to the reflectometry package is to work
from a copy of the source tree in the revision control system.

Expand All @@ -18,27 +23,55 @@ be downloaded from the `git page <http://www.git-scm.com/>`_, or you can use
an integrated development environment (IDE) such as Eclipse and PyCharm, which
may have git built in.

Simple patches
--------------

If you want to make one or two tiny changes, it is easiest to clone the
project, make the changes, document and test, then send a patch.
Getting the Code
================

To get the code, you will need to clone the repository. If you are planning
on making only a few small changes, you can clone the repository directly,
make the changes, document and test, then send a patch (see `Simple patches <#Simple-patches>`_ below).

If you are planning on making larger changes, you should fork the repository
on github, make the changes in your fork, then issue a pull request to the
main repository (see `Larger changes <#Larger-changes>`_ below).

.. note::

If you are working on a fork, the clone line is slightly different::

git clone https://github.com/YourGithubAccount/refl1d


You will also need to keep your fork up to date
with the main repository. You can do this by adding the main repository
as a remote, fetching the changes, then merging them into your fork.

.. code-block:: bash

# Add the main repository as a remote
git remote add refl1d

Clone the project as follows::
# Fetch the changes from the main repository
git fetch refl1d

git clone https://github.com/reflectometry/refl1d.git
# Merge the changes into your fork
git merge refl1d/master

You will need bumps and periodictable to run. If you are fixing bugs in the
scattering length density calculator or the fitting engine, you will want to
clone the repositories as sister directories to the refl1d source tree::
# Push the changes to your fork
git push

git clone https://github.com/bumps/bumps.git
git clone https://github.com/pkienzle/periodictable.git

If you are only working with the refl1d modeling code, then you can install
bumps and periodictable using pip::
Once you have the code, you will need to install Refl1D, including its dependencies.
You can do this by following the instructions in the `Installation guide <install.html>`_.

pip install periodictable bumps
.. simple-patches:

Simple patches
--------------

If you want to make one or two tiny changes, it is easiest to clone the
repository, make the changes, then send a patch. This is the simplest way
to contribute to the project.

To run the package from the source tree use the following::

Expand All @@ -55,13 +88,13 @@ As you make changes to the package, you can see what you have done using git::
git diff

Please update the documentation and add tests for your changes. We use
doctests on all of our examples that we know our documentation is correct.
More thorough tests are found in test directory. With the nosetest package,
you can run the tests using::

python tests.py
doctests on all of our examples so that we know our documentation is correct.
More thorough tests are found in test directory. You can run these tests via pytest,
or via the convenience Makefile target::

Nose is available on linux form apt-get
pytest
# or
make test

When all the tests run, create a patch and send it to paul.kienzle@nist.gov::

Expand All @@ -73,14 +106,9 @@ Larger changes
For a larger set of changes, you should fork refl1d on github, and issue pull
requests for each part.

Once you have create the fork, the clone line is slightly different::

git clone https://github.com/YourGithubAccount/refl1d

After you have tested your changes, you will need to push them to your github
fork::

git log
git commit -a -m "short sentence describing what the change is for"
git push

Expand All @@ -97,12 +125,14 @@ track updates to the original refl1d package using::
git push

When making changes, you need to take care that they work on different
versions of python. In particular, RHEL6, Centos6.5, Rocks and
ScientificLinux all run python 2.6, most linux/windows/mac users run
python 2.7, but some of the more bleeding edge distributions run 3.3/3.4.
The anaconda distribution makes it convenient to maintain multiple independent
environments
Even better is to test against all python versions 2.6, 2.7, 3.3, 3.4::
versions of python. Using conda makes it convenient to maintain multiple independent
environments. You can create a new environment for testing with, for example::

conda create -n py312 python=3.12
conda activate py312
pip install -e .[dev]

Even better is to test against all current python versions::

pythonX.Y tests.py
pythonX.Y run.py
Expand All @@ -113,7 +143,7 @@ Building Documentation
======================

Building the package documentation requires a working Sphinx installation,
and latex to build the pdf. As of this writing we are using sphinx 1.2.
and latex to build the pdf. As of this writing we are using sphinx 8.0.2.

The command line to build the docs is as follows::

Expand All @@ -124,8 +154,8 @@ You can see the result by pointing your browser to::
doc/_build/html/index.html
doc/_build/latex/Refl1d.pdf

Note that this only works with a unix-like environment for now since we are
using *make*. On windows, you can run sphinx directly from python::
On Windows, you may first need to install `mingw32-make` via conda,
or simply run sphinx directly from python::

cd doc
python -m sphinx.__init__ -b html -d _build/doctrees . _build/html
Expand Down Expand Up @@ -168,17 +198,17 @@ to a checkin on the master branch via GitHub Actions.
OS/X Installer
==============

Note: OS/X installer is no longer maintained.
A Python script is available to build the OS/X installer::

To build a Mac OS/X standalone executable you will need the py2app package.
This should already be available in your mac python environment.
extra/build_dmg.py

Build the executable using::
This script builds a `.dmg` based on the contents of the `dist/<product version>.app` directory.
It can be called with the name and version of the product as arguments, e.g.::

python setup_py2app
python extra/build_dmg.py Refl1D 0.8.17

This creates a *.dmg* file in the *dist* directory with the Refl1D app
inside.
This script is also run automatically on github in response
to a checkin on the master branch via GitHub Actions.

Creating a new release
----------------------
Expand Down
Loading
Loading